aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Browser.js24
-rw-r--r--test/BrowserSpecs.js24
2 files changed, 41 insertions, 7 deletions
diff --git a/src/Browser.js b/src/Browser.js
index d6b2b8d0..535396bd 100644
--- a/src/Browser.js
+++ b/src/Browser.js
@@ -416,16 +416,26 @@ function Browser(window, document, body, XHR, $log) {
* @methodOf angular.service.$browser
*
* @param {string} url Url to js file
- * @param {string=} dom_id Optional id for the script tag
+ * @param {string=} domId Optional id for the script tag
*
* @description
* Adds a script tag to the head.
*/
- self.addJs = function(url, dom_id) {
- var script = jqLite(rawDocument.createElement('script'));
- script.attr('type', 'text/javascript');
- script.attr('src', url);
- if (dom_id) script.attr('id', dom_id);
- body.append(script);
+ self.addJs = function(url, domId) {
+ // we can't use jQuery/jqLite here because jQuery does crazy shit with script elements, e.g.:
+ // - fetches local scripts via XHR and evals them
+ // - adds and immediately removes script elements from the document
+ //
+ // We need addJs to be able to add angular-ie-compat.js which is very special and must remain
+ // part of the DOM so that the embedded images can reference it. jQuery's append implementation
+ // (v1.4.2) fubars it.
+ var script = rawDocument.createElement('script');
+
+ script.type = 'text/javascript';
+ script.src = url;
+ if (domId) script.id = domId;
+ body[0].appendChild(script);
+
+ return script;
};
}
diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js
index 96839a1c..f87e98f8 100644
--- a/test/BrowserSpecs.js
+++ b/test/BrowserSpecs.js
@@ -505,4 +505,28 @@ describe('browser', function(){
});
});
});
+
+ describe('addJs', function() {
+
+ it('should append a script tag to body', function() {
+ browser.addJs('http://localhost/bar.js');
+ expect(scripts.length).toBe(1);
+ expect(scripts[0].src).toBe('http://localhost/bar.js');
+ expect(scripts[0].id).toBe('');
+ });
+
+
+ it('should append a script with an id to body', function() {
+ browser.addJs('http://localhost/bar.js', 'foo-id');
+ expect(scripts.length).toBe(1);
+ expect(scripts[0].src).toBe('http://localhost/bar.js');
+ expect(scripts[0].id).toBe('foo-id');
+ });
+
+
+ it('should return the appended script element', function() {
+ var script = browser.addJs('http://localhost/bar.js');
+ expect(script).toBe(scripts[0]);
+ });
+ });
});