xref: /plugin/bpmnio/script.js (revision 2e6cafaff88f2424fe44dd99af778202ce4caa71)
1jQuery(document).ready(function() {
2    jQuery("textarea[id^=__bpmnio_]").each(function(i, tag) { try {
3    var xml = jQuery(tag).text();
4    xml = decodeURIComponent(escape(window.atob(xml)));
5  	var id = jQuery(tag).attr('id');
6	// avoid doing it twice
7	jQuery(tag).removeAttr('id');
8
9	// bundle exposes the viewer / modeler via the BpmnJS variable
10  	var BpmnViewer = window.BpmnJS;
11  	var containerdiv = document.createElement('div');
12  	containerdiv.className = "canvas";
13  	jQuery(tag).parent().append(containerdiv);
14  	var viewer = new BpmnViewer({ container: containerdiv });
15	viewer.importXML(xml, function(err) {
16	    if (err) {
17	        containerdiv.text = err;
18      	        console.log('error rendering', err);
19    	    } else {
20                var canvas = viewer.get('canvas');
21                var bboxViewport = canvas.getDefaultLayer().getBBox();
22                var bboxSvg = canvas.getSize();
23                canvas.viewbox({ x: bboxViewport.x, y: bboxViewport.y, width: bboxSvg.width, height: bboxSvg.height });
24                var height = bboxViewport.height + 4;
25                // hack: adjust the div height because it doesn't automatically.
26                containerdiv.style.height = "" + height + 'px';
27                containerdiv.style.width = "" + bboxViewport.width + 'px';
28                // Fix #3 by introducing a small space to allow clicks.
29                containerdiv.style.marginRight = "32px";
30            }
31	});
32	jQuery(tag).remove();
33    }catch(err){
34        console.warn(err.message);
35    }});
36});
37