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 media = '';
13        if (typeof $diagram.data('id') !== "undefined") {
14            media = $diagram.data('id');
15        }
16
17        // download
18        diagramActions.prepend(ButtonFunctions.getDownloadButton('svg', url, media));
19        if (pngcache) {
20            diagramActions.prepend(ButtonFunctions.getDownloadButton('png', pngcache, media));
21        }
22
23        // open
24        diagramActions.prepend(ButtonFunctions.getOpenButton(url));
25    });
26});
27