[Pkg-mozext-commits] [itsalltext] 102/459: Added a remote API.

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:11 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 6a1496462b9e21e60c01b5a4ad7c38d35a54b9f2
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sat Feb 3 12:40:32 2007 -0500

    Added a remote API.
---
 chrome/content/API.js        | 63 ++++++++++++++++++++++++++++++++++++++++++++
 chrome/content/itsalltext.js | 48 ++++++++++++++++++++-------------
 2 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/chrome/content/API.js b/chrome/content/API.js
new file mode 100644
index 0000000..38cc103
--- /dev/null
+++ b/chrome/content/API.js
@@ -0,0 +1,63 @@
+/*
+  This file is used to allow external editors to work inside your XUL chrome://
+
+  ***** How To Use This API *****
+  At the top of your .xul file, put this script line:
+  <script type="application/javascript" src="chrome://itsalltext/content/API.js"/>
+
+  It will fail with only an info message in the Error Console
+  if It's All Text! doesn't exist.
+
+  Then you need to create a button for the user to click to execute 
+  the editor.  This button must have four properties:
+    1) It must be a 'button' element.
+    2) The class must be "ItsAllTextEditButton".
+    3) The onclick attribute must be the JavaScript snippet:
+       ItsAllText.openEditor('id-of-your-textbox');
+       The string 'id-of-your-textbox' should be the id of the textbox
+       you want to be editable.
+    4) The style should include "display: none" so that the button won't
+       show up if It's All Text! isn't installed.
+
+  Example:
+      <hbox>
+        <spacer flex="1"/>
+        <button label="It's All Text!" class="ItsAllTextEditButton" style="display: none;" onclick="ItsAllText.openEditor('code');"/>
+      </hbox>
+
+ */
+
+(function () {
+    /* Load up the main It's All Text! file */
+    var objScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
+    objScriptLoader.loadSubScript('chrome://itsalltext/content/itsalltext.js');
+    
+    var onload = function (event) {
+        /* Start watching the document, but force it. */
+        ItsAllText.monitor.watch(document, true);
+
+        /* Turn on all the buttons */
+        var nodes = document.getElementsByTagName('button');
+        for(var i=0; i < nodes.length; i++) {
+            var button = nodes[i];
+            if (button.className == "ItsAllTextEditButton") { 
+                button.style.display = '';
+            }
+        }
+    };
+    window.addEventListener("load", onload, true);
+
+})();
+
+
+ItsAllText.openEditor = function(id) {
+    var node = document.getElementById(id);
+    /* The only way I can adjust the background of the textbox is
+     * to turn off the -moz-appearance attribute.
+     */
+    node.style.MozAppearance = 'none';
+    var cache_object = node && ItsAllText.getCacheObj(node);
+    if(!cache_object) { return; }
+    cache_object.edit();
+};
+
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index ba32ee7..e257040 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -417,6 +417,8 @@ var ItsAllText = function() {
             if (typeof(retried) == 'undefined') { retried = false; }
             var filename = self.write();
             self.initial_color = self.node.style.backgroundColor;
+            self.is_moz = self.node.style.backgroundColor;
+            that.debuglog('narf:',self.initial_color);
             try {
                 var program = that.getEditor();
 
@@ -506,6 +508,7 @@ var ItsAllText = function() {
                 if (step < pallet.length) {
                     self.node.style.backgroundColor = pallet[step++].hex();
                     setTimeout(self.fadeStep(pallet, step, delay),delay);
+                    that.debuglog('narf:',self.node.style.backgroundColor);
                 }
             };
         };
@@ -614,12 +617,12 @@ var ItsAllText = function() {
      * Refresh Textarea.
      * @param {Object} node A specific textarea dom object to update.
      */
-    that.refreshTextarea = function(node) {
+    that.refreshTextarea = function(node, is_chrome) {
         var cobj = that.getCacheObj(node);
         if(!cobj) { return; }
 
         cobj.update();
-        that.addGumDrop(cobj);
+        if (!is_chrome) { that.addGumDrop(cobj); }
     };
 
     // @todo [med] If the textarea is focused, we should refresh it.
@@ -632,13 +635,15 @@ var ItsAllText = function() {
      */
     that.refreshDocument = function(doc) {
         // @todo [high] Confirm that we find textareas inside iframes and frames.
+        var is_chrome = (doc.location.protocol == 'chrome:');
         var nodes = doc.getElementsByTagName('textarea');
-        for(var i=0; i < nodes.length; i++) {
-            that.refreshTextarea(nodes[i]);
+        var i;
+        for(i=0; i < nodes.length; i++) {
+            that.refreshTextarea(nodes[i], is_chrome);
         }
         nodes = doc.getElementsByTagName('textbox');
-        for(var i=0; i < nodes.length; i++) {
-            that.refreshTextarea(nodes[i]);
+        for(i=0; i < nodes.length; i++) {
+            that.refreshTextarea(nodes[i], is_chrome);
         }
     };
 
@@ -740,18 +745,22 @@ var ItsAllText = function() {
          * watches the document 'doc'.
          * @param {Object} doc The document to watch.
          */
-        watch: function(doc) {
-            /* Check that this is a document we want to play with. */
-            var contentType = doc.contentType;
-            var location = doc.location;
-            var is_html = (contentType == 'text/html' ||
-                           contentType == 'text/xhtml');
-            var is_xul  = (contentType == 'application/vnd.mozilla.xul+xml');
-            var is_usable = (is_html/* || is_xul*/) && 
-                location.protocol != 'about:';
-            if (!is_usable) { 
-                that.debuglog('watch(): ignoring -- ', location, contentType);
-                return;
+        watch: function(doc, force) {
+            if (!force) {
+                /* Check that this is a document we want to play with. */
+                var contentType = doc.contentType;
+                var location = doc.location;
+                var is_html = (contentType=='text/html' ||
+                               contentType=='text/xhtml');
+                //var is_xul=(contentType=='application/vnd.mozilla.xul+xml');
+                var is_usable = (is_html) && 
+                    location.protocol != 'about:' &&
+                    location.protocol != 'chrome:';
+                if (!is_usable) { 
+                    that.debuglog('watch(): ignoring -- ',
+                                  location, contentType);
+                    return;
+                }
             }
 
             that.refreshDocument(doc);
@@ -867,6 +876,7 @@ var ItsAllText = function() {
 
     // Start the monitor
     that.monitor.restart();
-}
+};
 
 ItsAllText = new ItsAllText();
+

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