fix sprite loader not working
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
;(function(window, document) {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var isSvg = document.createElementNS && document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ).createSVGRect;
|
var isSvg = document.createElementNS && document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ).createSVGRect;
|
||||||
var localStorage = 'localStorage' in window && window['localStorage'] !== null ? window.localStorage : false;
|
var localStorage = 'localStorage' in window && window['localStorage'] !== null ? window.localStorage : false;
|
||||||
|
|
||||||
function svgSpriteInjector(source, opts) {
|
function svgSpriteInjector(source, opts) {
|
||||||
var file;
|
var file;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
@@ -24,9 +23,9 @@
|
|||||||
} else {
|
} else {
|
||||||
console.error('svg-sprite-injector require ie9 or greater!');
|
console.error('svg-sprite-injector require ie9 or greater!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function injector(filepath, opts) {
|
function injector(filepath, opts) {
|
||||||
var name = 'injectedSVGSprite' + filepath,
|
var name = 'injectedSVGSprite' + filepath,
|
||||||
revision = opts.revision,
|
revision = opts.revision,
|
||||||
request;
|
request;
|
||||||
@@ -51,9 +50,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectOnLoad(data) {
|
function injectOnLoad(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
if (document.body) {
|
if (document.body) {
|
||||||
injectData(data);
|
injectData(data);
|
||||||
@@ -61,20 +60,14 @@
|
|||||||
document.addEventListener('DOMContentLoaded', injectData.bind(null, data));
|
document.addEventListener('DOMContentLoaded', injectData.bind(null, data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectData(data) {
|
function injectData(data) {
|
||||||
var body = document.body;
|
var body = document.body;
|
||||||
body.insertAdjacentHTML('afterbegin', data);
|
body.insertAdjacentHTML('afterbegin', data);
|
||||||
if (body.firstChild.tagName === 'svg') {
|
if (body.firstChild.tagName === 'svg') {
|
||||||
body.firstChild.style.display = 'none';
|
body.firstChild.style.display = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof exports === 'object') {
|
export default svgSpriteInjector;
|
||||||
module.exports = svgSpriteInjector;
|
|
||||||
} else {
|
|
||||||
window.svgSpriteInjector = svgSpriteInjector;
|
|
||||||
}
|
|
||||||
|
|
||||||
} (window, document));
|
|
||||||
|
|||||||
Reference in New Issue
Block a user