diff --git a/ajax/libs/hydra.js/3.1.3/hydra.js b/ajax/libs/hydra.js/3.1.3/hydra.js new file mode 100644 index 000000000..8d7d31252 --- /dev/null +++ b/ajax/libs/hydra.js/3.1.3/hydra.js @@ -0,0 +1,1346 @@ +/*global exports, module, require, define, setTimeout*/ +(function () +{ + 'use strict'; + var root, sNotDefined, oModules, oVars, _null_, bUnblockUI, _false_, sVersion, FakeModule, Hydra, bDebug, ErrorHandler, Module, Bus, oChannels, isNodeEnvironment, oObjProto; + + /** + * Used to generate an unique key for instance ids that are not supplied by the user. + * @return {String} + */ + function generateUniqueKey() + { + var sFirstToken = +new Date() + '', + sSecondToken = Math.floor( Math.random() * (999999 - 1 + 1) ) + 1; + return sFirstToken + '_' + sSecondToken; + } + + /** + * Return the length of properties of one object + * @param oObj + * @return {*} + */ + function getObjectLength( oObj ) + { + var nLen, sKey; + if ( Object.keys ) + { + nLen = Object.keys( oObj ).length; + } + else + { + nLen = 0; + for ( sKey in oObj ) + { + if ( ownProp( oObj, sKey ) ) + { + nLen++; + } + } + } + return nLen; + } + + /** + * Check if Object.create exist, if not exist we create it to be used inside the code. + */ + if ( typeof Object.create !== 'function' ) + { + Object.create = function ( oObject ) + { + function Copy() + { + } + + Copy.prototype = oObject; + return new Copy(); + }; + } + /** + * Check if Hydra.js is loaded in Node.js environment + * @type {Boolean} + */ + isNodeEnvironment = typeof exports === 'object' && typeof module === 'object' && typeof module.exports === 'object' && typeof require === 'function'; + /** + * Cache 'undefined' string to test typeof + * @type {String} + */ + sNotDefined = 'undefined'; + /** + * Cache of object prototype to use it in other functions + * @type {Object} + */ + oObjProto = Object.prototype; + /** + * set the correct root depending from the environment. + */ + root = this; + + /** + * Contains a reference to null object to decrease final size + * @type {Object} + * @private + */ + _null_ = null; + + /** + * Contains a reference to false to decrease final size + * @type {Boolean} + * @private + */ + _false_ = false; + + /** + * Property that will save the registered modules + * @private + * @type {Object} + */ + oModules = {}; + + /** + * Version of Hydra + * @private + * @type {String} + */ + sVersion = '3.1.3'; + + /** + * Used to activate the debug mode + * @private + * @type {Boolean} + */ + bDebug = _false_; + + /** + * Use to activate the unblock UI when notifies are executed. + * WARNING!!! This will not block your UI but could give problems with the order of execution. + * @type {Boolean} + */ + bUnblockUI = _false_; + + /** + * Wrapper of Object.prototype.toString to detect type of object in cross browsing mode. + * @private + * @param {Object} oObject + * @return {String} + */ + function toString( oObject ) + { + return oObjProto.toString.call( oObject ); + } + + /** + * isFunction is a function to know if the object passed as parameter is a Function object. + * @private + * @param {Object} fpCallback + * @return {Boolean} + */ + function isFunction( fpCallback ) + { + return toString( fpCallback ) === '[object Function]'; + } + + /** + * isArray is a function to know if the object passed as parameter is an Array object. + * @private + * @param {String|Array|Object} aArray + * @return {Boolean} + */ + function isArray( aArray ) + { + return toString( aArray ) === '[object Array]'; + } + + /** + * setDebug is a method to set the bDebug flag. + * @private + * @param {Boolean} _bDebug + */ + function setDebug( _bDebug ) + { + bDebug = _bDebug; + } + + /** + * setUnblockUI is a method to set the bUnblockUI flag. + * @private + * @param {Boolean} _bUnblockUI + */ + function setUnblockUI( _bUnblockUI ) + { + bUnblockUI = _bUnblockUI; + } + + /** + * Converts objects like node list to real array. + * @private + * @param {Object} oLikeArray + * @param {Number} nElements + * @return {Array} + */ + function slice( oLikeArray, nElements ) + { + return [].slice.call( oLikeArray, nElements || 0 ); + } + + /** + * Wrapper of Object.hasOwnProperty + * @private + * @param {Object} oObj + * @param {String} sKey + * @return {Boolean} + */ + function ownProp( oObj, sKey ) + { + return oObj.hasOwnProperty( sKey ); + } + + /** + * Method to modify the init method to use it for extend. + * @param oInstance + * @param oModifyInit + * @param oData + * @param bSingle + */ + function beforeInit(oInstance, oModifyInit, oData, bSingle){ + var sKey; + for(sKey in oModifyInit){ + if(oModifyInit.hasOwnProperty(sKey)){ + if(oInstance[sKey] && typeof oModifyInit[sKey] === 'function'){ + oModifyInit[sKey](oInstance, oData, bSingle); + } + } + } + } + /** + * startSingleModule is the method that will initialize the module. + * When start is called the module instance will be created and the init method is called. + * If bSingle is true and the module is started the module will be stopped before instance it again. + * This avoid execute the same listeners more than one time. + * @param {Object} oWrapper + * @param {String} sModuleId + * @param {String} sIdInstance + * @param {Object} oData + * @param {Boolean} bSingle + * @return {Module} instance of the module + * @private + */ + function startSingleModule( oWrapper, sModuleId, sIdInstance, oData, bSingle ) + { + var oModule, oInstance; + oModule = oModules[sModuleId]; + if ( bSingle && oWrapper.isModuleStarted( sModuleId, sIdInstance ) ) + { + oWrapper.stop( sModuleId, sIdInstance ); + } + if ( typeof oModule !== sNotDefined ) + { + oInstance = createInstance( sModuleId ); + oModule.instances[sIdInstance] = oInstance; + oInstance.__instance_id__ = sIdInstance; + + beforeInit(oInstance, oWrapper.oModifyInit, oData, bSingle); + + if ( typeof oData !== sNotDefined ) + { + oInstance.init( oData ); + } + else + { + oInstance.init(); + } + } + return oInstance; + } + + /** + * Do a simple merge of two objects overwriting the target properties with source properties + * @param {Object} oTarget + * @param {Object} oSource + * @private + */ + function simpleMerge( oTarget, oSource ) + { + var sKey; + for ( sKey in oSource ) + { + if ( ownProp( oSource, sKey ) ) + { + oTarget[sKey] = oSource[sKey]; + } + } + return oTarget; + } + + /** + * wrapMethod is a method to wrap the original method to avoid failing code. + * This will be only called if bDebug flag is set to false. + * @private + * @param {Object} oInstance + * @param {String} sName + * @param {String} sModuleId + * @param {Function} fpMethod + */ + function wrapMethod( oInstance, sName, sModuleId, fpMethod ) + { + oInstance[sName] = (function ( sName, fpMethod ) + { + return function () + { + var aArgs = slice( arguments, 0 ); + try + { + return fpMethod.apply( this, aArgs ); + } + catch ( erError ) + { + ErrorHandler.log( sModuleId, sName, erError ); + return false; + } + }; + }( sName, fpMethod )); + } + + /** + * Private object to save the channels for communicating event driven + * @private + * @type {Object} + */ + oChannels = { + global: {} + }; + + /** + * subscribersByEvent return all the subscribers of the event in the channel. + * @param {Object} oChannel + * @param {String} sEventName + * @return {Array} + * @private + */ + function subscribersByEvent( oChannel, sEventName ) + { + var aSubscribers = [], + sEvent; + if ( typeof oChannel !== 'undefined' ) + { + for ( sEvent in oChannel ) + { + if ( ownProp( oChannel, sEvent ) && sEvent === sEventName ) + { + aSubscribers = oChannel[sEvent]; + } + } + } + return aSubscribers; + } + + + /** + * Bus is the object that must be used to manage the notifications by channels + * @constructor + */ + Bus = { + /** + * subscribers return the array of subscribers to one channel and event. + * @param {String} sChannelId + * @param {String} sEventName + * @return {Array} + */ + subscribers: function ( sChannelId, sEventName ) + { + return subscribersByEvent( oChannels[sChannelId], sEventName ); + }, + /** + * _getChannelEvents return the events array in channel. + * @param aEventsParts + * @param sChannelId + * @param sEvent + * @return {Object} + * @private + */ + _getChannelEvents: function ( sChannelId, sEvent ) + { + if ( typeof oChannels[sChannelId] === 'undefined' ) + { + oChannels[sChannelId] = {}; + } + if ( typeof oChannels[sChannelId][sEvent] === 'undefined' ) + { + oChannels[sChannelId][sEvent] = []; + } + return oChannels[sChannelId][sEvent]; + }, + /** + * _addSubscribers add all the events of one channel from the subscriber + * @param oEventsCallbacks + * @param sChannelId + * @param oSubscriber + * @private + */ + _addSubscribers: function ( oEventsCallbacks, sChannelId, oSubscriber ) + { + var sEvent; + for ( sEvent in oEventsCallbacks ) + { + if ( ownProp( oEventsCallbacks, sEvent ) ) + { + this.subscribeTo( sChannelId, sEvent, oEventsCallbacks[sEvent], oSubscriber ); + } + } + }, + /** + * Method to unsubscribe a subscriber from a channel and event type. + * It iterates in reverse order to avoid messing with array length when removing items. + * @param sChannelId + * @param sEventType + * @param oSubscriber + */ + unsubscribeFrom: function ( sChannelId, sEventType, oSubscriber ) + { + var aChannelEvents = this._getChannelEvents( sChannelId, sEventType ), + oItem, + nEvent = aChannelEvents.length - 1; + + for ( ; nEvent >= 0; nEvent-- ) + { + oItem = aChannelEvents[nEvent]; + if ( oItem.subscriber === oSubscriber ) + { + aChannelEvents.splice( nEvent, 1 ); + } + } + }, + /** + * Method to add a single callback in one channel an in one event. + * @param sChannelId + * @param sEventType + * @param fpHandler + * @param oSubscriber + */ + subscribeTo: function ( sChannelId, sEventType, fpHandler, oSubscriber ) + { + var aChannelEvents = this._getChannelEvents( sChannelId, sEventType ); + aChannelEvents.push( { + subscriber: oSubscriber, + handler: fpHandler + } ); + }, + /** + * subscribe method gets the oEventsCallbacks object with all the handlers and add these handlers to the channel. + * @param {Module/Object} oSubscriber + * @return {Boolean} + */ + subscribe: function ( oSubscriber ) + { + var sChannelId, oEventsCallbacks = oSubscriber.events; + if ( !oSubscriber || typeof oEventsCallbacks === 'undefined' ) + { + return false; + } + for ( sChannelId in oEventsCallbacks ) + { + if ( ownProp( oEventsCallbacks, sChannelId ) ) + { + if ( typeof oChannels[sChannelId] === 'undefined' ) + { + oChannels[sChannelId] = {}; + } + this._addSubscribers( oEventsCallbacks[sChannelId], sChannelId, oSubscriber ); + } + } + + return true; + }, + /** + * _removeSubscribers remove the subscribers to one channel and return the number of + * subscribers that have been unsubscribed. + * @param aSubscribers + * @param oSubscriber + * @return {Number} + * @private + */ + _removeSubscribers: function ( aSubscribers, oSubscriber ) + { + var nLenSubscribers, + nIndex = 0, + nUnsubscribed = 0; + if ( typeof aSubscribers !== sNotDefined ) + { + nLenSubscribers = aSubscribers.length; + for ( ; nIndex < nLenSubscribers; nIndex++ ) + { + if ( aSubscribers[nIndex].subscriber === oSubscriber ) + { + nUnsubscribed++; + aSubscribers.splice( nIndex, 1 ); + } + } + } + return nUnsubscribed; + }, + /** + * Loops per all the events to remove subscribers. + * @param oEventsCallbacks + * @param bOnlyGlobal + * @param sChannelId + * @param oSubscriber + * @return {*} + * @private + */ + _removeSubscribersPerEvent: function ( oEventsCallbacks, sChannelId, oSubscriber ) + { + var sEvent, aEventsParts, sChannel, sEventType, nUnsubscribed = 0; + for ( sEvent in oEventsCallbacks ) + { + if ( ownProp( oEventsCallbacks, sEvent ) ) + { + aEventsParts = sEvent.split( ':' ); + + sChannel = sChannelId; + sEventType = sEvent; + if ( aEventsParts[0] === 'global' ) + { + sChannel = aEventsParts[0]; + sEventType = aEventsParts[1]; + } + nUnsubscribed += this._removeSubscribers( oChannels[sChannel][sEventType], oSubscriber ); + } + } + return nUnsubscribed; + }, + /** + * unsubscribe gets the oEventsCallbacks methods and removes the handlers of the channel. + * @param {Module/Object} oSubscriber + * @return {Boolean} + */ + unsubscribe: function ( oSubscriber ) + { + var nUnsubscribed = 0, sChannelId, oEventsCallbacks = oSubscriber.events; + if ( !oSubscriber || typeof oEventsCallbacks === 'undefined' ) + { + return false; + } + + for ( sChannelId in oEventsCallbacks ) + { + if ( ownProp( oEventsCallbacks, sChannelId ) ) + { + if ( typeof oChannels[sChannelId] === 'undefined' ) + { + oChannels[sChannelId] = {}; + } + nUnsubscribed = this._removeSubscribersPerEvent( oEventsCallbacks[sChannelId], sChannelId, oSubscriber ); + } + } + + return nUnsubscribed > 0; + }, + /** + * Method to execute all the callbacks but without blocking the user interface. + * @private + * @param {Array} aSubscribers + * @param {Object} oData + * @param {String} sChannelId + * @param {String} sEvent + */ + _avoidBlockUI: function ( aSubscribers, oData, sChannelId, sEvent ) + { + var oHandlerObject, + aSubs = aSubscribers.concat(); + setTimeout( function recall() + { + var nStart = +new Date(); + do { + oHandlerObject = aSubs.shift(); + oHandlerObject.handler.call( oHandlerObject.subscriber, oData ); + if ( bDebug ) + { + ErrorHandler.log( sChannelId, sEvent, oHandlerObject ); + } + } + while ( aSubs.length > 0 && ( +new Date() - nStart < 50 ) ); + if ( aSubs.length > 0 ) + { + setTimeout( recall, 25 ); + } + }, 25 ); + }, + /** + * Publish the event in one channel. + * @param {String} sChannelId + * @param {String} sEvent + * @param {String} oData + */ + publish: function ( sChannelId, sEvent, oData ) + { + var aSubscribers = this.subscribers( sChannelId, sEvent ).slice(), + nLenSubscribers = aSubscribers.length, + nIndex, + oHandlerObject; + if ( nLenSubscribers === 0 ) + { + return false; + } + if ( bUnblockUI ) + { + this._avoidBlockUI( aSubscribers, oData, sChannelId, sEvent ); + } + else + { + for ( nIndex = 0; nIndex < nLenSubscribers; nIndex++ ) + { + oHandlerObject = aSubscribers[nIndex]; + oHandlerObject.handler.call( oHandlerObject.subscriber, oData ); + if ( bDebug ) + { + ErrorHandler.log( sChannelId, sEvent, oHandlerObject ); + } + } + } + return true; + }, + /** + * Reset channels + */ + reset: function () + { + oChannels = { + global: {} + }; + } + }; + /** + * Add common properties and methods to avoid repeating code in modules + * @param {String} sModuleId + * @param {Object} Bus + */ + function addPropertiesAndMethodsToModule( sModuleId, Bus ) + { + var oModule, + fpInitProxy; + oModule = oModules[sModuleId].creator( Bus ); + oModule.__module_id__ = sModuleId; + fpInitProxy = oModule.init || function () + { + }; + oModule.__action__ = Bus; + oModule.events = oModule.events || {}; + oModule.init = function () + { + var aArgs = slice( arguments, 0 ).concat( oVars ); + Bus.subscribe( oModule ); + fpInitProxy.apply( this, aArgs ); + }; + oModule.handleAction = function ( oNotifier ) + { + var fpCallback = this.events[oNotifier.type]; + if ( typeof fpCallback === sNotDefined ) + { + return; + } + fpCallback.call( this, oNotifier ); + }; + oModule.onDestroy = oModule.onDestroy || function () + { + }; + oModule.destroy = function () + { + this.onDestroy(); + Bus.unsubscribe( oModule ); + }; + return oModule; + } + + /** + * createInstance is the method that will create the module instance and wrap the method if needed. + * @private + * @param {String} sModuleId + * @return {Object} Module instance + */ + function createInstance( sModuleId ) + { + var oInstance, sName; + if ( typeof oModules[sModuleId] === sNotDefined ) + { + throw new Error( 'The module ' + sModuleId + ' is not registered!' ); + } + oInstance = addPropertiesAndMethodsToModule( sModuleId, Bus ); + if ( !bDebug ) + { + for ( sName in oInstance ) + { + if ( ownProp( oInstance, sName ) && isFunction( oInstance[sName] ) ) + { + wrapMethod( oInstance, sName, sModuleId, oInstance[sName] ); + } + } + } + return oInstance; + } + + /** + * Simple object to abstract the error handler, the most basic is to be the console object + */ + ErrorHandler = root.console || { + log: function () + { + } + }; + /** + * Class to manage the modules. + * @constructor + * @class Module + * @name Module + */ + Module = function () + { + }; + + Module.prototype = { + /** + * type is a property to be able to know the class type. + * @member Module.prototype + * @type String + */ + type: 'Module', + /** + * Wrapper to use createInstance for plugins if needed. + */ + getInstance: createInstance, + /** + * oModifyInit is an object where save the extensions to modify the init function to use by extensions. + * @param sModuleId + * @param fpCreator + * @returns {*} + */ + oModifyInit: {}, + /** + * register is the method that will add the new module to the oModules object. + * sModuleId will be the key where it will be stored. + * @member Module.prototype + * @param {String} sModuleId + * @param {Function} fpCreator + * @return {Module} + */ + register: function ( sModuleId, fpCreator ) + { + oModules[sModuleId] = new FakeModule( sModuleId, fpCreator ); + return oModules[sModuleId]; + }, + /** + * _setSuper add the __super__ support to access to the methods in parent module. + * @param oFinalModule + * @param oModuleBase + * @private + */ + _setSuper: function ( oFinalModule, oModuleBase ) + { + oFinalModule.__super__ = {}; + oFinalModule.__super__.__instance__ = oModuleBase; + oFinalModule.__super__.__call__ = function ( sKey, aArgs ) + { + var oObject = this; + while ( ownProp( oObject, sKey ) === _false_ ) + { + oObject = oObject.__instance__.__super__; + } + oObject[sKey].apply( oFinalModule, aArgs ); + }; + }, + /** + * Callback that is used to call the methods in parent module. + * @private + * @param fpCallback + * @return {Function} + */ + _callInSuper: function ( fpCallback ) + { + return function () + { + var aArgs = slice( arguments, 0 ); + fpCallback.apply( this, aArgs ); + }; + }, + /** + * Adds the extended properties and methods to final module. + * @param oFinalModule + * @param oModuleExtended + * @private + */ + _mergeModuleExtended: function ( oFinalModule, oModuleExtended ) + { + var sKey; + for ( sKey in oModuleExtended ) + { + if ( ownProp( oModuleExtended, sKey ) ) + { + if ( typeof oFinalModule.__super__ !== sNotDefined && isFunction( oFinalModule[sKey] ) ) + { + oFinalModule.__super__[sKey] = (this._callInSuper( oFinalModule[sKey] )); + } + oFinalModule[sKey] = oModuleExtended[sKey]; + } + } + }, + /** + * Adds the base properties and methods to final module. + * @param oFinalModule + * @param oModuleBase + * @private + */ + _mergeModuleBase: function ( oFinalModule, oModuleBase ) + { + var sKey; + for ( sKey in oModuleBase ) + { + if ( ownProp( oModuleBase, sKey ) ) + { + if ( sKey !== '__super__' ) + { + oFinalModule[sKey] = oModuleBase[sKey]; + } + } + } + }, + /** + * _merge is the method that gets the base module and the extended and returns the merge of them + * @private + * @param {Object} oModuleBase + * @param {Object} oModuleExtended + * @return {Object} + */ + _merge: function ( oModuleBase, oModuleExtended ) + { + var oFinalModule = {}; + this._setSuper( oFinalModule, oModuleBase ); + this._mergeModuleBase( oFinalModule, oModuleBase ); + this._mergeModuleExtended( oFinalModule, oModuleExtended ); + return oFinalModule; + }, + /** + * extend is the method that will be used to extend a module with new features. + * can be used to remove some features too, without touching the original code. + * You can extend a module and create a extended module with a different name. + * @member Module.prototype + * @param {String} sModuleId + * @param {Function/String} oSecondParameter can be the name of the new module that extends the baseModule or a function if we want to extend an existent module. + * @param {Function} oThirdParameter [optional] this must exist only if we need to create a new module that extends the baseModule. + */ + extend: function ( sModuleId, oSecondParameter, oThirdParameter ) + { + var oModule, sFinalModuleId, fpCreator, oBaseModule, oExtendedModule, oFinalModule, self; + self = this; + oModule = oModules[sModuleId]; + sFinalModuleId = sModuleId; + fpCreator = function () + { + }; + + // Function "overloading". + // If the 2nd parameter is a string, + if ( typeof oSecondParameter === 'string' ) + { + sFinalModuleId = oSecondParameter; + fpCreator = oThirdParameter; + } + else + { + fpCreator = oSecondParameter; + } + if ( typeof oModule === sNotDefined ) + { + return; + } + oExtendedModule = fpCreator( Bus ); + oBaseModule = oModule.creator( Bus ); + + oModules[sFinalModuleId] = new FakeModule( sFinalModuleId, function ( Bus ) + { + // If we extend the module with the different name, we + // create proxy class for the original methods. + oFinalModule = self._merge( oBaseModule, oExtendedModule ); + // This gives access to the Action instance used to listen and notify. + oFinalModule.__action__ = Bus; + return oFinalModule; + } ); + return oModules[sFinalModuleId]; + }, + /** + * Method to set an instance of a module + * @param {String} sModuleId + * @param {String} sIdInstance + * @param {Object} oInstance + * @return {Module} + */ + setInstance: function ( sModuleId, sIdInstance, oInstance ) + { + var oModule = oModules[sModuleId]; + if ( !oModule ) + { + throw new Error( 'The module ' + sModuleId + ' is not registered!' ); + } + oModule.instances[sIdInstance] = oInstance; + return oModule; + }, + /** + * Sets an object of vars and add it's content to oVars private variable + * @param {Object} oVar + */ + setVars: function ( oVar ) + { + if ( typeof oVars !== sNotDefined ) + { + oVars = simpleMerge( oVars, oVar ); + } + else + { + oVars = oVar; + } + }, + /** + * Returns the private vars object by copy. + * @returns {Object} global vars. + */ + getVars: function () + { + return simpleMerge( {}, oVars ); + }, + /** + * start more than one module at the same time. + * @param aModulesIds + * @param sIdInstance + * @param oData + * @param bSingle + * @private + */ + _multiModuleStart: function ( aModulesIds, sIdInstance, oData, bSingle ) + { + var aInstancesIds, aData, aSingle, nIndex, nLenModules, sModuleId; + if ( isArray( sIdInstance ) ) + { + aInstancesIds = sIdInstance.slice( 0 ); + } + if ( isArray( oData ) ) + { + aData = oData.slice( 0 ); + } + if ( isArray( bSingle ) ) + { + aSingle = bSingle.slice( 0 ); + } + for ( nIndex = 0, nLenModules = aModulesIds.length; nIndex < nLenModules; nIndex++ ) + { + sModuleId = aModulesIds[nIndex]; + sIdInstance = aInstancesIds && aInstancesIds[nIndex] || generateUniqueKey(); + oData = aData && aData[nIndex] || oData; + bSingle = aSingle && aSingle[nIndex] || bSingle; + startSingleModule( this, sModuleId, sIdInstance, oData, bSingle ); + } + }, + /** + * Start only one module. + * @param sModuleId + * @param sIdInstance + * @param oData + * @param bSingle + * @private + */ + _singleModuleStart: function ( sModuleId, sIdInstance, oData, bSingle ) + { + if ( typeof sIdInstance !== 'string' ) + { + oData = sIdInstance; + bSingle = oData; + sIdInstance = generateUniqueKey(); + } + + startSingleModule( this, sModuleId, sIdInstance, oData, bSingle ); + }, + /** + * start is the method that initialize the module/s + * If you use array instead of arrays you can start more than one module even adding the instance, the data and if it must be executed + * as single module start. + * @param {String/Array} sModuleId + * @param {String/Array} sIdInstance + * @param {Object/Array} oData + * @param {Boolean/Array} bSingle + */ + start: function ( sModuleId, sIdInstance, oData, bSingle ) + { + var bStartMultipleModules = isArray( sModuleId ); + + if ( bStartMultipleModules ) + { + this._multiModuleStart( sModuleId.slice( 0 ), sIdInstance, oData, bSingle ); + } + else + { + this._singleModuleStart( sModuleId, sIdInstance, oData, bSingle ); + } + }, + /** + * Checks if module was already successfully started + * @member Module.prototype + * @param {String} sModuleId Name of the module + * @param {String} sInstanceId Id of the instance + * @return {Boolean} + */ + isModuleStarted: function ( sModuleId, sInstanceId ) + { + var bStarted = false; + if ( typeof sInstanceId === sNotDefined ) + { + bStarted = ( typeof oModules[sModuleId] !== sNotDefined && getObjectLength( oModules[sModuleId].instances ) > 0 ); + } + else + { + bStarted = ( typeof oModules[sModuleId] !== sNotDefined && typeof oModules[sModuleId].instances[sInstanceId] !== sNotDefined ); + } + return bStarted; + }, + /** + * startAll is the method that will initialize all the registered modules. + * @member Module.prototype + */ + startAll: function () + { + var sModuleId, oModule; + for ( sModuleId in oModules ) + { + if ( ownProp( oModules, sModuleId ) ) + { + oModule = oModules[sModuleId]; + if ( typeof oModule !== sNotDefined ) + { + this.start( sModuleId, generateUniqueKey() ); + } + } + } + }, + /** + * stop more than one module at the same time. + * @param oModule + * @private + */ + _multiModuleStop: function ( oModule ) + { + var sKey, + oInstances = oModule.instances, + oInstance; + for ( sKey in oInstances ) + { + if ( ownProp( oInstances, sKey ) ) + { + oInstance = oInstances[sKey]; + if ( typeof oModule !== sNotDefined && typeof oInstance !== sNotDefined ) + { + oInstance.destroy(); + } + } + } + oModule.instances = {}; + }, + /** + * Stop only one module. + * @param oModule + * @param sModuleId + * @param sInstanceId + * @private + */ + _singleModuleStop: function ( oModule, sModuleId, sInstanceId ) + { + var oInstance = oModule.instances[sInstanceId]; + if ( typeof oModule !== sNotDefined && typeof oInstance !== sNotDefined ) + { + oInstance.destroy(); + delete oModule.instances[sInstanceId]; + } + }, + /** + * stop is the method that will finish the module if it was registered and started. + * When stop is called the module will call the destroy method and will nullify the instance. + * @member Module.prototype + * @param {String} sModuleId + * @param {String} sInstanceId + * @return {Boolean} + */ + stop: function ( sModuleId, sInstanceId ) + { + var oModule; + oModule = oModules[sModuleId]; + if ( typeof oModule === sNotDefined ) + { + return false; + } + if ( typeof sInstanceId !== sNotDefined ) + { + this._singleModuleStop( oModule, sModuleId, sInstanceId ); + } + else + { + this._multiModuleStop( oModule ); + } + return true; + }, + /** + * Loops over instances of modules to stop them. + * @param oInstances + * @param sModuleId + * @private + */ + _stopOneByOne: function ( oInstances, sModuleId ) + { + var sInstanceId; + for ( sInstanceId in oInstances ) + { + if ( ownProp( oInstances, sInstanceId ) ) + { + this.stop( sModuleId, sInstanceId ); + } + } + }, + /** + * stopAll is the method that will finish all the registered and started modules. + * @member Module.prototype + */ + stopAll: function () + { + var sModuleId; + for ( sModuleId in oModules ) + { + if ( ownProp( oModules, sModuleId ) && typeof oModules[sModuleId] !== sNotDefined ) + { + this._stopOneByOne( oModules[sModuleId].instances, sModuleId ); + } + } + }, + /** + * _delete is a wrapper method that will call the native delete javascript function + * It's important to test the full code. + * @member Module.prototype + * @param {String} sModuleId + */ + _delete: function ( sModuleId ) + { + if ( typeof oModules[sModuleId] !== sNotDefined ) + { + delete oModules[sModuleId]; + } + }, + /** + * remove is the method that will remove the full module from the oModules object + * @member Module.prototype + * @param {String} sModuleId + */ + remove: function ( sModuleId ) + { + var oModule = oModules[sModuleId]; + if ( typeof oModule === sNotDefined ) + { + return null; + } + if ( typeof oModule !== sNotDefined ) + { + try + { + return oModule; + } + finally + { + this._delete( sModuleId ); + } + } + return null; + } + }; + + /** + * getErrorHandler is a method to gain access to the private ErrorHandler constructor. + * @private + * @return ErrorHandler class + */ + function getErrorHandler() + { + return ErrorHandler; + } + + /** + * setErrorHandler is a method to set the ErrorHandler to a new object to add more logging logic. + * @private + * @param {Function} oErrorHandler + */ + function setErrorHandler( oErrorHandler ) + { + ErrorHandler = oErrorHandler; + } + + /** + * Hydra is the api that will be available to use by developers + * @constructor + * @class Hydra + * @name Hydra + */ + Hydra = function () + { + }; + + /** + * Version number of Hydra. + * @static + * @member Hydra + * @type String + */ + Hydra.version = sVersion; + + /** + * bus is a singleton instance of the bus to subscribe and publish content in channels. + * @type {Object} + */ + Hydra.bus = Bus; + /** + * Returns the actual ErrorHandler + * @static + * @member Hydra + * @type ErrorHandler + */ + Hydra.errorHandler = getErrorHandler; + + /** + * Sets and overwrites the ErrorHandler object to log errors and messages + * @static + * @param ErrorHandler + * @member Hydra + */ + Hydra.setErrorHandler = setErrorHandler; + + /** + * Return a singleton of Module + * @static + * @member Hydra + */ + Hydra.module = new Module(); + + /** + * Change the unblock UI mode to on/off + * @static + * @Member Hydra + */ + Hydra.setUnblockUI = setUnblockUI; + + /** + * Change the debug mode to on/off + * @static + * @member Hydra + */ + Hydra.setDebug = setDebug; + + /** + * Get the debug status + * @static + * @member Hydra + */ + Hydra.getDebug = function () + { + return bDebug; + }; + /** + * Extends Hydra object with new functionality + * @static + * @member Hydra + * @param {String} sIdExtension + * @param {Object} oExtension + */ + Hydra.extend = function ( sIdExtension, oExtension ) + { + if ( typeof this[sIdExtension] === sNotDefined ) + { + this[sIdExtension] = oExtension; + } + else + { + this[sIdExtension] = simpleMerge( this[sIdExtension], oExtension ); + } + }; + + /** + * Adds an alias to parts of Hydra + * @static + * @member Hydra + * @param {String} sOldName + * @param {Object} oNewContext + * @param {String} sNewName + * @return {Boolean} + */ + Hydra.noConflict = function ( sOldName, oNewContext, sNewName ) + { + if ( typeof this[sOldName] !== sNotDefined ) + { + oNewContext[sNewName] = this[sOldName]; + return true; + } + return false; + }; + + /** + * Merges an object to oModifyInit that will be executed before executing the init. + * { + * 'property_in_module_to_check': function(oModule){} // Callback to execute if the property exist + * } + * @param {Object} oVar + */ + Hydra.addExtensionBeforeInit = function(oVar){ + + Hydra.module.oModifyInit = simpleMerge( Hydra.module.oModifyInit, oVar ); + }; + /** + * Module to be stored, adds two methods to start and extend modules. + * @private + * @param {String} sModuleId + * @param {Function} fpCreator + * @constructor + */ + FakeModule = function ( sModuleId, fpCreator ) + { + if ( typeof fpCreator === sNotDefined ) + { + throw new Error( 'Something goes wrong!' ); + } + this.creator = fpCreator; + this.instances = {}; + this.sModuleId = sModuleId; + }; + + FakeModule.prototype = { + start: function ( oData ) + { + Hydra.module.start( this.sModuleId, oData ); + return this; + }, + extend: function ( oSecondParameter, oThirdParameter ) + { + Hydra.module.extend( this.sModuleId, oSecondParameter, oThirdParameter ); + return this; + }, + stop: function () + { + Hydra.module.stop( this.sModuleId ); + return this; + } + }; + + /* + * Expose Hydra to be used in node.js, as AMD module or as global + */ + root.Hydra = Hydra; + if ( isNodeEnvironment ) + { + module.exports = Hydra; + } + else if ( typeof define !== 'undefined' ) + { + define( 'hydra', [], function () + { + return Hydra; + } ); + } +}.call( this )); diff --git a/ajax/libs/hydra.js/3.1.3/hydra.min.js b/ajax/libs/hydra.js/3.1.3/hydra.min.js new file mode 100644 index 000000000..b2e2767fe --- /dev/null +++ b/ajax/libs/hydra.js/3.1.3/hydra.min.js @@ -0,0 +1,5 @@ +/*! Hydra.js v3.1.3 | Date:2013-05-26 | License: https://raw.github.com/tcorral/Hydra.js/master/LICENSE| (c) 2009, 2013 +//@ sourceMappingURL=hydra.min.map +*/ +!function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;function r(){var a=+new Date+"",b=Math.floor(999999*Math.random())+1;return a+"_"+b}function s(a){var b,c;if(Object.keys)b=Object.keys(a).length;else{b=0;for(c in a)z(a,c)&&b++}return b}"function"!=typeof Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b}),p="object"==typeof exports&&"object"==typeof module&&"object"==typeof module.exports&&"function"==typeof require,b="undefined",q=Object.prototype,a=this,e=null,g=!1,c={},h="3.1.3",k=g,f=g;function t(a){return q.toString.call(a)}function u(a){return"[object Function]"===t(a)}function v(a){return"[object Array]"===t(a)}function w(a){k=a}function x(a){f=a}function y(a,b){return[].slice.call(a,b||0)}function z(a,b){return a.hasOwnProperty(b)}function A(a,b,c,d){var e;for(e in b)b.hasOwnProperty(e)&&a[e]&&"function"==typeof b[e]&&b[e](a,c,d)}function B(a,d,e,f,g){var h,i;return h=c[d],g&&a.isModuleStarted(d,e)&&a.stop(d,e),typeof h!==b&&(i=G(d),h.instances[e]=i,i.__instance_id__=e,A(i,a.oModifyInit,f,g),typeof f!==b?i.init(f):i.init()),i}function C(a,b){var c;for(c in b)z(b,c)&&(a[c]=b[c]);return a}function D(a,b,c,d){a[b]=function(a,b){return function(){var d=y(arguments,0);try{return b.apply(this,d)}catch(e){return l.log(c,a,e),!1}}}(b,d)}o={global:{}};function E(a,b){var c=[],d;if("undefined"!=typeof a)for(d in a)z(a,d)&&d===b&&(c=a[d]);return c}n={subscribers:function(a,b){return E(o[a],b)},_getChannelEvents:function(a,b){return"undefined"==typeof o[a]&&(o[a]={}),"undefined"==typeof o[a][b]&&(o[a][b]=[]),o[a][b]},_addSubscribers:function(a,b,c){var d;for(d in a)z(a,d)&&this.subscribeTo(b,d,a[d],c)},unsubscribeFrom:function(a,b,c){var d=this._getChannelEvents(a,b),e,f=d.length-1;for(;f>=0;f--)e=d[f],e.subscriber===c&&d.splice(f,1)},subscribeTo:function(a,b,c,d){var e=this._getChannelEvents(a,b);e.push({subscriber:d,handler:c})},subscribe:function(a){var b,c=a.events;if(!a||"undefined"==typeof c)return!1;for(b in c)z(c,b)&&("undefined"==typeof o[b]&&(o[b]={}),this._addSubscribers(c[b],b,a));return!0},_removeSubscribers:function(a,c){var d,e=0,f=0;if(typeof a!==b)for(d=a.length;d>e;e++)a[e].subscriber===c&&(f++,a.splice(e,1));return f},_removeSubscribersPerEvent:function(a,b,c){var d,e,f,g,h=0;for(d in a)z(a,d)&&(e=d.split(":"),f=b,g=d,"global"===e[0]&&(f=e[0],g=e[1]),h+=this._removeSubscribers(o[f][g],c));return h},unsubscribe:function(a){var b=0,c,d=a.events;if(!a||"undefined"==typeof d)return!1;for(c in d)z(d,c)&&("undefined"==typeof o[c]&&(o[c]={}),b=this._removeSubscribersPerEvent(d[c],c,a));return b>0},_avoidBlockUI:function(a,b,c,d){var e,f=a.concat();setTimeout(function g(){var a=+new Date;do e=f.shift(),e.handler.call(e.subscriber,b),k&&l.log(c,d,e);while(f.length>0&&+new Date-a<50);f.length>0&&setTimeout(g,25)},25)},publish:function(a,b,c){var d=this.subscribers(a,b).slice(),e=d.length,g,h;if(0===e)return!1;if(f)this._avoidBlockUI(d,c,a,b);else for(g=0;e>g;g++)h=d[g],h.handler.call(h.subscriber,c),k&&l.log(a,b,h);return!0},reset:function(){o={global:{}}}};function F(a,e){var f,g;return f=c[a].creator(e),f.__module_id__=a,g=f.init||function(){},f.__action__=e,f.events=f.events||{},f.init=function(){var a=y(arguments,0).concat(d);e.subscribe(f),g.apply(this,a)},f.handleAction=function(a){var c=this.events[a.type];typeof c!==b&&c.call(this,a)},f.onDestroy=f.onDestroy||function(){},f.destroy=function(){this.onDestroy(),e.unsubscribe(f)},f}function G(a){var d,e;if(typeof c[a]===b)throw new Error("The module "+a+" is not registered!");if(d=F(a,n),!k)for(e in d)z(d,e)&&u(d[e])&&D(d,e,a,d[e]);return d}l=a.console||{log:function(){}},m=function(){},m.prototype={type:"Module",getInstance:G,oModifyInit:{},register:function(a,b){return c[a]=new i(a,b),c[a]},_setSuper:function(a,b){a.__super__={},a.__super__.__instance__=b,a.__super__.__call__=function(b,c){var d=this;while(z(d,b)===g)d=d.__instance__.__super__;d[b].apply(a,c)}},_callInSuper:function(a){return function(){var b=y(arguments,0);a.apply(this,b)}},_mergeModuleExtended:function(a,c){var d;for(d in c)z(c,d)&&(typeof a.__super__!==b&&u(a[d])&&(a.__super__[d]=this._callInSuper(a[d])),a[d]=c[d])},_mergeModuleBase:function(a,b){var c;for(c in b)z(b,c)&&"__super__"!==c&&(a[c]=b[c])},_merge:function(a,b){var c={};return this._setSuper(c,a),this._mergeModuleBase(c,a),this._mergeModuleExtended(c,b),c},extend:function(a,d,e){var f,g,h,j,k,l,m;return m=this,f=c[a],g=a,h=function(){},"string"==typeof d?(g=d,h=e):h=d,typeof f!==b?(k=h(n),j=f.creator(n),c[g]=new i(g,function(a){return l=m._merge(j,k),l.__action__=a,l}),c[g]):void 0},setInstance:function(a,b,d){var e=c[a];if(!e)throw new Error("The module "+a+" is not registered!");return e.instances[b]=d,e},setVars:function(a){d=typeof d!==b?C(d,a):a},getVars:function(){return C({},d)},_multiModuleStart:function(a,b,c,d){var e,f,g,h,i,j;for(v(b)&&(e=b.slice(0)),v(c)&&(f=c.slice(0)),v(d)&&(g=d.slice(0)),h=0,i=a.length;i>h;h++)j=a[h],b=e&&e[h]||r(),c=f&&f[h]||c,d=g&&g[h]||d,B(this,j,b,c,d)},_singleModuleStart:function(a,b,c,d){"string"!=typeof b&&(c=b,d=c,b=r()),B(this,a,b,c,d)},start:function(a,b,c,d){var e=v(a);e?this._multiModuleStart(a.slice(0),b,c,d):this._singleModuleStart(a,b,c,d)},isModuleStarted:function(a,d){var e=!1;return e=typeof d===b?typeof c[a]!==b&&s(c[a].instances)>0:typeof c[a]!==b&&typeof c[a].instances[d]!==b},startAll:function(){var a,d;for(a in c)z(c,a)&&(d=c[a],typeof d!==b&&this.start(a,r()))},_multiModuleStop:function(a){var c,d=a.instances,e;for(c in d)z(d,c)&&(e=d[c],typeof a!==b&&typeof e!==b&&e.destroy());a.instances={}},_singleModuleStop:function(a,c,d){var e=a.instances[d];typeof a!==b&&typeof e!==b&&(e.destroy(),delete a.instances[d])},stop:function(a,d){var e;return e=c[a],typeof e===b?!1:(typeof d!==b?this._singleModuleStop(e,a,d):this._multiModuleStop(e),!0)},_stopOneByOne:function(a,b){var c;for(c in a)z(a,c)&&this.stop(b,c)},stopAll:function(){var a;for(a in c)z(c,a)&&typeof c[a]!==b&&this._stopOneByOne(c[a].instances,a)},_delete:function(a){typeof c[a]!==b&&delete c[a]},remove:function(a){var d=c[a];if(typeof d===b)return null;if(typeof d!==b)try{return d}finally{this._delete(a)}return null}};function H(){return l}function I(a){l=a}j=function(){},j.version=h,j.bus=n,j.errorHandler=H,j.setErrorHandler=I,j.module=new m,j.setUnblockUI=x,j.setDebug=w,j.getDebug=function(){return k},j.extend=function(a,c){this[a]=typeof this[a]===b?c:C(this[a],c)},j.noConflict=function(a,c,d){return typeof this[a]!==b?(c[d]=this[a],!0):!1},j.addExtensionBeforeInit=function(a){j.module.oModifyInit=C(j.module.oModifyInit,a)},i=function(a,c){if(typeof c===b)throw new Error("Something goes wrong!");this.creator=c,this.instances={},this.sModuleId=a},i.prototype={start:function(a){return j.module.start(this.sModuleId,a),this},extend:function(a,b){return j.module.extend(this.sModuleId,a,b),this},stop:function(){return j.module.stop(this.sModuleId),this}},a.Hydra=j,p?module.exports=j:"undefined"!=typeof define&&define("hydra",[],function(){return j})}.call(this); +//# sourceMappingURL=hydra.min.map diff --git a/ajax/libs/hydra.js/package.json b/ajax/libs/hydra.js/package.json index 0dea1eeb8..65725dbe1 100644 --- a/ajax/libs/hydra.js/package.json +++ b/ajax/libs/hydra.js/package.json @@ -1,7 +1,7 @@ { "name": "hydra.js", "filename": "hydra.min.js", - "version": "3.1.2", + "version": "3.1.3", "description": "Framework that gives you the tools to write your application using modules or widgets and make easy to work with them.", "homepage": "http://tcorral.github.com/Hydra.js/", "keywords": [