diff --git a/build/aui-parse-content/aui-parse-content-debug.js b/build/aui-parse-content/aui-parse-content-debug.js index dfc1e557e89..749a89946ec 100644 --- a/build/aui-parse-content/aui-parse-content-debug.js +++ b/build/aui-parse-content/aui-parse-content-debug.js @@ -24,6 +24,7 @@ var L = A.Lang, PARSE_CONTENT = 'ParseContent', QUEUE = 'queue', SCRIPT = 'script', + SEMICOLON = ';', SRC = 'src', SCRIPT_TYPES = { @@ -146,6 +147,7 @@ var ParseContent = A.Component.create( */ parseContent: function(content) { var instance = this; + var output = instance._clean(content); instance._dispatch(output); @@ -153,6 +155,26 @@ var ParseContent = A.Component.create( return output; }, + /** + * Add inline script data to the queue. + * + * @method _addInlineScript + * @param {String} data The script content which should be added to the queue + * @protected + */ + _addInlineScript: function(data) { + var instance = this; + + instance.get(QUEUE).add( + { + args: data, + context: instance, + fn: instance.globalEval, + timeout: 0 + } + ); + }, + /** * Bind listeners on the insert and setContent * methods of the Node instance where you are plugging the ParseContent. @@ -242,12 +264,21 @@ var ParseContent = A.Component.create( */ _dispatch: function(output) { var instance = this; + var queue = instance.get(QUEUE); + var scriptContent = []; + output.js.each(function(node, i) { var src = node.get(SRC); if (src) { + if (scriptContent.length) { + instance._addInlineScript(scriptContent.join(SEMICOLON)); + + scriptContent.length = 0; + } + queue.add({ autoContinue: false, fn: function () { @@ -262,19 +293,16 @@ var ParseContent = A.Component.create( }); } else { - queue.add({ - fn: function () { - var dom = node._node; + var dom = node._node; - instance.globalEval( - dom.text || dom.textContent || dom.innerHTML || '' - ); - }, - timeout: 0 - }); + scriptContent.push(dom.text || dom.textContent || dom.innerHTML || ''); } }); + if (scriptContent.length) { + instance._addInlineScript(scriptContent.join(SEMICOLON)); + } + queue.run(); } } diff --git a/build/aui-parse-content/aui-parse-content-min.js b/build/aui-parse-content/aui-parse-content-min.js index 63f8cb3f464..46f3d98aaf0 100644 --- a/build/aui-parse-content/aui-parse-content-min.js +++ b/build/aui-parse-content/aui-parse-content-min.js @@ -1 +1 @@ -AUI.add("aui-parse-content",function(d){var l=d.Lang,c=l.isString,m="append",a="documentElement",o="firstChild",i="head",n="host",f="innerHTML",g="ParseContent",e="queue",k="script",h="src",j={"":1,"text/javascript":1};var b=d.Component.create({NAME:g,NS:g,ATTRS:{queue:{value:null}},EXTENDS:d.Plugin.Base,prototype:{initializer:function(){var p=this;b.superclass.initializer.apply(this,arguments);p.set(e,new d.AsyncQueue());p._bindAOP();},globalEval:function(r){var s=d.getDoc();var q=s.one(i)||s.get(a);var p=document.createElement(k);p.type="text/javascript";if(r){p.text=l.trim(r);}q.appendChild(p).remove();},parseContent:function(r){var p=this;var q=p._clean(r);p._dispatch(q);return q;},_bindAOP:function(){var q=this;var p=function(u){var t=Array.prototype.slice.call(arguments);var s=q.parseContent(u);t.splice(0,1,s.fragment);return new d.Do.AlterArgs(null,t);};this.doBefore("insert",p);this.doBefore("replaceChild",p);var r=function(t){var s=q.parseContent(t);return new d.Do.AlterArgs(null,[s.fragment]);};this.doBefore("replace",r);this.doBefore("setContent",r);},_clean:function(r){var p={};var q=d.Node.create("
");q.append("
_
");if(c(r)){d.DOM.addHTML(q,r,m);}else{q.append(r);}p.js=q.all(k).filter(function(s){return j[s.getAttribute("type").toLowerCase()];});p.js.each(function(t,s){t.remove();});q.get(o).remove();p.fragment=q.get("childNodes").toFrag();return p;},_dispatch:function(r){var q=this;var p=q.get(e);r.js.each(function(t,s){var u=t.get(h);if(u){p.add({autoContinue:false,fn:function(){d.Get.script(u,{onEnd:function(v){v.purge();p.run();}});},timeout:0});}else{p.add({fn:function(){var v=t._node;q.globalEval(v.text||v.textContent||v.innerHTML||"");},timeout:0});}});p.run();}}});d.namespace("Plugin").ParseContent=b;},"@VERSION@",{skinnable:false,requires:["async-queue","aui-base","plugin"]}); \ No newline at end of file +AUI.add("aui-parse-content",function(d){var l=d.Lang,c=l.isString,n="append",a="documentElement",p="firstChild",i="head",o="host",f="innerHTML",g="ParseContent",e="queue",k="script",m=";",h="src",j={"":1,"text/javascript":1};var b=d.Component.create({NAME:g,NS:g,ATTRS:{queue:{value:null}},EXTENDS:d.Plugin.Base,prototype:{initializer:function(){var q=this;b.superclass.initializer.apply(this,arguments);q.set(e,new d.AsyncQueue());q._bindAOP();},globalEval:function(s){var t=d.getDoc();var r=t.one(i)||t.get(a);var q=document.createElement(k);q.type="text/javascript";if(s){q.text=l.trim(s);}r.appendChild(q).remove();},parseContent:function(s){var q=this;var r=q._clean(s);q._dispatch(r);return r;},_addInlineScript:function(r){var q=this;q.get(e).add({args:r,context:q,fn:q.globalEval,timeout:0});},_bindAOP:function(){var r=this;var q=function(v){var u=Array.prototype.slice.call(arguments);var t=r.parseContent(v);u.splice(0,1,t.fragment);return new d.Do.AlterArgs(null,u);};this.doBefore("insert",q);this.doBefore("replaceChild",q);var s=function(u){var t=r.parseContent(u);return new d.Do.AlterArgs(null,[t.fragment]);};this.doBefore("replace",s);this.doBefore("setContent",s);},_clean:function(s){var q={};var r=d.Node.create("
");r.append("
_
");if(c(s)){d.DOM.addHTML(r,s,n);}else{r.append(s);}q.js=r.all(k).filter(function(t){return j[t.getAttribute("type").toLowerCase()];});q.js.each(function(u,t){u.remove();});r.get(p).remove();q.fragment=r.get("childNodes").toFrag();return q;},_dispatch:function(t){var r=this;var q=r.get(e);var s=[];t.js.each(function(v,u){var x=v.get(h);if(x){if(s.length){r._addInlineScript(s.join(m));s.length=0;}q.add({autoContinue:false,fn:function(){d.Get.script(x,{onEnd:function(y){y.purge();q.run();}});},timeout:0});}else{var w=v._node;s.push(w.text||w.textContent||w.innerHTML||"");}});if(s.length){r._addInlineScript(s.join(m));}q.run();}}});d.namespace("Plugin").ParseContent=b;},"@VERSION@",{skinnable:false,requires:["async-queue","aui-base","plugin"]}); \ No newline at end of file diff --git a/build/aui-parse-content/aui-parse-content.js b/build/aui-parse-content/aui-parse-content.js index dfc1e557e89..749a89946ec 100644 --- a/build/aui-parse-content/aui-parse-content.js +++ b/build/aui-parse-content/aui-parse-content.js @@ -24,6 +24,7 @@ var L = A.Lang, PARSE_CONTENT = 'ParseContent', QUEUE = 'queue', SCRIPT = 'script', + SEMICOLON = ';', SRC = 'src', SCRIPT_TYPES = { @@ -146,6 +147,7 @@ var ParseContent = A.Component.create( */ parseContent: function(content) { var instance = this; + var output = instance._clean(content); instance._dispatch(output); @@ -153,6 +155,26 @@ var ParseContent = A.Component.create( return output; }, + /** + * Add inline script data to the queue. + * + * @method _addInlineScript + * @param {String} data The script content which should be added to the queue + * @protected + */ + _addInlineScript: function(data) { + var instance = this; + + instance.get(QUEUE).add( + { + args: data, + context: instance, + fn: instance.globalEval, + timeout: 0 + } + ); + }, + /** * Bind listeners on the insert and setContent * methods of the Node instance where you are plugging the ParseContent. @@ -242,12 +264,21 @@ var ParseContent = A.Component.create( */ _dispatch: function(output) { var instance = this; + var queue = instance.get(QUEUE); + var scriptContent = []; + output.js.each(function(node, i) { var src = node.get(SRC); if (src) { + if (scriptContent.length) { + instance._addInlineScript(scriptContent.join(SEMICOLON)); + + scriptContent.length = 0; + } + queue.add({ autoContinue: false, fn: function () { @@ -262,19 +293,16 @@ var ParseContent = A.Component.create( }); } else { - queue.add({ - fn: function () { - var dom = node._node; + var dom = node._node; - instance.globalEval( - dom.text || dom.textContent || dom.innerHTML || '' - ); - }, - timeout: 0 - }); + scriptContent.push(dom.text || dom.textContent || dom.innerHTML || ''); } }); + if (scriptContent.length) { + instance._addInlineScript(scriptContent.join(SEMICOLON)); + } + queue.run(); } }