Created
April 16, 2012 11:11
-
-
Save vstorm83/2397816 to your computer and use it in GitHub Desktop.
Juzu ajax bug on IE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/core/src/main/java/org/juzu/impl/plugin/ajax/ApplicationAsset.java b/core/src/main/java/org/juzu/impl/plugin/ajax/ApplicationAsset.java | |
| index 85739cb..ada70f7 100644 | |
| --- a/core/src/main/java/org/juzu/impl/plugin/ajax/ApplicationAsset.java | |
| +++ b/core/src/main/java/org/juzu/impl/plugin/ajax/ApplicationAsset.java | |
| @@ -51,8 +51,10 @@ public class ApplicationAsset extends Route implements Provider<ApplicationAsset | |
| resp.setContentType("text/javascript"); | |
| PrintWriter printer = resp.getWriter(); | |
| - // | |
| - printer.println("HTMLElement.prototype." + scope + "=function(){"); | |
| + // | |
| + printer.println("(function(){"); | |
| + printer.println("var bind=function(p){"); | |
| + printer.println("p." + scope + "=function(){"); | |
| printer.println("var capture=this;"); | |
| printer.println("return {"); | |
| @@ -74,7 +76,13 @@ public class ApplicationAsset extends Route implements Provider<ApplicationAsset | |
| // | |
| printer.println("};"); | |
| - printer.println("};"); | |
| + printer.println("};}"); | |
| + | |
| + // | |
| + printer.println("if (typeof(HTMLElement)!=='undefined') {bind(HTMLElement.prototype);"); | |
| + printer.println("}else{"); | |
| + printer.println("window.attachEvent('onload', function() {$('.jz').find('*').each(function() {bind(this);});})}"); | |
| + printer.println("})();"); | |
| // | |
| return true; | |
| diff --git a/core/src/main/resources/org/juzu/impl/plugin/ajax/script.js b/core/src/main/resources/org/juzu/impl/plugin/ajax/script.js | |
| index f3926fb..9bb270d 100644 | |
| --- a/core/src/main/resources/org/juzu/impl/plugin/ajax/script.js | |
| +++ b/core/src/main/resources/org/juzu/impl/plugin/ajax/script.js | |
| @@ -1,27 +1,38 @@ | |
| -var p=HTMLElement.prototype; | |
| -p.jz=function(){ | |
| - var e=this; | |
| - while(e!=null&&(" "+e.className+" ").indexOf(" jz ")<0){ | |
| - e=e.parentNode; | |
| - } | |
| - return e; | |
| -}; | |
| -p.foo=function(k){ | |
| - var e=this.jz(); | |
| - if(e!=null){ | |
| - var n=e.getElementsByTagName("div"); | |
| - for(var i=0;i<n.length;i++){ | |
| - var c=n[i]; | |
| - var d=c.getAttribute("data-method-id"); | |
| - if(d==k){ | |
| - return c.getAttribute("data-url"); | |
| - } | |
| - } | |
| - } | |
| - return k; | |
| -}; | |
| -p.$=function(){return $(this.jz());}; | |
| -p.$find=function(){ | |
| - var elt=this.$(); | |
| - return elt.find.apply(elt, arguments); | |
| -}; | |
| +(function() { | |
| + var bind = function(p) { | |
| + p.jz=function(){ | |
| + var e=this; | |
| + while(e!=null&&(" "+e.className+" ").indexOf(" jz ")<0){ | |
| + e=e.parentNode; | |
| + } | |
| + return e; | |
| + }; | |
| + p.foo=function(k){ | |
| + var e=this.jz(); | |
| + if(e!=null){ | |
| + var n=e.getElementsByTagName("div"); | |
| + for(var i=0;i<n.length;i++){ | |
| + var c=n[i]; | |
| + var d=c.getAttribute("data-method-id"); | |
| + if(d==k){ | |
| + return c.getAttribute("data-url"); | |
| + } | |
| + } | |
| + } | |
| + return k; | |
| + }; | |
| + p.$=function(){return $(this.jz());}; | |
| + p.$find=function(){ | |
| + var elt=this.$(); | |
| + return elt.find.apply(elt, arguments); | |
| + }; | |
| + } | |
| + | |
| + if (typeof(HTMLElement)!=="undefined") { | |
| + bind(HTMLElement.prototype); | |
| + } else {//Workaround for IE7, 8 | |
| + window.attachEvent("onload", function() {$(".jz").find("*").each(function() { | |
| + bind(this); | |
| + })}); | |
| + } | |
| +})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment