Skip to content

Commit

Permalink
Add removeElements plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
elidupuis committed Jul 6, 2016
1 parent e0ca3f0 commit f4b455a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
53 changes: 53 additions & 0 deletions plugins/removeElements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

exports.type = 'perItem';

exports.active = false;

exports.description = 'removes arbitrary elements by ID (disabled by default)';

exports.params = {
ids: []
};

/**
* Remove SVG elements by ID.
*
* @param ids
* examples:
*
* > single: remove element with ID of `elementID`
* ---
* removeElements:
* ids: 'elementID'
*
* > list: remove multiple elements by ID
* ---
* removeElements:
* ids:
* - 'elementID'
* - 'anotherID'
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Eli Dupuis
*/
exports.fn = function(item, params) {
var elemId;

// wrap into an array if params is not
if (!Array.isArray(params.ids)) {
params.ids = [params.ids];
}

if (!item.isElem()) {
return;
}

elemId = item.attr('id');
if (elemId) {
return params.ids.indexOf(elemId.value) === -1;
}
};
14 changes: 14 additions & 0 deletions test/plugins/removeElements.01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test/plugins/removeElements.02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/plugins/removeElements.03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f4b455a

Please sign in to comment.