1/** 2 * Sample plugin. 3 */ 4Draw.loadPlugin(function(ui) { 5 6 // Sidebar is null in lightbox 7 if (ui.sidebar != null) 8 { 9 // Adds custom sidebar entry 10 ui.sidebar.addPalette('esolia', 'eSolia', true, function(content) { 11 12 // content.appendChild(ui.sidebar.createVertexTemplate(null, 120, 60)); 13 content.appendChild(ui.sidebar.createVertexTemplate('shape=image;image=http://download.esolia.net.s3.amazonaws.com/img/eSolia-Logo-Color.svg;resizable=0;movable=0;rotatable=0', 100, 100)); 14 content.appendChild(ui.sidebar.createVertexTemplate('text;spacingTop=-5;fontFamily=Courier New;fontSize=8;fontColor=#999999;resizable=0;movable=0;rotatable=0', 100, 100)); 15 content.appendChild(ui.sidebar.createVertexTemplate('rounded=1;whiteSpace=wrap;gradientColor=none;fillColor=#004C99;shadow=1;strokeColor=#FFFFFF;align=center;fontColor=#FFFFFF;strokeWidth=3;fontFamily=Courier New;verticalAlign=middle', 100, 100)); 16 content.appendChild(ui.sidebar.createVertexTemplate('curved=1;strokeColor=#004C99;endArrow=oval;endFill=0;strokeWidth=3;shadow=1;dashed=1', 100, 100)); 17 }); 18 19 // Collapses default sidebar entry and inserts this before 20 var c = ui.sidebar.container; 21 c.firstChild.click(); 22 c.insertBefore(c.lastChild, c.firstChild); 23 c.insertBefore(c.lastChild, c.firstChild); 24 25 // Adds logo to footer 26 ui.footerContainer.innerHTML = '<img width=50px height=17px align="right" style="margin-top:14px;margin-right:12px;" ' + 'src="http://download.esolia.net.s3.amazonaws.com/img/eSolia-Logo-Color.svg"/>'; 27 28 // Adds placeholder for %today% and %filename% 29 var graph = ui.editor.graph; 30 var graphGetGlobalVariable = graph.getGlobalVariable; 31 32 graph.getGlobalVariable = function(name) 33 { 34 if (name == 'today') 35 { 36 return new Date().toLocaleString(); 37 } 38 else if (name == 'filename') 39 { 40 var file = ui.getCurrentFile(); 41 42 return (file != null && file.getTitle() != null) ? file.getTitle() : ''; 43 } 44 45 return graphGetGlobalVariable.apply(this, arguments); 46 }; 47 48 // Adds support for exporting PDF with placeholders 49 var graphGetExportVariables = graph.getExportVariables; 50 51 Graph.prototype.getExportVariables = function() 52 { 53 var vars = graphGetExportVariables.apply(this, arguments); 54 var file = ui.getCurrentFile(); 55 56 vars['today'] = new Date().toLocaleString(); 57 vars['filename'] = (file != null && file.getTitle() != null) ? file.getTitle() : ''; 58 59 return vars; 60 }; 61 62// // Adds resource for action 63// mxResources.parse('helloWorldAction=Hello, World!'); 64// 65// // Adds action 66// ui.actions.addAction('helloWorldAction', function() { 67// var ran = Math.floor((Math.random() * 100) + 1); 68// mxUtils.alert('A random number is ' + ran); 69// }); 70// 71// // Adds menu 72// ui.menubar.addMenu('Hello, World Menu', function(menu, parent) { 73// ui.menus.addMenuItem(menu, 'helloWorldAction'); 74// }); 75// 76// // Reorders menubar 77// ui.menubar.container.insertBefore(ui.menubar.container.lastChild, 78// ui.menubar.container.lastChild.previousSibling.previousSibling); 79// 80// // Adds toolbar button 81// ui.toolbar.addSeparator(); 82// var elt = ui.toolbar.addItem('', 'helloWorldAction'); 83// 84// // Cannot use built-in sprites 85// elt.firstChild.style.backgroundImage = 'url(https://www.draw.io/images/logo-small.gif)'; 86// elt.firstChild.style.backgroundPosition = '2px 3px'; 87 } 88});