--- /dev/null
+/**\r
+ * Copyright (c) 2006-2007, TIBCO Software Inc.\r
+ * Use, modification, and distribution subject to terms of license.\r
+ * \r
+ * TIBCO(R) PageBus 1.1.0\r
+ */\r
+\r
+if(typeof window.PageBus == 'undefined') {\r
+\r
+PageBus = {\r
+ version: "1.1.0",\r
+ S: {c:{},s:[]}, \r
+ X: 0,\r
+ P: 0,\r
+ U: [],\r
+ H: "undefined"\r
+};\r
+\r
+PageBus.subscribe = function(name, scope, callback, subscriberData) \r
+{\r
+ if(name == null)\r
+ this._badName();\r
+ if(scope == null)\r
+ scope = window;\r
+ var path = name.split(".");\r
+ var sub = { f: callback, d: subscriberData, i: this.X++, p: path, w: scope };\r
+ for(var i = 0; i < path.length; i++) {\r
+ if((path[i].indexOf("*") != -1) && (path[i] != "*") && (path[i] != "**"))\r
+ this._badName();\r
+ }\r
+ this._subscribe(this.S, path, 0, sub);\r
+ return sub; \r
+}\r
+\r
+PageBus.publish = function (name, message) \r
+{ \r
+ if((name == null) || (name.indexOf("*") != -1)) \r
+ this._badName();\r
+ var path = name.split(".");\r
+ if(this.P > 100) \r
+ this._throw("StackOverflow");\r
+ try {\r
+ this.P++;\r
+ this._publish(this.S, path, 0, name, message);\r
+ }\r
+ catch(err) {\r
+ this.P--;\r
+ throw err;\r
+ }\r
+ try {\r
+ this.P--;\r
+ if((this.U.length > 0) && (this.P == 0)) {\r
+ for(var i = 0; i < this.U.length; i++)\r
+ this.unsubscribe(this.U[i]);\r
+ this.U = [];\r
+ }\r
+ }\r
+ catch(err) { \r
+ // All unsubscribe exceptions should already have \r
+ // been handled when unsubscribe was called in the\r
+ // publish callback. This is a repeat appearance \r
+ // of this exception. Discard it.\r
+ }\r
+}\r
+\r
+PageBus.unsubscribe = function(sub) \r
+{\r
+ this._unsubscribe(this.S, sub.p, 0, sub.i);\r
+}\r
+\r
+/*\r
+ * @private @jsxobf-clobber\r
+ */\r
+PageBus._throw = function(n) \r
+{ \r
+ throw new Error("PageBus." + n); \r
+}\r
+\r
+/*\r
+ * @private @jsxobf-clobber\r
+ */\r
+PageBus._badName = function(n) \r
+{ \r
+ this._throw("BadName"); \r
+}\r
+\r
+/*\r
+ * @private @jsxobf-clobber\r
+ */\r
+PageBus._subscribe = function(tree, path, index, sub) \r
+{\r
+ var tok = path[index];\r
+ if(tok == "")\r
+ this._badName();\r
+ if(index == path.length) \r
+ tree.s.push(sub);\r
+ else { \r
+ if(typeof tree.c == this.H) \r
+ tree.c = {};\r
+ if(typeof tree.c[tok] == this.H) {\r
+ try {\r
+ tree.c[tok] = { c: {}, s: [] }; \r
+ this._subscribe(tree.c[tok], path, index + 1, sub);\r
+ }\r
+ catch(err) {\r
+ delete tree.c[tok];\r
+ throw err;\r
+ }\r
+ }\r
+ else \r
+ this._subscribe( tree.c[tok], path, index + 1, sub );\r
+ }\r
+}\r
+\r
+/*\r
+ * @private @jsxobf-clobber\r
+ */\r
+PageBus._publish = function(tree, path, index, name, msg) {\r
+ if(path[index] == "")\r
+ this._badName();\r
+ if(typeof tree != this.H) {\r
+ if(index < path.length) {\r
+ this._publish(tree.c[path[index]], path, index + 1, name, msg);\r
+ this._publish(tree.c["*"], path, index + 1, name, msg); \r
+ this._call(tree.c["**"], name, msg);\r
+ }\r
+ else\r
+ this._call(tree, name, msg);\r
+ }\r
+}\r
+\r
+/*\r
+ * @private @jsxobf-clobber\r
+ */\r
+PageBus._call = function(node, name, msg) {\r
+ if(typeof node != this.H) {\r
+ var callbacks = node.s;\r
+ var max = callbacks.length;\r
+ for(var i = 0; i < max; i++) \r
+ if(callbacks[i].f != null) \r
+ callbacks[i].f.apply(callbacks[i].w, [name, msg, callbacks[i].d]); \r
+ }\r
+}\r
+ \r
+/*\r
+ * @jsxobf-clobber\r
+ */\r
+PageBus._unsubscribe = function(tree, path, index, sid) {\r
+ if(typeof tree != this.H) {\r
+ if(index < path.length) {\r
+ var childNode = tree.c[path[index]];\r
+ this._unsubscribe(childNode, path, index + 1, sid);\r
+ if(childNode.s.length == 0) {\r
+ for(var x in childNode.c) // not empty. We're done.\r
+ return;\r
+ delete tree.c[path[index]]; // if we got here, c is empty\r
+ }\r
+ return;\r
+ }\r
+ else {\r
+ var callbacks = tree.s;\r
+ var max = callbacks.length;\r
+ for(var i = 0; i < max; i++) {\r
+ if(sid == callbacks[i].i) {\r
+ if(this.P > 0) {\r
+ if(callbacks[i].f == null) \r
+ this._throw("BadParameter");\r
+ callbacks[i].f = null;\r
+ this.U.push(callbacks[i]); \r
+ }\r
+ else\r
+ callbacks.splice(i, 1);\r
+ return; \r
+ }\r
+ }\r
+ // Not found. Fall through\r
+ }\r
+ }\r
+ this._throw("BadParameter");\r
+}\r
+\r
+}
\ No newline at end of file