Skip to content

Commit

Permalink
Merge branch 'patch-1' of github.com:stryju/SVGInjector into stryju-p…
Browse files Browse the repository at this point in the history
…atch-1

Conflicts:
	svg-injector.js
  • Loading branch information
protodave committed Jun 27, 2014
2 parents 8066bf6 + 972fdf6 commit 56d22c0
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions svg-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@
return out.join(' ');
}

/**
* cache (or polyfill for <= IE8) Array.forEach()
* source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
*/
var forEach = Array.prototype.forEach || function (fn, scope) {
if (this === void 0 || this === null || typeof fn !== 'function') {
throw new TypeError();
}

/* jshint bitwise: false */
var i, len = this.length >>> 0;
/* jshint bitwise: true */

for (i = 0; i < len; ++i) {
if (i in this) {
fn.call(scope, this[i], i, this);
}
}
};

// SVG Cache
var svgCache = {};

Expand Down Expand Up @@ -229,7 +249,7 @@
var imgData = [].filter.call(el.attributes, function (at) {
return (/^data-\w[\w\-]*$/).test(at.name);
});
Array.prototype.forEach.call(imgData, function (dataAttr) {
forEach.call(imgData, function (dataAttr) {
if (dataAttr.name && dataAttr.value) {
svg.setAttribute(dataAttr.name, dataAttr.value);
}
Expand Down Expand Up @@ -313,28 +333,6 @@
});
};

/**
* Array.forEach() polyfill for <= IE8
* source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
*/
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fn, scope) {
if (this === void 0 || this === null || typeof fn !== 'function') {
throw new TypeError();
}

/* jshint bitwise: false */
var i, len = this.length >>> 0;
/* jshint bitwise: true */

for (i = 0; i < len; ++i) {
if (i in this) {
fn.call(scope, this[i], i, this);
}
}
};
}

/**
* SVGInjector
*
Expand Down Expand Up @@ -370,7 +368,7 @@
// Do the injection...
if (elements.length !== undefined) {
var elementsLoaded = 0;
Array.prototype.forEach.call(elements, function (element) {
forEach.call(elements, function (element) {
injectElement(element, evalScripts, pngFallback, function (svg) {
if (eachCallback && typeof (eachCallback) === 'function') eachCallback(svg);
if (done && elements.length === ++elementsLoaded) done(elementsLoaded);
Expand Down

0 comments on commit 56d22c0

Please sign in to comment.