Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mark scripts so they can be removed easily

  • Loading branch information...
commit 5ee6c7bc194a869400a4861aa2a4f707b38e1dbf 1 parent 808fc95
@unscriptable authored
Showing with 17 additions and 16 deletions.
  1. +17 −16 src/curl/tdd/undefine.js
View
33 src/curl/tdd/undefine.js
@@ -9,11 +9,20 @@
*/
define(['curl/_privileged', 'require'], function (priv, require) {
- var cache, cleanupScript;
+ var cache, cleanupScript, loadScript;
cache = priv['cache'];
- cleanupScript = typeof document != 'undefined' ? removeScript : noop;
+ cleanupScript = noop;
+
+ if (typeof document != 'undefined') {
+ cleanupScript = removeScript;
+ loadScript = priv['core'].loadScript;
+ priv['core'].loadScript = function (def) {
+ var el = loadScript.apply(this, arguments);
+ el._curl_id = def.id;
+ }
+ }
/**
* Removes a module from curl.js's cache so that it can
@@ -22,30 +31,22 @@ define(['curl/_privileged', 'require'], function (priv, require) {
* @param moduleId {String|Array} the id of a module (or modules)
*/
return function undefine (moduleId) {
- var ids, id, url;
-
+ var ids, id;
ids = [].concat(moduleId);
while ((id = ids.pop())) {
- if (cache[id] instanceof priv.Promise) {
- url = require.toUrl(cache[id].ctxId || id);
- }
- else {
- url = require.toUrl(id);
- }
delete cache[id];
- cleanupScript(url);
+ cleanupScript(id);
}
};
- function removeScript (url) {
- var rx, scripts, i, script;
- rx = new RegExp(url + '($|\\.)', 'i');
+ function removeScript (id) {
+ var scripts, i, script;
scripts = document.getElementsByTagName('script');
i = 0;
while ((script = scripts[i++])) {
- if (rx.test(script.src)) {
+ if (script._curl_id == id) {
script.parentNode.removeChild(script);
- scripts = []; // all done!
+ return; // all done!
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.