// Re-evaluate scripts found in DOM
// Main use case is to run it on DOM nodes for which content was injected via innerHTML
// (as in such case browsers intercepts evaluation of injected scripts)

'use strict';

var aFrom            = require('es5-ext/array/from')
  , ensureCallable   = require('es5-ext/object/valid-callable')
  , ensureObject     = require('es5-ext/object/valid-object')
  , ensureParentNode = require('dom-ext/parent-node/ensure')

  , forEach = Array.prototype.forEach, push = Array.prototype.push, create = Object.create;

var reload = function (oldScript) {
	var nuScript = oldScript.ownerDocument.createElement('script');
	forEach.call(oldScript.attributes, function (attr) {
		nuScript.setAttribute(attr.name, attr.value);
	});
	forEach.call(oldScript.childNodes, function (node) {
		nuScript.appendChild(node.cloneNode(true));
	});
	oldScript.parentNode.insertBefore(nuScript, oldScript);
	oldScript.parentNode.removeChild(oldScript);
};

var getScripts = function (node, ignoredSources, filter) {
	if (node.getElementsByTagName) return aFrom(node.getElementsByTagName('script'));
	var result = [];
	forEach.call(node.childNodes, function (node) {
		if (node.nodeType !== 1) return;
		if (node.nodeName.toLowerCase() === 'script') {
			if (node.src && ignoredSources[node.src]) return;
			if (filter && !filter(node)) return;
			result.push(node);
			return;
		}
		push.apply(result, getScripts(node, ignoredSources, filter));
	});
	return result;
};

module.exports = exports = function (/* options */) {
	var options = Object(arguments[0]), filter;
	var ignoredSources = (options.ignoredSources != null)
		? ensureObject(options.ignoredSources) : create(null);
	if (options.filter != null) filter = ensureCallable(options.filter);
	getScripts(ensureParentNode(this), ignoredSources, filter).forEach(reload);
};

@@ -258,16 +258,75 @@
 /from')%0A
+  , includes         = require('es5-ext/array/#/includes')%0A
   , ensu
@@ -395,16 +395,16 @@
 sure
-Object  
+Iterable
    =
@@ -421,28 +421,33 @@
 es5-ext/
-object
+iterable
 /valid
+ate
 -object'
@@ -580,32 +580,8 @@
 push
-, create = Object.create
 ;%0A%0Av
@@ -1312,16 +1312,30 @@
 .src && 
+includes.call(
 ignoredS
@@ -1344,17 +1344,18 @@
 rces
-%5B
+, 
 node.src
 %5D) r
@@ -1350,17 +1350,17 @@
 node.src
-%5D
+)
 ) return
@@ -1689,20 +1689,28 @@
 %09%09? 
-ensureObject
+aFrom(ensureIterable
 (opt
@@ -1733,23 +1733,14 @@
 ces)
+)
  : 
-create(null)
+%5B%5D
 ;%0A%09i

Support ignoredSources as an array