[Pkg-mozext-commits] [itsalltext] 361/459: Changed over to using set/get UserData

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:38 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 707f8fb55ee605a231938cca9237e941b667478e
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sat Jan 23 16:05:27 2010 -0500

    Changed over to using set/get UserData
---
 src/chrome/content/cacheobj.js   | 50 +++++++++++++++++++++++++---------------
 src/chrome/content/itsalltext.js | 26 ++++++++++-----------
 src/chrome/content/monitor.js    | 18 +++++++--------
 3 files changed, 53 insertions(+), 41 deletions(-)

diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 5e531ee..a65104e 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -25,11 +25,23 @@
  */
 function CacheObj(node) {
     var that = this,
+        hitch_re = /^hitched_/,
         doc = node.ownerDocument,
         host,
         hash,
         extension;
 
+    this.uuid = Math.floor(Math.random()*2000);
+    //disabled-debug -- ItsAllText.debug('CacheObject ', this.uuid, node);
+
+    for (method in this) {
+        if (hitch_re.test(method)) {
+
+            //disabled-debug -- ItsAllText.debug('CacheObj ', this.uuid, 'hitching ', method, ' -> ', method.replace(hitch_re, ''));
+            this[method.replace(hitch_re, '')] = ItsAllText.hitch(this, method);
+        }
+    }
+
     /* Gumdrop Image URL */
     that.gumdrop_url    = 'chrome://itsalltext/locale/gumdrop.png';
     /* Gumdrop Image Width */
@@ -58,7 +70,7 @@ function CacheObj(node) {
                                  that.node_id ].join(':'));
     // @todo [security] Add a serial to the uid hash.
 
-    node.setAttribute(ItsAllText.MYSTRING + '_UID', that.uid);
+    node.setUserData(ItsAllText.MYSTRING + '_UID', that.uid, null);
     ItsAllText.tracker[that.uid] = that;
 
     /* Figure out where we will store the file.  While the filename can
@@ -124,7 +136,7 @@ function CacheObj(node) {
      * @param {Event} event The event object.
      */
     that.mouseout = function (event) {
-        ItsAllText.debug("mouseout: %o", event, event.target, that.is_focused);
+        //disabled-debug -- ItsAllText.debug("mouseout: %o", event, event.target, that.is_focused);
         if (that.button_fade_timer) {
             clearTimeout(that.button_fade_timer);
         }
@@ -161,13 +173,13 @@ function CacheObj(node) {
  * Destroys the object, unallocating as much as possible to prevent leaks.
  */
 CacheObj.prototype.destroy = function () {
-    ItsAllText.debug('destroying', this.node_id, this.uid);
+    //disabled-debug -- ItsAllText.debug('destroying', this.node_id, this.uid);
     var node = this.node,
         doc  = this.node.ownerDocument,
         html = doc.getElementsByTagName('html')[0];
 
-    node.removeAttribute(ItsAllText.MYSTRING + '_UID');
-    html.removeAttribute(ItsAllText.MYSTRING + '_id_serial');
+    //node.removeAttribute(ItsAllText.MYSTRING + '_UID');
+    //html.removeAttribute(ItsAllText.MYSTRING + '_id_serial');
 
     delete this.node;
     delete this.button;
@@ -221,7 +233,7 @@ CacheObj.prototype.initFromExistingFile = function () {
             try {
                 entry.remove(false);
             } catch (e) {
-                ItsAllText.debug('unable to remove', entry, 'because:', e);
+                //disabled-debug -- ItsAllText.debug('unable to remove', entry, 'because:', e);
             }
         }
     }
@@ -247,14 +259,14 @@ CacheObj.prototype.getNodeIdentifier = function (node) {
         attr = ItsAllText.MYSTRING + '_id_serial';
 
         /* Get a serial that's unique to this document */
-        serial = doc.getAttribute(attr);
+        serial = doc.getUserData(attr);
         if (serial) {
             serial = parseInt(serial, 10) + 1;
         } else {
             serial = 1;
         }
         id = [ItsAllText.MYSTRING, 'generated_id', name, serial].join('_');
-        doc.setAttribute(attr, serial);
+        doc.setUserData(attr, serial, null);
         node.setAttribute('id', id);
     }
     return id;
@@ -334,7 +346,7 @@ CacheObj.prototype.getStyle = function (node, attr) {
  * @param {boolean} clobber Should an existing file be clobbered?
  */
 CacheObj.prototype.edit = function (extension, clobber) {
-    ItsAllText.debug('edit(', extension, ', ', clobber, ')');
+    ItsAllText.debug(this.uuid, 'edit(', extension, ', ', clobber, ')', this.uid);
     extension = typeof(extension) === 'string'?extension:this.extension;
     this.setExtension(extension);
 
@@ -404,7 +416,7 @@ CacheObj.prototype.remove = function () {
         try {
             this.file.remove();
         } catch (e) {
-            ItsAllText.debug('remove(', this.file.path, '): ', e);
+            //disabled-debug -- ItsAllText.debug('remove(', this.file.path, '): ', e);
             return false;
         }
     }
@@ -522,8 +534,8 @@ CacheObj.prototype.update = function () {
 /**
  * Capture keypresses to do the hotkey edit.
  */
-CacheObj.prototype.keypress = function (event) {
-    ItsAllText.debug('keypress()', event);
+CacheObj.prototype.hitched_keypress = function (event) {
+    ItsAllText.debug(this.uuid, 'keypress()', event);
     var km = ItsAllText.marshalKeyEvent(event), cobj;
     if (km === ItsAllText.preferences.hotkey) {
         cobj = CacheObj.get(event.target);
@@ -538,7 +550,7 @@ CacheObj.prototype.keypress = function (event) {
  * @param {Object} event The event that triggered this.
  */
 CacheObj.prototype.onClick = function (event) {
-    ItsAllText.debug('onClick()', event);
+    //disabled-debug -- ItsAllText.debug('onClick()', event);
     var cobj = CacheObj.get(event.target);
     cobj.edit();
     event.stopPropagation();
@@ -597,16 +609,15 @@ CacheObj.prototype.addGumDrop = function () {
             return; /*already done*/
         }
 
-        ItsAllText.debug('addGumDrop');
-
         // Add the textarea mouseovers even if the button is disabled
         node = cache_object.node;
+        ItsAllText.debug('addGumDrop', cache_object.uuid, node);
         if (!cache_object.is_listening) {
             ItsAllText.listen(node, "mouseover", ItsAllText.hitch(cache_object, "mouseover"), false);
             ItsAllText.listen(node, "mouseout",  ItsAllText.hitch(cache_object, "mouseout"),  false);
             ItsAllText.listen(node, "focus",     ItsAllText.hitch(cache_object, "mouseover"), false);
             ItsAllText.listen(node, "blur",      ItsAllText.hitch(cache_object, "mouseout"),  false);
-            ItsAllText.listen(node, "keypress",  ItsAllText.hitch(cache_object, "keypress"),  false);
+            ItsAllText.listen(node, "keypress",  cache_object.keypress,  false);
             cache_object.is_listening = true;
         }
         if (ItsAllText.getDisableGumdrops()) {
@@ -643,7 +654,7 @@ CacheObj.prototype.addGumDrop = function () {
         gumdrop.style.setProperty('width',  this.gumdrop_width + 'px', 'important');
         gumdrop.style.setProperty('height', this.gumdrop_height + 'px', 'important');
 
-        gumdrop.setAttribute(ItsAllText.MYSTRING + '_UID', cache_object.uid);
+        gumdrop.setUserData(ItsAllText.MYSTRING + '_UID', cache_object.uid, null);
 
         // Click event handlers
         ItsAllText.listen(gumdrop, "click", ItsAllText.hitch(cache_object, 'onClick'), false);
@@ -803,8 +814,8 @@ CacheObj.get = function (node) {
         id = null;
     if (typeof(node) === 'string') {
         id = node;
-    } else if (node && node.hasAttribute(str)) {
-        id = node.getAttribute(str);
+    } else if (node && node.getUserData(str)) {
+        id = node.getUserData(str);
     }
     if (id && ItsAllText.tracker.hasOwnProperty(id)) {
         return ItsAllText.tracker[id];
@@ -822,6 +833,7 @@ CacheObj.get = function (node) {
  */
 CacheObj.make = function (node, create_gumdrop) {
     var cobj = CacheObj.get(node);
+    ItsAllText.debug('CacheObj.make(',node,', ', create_gumdrop,') = ',cobj, ' : ', cobj ? cobj.uid : 'null');
     if (!cobj) {
         cobj = new CacheObj(node);
         if (create_gumdrop) {
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 02a56a4..b131903 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -190,15 +190,14 @@ var ItsAllText = function () {
     /* Clean the edit directory whenever we create a new window. */
     that.cleanEditDir();
 
-    loadthings = function () {
-        /* Load the various bits needed to make this work. */
+    /* Load the various bits needed to make this work. */
+    (function () {
         var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
         loader.loadSubScript('chrome://itsalltext/content/Color.js', that);
         loader.loadSubScript('chrome://itsalltext/content/monitor.js', that);
         loader.loadSubScript('chrome://itsalltext/content/cacheobj.js', that);
         that.monitor = new that.monitor(that);
-    };
-    loadthings();
+    })();
 
     /**
      * Dictionary for storing the preferences in.
@@ -323,7 +322,7 @@ var ItsAllText = function () {
     that.getRefresh = function () {
         var refresh = that.preferences.refresh;
         if (!refresh || refresh < 1) {
-            that.debug('Invalid refresh:', refresh);
+            //disabled-debug -- that.debug('Invalid refresh:', refresh);
             refresh = 1;
         }
         return 1000 * refresh;
@@ -479,7 +478,7 @@ var ItsAllText = function () {
                 }
             }
         }
-        that.debug('textarea count (tracker):', count);
+        //disabled-debug -- that.debug('textarea count (tracker):', count);
     };
 
     // @todo [wish] Refresh textarea on editor quit.
@@ -643,7 +642,7 @@ var ItsAllText = function () {
             var browser = getBrowser();
             browser.selectedTab = browser.addTab(that.README);
         } catch (e) {
-            that.debug("failed to openReadme:", e);
+            //disabled-debug -- that.debug("failed to openReadme:", e);
         }
     };
 
@@ -651,7 +650,7 @@ var ItsAllText = function () {
     // Do the startup when things are loaded.
     // TODONOW: move to separate function
     that.listen(window, 'load', function (event) {
-        that.debug('!!load', event);
+        //disabled-debug -- that.debug('!!load', event);
         if (typeof(gBrowser) === 'undefined') {
             that.monitor.registerPage(event);
         } else {
@@ -677,7 +676,7 @@ var ItsAllText = function () {
             that.monitor.stopPage(event);
         }
         var doc = event.originalTarget;
-        that.debug("pageunload(): A page has been unloaded", doc && doc.location);
+        //disabled-debug -- that.debug("pageunload(): A page has been unloaded", doc && doc.location);
         that.cleanCacheObjs();
         that.preference_observer.unregister();
         that.monitor.destroy();
@@ -726,7 +725,8 @@ ItsAllText.prototype.hitch = function (object, method) {
  */
 ItsAllText.prototype.listen = function (source, event, listener, opt_capture) {
     opt_capture = !!opt_capture;
-    this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
+    this.unlisten(source, event, listener, opt_capture);
+    //disabled-debug -- this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
     if (source) {
         source.addEventListener(event, listener, opt_capture);
     }
@@ -741,11 +741,11 @@ ItsAllText.prototype.listen = function (source, event, listener, opt_capture) {
  */
 ItsAllText.prototype.unlisten = function (source, event, listener, opt_capture) {
     opt_capture = !!opt_capture;
-    this.debug("unlisten(%o, %o, -, %o)", source, event, opt_capture);
+    //disabled-debug -- this.debug("unlisten(%o, %o, -, %o)", source, event, opt_capture);
     try {
         source && source.removeEventListener(event, listener, opt_capture);
     } catch (err) {
-        this.debug("didn't unlisten: %o", err);
+        //disabled-debug -- this.debug("didn't unlisten: %o", err);
     }
 };
 
@@ -848,7 +848,7 @@ ItsAllText.prototype.menuExtEdit = function (ext, clobber, event) {
     if (ext !== null) {
         ext = typeof(ext) === 'string'?ext:event.target.getAttribute('label');
     }
-    this.debug('menuExtEdit:', uid, ext, clobber);
+    //disabled-debug -- this.debug('menuExtEdit:', uid, ext, clobber);
     cobj.edit(ext, clobber);
 };
 
diff --git a/src/chrome/content/monitor.js b/src/chrome/content/monitor.js
index 9f22794..dcdf23c 100644
--- a/src/chrome/content/monitor.js
+++ b/src/chrome/content/monitor.js
@@ -22,12 +22,12 @@ function monitor(iat) {
     var hitch_re = /^hitched_/,
         method;
     this.iat = iat;
-    this.iat.debug('monitor');
+    //disabled-debug -- this.iat.debug('monitor');
 
     for (method in this) {
         if (hitch_re.test(method)) {
 
-            this.iat.debug('hitching ', method, ' -> ', method.replace(hitch_re, ''));
+            //disabled-debug -- this.iat.debug('hitching ', method, ' -> ', method.replace(hitch_re, ''));
             this[method.replace(hitch_re, '')] = this.iat.hitch(this, method);
         }
     }
@@ -55,7 +55,7 @@ monitor.prototype.hitched_registerPage = function (event) {
     var doc, appContent;
     if (event.originalTarget instanceof HTMLDocument) {
         doc = event.originalTarget;
-        this.iat.debug('registerPage: ', doc && doc.location);
+        //disabled-debug -- this.iat.debug('registerPage: ', doc && doc.location);
 
         /* appContent is the browser chrome. */
         appContent = document.getElementById("appcontent");
@@ -63,7 +63,7 @@ monitor.prototype.hitched_registerPage = function (event) {
         this.iat.listen(document, 'unload', this.stopPage, true);
         this.iat.listen(gBrowser.tabContainer, 'TabSelect', this.watcher, true);
         this.startPage({originalTarget: doc});
-        this.iat.debug('RegisterPage: END');
+        //disabled-debug -- this.iat.debug('RegisterPage: END');
     }
 };
 
@@ -128,7 +128,7 @@ monitor.prototype.hitched_watcher = function (offset, init) {
         node;
 
     if (!init && now - this.last_watcher_call < Math.round(rate * 0.9)) {
-        this.iat.debug('watcher(', offset, '/', (now - this.last_watcher_call), ') -- skipping catchup refresh');
+        //disabled-debug -- this.iat.debug('watcher(', offset, '/', (now - this.last_watcher_call), ') -- skipping catchup refresh');
         return;
     }
     this.last_watcher_call = now;
@@ -140,7 +140,7 @@ monitor.prototype.hitched_watcher = function (offset, init) {
         /* If we're in a tabbed browser. */
         doc = gBrowser.selectedBrowser.contentDocument;
     }
-    this.iat.debug('watcher: ', offset, init, doc && doc.location);
+    //disabled-debug -- this.iat.debug('watcher: ', offset, init, doc && doc.location);
     nodes = this.findnodes(doc);
     /* Now that we have the nodes, walk through and either make or
      * get the cache objects and update them. */
@@ -176,7 +176,7 @@ monitor.prototype.hitched_handleSubtreeModified = function (event) {
     }
     has_textareas = event.originalTarget.getElementsByTagName('textarea').length > 0;
     if (has_textareas) {
-        ItsAllText.debug('handleSubtreeModified: %o', event.target);
+        //disabled-debug -- ItsAllText.debug('handleSubtreeModified: %o', event.target);
         try {
             // Ignore events while adding the gumdrops.
             this.incrementLock();
@@ -191,7 +191,7 @@ monitor.prototype.hitched_handleSubtreeModified = function (event) {
 monitor.prototype.hitched_startPage = function (event, force) {
     var doc = event.originalTarget,
         unsafeWin;
-    this.iat.debug('startPage', doc && doc.location, force);
+    //disabled-debug -- this.iat.debug('startPage', doc && doc.location, force);
     if (!(force || this.isHTML(doc))) {
         this.stopPage(event);
         return;
@@ -217,7 +217,7 @@ monitor.prototype.hitched_startPage = function (event, force) {
 monitor.prototype.hitched_stopPage = function (event) {
     var doc = event.originalTarget,
         unsafeWin;
-    this.iat.debug('stopPage', doc && doc.location);
+    //disabled-debug -- this.iat.debug('stopPage', doc && doc.location);
 
     unsafeWin = doc.defaultView.wrappedJSObject;
     if (unsafeWin) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list