myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r1182751 - in /myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/_Dom.js xhrCore/_AjaxResponse.js xhrCore/engine/Xhr1.js
Date Thu, 13 Oct 2011 09:58:31 GMT
Author: werpu
Date: Thu Oct 13 09:58:31 2011
New Revision: 1182751

URL: http://svn.apache.org/viewvc?rev=1182751&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-3106

introducing head style replacement via javascript

Modified:
    myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
    myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
    myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/Xhr1.js

Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=1182751&r1=1182750&r2=1182751&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
(original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
Thu Oct 13 09:58:31 2011
@@ -100,6 +100,78 @@ myfaces._impl.core._Runtime.singletonExt
         //now of the onload handler also is overwritten we have a problem
     },
 
+    runCss: function(item, xmlData) {
+
+        var stylesheets = document.styleSheets;
+        var finalCss    = [];
+
+        var applyStyle = this._Lang.hitch(this, function(item, style) {
+            var newSS = document.createElement("style");
+
+            newSS.setAttribute("rel",item.getAttribute("rel") || "stylesheet");
+            newSS.setAttribute("type",item.getAttribute("type") || "text/css");
+            document.getElementsByTagName("head")[0].appendChild(newSS);
+            //ie merrily again goes its own way
+            if(window.attachEvent && !this._RT.isOpera  && 'undefined' !=
typeof newSS.styleSheet && 'undefined' != newSS.styleSheet.cssText) newSS.styleSheet.cssText
= style;
+            else newSS.appendChild(document.createTextNode(style));
+        });
+
+        var execCss = this._Lang.hitch(this, function(item) {
+            var _eqi = this._Lang.equalsIgnoreCase;
+
+            if (item.tagName && _eqi(item.tagName, "link") && _eqi(item.getAttribute("type"),
"text/css")) {
+                var style = "@import url('"+item.getAttribute("href")+"');";
+                applyStyle(item, style);
+            } else if(item.tagName && _eqi(item.tagName, "style") && _eqi(item.getAttribute("type"),
"text/css")) {
+                var innerText = [];
+                //compliant browsers know childnodes
+                if(item.childNodes) {
+                    var len = item.childNodes.length;
+                    for(var cnt = 0; cnt < len; cnt++) {
+                        innerText.push(item.childNodes[cnt].innerHTML || item.childNodes[cnt].data);
+                    }
+                //non compliant ones innerHTML
+                } else if(item.innerHTML) {
+                    innerText.push(item.innerHTML);
+                }
+
+                var style = innerText.join("");
+                applyStyle(item, style);
+            }
+        });
+
+        try {
+            var scriptElements = this.findByTagNames(item, {"link":true,"style":true}, true);
+            if (scriptElements == null) return;
+            for (var cnt = 0; cnt < scriptElements.length; cnt++) {
+                execCss(scriptElements[cnt]);
+            }
+
+        } finally {
+            //the usual ie6 fix code
+            //the IE6 garbage collector is broken
+            //nulling closures helps somewhat to reduce
+            //mem leaks, which are impossible to avoid
+            //at this browser
+            execCss = null;
+            applyStyle = null;
+        }
+    },
+
+
+    deleteScripts: function(nodeList) {
+        if(!nodeList || !nodeList.length) return;
+        var len = nodeList.length;
+        for(var cnt = 0; cnt < len; cnt++) {
+             var item = nodeList[cnt];
+             var src = item.getAttribute('src');
+             if (src  && src.length > 0 && (src.indexOf("/jsf.js") !=
-1 || src.indexOf("/jsf-uncompressed.js") != -1))  {
+                        continue;
+             }
+             this.deleteItem(item);
+        }
+    },
+
     /**
      * Run through the given Html item and execute the inline scripts
      * (IE doesn't do this by itself)
@@ -232,6 +304,13 @@ myfaces._impl.core._Runtime.singletonExt
         return null;
     },
 
+    deleteItems: function(items) {
+        if(! items || ! items.length) return;
+        for(var cnt = 0; cnt < items.length; cnt++) {
+            this.deleteItem(items[cnt]);
+        }
+    },
+
     /**
      * Simple delete on an existing item
      */
@@ -455,7 +534,7 @@ myfaces._impl.core._Runtime.singletonExt
             } else {
                 return this.replaceElements(item, evalNodes);
             }
-       
+
         } finally {
 
             var dummyPlaceHolder = this.getDummyPlaceHolder();

Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=1182751&r1=1182750&r2=1182751&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
(original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
Thu Oct 13 09:58:31 2011
@@ -495,11 +495,17 @@ myfaces._impl.core._Runtime.singletonExt
                     newHead = doc.getElementsByTagName("head")[0];
                 }
 
+                var oldTags = this._Dom.findByTagNames(document.getElementsByTagName("head")[0],
{"link": true, "style":true});
+                this._Dom.runCss(newHead, true);
+                this._Dom.deleteItems(oldTags);
+
+                //var oldTags = this._Dom.findByTagNames(document.getElementsByTagName("head")[0],
{"script": true});
+                //this._Dom.deleteScripts(oldTags);
                 this._Dom.runScripts(newHead, true);
 
+
                 return doc;
-            }
-            ,
+            },
 
 
             /**

Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/Xhr1.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/Xhr1.js?rev=1182751&r1=1182750&r2=1182751&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/Xhr1.js
(original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/engine/Xhr1.js
Thu Oct 13 09:58:31 2011
@@ -128,7 +128,6 @@ myfaces._impl.core._Runtime.extendClass(
                         try {
                             var status = xhr.status;
                             if (status >= XHRConst.STATUS_OK_MINOR && status <
XHRConst.STATUS_OK_MAJOR) {
-
                                 this.onload(myevt);
                             } else {
                                 evt.type = "error";



Mime
View raw message