/**
* Created by z on 29.2.2016.
*/
'use strict';
/**
* This object wraps angular js $rootScope.$on and $rootScope.$broadcast functionality.
* Usage:
* SUXESS.eventManager.on(name, listenerFn (event,(optional)args...){})
* SUXESS.eventManager.emit(name, (optional) args...)
*
* Event names should use 'suxess:' prefix e.g. 'suxess:element-deleted'
*
* @type {{on, emit, setRootScope}}
*/
SUXESS.eventManager = (function () {
var rootScope = null;
function registerListener(name, listener) {
if ( rootScope == null ) return;
rootScope.$on.apply(rootScope,arguments);
}
function emitEvent(name, args) {
if ( rootScope == null ) return;
rootScope.$broadcast.apply(rootScope,arguments);
}
function setRootScope ( r ) {
rootScope = r;
}
return {
on: registerListener,
emit: emitEvent,
setRootScope: setRootScope
};
})();