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