1jQuery(function () { 2 /* DOKUWIKI:include script/DiagramsEditor.js */ 3 /* DOKUWIKI:include script/helpers.js */ 4 /* DOKUWIKI:include script/service.js */ 5 /* DOKUWIKI:include script/elements.js */ 6 /* DOKUWIKI:include script/mediamanager.js */ 7 /* DOKUWIKI:include script/embed.js */ //FIXME load only if mode enabled 8 9 // add diagram edit button to diagram SVGs included in wiki pages 10 const $images = jQuery('object').filter('.diagrams-svg'); 11 12 // collect image IDs with file extension 13 const imageIds = $images.map(function (key, image) { 14 return extractIdFromMediaUrl(image.data); 15 }).toArray(); 16 17 let ajaxData = {}; 18 ajaxData['call'] = 'plugin_diagrams_images'; 19 ajaxData['images'] = imageIds; 20 21 // callback to attach buttons to editable diagrams 22 const attachButtons = function (result) { 23 const diagrams = JSON.parse(result); 24 $images.each(function () { 25 const id = extractIdFromMediaUrl(this.data); 26 const $current = jQuery(this); 27 if (diagrams.includes(id)) { 28 let $editButton = editDiagramButton(id); 29 if ($current.parent()[0].nodeName === 'A') { 30 $current.parent().after("<br>", $editButton); 31 } else { 32 $current.after("<br>", $editButton); 33 } 34 } 35 }); 36 }; 37 38 // query backend about permissions and SVG properties before attaching edit buttons 39 jQuery.get( 40 DOKU_BASE + 'lib/exe/ajax.php', 41 ajaxData, 42 attachButtons 43 ); 44 45 46}); 47 48// open links in diagrams in the browser window instead of SVG frame 49jQuery(window).on('load', function() { 50 jQuery('object.diagrams-svg').each( function() { 51 jQuery(this.contentDocument).find('svg').find('a').attr({'target': '_parent', 'style': 'pointer-events: all;'}); 52 }); 53}); 54