diff --git a/Docs/Types/String.md b/Docs/Types/String.md index 9656e8e79..0093d1c06 100644 --- a/Docs/Types/String.md +++ b/Docs/Types/String.md @@ -385,7 +385,12 @@ Strips the String of its * tags. +* (*string*) - The stripped text. +* (*array*) - Array of urls of external JavaScript files (if any). +* (*function*) - Callback function that executes all stripped JavaScript (inline + external) synchronously. ### Returns: @@ -396,6 +401,18 @@ Strips the String of its *Hello, World."; myString.stripScripts(); // returns 'Hello, World.' myString.stripScripts(true); // alerts 'Hello', then returns 'Hello, World.' + + var html = '
' + + '' + + ''; + html.stripScripts(function(code, html, urls, exec){ + // inject the stripped HTML + document.body.innerHTML = html; + // execute all JavaScript + exec(function(){ + alert('All scripts loaded and executed!'); + }); + }); diff --git a/Source/Browser/Browser.js b/Source/Browser/Browser.js index e59b16c9a..3e82faffa 100644 --- a/Source/Browser/Browser.js +++ b/Source/Browser/Browser.js @@ -144,13 +144,40 @@ Browser.exec = function(text){ }; String.implement('stripScripts', function(exec){ - var scripts = ''; - var text = this.replace(/'.stripScripts(true)).toEqual(''); expect(window.stripScriptsSpec).toEqual(42); - expect(''.stripScripts(true)).toEqual(''); + expect(''.stripScripts(true)).toEqual(''); expect(window.stripScriptsSpec).toEqual(24); expect(''.stripScripts(true)).toEqual(''); expect(window.stripScriptsSpec).toEqual(4242); }); + + it('should load & execute script files synchronously', function(){ + var div = new Element('div').inject(document.body); + [ + '', + '', + '', + '', + '', + '' + ].join('').stripScripts(function(code, html, urls, fn){ + div.set('html', html); + fn(); + expect(div.get('text')).toEqual('dynamic content'); + }); + }); });