Skip to content

Instantly share code, notes, and snippets.

@alderg
Created February 19, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alderg/9096287 to your computer and use it in GitHub Desktop.
Save alderg/9096287 to your computer and use it in GitHub Desktop.
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