/** * Copyright (c) 2020-2025, JGraph Holdings Ltd * Copyright (c) 2020-2025, draw.io AG */ /** * URL Parameters and protocol description are here: * * https://www.drawio.com/doc/faq/supported-url-parameters * * Parameters for developers: * * - dev=1: For developers only * - test=1: For developers only * - export=URL for export: For developers only * - ignoremime=1: For developers only (see DriveClient.js). Use Cmd-S to override mime. * - createindex=1: For developers only (see etc/build/README) * - filesupport=0: For developers only (see Editor.js in core) * - savesidebar=1: For developers only (see Sidebar.js) * - pages=1: For developers only (see Pages.js) * - lic=email: For developers only (see LicenseServlet.java) * -- * - networkshapes=1: For testing network shapes (temporary) */ // Parses URL parameters var urlParams = (function() { var result = new Object(); var params = window.location.search.slice(1).split('&'); for (var i = 0; i < params.length; i++) { var idx = params[i].indexOf('='); if (idx > 0) { result[params[i].substring(0, idx)] = params[i].substring(idx + 1); } } return result; })(); // Forces CDN caches by passing URL parameters via URL hash if (window.location.hash != null && window.location.hash.substring(0, 2) == '#P') { try { urlParams = JSON.parse(decodeURIComponent(window.location.hash.substring(2))); if (urlParams.hash != null) { window.location.hash = urlParams.hash; } } catch (e) { // ignore } } // Global variable for desktop var mxIsElectron = navigator.userAgent != null && navigator.userAgent.toLowerCase().indexOf(' electron/') > -1 && navigator.userAgent.indexOf(' draw.io/') > -1; // Redirects page if required if (urlParams['dev'] != '1') { (function() { var proto = window.location.protocol; if (!mxIsElectron) { var host = window.location.host; // Redirects apex, drive and rt to www if (host === 'draw.io' || host === 'rt.draw.io' || host === 'drive.draw.io') { host = 'www.draw.io'; } var href = proto + '//' + host + window.location.href.substring( window.location.protocol.length + window.location.host.length + 2); // Redirects if href changes if (href != window.location.href) { window.location.href = href; } } })(); } /** * Adds meta tag to the page. */ function mxmeta(name, content, httpEquiv) { try { var s = document.createElement('meta'); if (name != null) { s.setAttribute('name', name); } s.setAttribute('content', content); if (httpEquiv != null) { s.setAttribute('http-equiv', httpEquiv); } var t = document.getElementsByTagName('meta')[0]; t.parentNode.insertBefore(s, t); } catch (e) { // ignore } }; /** * Synchronously adds scripts to the page. */ function mxscript(src, onLoad, id, dataAppKey, noWrite, onError) { var defer = onLoad == null && !noWrite; if ((urlParams['dev'] != '1' && typeof document.createElement('canvas').getContext === "function") || onLoad != null || noWrite) { var s = document.createElement('script'); s.setAttribute('type', 'text/javascript'); s.setAttribute('defer', 'true'); s.setAttribute('src', src); if (id != null) { s.setAttribute('id', id); } if (dataAppKey != null) { s.setAttribute('data-app-key', dataAppKey); } if (onLoad != null) { var r = false; s.onload = s.onreadystatechange = function() { if (!r && (!this.readyState || this.readyState == 'complete')) { r = true; onLoad(); } }; } if (onError != null) { s.onerror = function(e) { onError('Failed to load ' + src, e); }; } var t = document.getElementsByTagName('script')[0]; if (t != null) { t.parentNode.insertBefore(s, t); } } else { document.write('