]> git.ktnx.net Git - icedeb.git/commitdiff
encapsulate all functions in a single global object
authorDamyan Ivanov <dmn@debian.org>
Thu, 20 Jan 2011 07:17:48 +0000 (09:17 +0200)
committerDamyan Ivanov <dmn@debian.org>
Thu, 20 Jan 2011 07:30:35 +0000 (09:30 +0200)
chrome/content/icedeb.js

index af5026c31e3833cbdb716ca580219e16ca3c81a1..391d2538bae14345cd8bbeafcd5620ba14009c92 100644 (file)
-function getClipboardText() {
-    var clip = Components.classes['@mozilla.org/widget/clipboard;1']
-        .getService(Components.interfaces.nsIClipboard);
-    if (!clip) return null;
-
-    var trans = Components.classes['@mozilla.org/widget/transferable;1']
-        .createInstance(Components.interfaces.nsITransferable);
-    if (!trans) return null;
-
-    trans.addDataFlavor("text/unicode");
-    clip.getData(trans,
-            clip.supportsSelectionClipboard()
-            ? clip.kSelectionClipboard
-            : clip.kGlobalClipboard
-    );
-
-    var str = new Object;
-    var strLength = new Object;
-    trans.getTransferData("text/unicode", str, strLength);
-
-    var text = null;
-
-    if (str) str  = str.value.QueryInterface(Components.interfaces.nsISupportsString);
-    if (str) text = str.data.substring(0, strLength.value / 2);
-
-    return text;
-}
-
-function trim_keyword(word) {
-    if (!word) return word;
+IceDeb = {
+    getClipboardText: function() {
+        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
+            .getService(Components.interfaces.nsIClipboard);
+        if (!clip) return null;
 
 
-    var oldword;
-    do {
-        oldword = word;
+        var trans = Components.classes['@mozilla.org/widget/transferable;1']
+            .createInstance(Components.interfaces.nsITransferable);
+        if (!trans) return null;
 
 
-        word = word.replace(/^\s+/, '');
-        word = word.replace(/\s+$/, '');
-        word = word.replace(/^#/, '');
-        word = word.replace(/[-:\/,.]$/, '');
-    } while ( oldword != word );
+        trans.addDataFlavor("text/unicode");
+        clip.getData(trans,
+                clip.supportsSelectionClipboard()
+                ? clip.kSelectionClipboard
+                : clip.kGlobalClipboard
+        );
 
 
-    return word;
-}
+        var str = new Object;
+        var strLength = new Object;
+        trans.getTransferData("text/unicode", str, strLength);
 
 
-function lookup_bts(in_new) {
-    var bug = trim_keyword(getClipboardText());
-    if (!bug) return null;
-    var uri="http://bugs.debian.org/" + bug;
+        var text = null;
 
 
-    if (in_new) {
-        var b = getBrowser();
-        var new_tab = b.addTab(uri);
-        b.selectedTab = new_tab;
-    }
-    else {
-        loadURI(uri);
-    }
-}
+        if (str) str  = str.value.QueryInterface(Components.interfaces.nsISupportsString);
+        if (str) text = str.data.substring(0, strLength.value / 2);
 
 
-function lookup_pts(in_new) {
-    var pkg = trim_keyword(getClipboardText());
-    if (!pkg) return null;
-    var uri="http://packages.qa.debian.org/" + pkg;
+        return text;
+    },
+    trim_keyword: function(word) {
+        if (!word) return word;
 
 
-    if (in_new) {
-        var b = getBrowser();
-        var new_tab = b.addTab(uri);
-        b.selectedTab = new_tab;
-    }
-    else {
-        loadURI(uri);
-    }
-}
+        var oldword;
+        do {
+            oldword = word;
 
 
-function lookup_deb(in_new) {
-    var pkg = trim_keyword(getClipboardText());
-    if (!pkg) return null;
-    var uri="http://packages.debian.org/" + pkg;
+            word = word.replace(/^\s+/, '');
+            word = word.replace(/\s+$/, '');
+            word = word.replace(/^#/, '');
+            word = word.replace(/[-:\/,.]$/, '');
+        } while ( oldword != word );
 
 
-    if (in_new) {
-        var b = getBrowser();
-        var new_tab = b.addTab(uri);
-        b.selectedTab = new_tab;
-    }
-    else {
-        loadURI(uri);
-    }
-}
+        return word;
+    },
+    lookup_bts: function(in_new) {
+        var bug = IceDeb.trim_keyword(IceDeb.getClipboardText());
+        if (!bug) return null;
+        var uri="http://bugs.debian.org/" + bug;
+
+        if (in_new) {
+            var b = getBrowser();
+            var new_tab = b.addTab(uri);
+            b.selectedTab = new_tab;
+        }
+        else {
+            loadURI(uri);
+        }
+    },
+    lookup_pts: function(in_new) {
+        var pkg = IceDeb.trim_keyword(IceDeb.getClipboardText());
+        if (!pkg) return null;
+        var uri="http://packages.qa.debian.org/" + pkg;
+
+        if (in_new) {
+            var b = getBrowser();
+            var new_tab = b.addTab(uri);
+            b.selectedTab = new_tab;
+        }
+        else {
+            loadURI(uri);
+        }
+    },
+    lookup_deb: function(in_new) {
+        var pkg = IceDeb.trim_keyword(IceDeb.getClipboardText());
+        if (!pkg) return null;
+        var uri="http://packages.debian.org/" + pkg;
+
+        if (in_new) {
+            var b = getBrowser();
+            var new_tab = b.addTab(uri);
+            b.selectedTab = new_tab;
+        }
+        else {
+            loadURI(uri);
+        }
+    },
 
 
-IceDeb = {
     btsButton: function (e) {
         if ( e.button == 0 )
     btsButton: function (e) {
         if ( e.button == 0 )
-            lookup_bts(false)
+            IceDeb.lookup_bts(false)
         else if ( e.button == 1 )
         else if ( e.button == 1 )
-            lookup_bts(true);
+            IceDeb.lookup_bts(true);
     },
     ptsButton: function (e) {
         if ( e.button == 0 )
     },
     ptsButton: function (e) {
         if ( e.button == 0 )
-            lookup_pts(false)
+            IceDeb.lookup_pts(false)
         else if ( e.button == 1 )
         else if ( e.button == 1 )
-            lookup_pts(true);
+            IceDeb.lookup_pts(true);
     },
     debButton: function (e) {
         if ( e.button == 0 )
     },
     debButton: function (e) {
         if ( e.button == 0 )
-            lookup_deb(false)
+            IceDeb.lookup_deb(false)
         else if ( e.button == 1 )
         else if ( e.button == 1 )
-            lookup_deb(true);
+            IceDeb.lookup_deb(true);
     }
 }
 
     }
 }