Sergey Astanin avatar Sergey Astanin committed a81563e

use cross-browser compatible button CSS (thanks to @RedBanHammer)

+ refactor button callback

Comments (0)

Files changed (1)

Minimize_Navigation_in_Google_Webapps.user.js

 // @grant       none
 // ==/UserScript==
 
+// cross-browser arrow styles; thanks to @RedBanHammer
+var baseStyle = "background: url('https://ssl.gstatic.com/ui/v1/zippy/arrow_down.png') no-repeat center #f2f2f2;" +
+    "height: 8px;" +
+    "width: 100%;" +
+    "cursor: pointer;";
+
+var flippedStyle = "-moz-transform: scaleY(-1);" +
+    "-o-transform: scaleY(-1);" +
+    "-webkit-transform: scaleY(-1);" +
+    "transform: scaleY(-1);" +
+    "filter: FlipV;" +
+    "-ms-filter: 'FlipV';";
+
 function resizableElements() {
     // elements to be resized when navigation bar is toggled
     var elms  = [].concat(document.getElementsByClassName("aeN")[0],
 function createToggleButton() {
     var tb = document.createElement("div");
     tb.setAttribute("id","toggle_google_bars");
-    // styles
-    tb.style.background = "url('https://ssl.gstatic.com/ui/v1/zippy/arrow_down.png') no-repeat center #f2f2f2";
-    tb.style.height = "8px";
-    tb.style.width = "100%";
+    tb.setAttribute("style", baseStyle);
     return tb;
- }
+}
 
 function insertToggleButton(gb, tb) {
-    if (document.domain.indexOf("groups") >= 0) {
-        gb.parentNode.insertBefore(tb, gb.nextSibling.nextSibling);
-    } else {
-        gb.parentNode.insertBefore(tb, gb.nextSibling);
+    gb.parentNode.insertBefore(tb, gb.nextSibling);
+}
+
+function hideGoogleBar(gb, tb, headHeight) {
+    adjustResizableElements(headHeight);
+    gb.style.display = "none";
+    tb.setAttribute("style", baseStyle);
+}
+
+function showGoogleBar(gb, tb, headHeight) {
+    adjustResizableElements(-headHeight);
+    gb.style.display = "block";
+    tb.setAttribute("style", baseStyle + flippedStyle);
+}
+
+function createButtonCallback(headHeight) {
+    function toggleButtonCallback() {
+        var gb = getNavigationContainer();
+        var tb = document.getElementById("toggle_google_bars");
+        if (gb && (gb.style.display == "block")) {
+            hideGoogleBar(gb, tb, headHeight);
+        } else {
+            showGoogleBar(gb, tb, headHeight);
+        }
+        return false;
     }
+    return toggleButtonCallback;
 }
 
 function addToggleButton() {
     }
     // create a toggle button
     var tb = createToggleButton();
-    // hide google bar
     var headHeight = gb.offsetHeight - 8;
-    adjustResizableElements(headHeight);
-    gb.style.display = "none";
+    hideGoogleBar(gb, tb, headHeight);
     // avoid spacing between googlebar and the toggle button
     tb.style.marginBottom = gb.style.marginBottom;
     gb.style.marginBottom = "0px";
     // insert toggle button
     insertToggleButton(gb, tb);
     // add callback
-    tb.addEventListener("click", function() {
-        var gb = getNavigationContainer();
-        var tb = document.getElementById("toggle_google_bars");
-        if (gb && (gb.style.display == "block")) {
-            adjustResizableElements(headHeight);
-            gb.style.display = "none";
-            tb.style.MozTransform = "rotate(0deg)";
-        } else {
-            adjustResizableElements(-headHeight);
-            gb.style.display = "block";
-            tb.style.MozTransform = "rotate(180deg)";
-        }
-        return false;
-    }, false);
+    tb.addEventListener("click", createButtonCallback(), false);
     return;
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.