[Pkg-mozext-commits] [itsalltext] 37/459: switch to using setInterval, removed cronjob cruft.

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:04 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 186b8f4258df4c642b19e9e0848fec0390071a11
Author: Christian Höltje <docwhat at gerf.org>
Date:   Thu Dec 28 10:40:07 2006 -0500

    switch to using setInterval, removed cronjob cruft.
---
 chrome/content/itsalltext.js  | 53 ++++++++++++++++++++-----------------------
 chrome/content/itsalltext.xul | 13 ++++++++++-
 2 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 4c6139e..2b69ca6 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -43,7 +43,7 @@ function hashString(some_string) {
   var hash = ch.finish(true);
   
   // return the two-digit hexadecimal code for a byte
-  toHexString = function(charCode) {
+  var toHexString = function(charCode) {
     return ("0" + charCode.toString(36)).slice(-2);
   };
   
@@ -429,7 +429,7 @@ function ItsAllTextOverlay() {
      * @returns {boolean} Returns true ifthe file changed.
      */
     self.update = function() {
-      // @todo This should really use something like YFT.
+      // @todo This should really use something like FTY.
       if (self.hasChanged()) {
         var value = self.read();
         if (value !== null) {
@@ -470,12 +470,14 @@ function ItsAllTextOverlay() {
     //that.debug('refreshNode():',cobj);
     if(!cobj) { return; }
 
-    if (that.getDebug()) {
+    if (that.getDebug() && cobj.button !== null) {
       if (!cobj._toggle) {
-        cobj.node.style.background = '#fed';
+        cobj.button.style.borderColor = 'yellow';
+        cobj.button.style.color       = 'yellow';
         cobj._toggle = true;
       } else {
-        cobj.node.style.background = '#def';
+        cobj.button.style.borderColor = 'red';
+        cobj.button.style.color       = 'white';
         cobj._toggle = false;
       }
     }
@@ -515,6 +517,7 @@ function ItsAllTextOverlay() {
     var offsetNode = node;
     if (!node.parentNode) { return; }
 
+    // @todo The gumdrop shouldn't alter the layout of the page.
     var gumdrop = doc.createElementNS("http://www.w3.org/1999/xhtml", "div");
     gumdrop.appendChild(doc.createTextNode('edit'));
     cache_object.button = gumdrop; // Store it for easy finding in the future.
@@ -577,34 +580,28 @@ function ItsAllTextOverlay() {
   that.onDOMContentLoad = function(event) {
     if (event.originalTarget.nodeName != "#document") { return; }
     var doc = event.originalTarget;
-    var id = cron[doc.ItsAllText_CronJobID];
-    if (!id) {
-      id = cron.push(null);
-      doc.ItsAllText_CronJobID = id;
+    function startswith(needle, haystack) {
+      needle   = needle.toString();
+      haystack = haystack.toString();
+      return haystack.substring(0,needle.length) == needle;
+    }
+    if (startswith('chrome://', doc.URL) ||
+        startswith('about:', doc.URL) ) {
+      return; // Ignore these URLs
     }
 
-    that.debug('onDOMContentLoad: start',id);
-    var lasttime = new Date().valueOf();
-
-    /**
-     * This sets up the autorefresh for a given page.
-     */
-    var cronjob = function () {
-      var last = cron[id];
-      if(!last || last == lasttime) {
+    var id = null;
+    that.refreshDocument(doc);
+    id = setInterval(function() {
+      if (doc) {
+        that.debug('document %s %o "%s"', id, doc, doc.URL);
         that.refreshDocument(doc);
-        lasttime = new Date().valueOf();
-        cron[id] = lasttime;
-        setTimeout(cronjob, that.getRefresh());
-        /* @todo replace complicated setTimeout system with setinterval */
-        // example:
-        // var ourInterval = setInterval(functionhere, 1000);
-        // clearInterval(ourInterval);
+      } else {
+        that.debug('document %s (cancelled)', id);
+        clearInterval(id);
       }
-    };
-    cronjob();
+    }, that.getRefresh());
 
-    that.debug('onDOMContentLoad: done',id);
     return;
   };
 
diff --git a/chrome/content/itsalltext.xul b/chrome/content/itsalltext.xul
index 8061d31..aa4ae90 100644
--- a/chrome/content/itsalltext.xul
+++ b/chrome/content/itsalltext.xul
@@ -2,10 +2,21 @@
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/x-javascript" src="itsalltext.js"/>
+  <!-- The merge point is contentAreaContextMenu -->
   <popup id="contentAreaContextMenu">
      <menuitem id="its-all-text-edit" label="It's All Text" 
                oncommand="itsAllTextOverlay.onEditNode(document.popupNode)"
                accesskey="i" />
   </popup>
-</overlay>
 
+  <popupset>
+    <menupopup id="its-all-text-menu">
+      <menuitem label="Cut"/>
+      <menuitem label="Copy"/>
+      <menuitem label="Paste"/>
+    </menupopup>
+  </popupset>
+</overlay>
+<!-- Local Variables: -->
+<!-- mode: xml -->
+<!-- End: -->

-- 
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