diff --git a/example/app.css b/example/app.css index c0c0de5b..cde5562a 100644 --- a/example/app.css +++ b/example/app.css @@ -16,6 +16,7 @@ a:link { text-decoration: none; } + .content, .content > div { width: 100%; @@ -65,6 +66,23 @@ a:link { position: fixed; bottom: 20px; left: 20px; + + padding: 0; + margin: 0; + list-style: none; +} + +.buttons > li { + display: inline-block; + padding: 5px; +} + +.buttons a { + opacity: 0.3; +} + +.buttons a.active { + opacity: 1.0; } .logo { diff --git a/example/app.js b/example/app.js index 0d2a4147..2ebff033 100644 --- a/example/app.js +++ b/example/app.js @@ -1,14 +1,8 @@ -(function() { - - var Viewer = require('bpmn/Viewer'), - Modeler = require('bpmn/Modeler'), - Model = require('bpmn/Model'); +(function(BpmnJS) { var container = $('#js-drop-zone'); var canvas = $('#js-canvas'); - - var BpmnJS = canvas.is('.modeler') ? Modeler : Viewer; var renderer = new BpmnJS(canvas.get(0)); @@ -42,7 +36,7 @@ container.find('.error pre').text(err.message); - console.warn('[import] ' + err.message); + console.error(err); } else { container .removeClass('with-error') @@ -51,15 +45,15 @@ }); } + function saveSVG(done) { + renderer.saveSVG(done); + } + function saveDiagram(done) { - var definitions = renderer.definitions; - - if (definitions) { - Model.toXML(definitions, { format: true }, function(err, xml) { - done(err, xml); - }); - } + renderer.saveXML({ format: true }, function(err, xml) { + done(err, xml); + }); } ////// file drag / drop /////////////////////// @@ -115,23 +109,39 @@ }); var downloadLink = $('#js-download-diagram'); + var downloadSvgLink = $('#js-download-svg'); - setInterval(function() { - saveDiagram(function(err, xml) { + $('.buttons a').click(function(e) { + if (!$(this).is('.active')) { + e.preventDefault(); + e.stopPropagation(); + } + }); + + function setEncoded(link, name, data) { + var encodedData = encodeURIComponent(data); - if (!xml || err) { - return; - } - - var encoded = encodeURIComponent(xml); - - downloadLink.attr({ - 'href': 'data:application/bpmn20-xml;charset=UTF-8,' + encoded, - 'download': 'diagram.bpmn' + if (data) { + link.addClass('active').attr({ + 'href': 'data:application/bpmn20-xml;charset=UTF-8,' + encodedData, + 'download': name }); + } else { + link.removeClass('active'); + } + } + + setInterval(function() { + + saveSVG(function(err, svg) { + setEncoded(downloadSvgLink, 'diagram.svg', err ? null : svg); + }); + + saveDiagram(function(err, xml) { + setEncoded(downloadLink, 'diagram.bpmn', err ? null : xml); }); }, 5000); }); -})(); \ No newline at end of file +})(window.BpmnJS); \ No newline at end of file diff --git a/example/diagram-js.css b/example/diagram-js.css index cdc85c9d..f82c0248 100644 --- a/example/diagram-js.css +++ b/example/diagram-js.css @@ -50,7 +50,6 @@ .djs-hit { stroke-opacity: 0.0; stroke-width: 10px; - stroke: fuchsia; fill: none; } diff --git a/example/index.html b/example/index.html index 6c0f3d3c..8d30097d 100644 --- a/example/index.html +++ b/example/index.html @@ -28,19 +28,31 @@ -
+ - + + + +