Created
February 19, 2014 16:56
-
-
Save alderg/9096287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var clipboardKey = '.drawio-clipboard'; | |
mxClipboard.isEmpty = function() | |
{ | |
return localStorage.getItem(clipboardKey) == null; | |
}; | |
mxClipboard.setCells = function(cells) | |
{ | |
var codec = new mxCodec(); | |
var model = new mxGraphModel(); | |
var parent = model.getChildAt(model.getRoot(), 0); | |
for (var i = 0; i < cells.length; i++) | |
{ | |
model.add(parent, cells[i]); | |
} | |
localStorage.setItem(clipboardKey, mxUtils.getXml(codec.encode(model))); | |
}; | |
mxClipboard.getCells = function() | |
{ | |
var xml = localStorage.getItem(clipboardKey); | |
var doc = mxUtils.parseXml(xml); | |
var codec = new mxCodec(doc); | |
var model = codec.decode(doc.documentElement); | |
var parent = model.getChildAt(model.getRoot(), 0); | |
var childCount = model.getChildCount(parent); | |
var cells = []; | |
for (var i = 0; i < childCount; i++) | |
{ | |
cells.push(model.getChildAt(parent, i)); | |
} | |
return cells; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment