Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-sprite-loader

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-sprite-loader - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

10

lib/web/global-sprite.js
var Sprite = require('./sprite');
var globalSprite = new Sprite();
document.addEventListener('DOMContentLoaded', function () {
if (document.body) {
globalSprite.elem = globalSprite.render(document.body);
}, false);
} else {
document.addEventListener('DOMContentLoaded', function () {
globalSprite.elem = globalSprite.render(document.body);
}, false);
}
module.exports = globalSprite;
module.exports = globalSprite;

@@ -13,2 +13,6 @@ /**

var svgOpening = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink"';
var svgClosing = '</svg>';
var contentPlaceHolder = '{content}';
/**

@@ -24,3 +28,4 @@ * Representation of SVG sprite

Sprite.template = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink" style="'+ Sprite.styles.join(';') +'"><defs>{content}</defs></svg>';
Sprite.spriteTemplate = svgOpening + ' style="'+ Sprite.styles.join(';') +'"><defs>' + contentPlaceHolder + '</defs>' + svgClosing;
Sprite.symbolTemplate = svgOpening + '>' + contentPlaceHolder + svgClosing;

@@ -36,5 +41,21 @@ /**

Sprite.prototype.add = function (content) {
if (this.svg) {
this.appendSymbol(content);
}
this.content.push(content);
};
Sprite.prototype.wrapSVG = function (content, template) {
var svgString = template.replace(contentPlaceHolder, content);
return new DOMParser().parseFromString(svgString, 'image/svg+xml').documentElement;
};
Sprite.prototype.appendSymbol = function (content) {
var symbol = this.wrapSVG(content, Sprite.symbolTemplate).childNodes[0];
this.svg.querySelector('defs').appendChild(symbol);
};
/**

@@ -55,7 +76,6 @@ * @returns {String}

Sprite.prototype.render = function (target, prepend) {
var target = target || null;
var prepend = typeof prepend === 'boolean' ? prepend : true;
target = target || null;
prepend = typeof prepend === 'boolean' ? prepend : true;
var svgString = Sprite.template.replace('{content}', this.content.join(''));
var svg = new DOMParser().parseFromString(svgString, 'image/svg+xml').documentElement;
var svg = this.wrapSVG(this.content.join(''), Sprite.spriteTemplate);

@@ -68,10 +88,14 @@ // Because of Firefox bug #353575 gradients and patterns don't work if they are within a symbol.

if (target) {
prepend
? target.insertBefore(svg, target.childNodes[0])
: target.appendChild(svg);
if (prepend && target.childNodes[0]) {
target.insertBefore(svg, target.childNodes[0]);
} else {
target.appendChild(svg);
}
}
this.svg = svg;
return svg;
};
module.exports = Sprite;
module.exports = Sprite;
{
"name": "svg-sprite-loader",
"version": "0.0.5",
"version": "0.0.6",
"description": "SVG sprite webpack loader",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc