Created
April 4, 2013 12:53
-
-
Save davidjgraph/5310121 to your computer and use it in GitHub Desktop.
The patch used in draw.io to load diagrams that had their outer XML element stripped by saving in Firefox 20
This file contains 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
/** | |
* Sets the XML node for the current diagram. | |
*/ | |
Editor.prototype.setGraphXml = function(node) | |
{ | |
var dec = new mxCodec(node.ownerDocument); | |
if (node.nodeName == 'mxGraphModel') | |
{ | |
this.graph.view.scale = 1; | |
this.graph.gridEnabled = node.getAttribute('grid') != '0'; | |
this.graph.graphHandler.guidesEnabled = node.getAttribute('guides') != '0'; | |
this.graph.setTooltips(node.getAttribute('tooltips') != '0'); | |
this.graph.setConnectable(node.getAttribute('connect') != '0'); | |
this.graph.foldingEnabled = node.getAttribute('fold') != '0'; | |
this.graph.scrollbars = node.getAttribute('scrollbars') != '0'; | |
if (!this.graph.scrollbars) | |
{ | |
this.graph.container.scrollLeft = 0; | |
this.graph.container.scrollTop = 0; | |
this.graph.view.translate.x = Number(node.getAttribute('dx') || 0); | |
this.graph.view.translate.y = Number(node.getAttribute('dy') || 0); | |
} | |
this.graph.pageVisible = node.getAttribute('page') == '1'; | |
this.graph.pageBreaksVisible = this.graph.pageVisible; | |
this.graph.preferPageSize = this.graph.pageBreaksVisible; | |
// Loads the persistent state settings | |
var ps = node.getAttribute('pageScale'); | |
if (ps != null) | |
{ | |
this.graph.pageScale = ps; | |
} | |
else | |
{ | |
this.graph.pageScale = 1.5; | |
} | |
var pw = node.getAttribute('pageWidth'); | |
var ph = node.getAttribute('pageHeight'); | |
if (pw != null && ph != null) | |
{ | |
this.graph.pageFormat = new mxRectangle(0, 0, parseFloat(pw), parseFloat(ph)); | |
this.outline.outline.pageFormat = this.graph.pageFormat; | |
} | |
// Loads the persistent state settings | |
var bg = node.getAttribute('background'); | |
if (bg != null && bg.length > 0) | |
{ | |
this.graph.background = bg; | |
} | |
dec.decode(node, this.graph.getModel()); | |
this.updateGraphComponents(); | |
} | |
else | |
{ | |
// Workaround for invalid XML output in Firefox 20 due to bug in mxUtils.getXml | |
var wrapper = dec.document.createElement('mxGraphModel'); | |
wrapper.appendChild(node); | |
dec.decode(wrapper, this.graph.getModel()); | |
this.updateGraphComponents(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment