Skip to content

Commit

Permalink
chore(release): 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kisenka committed Aug 16, 2017
1 parent 4056d7b commit 83dfbf1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="3.2.0"></a>
# [3.2.0](https://github.com/kisenka/svg-sprite-loader/compare/v3.1.7...v3.2.0) (2017-08-16)


### Features

* **runtime:** add ability to create sprite from existing DOM node ([4056d7b](https://github.com/kisenka/svg-sprite-loader/commit/4056d7b))



<a name="3.1.7"></a>
## [3.1.7](https://github.com/kisenka/svg-sprite-loader/compare/v3.1.6...v3.1.7) (2017-08-15)

Expand Down
38 changes: 30 additions & 8 deletions examples/browser-sprite-with-dll/build/dll.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,8 @@ var BrowserSprite = (function (Sprite$$1) {
* @return {Element|null} attached DOM Element. null if node to attach not found.
*/
BrowserSprite.prototype.attach = function attach (target) {
var this$1 = this;

var sprite = this;

if (sprite.isMounted) {
Expand All @@ -1233,15 +1235,23 @@ var BrowserSprite = (function (Sprite$$1) {

/** @type Element */
var node = typeof target === 'string' ? document.querySelector(target) : target;
sprite.node = node;

// Already added symbols needs to be mounted
this.symbols.forEach(function (symbol) {
symbol.mount(sprite.node);
this$1._emitter.emit(Events.SYMBOL_MOUNT, symbol.node);
});

// Create symbols from existing DOM nodes, add and mount them
arrayFrom(node.querySelectorAll('symbol'))
.forEach(function (symbolNode) {
var symbol = BrowserSpriteSymbol.createFromExistingNode(symbolNode);
symbol.node = symbolNode;
symbol.node = symbolNode; // hack to prevent symbol mounting to sprite when adding
sprite.add(symbol);
});

sprite.node = node;
this._emitter.emit(Events.MOUNT, node);

return node;
};
Expand Down Expand Up @@ -1366,21 +1376,33 @@ var ready$1 = createCommonjsModule(function (module) {
});
});

var globaVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[globaVarName];
var spriteNodeId = '__SVG_SPRITE_NODE__';
var spriteGlobalVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[spriteGlobalVarName];

// eslint-disable-next-line import/no-mutable-exports
var sprite;

if (isSpriteExists) {
sprite = window[globaVarName];
sprite = window[spriteGlobalVarName];
} else {
sprite = new BrowserSprite();
window[globaVarName] = sprite;
sprite = new BrowserSprite({ attrs: { id: spriteNodeId } });
window[spriteGlobalVarName] = sprite;
}

var loadSprite = function () {
sprite.mount(document.body, true);
/**
* Check for page already contains sprite node
* If found - attach to and reuse it's content
* If not - render and mount the new sprite
*/
var existing = document.getElementById(spriteNodeId);

if (existing) {
sprite.attach(existing);
} else {
sprite.mount(document.body, true);
}
};

if (document.body) {
Expand Down
38 changes: 30 additions & 8 deletions examples/browser-sprite/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,8 @@ var BrowserSprite = (function (Sprite$$1) {
* @return {Element|null} attached DOM Element. null if node to attach not found.
*/
BrowserSprite.prototype.attach = function attach (target) {
var this$1 = this;

var sprite = this;

if (sprite.isMounted) {
Expand All @@ -1220,15 +1222,23 @@ var BrowserSprite = (function (Sprite$$1) {

/** @type Element */
var node = typeof target === 'string' ? document.querySelector(target) : target;
sprite.node = node;

// Already added symbols needs to be mounted
this.symbols.forEach(function (symbol) {
symbol.mount(sprite.node);
this$1._emitter.emit(Events.SYMBOL_MOUNT, symbol.node);
});

// Create symbols from existing DOM nodes, add and mount them
arrayFrom(node.querySelectorAll('symbol'))
.forEach(function (symbolNode) {
var symbol = BrowserSpriteSymbol.createFromExistingNode(symbolNode);
symbol.node = symbolNode;
symbol.node = symbolNode; // hack to prevent symbol mounting to sprite when adding
sprite.add(symbol);
});

sprite.node = node;
this._emitter.emit(Events.MOUNT, node);

return node;
};
Expand Down Expand Up @@ -1353,21 +1363,33 @@ var ready$1 = createCommonjsModule(function (module) {
});
});

var globaVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[globaVarName];
var spriteNodeId = '__SVG_SPRITE_NODE__';
var spriteGlobalVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[spriteGlobalVarName];

// eslint-disable-next-line import/no-mutable-exports
var sprite;

if (isSpriteExists) {
sprite = window[globaVarName];
sprite = window[spriteGlobalVarName];
} else {
sprite = new BrowserSprite();
window[globaVarName] = sprite;
sprite = new BrowserSprite({ attrs: { id: spriteNodeId } });
window[spriteGlobalVarName] = sprite;
}

var loadSprite = function () {
sprite.mount(document.body, true);
/**
* Check for page already contains sprite node
* If found - attach to and reuse it's content
* If not - render and mount the new sprite
*/
var existing = document.getElementById(spriteNodeId);

if (existing) {
sprite.attach(existing);
} else {
sprite.mount(document.body, true);
}
};

if (document.body) {
Expand Down
38 changes: 30 additions & 8 deletions examples/custom-runtime-generator/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10629,6 +10629,8 @@ var BrowserSprite = (function (Sprite$$1) {
* @return {Element|null} attached DOM Element. null if node to attach not found.
*/
BrowserSprite.prototype.attach = function attach (target) {
var this$1 = this;

var sprite = this;

if (sprite.isMounted) {
Expand All @@ -10637,15 +10639,23 @@ var BrowserSprite = (function (Sprite$$1) {

/** @type Element */
var node = typeof target === 'string' ? document.querySelector(target) : target;
sprite.node = node;

// Already added symbols needs to be mounted
this.symbols.forEach(function (symbol) {
symbol.mount(sprite.node);
this$1._emitter.emit(Events.SYMBOL_MOUNT, symbol.node);
});

// Create symbols from existing DOM nodes, add and mount them
arrayFrom(node.querySelectorAll('symbol'))
.forEach(function (symbolNode) {
var symbol = BrowserSpriteSymbol.createFromExistingNode(symbolNode);
symbol.node = symbolNode;
symbol.node = symbolNode; // hack to prevent symbol mounting to sprite when adding
sprite.add(symbol);
});

sprite.node = node;
this._emitter.emit(Events.MOUNT, node);

return node;
};
Expand Down Expand Up @@ -10770,21 +10780,33 @@ var ready$1 = createCommonjsModule(function (module) {
});
});

var globaVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[globaVarName];
var spriteNodeId = '__SVG_SPRITE_NODE__';
var spriteGlobalVarName = '__SVG_SPRITE__';
var isSpriteExists = !!window[spriteGlobalVarName];

// eslint-disable-next-line import/no-mutable-exports
var sprite;

if (isSpriteExists) {
sprite = window[globaVarName];
sprite = window[spriteGlobalVarName];
} else {
sprite = new BrowserSprite();
window[globaVarName] = sprite;
sprite = new BrowserSprite({ attrs: { id: spriteNodeId } });
window[spriteGlobalVarName] = sprite;
}

var loadSprite = function () {
sprite.mount(document.body, true);
/**
* Check for page already contains sprite node
* If found - attach to and reuse it's content
* If not - render and mount the new sprite
*/
var existing = document.getElementById(spriteNodeId);

if (existing) {
sprite.attach(existing);
} else {
sprite.mount(document.body, true);
}
};

if (document.body) {
Expand Down
2 changes: 1 addition & 1 deletion examples/server-side-rendering/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Sprite.prototype.destroy = function destroy () {
this.symbols.forEach(function (s) { return s.destroy(); });
};

var sprite = new Sprite();
var sprite = new Sprite({ attrs: { id: '__SVG_SPRITE_NODE__' } });

return sprite;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-sprite-loader",
"version": "3.1.7",
"version": "3.2.0",
"description": "Webpack loader for creating SVG sprites",
"keywords": [
"svg",
Expand Down

0 comments on commit 83dfbf1

Please sign in to comment.