Skip to content

Commit

Permalink
Merge branch 'stryju-patch-2'
Browse files Browse the repository at this point in the history
 to explain why this merge is necessary,
  • Loading branch information
protodave committed Jun 27, 2014
2 parents 70ec72e + 8f04917 commit fd321d6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions svg-injector.js
Expand Up @@ -51,6 +51,14 @@
}
};

function isFunction(value) {
return typeof value === 'function';
}

function isDefined(value) {
return typeof value !== 'undefined';
}

// SVG Cache
var svgCache = {};

Expand Down Expand Up @@ -85,10 +93,10 @@
};

var loadSvg = function (url, callback) {
if (svgCache[url] !== undefined) {
if (isDefined(svgCache[url])) {
if (svgCache[url] instanceof SVGSVGElement) {
// We already have it in cache, so use it
callback(svgCache[url].cloneNode(true));
callback(cloneSvg(svgCache[url]));
}
else {
// We don't have it in cache yet, but we are loading it, so queue this request
Expand Down Expand Up @@ -221,7 +229,7 @@
// Load it up
loadSvg(imgUrl, function (svg) {

if (svg === undefined || typeof svg === 'string') {
if (!isDefined(svg) || typeof svg === 'string') {
callback(svg);
return false;
}
Expand Down Expand Up @@ -366,19 +374,19 @@
var eachCallback = options.each;

// Do the injection...
if (elements.length !== undefined) {
if (isDefined(elements.length)) {
var elementsLoaded = 0;
forEach.call(elements, function (element) {
injectElement(element, evalScripts, pngFallback, function (svg) {
if (eachCallback && typeof (eachCallback) === 'function') eachCallback(svg);
if (isFunction(eachCallback)) eachCallback(svg);
if (done && elements.length === ++elementsLoaded) done(elementsLoaded);
});
});
}
else {
if (elements !== null) {
if (elements) {
injectElement(elements, evalScripts, pngFallback, function (svg) {
if (eachCallback && typeof (eachCallback) === 'function') eachCallback(svg);
if (isFunction(eachCallback)) eachCallback(svg);
if (done) done(1);
});
}
Expand All @@ -394,7 +402,7 @@
module.exports = exports = SVGInjector;
}
// AMD support
else if (typeof define === 'function' && define.amd) {
else if (isFunction(define) && define.amd) {
define(function () {
return SVGInjector;
});
Expand Down

0 comments on commit fd321d6

Please sign in to comment.