[Pkg-mozext-commits] [perspectives-extension] 02/14: init - Move init code to separate js file

David Prévot taffit at moszumanska.debian.org
Sat Jun 20 21:28:46 UTC 2015


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

taffit pushed a commit to branch master
in repository perspectives-extension.

commit 2c993ea8b86e38b11704e0f8776032b2c943e0df
Author: Dave Schaefer <dave.schaefer at gmail.com>
Date:   Sat May 30 14:17:34 2015 -0600

    init - Move init code to separate js file
    
    Fix for #162 - AMO bug - Initialization script too long
    
    Based on commit 6c4b87f9 from Alexey V
    All credit and thanks to Alexey. Thanks!
    
    Removing old-style init code while we're at it.
---
 plugin/chrome/content/init.js        |  79 ++++++++++++++++++++
 plugin/chrome/content/initialize.xul | 136 +----------------------------------
 2 files changed, 81 insertions(+), 134 deletions(-)

diff --git a/plugin/chrome/content/init.js b/plugin/chrome/content/init.js
new file mode 100644
index 0000000..5203acc
--- /dev/null
+++ b/plugin/chrome/content/init.js
@@ -0,0 +1,79 @@
+/*
+*   This file is part of the Perspectives Firefox Client
+*
+*   Copyright (C) 2011 Dan Wendlandt
+*
+*   This program is free software: you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License as published by
+*   the Free Software Foundation, version 3 of the License.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// This file contains initialization code that may be run when the extension starts
+// It is held separately from initialize.xul to comply with Mozilla review policies
+
+    function evtLoad(evt){
+      Perspectives.init_data();
+      Perspectives.initNotaries();
+      var root_prefs = Components.classes["@mozilla.org/preferences-service;1"]
+                                .getService(Components.interfaces.nsIPrefBranch);
+
+      // call this *after* the document has loaded
+      // so we have access to the stringbundle from statusbar.xul
+      Perspectives.prompt_update();
+
+      var firstrun = root_prefs.getBoolPref("perspectives.first_run");
+      if (firstrun) {
+          root_prefs.setBoolPref("perspectives.first_run", false);
+          var bname = "perspectives-status-button";
+
+          if (!document.getElementById(bname)) {
+            // user has just installed the extension and has no button. add one
+            addToolbarButton("nav-bar", bname, "urlbar-container");
+          }
+          // else the user has already added the button previously
+          // we don't want to touch it
+      }
+
+      if(!Perspectives.root_prefs.getBoolPref("perspectives.show_label")){
+        document.getElementById("perspective-statusbar-label").hidden = true;
+      }
+    }
+
+    // Thanks to Calomel SSL Validation plugin code
+    function addToolbarButton(toolbarId, buttonId, beforeId) {
+    Pers_debug.d_print("error","Inserting button " + buttonId + " into " + toolbarId + " before beforeId");
+    try {
+          var firefoxnav = document.getElementById(toolbarId);
+          var curSet = firefoxnav.currentSet;
+	  var re = new RegExp(beforeId);
+          if (curSet.indexOf(buttonId) == -1)
+          {
+            var set;
+            // Place the button before the urlbar
+            if (curSet.indexOf(beforeId) != -1){
+              set = curSet.replace(re, buttonId + "," + beforeId);
+	      Pers_debug.d_print("error", "inserting with RegEx");
+	    } else { // at the end
+              set = curSet + "," + buttonId;
+	      Pers_debug.d_print("error", "inserting at the end");
+	    }
+            firefoxnav.setAttribute("currentset", set);
+            firefoxnav.currentSet = set;
+            document.persist(toolbarId, "currentset");
+            // If you don't do the following call, funny things happen
+            try {
+              BrowserToolboxCustomizeDone(true);
+            }
+            catch (e) { }
+          }
+        }
+        catch(e) { }
+    }
diff --git a/plugin/chrome/content/initialize.xul b/plugin/chrome/content/initialize.xul
index 3eab959..951d2af 100644
--- a/plugin/chrome/content/initialize.xul
+++ b/plugin/chrome/content/initialize.xul
@@ -6,144 +6,12 @@
 
   <script type="application/x-javascript" src="common.js"/>
   <script type="application/x-javascript" src="notaries.js"/>
+  <script type="application/x-javascript" src="init.js" />
   <script type="text/javascript">
 				
     // don't load or run anything until after the page has loaded
-    window.addEventListener('load',evtLoad,false);
+    window.addEventListener('load', function(){ evtLoad(); }, false);
 
-    function evtLoad(evt){
-      Perspectives.init_data();
-      Perspectives.initNotaries();
-      var root_prefs = Components.classes["@mozilla.org/preferences-service;1"]
-                                .getService(Components.interfaces.nsIPrefBranch);
-
-      // call this *after* the document has loaded
-      // so we have access to the stringbundle from statusbar.xul
-      Perspectives.prompt_update();
-
-      var firstrun = root_prefs.getBoolPref("perspectives.first_run");
-      if (firstrun) {
-          root_prefs.setBoolPref("perspectives.first_run", false);
-          var bname = "perspectives-status-button";
-
-          if (!document.getElementById(bname)) {
-            // user has just installed the extension and has no button. add one
-            addToolbarButton("nav-bar", bname, "urlbar-container");
-          }
-          // else the user has already added the button previously
-          // we don't want to touch it
-      }
-
-      if(!Perspectives.root_prefs.getBoolPref("perspectives.show_label")){
-        document.getElementById("perspective-statusbar-label").hidden = true;
-      }
-    }
-
-    // Thanks to Calomel SSL Validation plugin code
-    function addToolbarButton(toolbarId, buttonId, beforeId) {
-    Pers_debug.d_print("error","Inserting button " + buttonId + " into " + toolbarId + " before beforeId");
-    try {
-          var firefoxnav = document.getElementById(toolbarId);
-          var curSet = firefoxnav.currentSet;
-	  var re = new RegExp(beforeId);
-          if (curSet.indexOf(buttonId) == -1)
-          {
-            var set;
-            // Place the button before the urlbar
-            if (curSet.indexOf(beforeId) != -1){
-              set = curSet.replace(re, buttonId + "," + beforeId);
-	      Pers_debug.d_print("error", "inserting with RegEx");
-	    } else { // at the end
-              set = curSet + "," + buttonId;
-	      Pers_debug.d_print("error", "inserting at the end");
-	    }
-            firefoxnav.setAttribute("currentset", set);
-            firefoxnav.currentSet = set;
-            document.persist(toolbarId, "currentset");
-            // If you don't do the following call, funny things happen
-            try {
-              BrowserToolboxCustomizeDone(true);
-            }
-            catch (e) { }
-          }
-        }
-        catch(e) { }
-    }
-/* old non-working version
-    function addToolbarButton(toolbarId, buttonId, beforeId) {
-        if(!buttonId) {
-          Pers_debug.d_print("error",
-                    "Could not add Perspectives button to toolbar: "
-                    + buttonId + " doesn't exist");
-          return;
-        }
-
-        if(!toolbarId) {
-          Pers_debug.d_print("error",
-                    "Could not add Perspectives button to toolbar: "
-                    + toolbarId + " doesn't exist");
-          return;
-        }
-        var toolbar = document.getElementById(toolbarId);
-        if (toolbar) {
-            if (toolbar.firstChild) {
-                var before = toolbar.firstChild;
-                if (beforeId) {
-                    var elem = document.getElementById(beforeId);
-                    if (elem) {
-                        if (elem.parentNode) {
-                            if (elem.parentNode == toolbar) {
-                                before = elem;
-                            }
-                            else {
-                                Pers_debug.d_print("error",
-                                  "Parent node of " + beforeId +
-                                  " is not " + toolbarId);
-                            }
-                        }
-                        else {
-                            Pers_debug.d_print("error",
-                              "Could not get parent node for " + beforeId);
-                        }
-                    }
-                    else {
-                        Pers_debug.d_print("error",
-                          "Could not get element " + beforeId + "");
-                    }
-                }
-                else {
-                    Pers_debug.d_print("error",
-                      "" + beforeId + " doesn't exist.");
-                }
-
-                try{
-                  toolbar.insertItem(buttonId, before);
-                }
-                catch(e) {
-                  Pers_debug.d_print("error",
-                      "Could not add Perspectives button to toolbar:" + e);
-                }
-
-                toolbar.setAttribute("currentset", toolbar.currentSet);
-                document.persist(toolbar.id, "currentset");
-
-                if (toolbarId == "addon-bar")  {
-                    toolbar.collapsed = false;
-                }
-            }
-            else {
-              Pers_debug.d_print("error",
-                      "Could not add Perspectives button to toolbar: "
-                      + ToolbarId + " has no child node");
-            }
-        }
-        else {
-          Pers_debug.d_print("error",
-                    "Could not add Perspectives button to toolbar: "
-                    + toolbarId + " doesn't exist");
-        }
-    }
-*/
   </script>
 </overlay>
 

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



More information about the Pkg-mozext-commits mailing list