dojo/OpenAjax.js

  • Provides:

    • dojo.OpenAjax
  • OpenAjax

    • type
      Function
    • ?? initialized = 1 (debug: boolean) ??
    • source: [view]
        var t = true;
        var f = false;
        var g = window;
        var libs;
        var ooh = "org.openajax.hub.";


        var h = {};
        this.hub = h;
        h.implementer = "http://openajax.org";
        h.implVersion = "0.6";
        h.specVersion = "0.6";
        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){
         if(typeof tree != "undefined"){
          var node;
          if(index == path.length) {
           node = tree;
          }else{
           this._publish(tree.c[path[index]], path, index + 1, name, msg);
           this._publish(tree.c["*"], path, index + 1, name, msg);
           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;
             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))) {
              cb.call(sc, name, msg, d);
             }
            }
           }
          }
         }
        }

         
        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", "0.6", {});


         delete OpenAjax._subscriptions;
         OpenAjax._subscriptions = {c:{},s:[]};
         delete OpenAjax._cleanup;
         OpenAjax._cleanup = [];
         OpenAjax._subIndex = 0;
         OpenAjax._pubDepth = 0;
        }
    • summary
      the OpenAjax hub
    • description
      see http://www.openajax.org/member/wiki/OpenAjax_Hub_Specification
  • OpenAjax.hub.registerLibrary

    • type
      Function
    • parameters:
      • prefix: (typeof )
      • nsURL: (typeof )
      • version: (typeof )
      • extra: (typeof )
    • source: [view]
         libs[prefix] = {
          prefix: prefix,
          namespaceURI: nsURL,
          version: version,
          extraData: extra
         };
         this.publish(ooh+"registerLibrary", libs[prefix]);
    • summary
  • OpenAjax.hub.unregisterLibrary

    • type
      Function
    • parameters:
      • prefix: (typeof )
    • source: [view]
         this.publish(ooh+"unregisterLibrary", libs[prefix]);
         delete libs[prefix];
    • summary
  • OpenAjax.hub.subscribe

    • type
      Function
    • parameters:
      • name: (typeof )
      • callback: (typeof )
      • scope: (typeof )
      • subscriberData: (typeof )
      • filter: (typeof )
    • source: [view]
         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;
    • summary
  • OpenAjax.hub.publish

    • type
      Function
    • parameters:
      • name: (typeof )
      • message: (typeof )
    • source: [view]
         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 = [];
         }
    • summary
  • OpenAjax.hub.publish._pubDepth

    • summary
  • OpenAjax.hub.publish._cleanup

    • summary
  • OpenAjax.hub.unsubscribe

    • type
      Function
    • parameters:
      • sub: (typeof )
    • source: [view]
         var path = sub.split(".");
         var sid = path.pop();
         this._unsubscribe(this._subscriptions, path, 0, sid);
    • summary
  • OpenAjax.hub._subscribe

    • type
      Function
    • parameters:
      • tree: (typeof )
      • path: (typeof )
      • index: (typeof )
      • sub: (typeof )
    • source: [view]
         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);
          }
         }
    • summary
  • OpenAjax.hub._publish

    • type
      Function
    • parameters:
      • tree: (typeof )
      • path: (typeof )
      • index: (typeof )
      • name: (typeof )
      • msg: (typeof )
    • source: [view]
         if(typeof tree != "undefined"){
          var node;
          if(index == path.length) {
           node = tree;
          }else{
           this._publish(tree.c[path[index]], path, index + 1, name, msg);
           this._publish(tree.c["*"], path, index + 1, name, msg);
           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;
             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))) {
              cb.call(sc, name, msg, d);
             }
            }
           }
          }
         }
    • summary
  • OpenAjax.hub._unsubscribe

    • type
      Function
    • parameters:
      • tree: (typeof )
      • path: (typeof )
      • index: (typeof )
      • sid: (typeof )
    • source: [view]
         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;
            }
          }
         }
    • summary
  • OpenAjax.hub.reinit

    • type
      Function
    • source: [view]
         for (var lib in OpenAjax.hub.libraries) {
          delete OpenAjax.hub.libraries[lib];
         }
         OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "0.6", {});


         delete OpenAjax._subscriptions;
         OpenAjax._subscriptions = {c:{},s:[]};
         delete OpenAjax._cleanup;
         OpenAjax._cleanup = [];
         OpenAjax._subIndex = 0;
         OpenAjax._pubDepth = 0;
    • summary
  • OpenAjax.hub.implementer

    • summary
  • OpenAjax.hub.implVersion

    • summary
  • OpenAjax.hub.specVersion

    • summary
  • OpenAjax.hub.implExtraData

    • summary
  • OpenAjax.hub.libraries

    • summary
  • OpenAjax.hub._subscriptions

    • summary
  • OpenAjax.hub._cleanup

    • summary
  • OpenAjax.hub._subIndex

    • summary
  • OpenAjax.hub._pubDepth

    • summary
  • OpenAjax.hub

    • summary
  • OpenAjax._pubDepth

    • summary
  • OpenAjax._cleanup

    • summary
  • dojo.OpenAjax

    • type
      Object
    • summary
  • dojo

    • type
      Object
    • summary