home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / Democracy-0.8.2.exe / components / jsbridge.js < prev    next >
Encoding:
Text File  |  2006-04-10  |  3.1 KB  |  110 lines

  1. const JSBRIDGE_CONTRACTID = "@participatoryculture.org/dtv/jsbridge;1";
  2. const JSBRIDGE_CLASSID    = Components.ID("{421AA951-F53D-4499-B362-E432CAE920F4}");
  3.  
  4. function writelog(str) {
  5.     Components.classes['@mozilla.org/consoleservice;1']
  6.     .getService(Components.interfaces.nsIConsoleService)    
  7.     .logStringMessage(str);
  8. }
  9.  
  10. function jsBridge() {
  11. }
  12.  
  13. jsBridge.prototype = {
  14.     QueryInterface: function(iid) {
  15.     if (iid.equals(Components.interfaces.pcfIDTVJSBridge) ||
  16.         iid.equals(Components.interfaces.nsISupports))
  17.         return this;
  18.     throw Components.results.NS_ERROR_NO_INTERFACE;
  19.     },
  20.  
  21.     xulNavigateDisplay: function(mainDocument, displayName, uri) {
  22.         var disp = mainDocument.getElementById(displayName);
  23.         disp.contentDocument.location = uri;
  24.     },
  25.  
  26.     xulAddElementAtEnd: function(xulElt, xml, id) {
  27.     elt = xulElt.contentDocument.getElementById(id);
  28.     r = xulElt.contentDocument.createRange();
  29.     r.selectNode(elt);
  30.     frag = r.createContextualFragment(xml);
  31.     elt.insertBefore(frag, null);
  32.     },
  33.     xulAddElementBefore: function(xulElt, xml, id) {
  34.     elt = xulElt.contentDocument.getElementById(id);
  35.     r = xulElt.contentDocument.createRange();
  36.     r.selectNode(elt);
  37.     frag = r.createContextualFragment(xml);
  38.     elt.parentNode.insertBefore(frag, elt);
  39.     },
  40.     xulRemoveElement: function(xulElt, id) {
  41.     elt = xulElt.contentDocument.getElementById(id);
  42.     elt.parentNode.removeChild(elt);
  43.     },
  44.     xulChangeElement: function(xulElt, id, xml) {
  45.     elt = xulElt.contentDocument.getElementById(id);
  46.     r = xulElt.contentDocument.createRange();
  47.     r.selectNode(elt);
  48.     frag = r.createContextualFragment(xml);
  49.     elt.parentNode.replaceChild(frag, elt);
  50.     },
  51.     xulHideElement: function(xulElt, id) {
  52.     elt = xulElt.contentDocument.getElementById(id);
  53.     elt.style.display = 'none';
  54.     },
  55.     xulShowElement: function(xulElt, id) {
  56.     elt = xulElt.contentDocument.getElementById(id);
  57.     elt.style.display = '';
  58.     }
  59.  
  60. };
  61.  
  62. var Module = {
  63.     _classes: {
  64.     jsBridge: {
  65.         classID: JSBRIDGE_CLASSID,
  66.         contractID: JSBRIDGE_CONTRACTID,
  67.         className: "DTV Javascript helpers",
  68.         factory: {
  69.         createInstance: function(delegate, iid) {
  70.             if (delegate)
  71.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  72.             return new jsBridge().QueryInterface(iid);
  73.         }
  74.         }
  75.     }
  76.     },
  77.  
  78.     registerSelf: function(compMgr, fileSpec, location, type) {
  79.     var reg = compMgr.QueryInterface(
  80.             Components.interfaces.nsIComponentRegistrar);
  81.  
  82.     for (var key in this._classes) {
  83.         var c = this._classes[key];
  84.         reg.registerFactoryLocation(c.classID, c.className, c.contractID,
  85.                     fileSpec, location, type);
  86.     }
  87.     },
  88.  
  89.     getClassObject: function(compMgr, cid, iid) {
  90.     if (!iid.equals(Components.interfaces.nsIFactory))
  91.         throw Components.results.NS_ERROR_NO_INTERFACE;
  92.  
  93.     for (var key in this._classes) {
  94.         var c = this._classes[key];
  95.         if (cid.equals(c.classID))
  96.         return c.factory;
  97.     }
  98.  
  99.     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  100.     },
  101.  
  102.     canUnload: function (aComponentManager) {
  103.     return true;
  104.     }
  105. };
  106.  
  107. function NSGetModule(compMgr, fileSpec) {
  108.   return Module;
  109. }
  110.