Skip to content

Commit

Permalink
chg: dev: more stable patch for mxgraph viewer (refs #105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Tessaro committed Jan 6, 2022
1 parent 36f276f commit 5e8671a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions assets/javascripts/drawioEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,12 @@ window.onDrawioViewerLoad = function() {
// To not keep a patched version of the `viewer-static.min.js` file, I will patch it runtime.
// Maybe it will broke in the future, but for now is working.

// Patch the code
//var code = GraphViewer.prototype.addToolbar.toString().replace(/t\.enabled\?t\.handler:function/, 't.enabled?("string"===typeof(t.handler)?eval(t.handler):t.handler):function');
var code = GraphViewer.prototype.addToolbar.toString().replace(/([a-z])\.enabled\?\n?\1\.handler:function/, '$1.enabled?("string"===typeof($1.handler)?eval($1.handler):$1.handler):function');
// Patch the code `mxEvent.addListener(g,"click",b)`
var code = GraphViewer.prototype.addToolbar.toString();
var searchRegex = /mxEvent\.addListener\(([a-zA-Z]),"click",([a-zA-Z])\)/;
var replaceRules = "mxEvent.addListener($1,\"click\",(typeof($2)==='string'?eval($2):$2))";

code = code.replace(searchRegex, replaceRules);
// Apply the patch
GraphViewer.prototype.addToolbar = eval("("+code+")");
// Draw graphs
Expand Down

0 comments on commit 5e8671a

Please sign in to comment.