diff --git a/resources/static/lib/hub.js b/resources/static/lib/hub.js new file mode 100644 index 0000000000000000000000000000000000000000..25a9fab1b4dd2bee07e808bfd956d3622d977830 --- /dev/null +++ b/resources/static/lib/hub.js @@ -0,0 +1,59 @@ +/** +* Author Shane Tomlinson +* Original source can be found at: +* https://github.com/stomlinson/message_hub/blob/master/src/hub.js +* Licenced under Mozilla Tri-License +*/ +Hub = (function() { + "use strict"; + + var listeners = {}, + currID = 0; + + function on(message, callback, context) { + var messageListeners = listeners[message] = listeners[message] || [], + id = currID; + + messageListeners.push({ + id: currID, + callback: context ? callback.bind(context) : callback + }); + + currID++; + return id; + } + + function fire(message) { + var messageListeners = listeners[message]; + + if(messageListeners) { + for(var i = 0, listener; listener = messageListeners[i]; ++i) { + listener.callback.apply(null, arguments); + } + } + } + + function off(id) { + for(var key in listeners) { + var messageListeners = listeners[key]; + for(var i = 0, listener; listener = messageListeners[i]; ++i) { + if(listener.id === id) { + messageListeners.splice(i, 1); + } + } + } + } + + function reset() { + listeners = {}; + currID = 0; + } + + return { + on: on, + fire: fire, + reset: reset, + off: off + }; +}()); + diff --git a/resources/static/lib/openajax.js b/resources/static/lib/openajax.js deleted file mode 100644 index 9160f49d23e05e80d6f35b365ba40c86d5e1a870..0000000000000000000000000000000000000000 --- a/resources/static/lib/openajax.js +++ /dev/null @@ -1,201 +0,0 @@ -//@steal-clean -/******************************************************************************* - * OpenAjax.js - * - * Reference implementation of the OpenAjax Hub, as specified by OpenAjax Alliance. - * Specification is under development at: - * - * http://www.openajax.org/member/wiki/OpenAjax_Hub_Specification - * - * Copyright 2006-2008 OpenAjax Alliance - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless - * required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ******************************************************************************/ -(function() { - // prevent re-definition of the OpenAjax object - if(!window["OpenAjax"]){ - /** - * @class OpenAjax - * Use OpenAjax.hub to publish and subscribe to messages. - */ - OpenAjax = new function(){ - var t = true; - var f = false; - var g = window; - var ooh = "org.openajax.hub."; - - var h = {}; - this.hub = h; - h.implementer = "http://openajax.org"; - h.implVersion = "1.0"; - h.specVersion = "1.0"; - h.implExtraData = {}; - var libs = {}; - h.libraries = libs; - - h.registerLibrary = function(prefix, nsURL, version, extra){ - libs[prefix] = { - prefix: prefix, - namespaceURI: nsURL, - version: version, - extraData: extra - }; - this.publish(ooh+"registerLibrary", libs[prefix]); - } - h.unregisterLibrary = function(prefix){ - this.publish(ooh+"unregisterLibrary", libs[prefix]); - delete libs[prefix]; - } - - h._subscriptions = { c:{}, s:[] }; - h._cleanup = []; - h._subIndex = 0; - h._pubDepth = 0; - - h.subscribe = function(name, callback, scope, subscriberData, filter) - { - if(!scope){ - scope = window; - } - var handle = name + "." + this._subIndex; - var sub = { scope: scope, cb: callback, fcb: filter, data: subscriberData, sid: this._subIndex++, hdl: handle }; - var path = name.split("."); - this._subscribe(this._subscriptions, path, 0, sub); - return handle; - } - - h.publish = function(name, message) - { - var path = name.split("."); - this._pubDepth++; - this._publish(this._subscriptions, path, 0, name, message); - this._pubDepth--; - if((this._cleanup.length > 0) && (this._pubDepth == 0)) { - for(var i = 0; i < this._cleanup.length; i++) - this.unsubscribe(this._cleanup[i].hdl); - delete(this._cleanup); - this._cleanup = []; - } - } - - h.unsubscribe = function(sub) - { - var path = sub.split("."); - var sid = path.pop(); - this._unsubscribe(this._subscriptions, path, 0, sid); - } - - h._subscribe = function(tree, path, index, sub) - { - var token = path[index]; - if(index == path.length) - tree.s.push(sub); - else { - if(typeof tree.c == "undefined") - tree.c = {}; - if(typeof tree.c[token] == "undefined") { - tree.c[token] = { c: {}, s: [] }; - this._subscribe(tree.c[token], path, index + 1, sub); - } - else - this._subscribe( tree.c[token], path, index + 1, sub); - } - } - - h._publish = function(tree, path, index, name, msg, pcb, pcid) { - if(typeof tree != "undefined") { - var node; - if(index == path.length) { - node = tree; - } else { - this._publish(tree.c[path[index]], path, index + 1, name, msg, pcb, pcid); - this._publish(tree.c["*"], path, index + 1, name, msg, pcb, pcid); - node = tree.c["**"]; - } - if(typeof node != "undefined") { - var callbacks = node.s; - var max = callbacks.length; - for(var i = 0; i < max; i++) { - if(callbacks[i].cb) { - var sc = callbacks[i].scope; - var cb = callbacks[i].cb; - var fcb = callbacks[i].fcb; - var d = callbacks[i].data; - var sid = callbacks[i].sid; - var scid = callbacks[i].cid; - if(typeof cb == "string"){ - // get a function object - cb = sc[cb]; - } - if(typeof fcb == "string"){ - // get a function object - fcb = sc[fcb]; - } - if((!fcb) || (fcb.call(sc, name, msg, d))) { - if((!pcb) || (pcb(name, msg, pcid, scid))) { - cb.call(sc, name, msg, d, sid); - } - } - } - } - } - } - } - - h._unsubscribe = function(tree, path, index, sid) { - if(typeof tree != "undefined") { - if(index < path.length) { - var childNode = tree.c[path[index]]; - this._unsubscribe(childNode, path, index + 1, sid); - if(childNode.s.length == 0) { - for(var x in childNode.c) - return; - delete tree.c[path[index]]; - } - return; - } - else { - var callbacks = tree.s; - var max = callbacks.length; - for(var i = 0; i < max; i++) - if(sid == callbacks[i].sid) { - if(this._pubDepth > 0) { - callbacks[i].cb = null; - this._cleanup.push(callbacks[i]); - } - else - callbacks.splice(i, 1); - return; - } - } - } - } - // The following function is provided for automatic testing purposes. - // It is not expected to be deployed in run-time OpenAjax Hub implementations. - h.reinit = function() - { - for (var lib in OpenAjax.hub.libraries) { - delete OpenAjax.hub.libraries[lib]; - } - OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {}); - - delete OpenAjax._subscriptions; - OpenAjax._subscriptions = {c:{},s:[]}; - delete OpenAjax._cleanup; - OpenAjax._cleanup = []; - OpenAjax._subIndex = 0; - OpenAjax._pubDepth = 0; - } - }; - // Register the OpenAjax Hub itself as a library. - OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {}); - } - -}()); diff --git a/resources/static/shared/mediator.js b/resources/static/shared/mediator.js index 33faab020acf709adc8430cb5ea4b1bfb7c6960f..ab026a1046d8131ccf5db934a4c95c4069c6f3b5 100644 --- a/resources/static/shared/mediator.js +++ b/resources/static/shared/mediator.js @@ -35,12 +35,12 @@ * ***** END LICENSE BLOCK ***** */ BrowserID.Mediator = (function() { - var hub = OpenAjax.hub; + var hub = Hub; return { - subscribe: hub.subscribe.bind(hub), - unsubscribe: hub.unsubscribe.bind(hub), - publish: hub.publish.bind(hub) + subscribe: hub.on.bind(hub), + unsubscribe: hub.off.bind(hub), + publish: hub.fire.bind(hub) }; }()); diff --git a/resources/static/test/qunit.html b/resources/static/test/qunit.html index ccfa2b7e2b26c6e124256976c6108ff2cfe6e2af..b05ae11393b474a044a436b03e3c83b798513a02 100644 --- a/resources/static/test/qunit.html +++ b/resources/static/test/qunit.html @@ -1,7 +1,12 @@ +<!doctype html> <html> <head> + <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="qunit.css" /> <title>BrowserID QUnit Test</title> + <!--[if lt IE 9]> + <script type="text/javascript" src="/lib/html5shim.js"></script> + <![endif]--> </head> <body> @@ -76,7 +81,7 @@ <script type="text/javascript" src="/lib/vepbundle.js"></script> <script type="text/javascript" src="/shared/browserid.js"></script> <script type="text/javascript" src="/lib/dom-jquery.js"></script> - <script type="text/javascript" src="/lib/openajax.js"></script> + <script type="text/javascript" src="/lib/hub.js"></script> <script type="text/javascript" src="/lib/module.js"></script> <script type="text/javascript" src="/lib/jschannel.js"></script> <script type="text/javascript" src="qunit/mocks/mocks.js"></script> diff --git a/scripts/compress.sh b/scripts/compress.sh index d5850fc8aab047f75c56439f3fa2a1e0cd5b127b..4879381abe8914fe0ffddd72018a17ec4c77d342 100755 --- a/scripts/compress.sh +++ b/scripts/compress.sh @@ -42,7 +42,7 @@ cp shared/templates.js shared/templates.js.orig cp dialog/views/templates.js shared/templates.js # produce the dialog js -cat dialog/resources/channel.js lib/jquery-1.6.2.min.js lib/jschannel.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js shared/browserid.js lib/openajax.js lib/dom-jquery.js lib/module.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js shared/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgotpassword.js dialog/controllers/checkregistration.js dialog/controllers/pickemail.js dialog/controllers/addemail.js dialog/controllers/required_email.js dialog/start.js > dialog/production.js +cat dialog/resources/channel.js lib/jquery-1.6.2.min.js lib/jschannel.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js shared/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgotpassword.js dialog/controllers/checkregistration.js dialog/controllers/pickemail.js dialog/controllers/addemail.js dialog/controllers/required_email.js dialog/start.js > dialog/production.js # produce the non interactive frame js cat lib/jquery-1.6.2.min.js lib/jschannel.js lib/underscore-min.js lib/vepbundle.js shared/javascript-extensions.js shared/browserid.js shared/storage.js shared/network.js shared/user.js communication_iframe/start.js > communication_iframe/production.js