From ef68436ac04da078ffdcacd7e1f785473a303d45 Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Sun, 02 Oct 2011 23:56:18 +0000 Subject: First version of the newly restructured repository --- (limited to 'frontend/beta/js/Clipperz/NotificationCenter.js') diff --git a/frontend/beta/js/Clipperz/NotificationCenter.js b/frontend/beta/js/Clipperz/NotificationCenter.js new file mode 100644 index 0000000..815d4fd --- a/dev/null +++ b/frontend/beta/js/Clipperz/NotificationCenter.js @@ -0,0 +1,325 @@ +/* + +Copyright 2008-2011 Clipperz Srl + +This file is part of Clipperz's Javascript Crypto Library. +Javascript Crypto Library provides web developers with an extensive +and efficient set of cryptographic functions. The library aims to +obtain maximum execution speed while preserving modularity and +reusability. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library is free software: you can redistribute + it and/or modify it under the terms of the GNU Affero General Public + License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. + +* Javascript Crypto Library is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + +* You should have received a copy of the GNU Affero General Public + License along with Javascript Crypto Library. If not, see + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.NotificationCenter) == 'undefined') { Clipperz.NotificationCenter = {}; } + + +//############################################################################# + +Clipperz.NotificationCenterEvent = function(args) { + args = args || {}; +// MochiKit.Base.bindMethods(this); + + this._source = args.source || null; + this._event = args.event || null; + this._parameters = args.parameters || null; + this._isSynchronous = args.isSynchronous || false; + + return this; +} + +//============================================================================= + +Clipperz.NotificationCenterEvent.prototype = MochiKit.Base.update(null, { + + //------------------------------------------------------------------------- + + 'toString': function() { + return "Clipperz.NotificationCenterEvent"; + //return "Clipperz.NotificationCenterEvent {source: " + this.source() + ", event: " + this.event() + ", parameters: " + this.parameters() + "}"; + }, + + //------------------------------------------------------------------------- + + 'source': function() { + return this._source; + }, + + 'setSource': function(aValue) { + this._source = aValue; + }, + + //------------------------------------------------------------------------- + + 'event': function() { + return this._event; + }, + + 'setEvent': function(aValue) { + this._event = aValue; + }, + + //------------------------------------------------------------------------- + + 'parameters': function() { + return this._parameters; + }, + + 'setParameters': function(aValue) { + this._parameters = aValue; + }, + + //------------------------------------------------------------------------- + + 'isSynchronous': function() { + return this._isSynchronous; + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + + +//############################################################################# +//############################################################################# + +Clipperz.NotificationCenter = function(args) { + args = args || {}; +// MochiKit.Base.bindMethods(this); + + this._listeners = {}; + this._useSynchronousListenerInvocation = args.useSynchronousListenerInvocation || false; + this._timeoutDelay = args.timeoutDelay || 0.1; + + return this; +} + +//============================================================================= + +Clipperz.NotificationCenter.prototype = MochiKit.Base.update(null, { + + //------------------------------------------------------------------------- + + 'toString': function() { + return "Clipperz.NotificationCenter"; + }, + + //------------------------------------------------------------------------- + + 'useSynchronousListenerInvocation': function() { + return this._useSynchronousListenerInvocation; + }, + + 'setUseSynchronousListenerInvocation': function(aValue) { + this._useSynchronousListenerInvocation = aValue; + }, + + //------------------------------------------------------------------------- + + 'timeoutDelay': function() { + return this._timeoutDelay; + }, + + 'setTimeoutDelay': function(aValue) { + this._timeoutDelay = aValue; + }, + + //------------------------------------------------------------------------- + + 'listeners': function() { + return this._listeners; + }, + + //------------------------------------------------------------------------- + + 'register': function(aSource, anEvent, aListener, aMethod) { + var eventListeners; + var listenerInfo; + var eventKey; + + if (anEvent != null) { + eventKey = anEvent; + } else { + eventKey = '_notificationCenter_matchAnyEvent_key_'; + } + + eventListeners = this.listeners()[eventKey]; + + if (eventListeners == null) { + eventListeners = []; + this.listeners()[eventKey] = eventListeners; + } + + listenerInfo = {}; + if (aSource != null) { + listenerInfo['source'] = aSource; + } else { + listenerInfo['source'] = 'any'; + } + + listenerInfo['listener'] = aListener; + listenerInfo['method'] = aMethod; + + eventListeners.push(listenerInfo); + + return listenerInfo; + }, + + //------------------------------------------------------------------------- + + 'removeListenerInfoFromListeners': function(aListener, someListeners) { + var listenerIndex; + var i,c; + + if (someListeners != null) { + listenerIndex = -1; + c = someListeners.length; + for (i=0; i>> NotificationCenter.notify"); + eventInfo = new Clipperz.NotificationCenterEvent({source:aSource, event:anEvent, parameters:someEventParameters, isSynchronous:isSynchronous}); +//MochiKit.Logging.logDebug("--- NotificationCenter.notify - 1"); + processInfoMethod = MochiKit.Base.bind(this.processListenerInfo, this); +//MochiKit.Logging.logDebug("--- NotificationCenter.notify - 2"); + + MochiKit.Base.map(MochiKit.Base.partial(processInfoMethod, eventInfo), this.listeners()[anEvent] || []); +//MochiKit.Logging.logDebug("--- NotificationCenter.notify - 3"); + MochiKit.Base.map(MochiKit.Base.partial(processInfoMethod, eventInfo), this.listeners()['_notificationCenter_matchAnyEvent_key_'] || []); +//MochiKit.Logging.logDebug("<<< NotificationCenter.notify"); + }, + + //------------------------------------------------------------------------- + + 'deferredNotification': function(aSource, anEvent, someEventParameters, aDeferredResult) { + + this.notify(aSource, anEvent, someEventParameters, true); + + return aDeferredResult; +// return MochiKit.Async.wait(1, aDeferredResult); + }, + + //------------------------------------------------------------------------- + + 'resetStatus': function() { + this._listeners = {}; + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + +//############################################################################# + +Clipperz.NotificationCenter.defaultNotificationCenter = new Clipperz.NotificationCenter(); + +Clipperz.NotificationCenter.notify = MochiKit.Base.method(Clipperz.NotificationCenter.defaultNotificationCenter, 'notify'); +Clipperz.NotificationCenter.register = MochiKit.Base.method(Clipperz.NotificationCenter.defaultNotificationCenter, 'register'); +Clipperz.NotificationCenter.unregister = MochiKit.Base.method(Clipperz.NotificationCenter.defaultNotificationCenter, 'unregister'); +Clipperz.NotificationCenter.deferredNotification = MochiKit.Base.method(Clipperz.NotificationCenter.defaultNotificationCenter, 'deferredNotification'); +/* +_clipperz_notificationCenter_defaultNotificationCenter = null; + +Clipperz.NotificationCenter.defaultNotificationCenter = function() { + if (_clipperz_notificationCenter_defaultNotificationCenter == null) { + _clipperz_notificationCenter_defaultNotificationCenter = new Clipperz.NotificationCenter(); + } + + return _clipperz_notificationCenter_defaultNotificationCenter; +}; +*/ -- cgit v0.9.0.2