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