[Pkg-mozext-commits] [perspectives-extension] 05/14: Perspectives - Move addToolbarButton() function to its own file

David Prévot taffit at moszumanska.debian.org
Sat Jun 20 21:28:47 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 8ae641354a4b18f0cfc5dedafea1ada5e6e91bde
Author: Dave Schaefer <dave.schaefer at gmail.com>
Date:   Sun May 31 23:54:47 2015 -0600

    Perspectives - Move addToolbarButton() function to its own file
    
    This code is based on examples from the MDN wiki
    and has been released under a different license (MIT).
    To separate this and denote this, and to note that
    the rest of Perspectives still exists under the GPL3 license,
    we separate addToolbarButton() into its own file.
    
    Also:
    
    - wrap both parts of the init and toolbar code in their own
    'Pers_' named objects, to reduce pollution of the global namespace.
    
    - hook up unit tests to verify these new objects
    
    - remove debug calls
---
 plugin/chrome/content/addtoolbarbutton.js | 62 +++++++++++++++++++++++++++++++
 plugin/chrome/content/init.js             | 39 +++----------------
 plugin/chrome/content/initialize.xul      |  5 ++-
 test/test.html                            |  4 ++
 4 files changed, 75 insertions(+), 35 deletions(-)

diff --git a/plugin/chrome/content/addtoolbarbutton.js b/plugin/chrome/content/addtoolbarbutton.js
new file mode 100644
index 0000000..3f449b2
--- /dev/null
+++ b/plugin/chrome/content/addtoolbarbutton.js
@@ -0,0 +1,62 @@
+/*
+
+The MIT License (MIT)
+
+Copyright (c) 2007 Shimono
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+// NOTE: This file and function *only* are used under a different license
+// from the rest of Perspectives.
+// code inspired by MDN toolbar examples
+// https://developer.mozilla.org/ja/docs/Code_snippets/Toolbar
+// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Toolbar
+// https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses
+
+var Pers_add_toolbar_button = {
+
+    addToolbarButton: function(toolbarId, buttonId, 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 element
+          if (curSet.indexOf(beforeId) != -1) {
+              set = curSet.replace(re, buttonId + "," + beforeId);
+          } else { // at the end
+              set = curSet + "," + buttonId;
+          }
+          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/init.js b/plugin/chrome/content/init.js
index 5203acc..e70df90 100644
--- a/plugin/chrome/content/init.js
+++ b/plugin/chrome/content/init.js
@@ -19,7 +19,9 @@
 // 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){
+var Pers_init = {
+
+    evtLoad: function(evt){
       Perspectives.init_data();
       Perspectives.initNotaries();
       var root_prefs = Components.classes["@mozilla.org/preferences-service;1"]
@@ -36,7 +38,7 @@
 
           if (!document.getElementById(bname)) {
             // user has just installed the extension and has no button. add one
-            addToolbarButton("nav-bar", bname, "urlbar-container");
+            Pers_add_toolbar_button.addToolbarButton("nav-bar", bname, "urlbar-container");
           }
           // else the user has already added the button previously
           // we don't want to touch it
@@ -46,34 +48,5 @@
         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 951d2af..8ac3910 100644
--- a/plugin/chrome/content/initialize.xul
+++ b/plugin/chrome/content/initialize.xul
@@ -4,13 +4,14 @@
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/x-javascript" src="extlib/spark-md5.min.js"/>
 
+  <script type="application/x-javascript" src="addtoolbarbutton.js" />
   <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="application/x-javascript" src="notaries.js"/>
   <script type="text/javascript">
 				
     // don't load or run anything until after the page has loaded
-    window.addEventListener('load', function(){ evtLoad(); }, false);
+    window.addEventListener('load', function(){ Pers_init.evtLoad(); }, false);
 
   </script>
 </overlay>
diff --git a/test/test.html b/test/test.html
index 2fc63a2..0419ea6 100644
--- a/test/test.html
+++ b/test/test.html
@@ -8,9 +8,11 @@
 <script type="text/javascript" src="../extlib/spark-md5.min.js"></script>
 
 <script type="text/javascript" src="../about.js"             ></script>
+<script type="text/javascript" src="../addtoolbarbutton.js"></script>
 <script type="text/javascript" src="../client_policy.js"     ></script>
 <script type="text/javascript" src="../common.js"            ></script>
 <script type="text/javascript" src="../generate_svg.js"      ></script>
+<script type="text/javascript" src="../init.js"></script>
 <script type="text/javascript" src="../notaries.js"          ></script>
 <script type="text/javascript" src="../notify.js"            ></script>
 <script type="text/javascript" src="../preferences_dialog.js"></script>
@@ -191,11 +193,13 @@ function meta_tests() {
 
     var objs =
         [ "Pers_about"
+        , "Pers_add_toolbar_button"
         , "Pers_client_policy"
         , "Pers_debug"
         , "Pers_util"
         , "Pers_keypress"
         , "Pers_gen"
+        , "Pers_init"
         , "Perspectives"
         , "Pers_notify"
         , "Pers_pref"

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