xref: /plugin/diagrams/script/download.js (revision baaaacc00af46798eefbccf0df34df85bfc68b4e)
1/**
2 * Attach download and open buttons to diagrams
3 */
4document.addEventListener('DOMContentLoaded', () => {
5
6    document.querySelectorAll('div.diagrams-buttons').forEach(diagramActions => {
7        $diagram = jQuery(diagramActions.parentNode.querySelector('object.diagrams-svg'));
8        const url = $diagram.attr('data');
9        const cacheurl = $diagram.data('cached');
10
11        let fileName = 'diagram';
12        if (typeof $diagram.data('id') !== "undefined") {
13            fileName = $diagram.data('id').split(':').pop();
14        }
15
16        // download
17        diagramActions.prepend(DiagramsFunctions.getDownloadButton('SVG', url, fileName));
18        if (cacheurl) {
19            diagramActions.prepend(DiagramsFunctions.getDownloadButton('PNG', cacheurl, fileName));
20        }
21
22        // open
23        diagramActions.prepend(DiagramsFunctions.getOpenButton(url));
24    });
25});
26
27
28