You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2012/05/12 13:14:07 UTC

svn commit: r1337513 - /myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js

Author: struberg
Date: Sat May 12 11:14:06 2012
New Revision: 1337513

URL: http://svn.apache.org/viewvc?rev=1337513&view=rev
Log:
EXTCDI-284 use less indenting to save 1kB

Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js?rev=1337513&r1=1337512&r2=1337513&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js Sat May 12 11:14:06 2012
@@ -18,102 +18,102 @@
  */
 (function() {
 //wrapping so that all internal functions are privately scoped
-    function isHtml5() {
-        try {
-            return !!localStorage.getItem;
-        } catch(e) {
-            return false;
-        }
+function isHtml5() {
+    try {
+        return !!localStorage.getItem;
+    } catch(e) {
+        return false;
     }
+}
 
 // some browsers don't understand JSON - guess which one ... :(
-    function stringify(someArray) {
-        if (JSON) {
-            return JSON.stringify(someArray);
-        }
-        return someArray.join("|||");
+function stringify(someArray) {
+    if (JSON) {
+        return JSON.stringify(someArray);
     }
+    return someArray.join("|||");
+}
 
 // store the current body in the html5 localstorage
-    function storeWindowTree() {
-        // first we store all CSS we also need on the intermediate page
-        var headNodes = document.getElementsByTagName("head")[0].childNodes;
-        var oldSS = new Array();
-        var j = 0;
-        for (var i = 0; i < headNodes.length; i++) {
-            var tagName = headNodes[i].tagName;
-            if (tagName && equalsIgnoreCase(tagName, "link") &&
-                    equalsIgnoreCase(headNodes[i].getAttribute("type"), "text/css")) {
-
-                // sort out media="print" and stuff
-                var media = headNodes[i].getAttribute("media");
-                if (!media || equalsIgnoreCase(media, "all") || equalsIgnoreCase(media, 'screen')) {
-                    oldSS[j++] = headNodes[i].getAttribute("href");
-                }
-            }
-        }
-        localStorage.setItem(window.name + '_css', stringify(oldSS));
-        var body = document.getElementsByTagName("body")[0];
-        localStorage.setItem(window.name + '_body', body.innerHTML);
-        //X TODO: store ALL attributes of the body tag
-        localStorage.setItem(window.name + '_bodyAttrs', body.getAttribute("class"));
-        return true;
-    }
-
-    function equalsIgnoreCase(source, destination) {
-        //either both are not set or null
-        if (!source && !destination) {
-            return true;
-        }
-        //source or dest is set while the other is not
-        if (!source || !destination) return false;
-
-        //in any other case we do a strong string comparison
-        return source.toLowerCase() === destination.toLowerCase();
-    }
-
-    function applyOnClick() {
-        var links = document.getElementsByTagName("a");
-        for (var i = 0; i < links.length; i++) {
-            if (!links[i].onclick) {
-                links[i].onclick = function() {storeWindowTree(); return true;};
-            } else {
-                //the function wrapper is important
-                //otherwise the last onclick handler would be assigned
-                //to oldonclick
-                (function storeEvent() {
-                    var oldonclick = links[i].onclick;
-                    links[i].onclick = function(evt) {
-                        //ie handling added
-                        evt = evt || window.event;
-
-                        return storeWindowTree() && oldonclick(evt);
-                    };
-                })();
+function storeWindowTree() {
+    // first we store all CSS we also need on the intermediate page
+    var headNodes = document.getElementsByTagName("head")[0].childNodes;
+    var oldSS = new Array();
+    var j = 0;
+    for (var i = 0; i < headNodes.length; i++) {
+        var tagName = headNodes[i].tagName;
+        if (tagName && equalsIgnoreCase(tagName, "link") &&
+                equalsIgnoreCase(headNodes[i].getAttribute("type"), "text/css")) {
+
+            // sort out media="print" and stuff
+            var media = headNodes[i].getAttribute("media");
+            if (!media || equalsIgnoreCase(media, "all") || equalsIgnoreCase(media, 'screen')) {
+                oldSS[j++] = headNodes[i].getAttribute("href");
             }
         }
     }
-
-    function assertWindowId() {
-        var freshWindow = window.name.length < 1;
-        if (freshWindow) {
-            var url = urlWithoutWindowId(window.location.href);
-            window.name = "window";
-            window.location = url;
-        }
+    localStorage.setItem(window.name + '_css', stringify(oldSS));
+    var body = document.getElementsByTagName("body")[0];
+    localStorage.setItem(window.name + '_body', body.innerHTML);
+    //X TODO: store ALL attributes of the body tag
+    localStorage.setItem(window.name + '_bodyAttrs', body.getAttribute("class"));
+    return true;
+}
+
+function equalsIgnoreCase(source, destination) {
+    //either both are not set or null
+    if (!source && !destination) {
+        return true;
     }
+    //source or dest is set while the other is not
+    if (!source || !destination) return false;
 
-    var oldWindowOnLoad = window.onload;
-
-    window.onload = function(evt) {
-        try {
-            (oldWindowOnLoad)? oldWindowOnLoad(evt): null;
-        } finally {
-            if (isHtml5()) {
-                applyOnClick();
-            }
-            // this ensures that even without the ClientSideWindowHandler
-            assertWindowId();
+    //in any other case we do a strong string comparison
+    return source.toLowerCase() === destination.toLowerCase();
+}
+
+function applyOnClick() {
+    var links = document.getElementsByTagName("a");
+    for (var i = 0; i < links.length; i++) {
+        if (!links[i].onclick) {
+            links[i].onclick = function() {storeWindowTree(); return true;};
+        } else {
+            //the function wrapper is important
+            //otherwise the last onclick handler would be assigned
+            //to oldonclick
+            (function storeEvent() {
+                var oldonclick = links[i].onclick;
+                links[i].onclick = function(evt) {
+                    //ie handling added
+                    evt = evt || window.event;
+
+                    return storeWindowTree() && oldonclick(evt);
+                };
+            })();
+        }
+    }
+}
+
+function assertWindowId() {
+    var freshWindow = window.name.length < 1;
+    if (freshWindow) {
+        var url = urlWithoutWindowId(window.location.href);
+        window.name = "window";
+        window.location = url;
+    }
+}
+
+var oldWindowOnLoad = window.onload;
+
+window.onload = function(evt) {
+    try {
+        (oldWindowOnLoad)? oldWindowOnLoad(evt): null;
+    } finally {
+        if (isHtml5()) {
+            applyOnClick();
         }
+        // this ensures that even without the ClientSideWindowHandler
+        assertWindowId();
     }
+}
 })();