cytoscape-clipboard
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -5,5 +5,5 @@ ;(function () { | ||
// registers the extension on a cytoscape lib ref | ||
var register = function (cytoscape) { | ||
var register = function (cytoscape, $) { | ||
if (!cytoscape) { | ||
if (!cytoscape || !$) { | ||
return; | ||
@@ -13,6 +13,17 @@ } // can't register if cytoscape unspecified | ||
var _instance; | ||
cytoscape('core', 'clipboard', function (opts) { | ||
var cy = this; | ||
var options = { | ||
clipboardSize: 0, | ||
beforeCopy: null, | ||
afterCopy: null, | ||
beforePaste: null, | ||
afterPaste: null | ||
}; | ||
$.extend(true, options, opts); | ||
function getScratch() { | ||
@@ -26,2 +37,5 @@ if (!cy.scratch("_clipboard")) { | ||
// get the scratchpad reserved for this extension on cy | ||
var scratchPad = getScratch(); | ||
var counter = 0; | ||
@@ -53,3 +67,3 @@ | ||
function changeIds(jsons) { | ||
jsons = [].concat(jsons); | ||
jsons = $.extend(true, [], jsons); | ||
for (var i = 0; i < jsons.length; i++) { | ||
@@ -82,8 +96,8 @@ var jsonFirst = jsons[i]; | ||
if (!getScratch().isInitialized) { | ||
getScratch().isInitialized = true; | ||
if (!scratchPad.isInitialized) { | ||
scratchPad.isInitialized = true; | ||
var ur; | ||
var clipboard = {}; | ||
_instance = { | ||
scratchPad.instance = { | ||
copy: function (eles, _id) { | ||
@@ -96,3 +110,9 @@ var id = _id ? _id : getItemId(); | ||
if(options.beforeCopy) { | ||
options.beforeCopy(nodes.union(edges)); | ||
} | ||
clipboard[id] = {nodes: nodes.jsons(), edges: edges.jsons()}; | ||
if(options.afterCopy) { | ||
options.afterCopy(clipboard[id]); | ||
} | ||
return id; | ||
@@ -103,2 +123,5 @@ }, | ||
var res = cy.collection(); | ||
if(options.beforePaste) { | ||
options.beforePaste(clipboard[id]); | ||
} | ||
if (clipboard[id]) { | ||
@@ -114,2 +137,5 @@ var nodes = changeIds(clipboard[id].nodes); | ||
} | ||
if(options.afterPaste) { | ||
options.afterPaste(res); | ||
} | ||
return res; | ||
@@ -122,3 +148,3 @@ } | ||
ur.action("paste", function (eles) { | ||
return eles.firstTime ? _instance.paste(eles.id) : eles.restore(); | ||
return eles.firstTime ? scratchPad.instance.paste(eles.id) : eles.restore(); | ||
}, function (eles) { | ||
@@ -130,3 +156,4 @@ return eles.remove(); | ||
} | ||
return _instance; // chainability | ||
return scratchPad.instance; // return the extension instance | ||
}); | ||
@@ -146,6 +173,6 @@ | ||
if (typeof cytoscape !== 'undefined') { // expose to global cytoscape (i.e. window.cytoscape) | ||
register(cytoscape); | ||
if (typeof cytoscape !== 'undefined' && typeof jQuery !== 'undefined') { // expose to global cytoscape (i.e. window.cytoscape) | ||
register(cytoscape, jQuery); | ||
} | ||
})(); |
@@ -20,3 +20,3 @@ var gulp = require('gulp'); | ||
gulp.task('publish', [], function( next ){ | ||
runSequence('confver', /*'lint',*/ 'pkgver','push', 'tag', 'npm', next); | ||
runSequence('confver', 'lint', 'pkgver','push', 'tag', 'npm', next); | ||
}); | ||
@@ -23,0 +23,0 @@ |
{ | ||
"name": "cytoscape-clipboard", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Adds copy-paste utilities to cytoscape.", | ||
@@ -5,0 +5,0 @@ "main": "cytoscape-clipboard.js", |
@@ -9,2 +9,6 @@ cytoscape-clipboard | ||
## Demo | ||
Click [here](https://rawgit.com/iVis-at-Bilkent/cytoscape.js-clipboard/master/demo.html) for demo | ||
## API | ||
@@ -33,3 +37,22 @@ | ||
var options = { | ||
clipboardSize: 0 | ||
clipboardSize: 0, | ||
// The following 4 options allow the user to provide custom behavior to | ||
// the extension. They can be used to maintain consistency of some data | ||
// when elements are duplicated. | ||
// These 4 options are set to null by default. The function prototypes | ||
// are provided below for explanation purpose only. | ||
// Function executed on the collection of elements being copied, before | ||
// they are serialized in the clipboard | ||
beforeCopy: function(eles) {}, | ||
// Function executed on the clipboard just after the elements are copied. | ||
// clipboard is of the form: {nodes: json, edges: json} | ||
afterCopy: function(clipboard) {}, | ||
// Function executed on the clipboard right before elements are pasted, | ||
// when they are still in the clipboard. | ||
beforePaste: function(clipboard) {}, | ||
// Function executed on the collection of pasted elements, after they | ||
// are pasted. | ||
afterPaste: function(eles) {} | ||
}; | ||
@@ -36,0 +59,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
111
3
3
33337
8
618