xref: /plugin/bpmnio/script.js (revision 1268b482a22742dddd77057f72f0957b66d8ccf7)
1jQuery(document).ready(function() {
2    jQuery("textarea[id^=__bpmnio_]").each(function(i, tag) { try {
3        var xml = jQuery(tag).text();
4	var id = jQuery(tag).attr('id');
5	// avoid doing it twice
6	jQuery(tag).removeAttr('id');
7        // bundle exposes the viewer / modeler via the BpmnJS variable
8  	var BpmnViewer = window.BpmnJS;
9  	var containerdiv = document.createElement('div');
10  	containerdiv.className = "canvas";
11  	jQuery(tag).parent().append(containerdiv);
12  	var viewer = new BpmnViewer({ container: containerdiv });
13	viewer.importXML(xml, function(err) {
14	    if (err) {
15	        containerdiv.text = err;
16      	        console.log('error rendering', err);
17    	    } else {
18                var canvas = viewer.get('canvas');
19                // hack: adjust the div height because it doesn't automatically..
20                var bBox = canvas._viewport.node.getBBox();
21                var height = bBox.height + 5;
22                containerdiv.style.height = "" + height + 'px';
23            }
24	});
25	jQuery(tag).remove();
26    }catch(err){
27        console.warn(err.message);
28    }});
29});
30