diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index e508748b..2fa69905 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -1005,13 +1005,13 @@ class Adminer { */ function syntaxHighlighting(array $tables): void { // this is matched by compile.php - echo script_src("../externals/jush/modules/jush.js"); - echo script_src("../externals/jush/modules/jush-autocomplete-sql.js"); - echo script_src("../externals/jush/modules/jush-textarea.js"); - echo script_src("../externals/jush/modules/jush-txt.js"); - echo script_src("../externals/jush/modules/jush-js.js"); + echo script_src("../externals/jush/modules/jush.js", true); + echo script_src("../externals/jush/modules/jush-autocomplete-sql.js", true); + echo script_src("../externals/jush/modules/jush-textarea.js", true); + echo script_src("../externals/jush/modules/jush-txt.js", true); + echo script_src("../externals/jush/modules/jush-js.js", true); if (support("sql")) { - echo script_src("../externals/jush/modules/jush-" . JUSH . ".js"); + echo script_src("../externals/jush/modules/jush-" . JUSH . ".js", true); echo "\n"; if ($tables) { $links = array(); @@ -1028,13 +1028,11 @@ class Adminer { $tablesColumns[$table][] = $field["field"]; } } - echo "autocompleter = jush.autocompleteSql('" . idf_escape("") . "', " . json_encode($tablesColumns) . ");\n"; + echo "addEventListener('DOMContentLoaded', () => { autocompleter = jush.autocompleteSql('" . idf_escape("") . "', " . json_encode($tablesColumns) . "); });\n"; } echo "\n"; } - echo script("syntaxHighlighting('" . preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) . "'" - . (connection()->flavor == 'maria' ? ", 'maria'" : (connection()->flavor == 'cockroach' ? ", 'cockroach'" : "")) . ");" - ); + echo script("syntaxHighlighting('" . preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) . "', '" . connection()->flavor . "');"); } /** Print databases list in menu */ diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index 91ce6cd8..575682cc 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -7,8 +7,8 @@ function script(string $source, string $trailing = "\n"): string { } /** Return \n"; +function script_src(string $url, bool $defer = false): string { + return "\n"; } /** Get a nonce="" attribute with CSP nonce */ diff --git a/adminer/static/editing.js b/adminer/static/editing.js index 61bd71ed..67a8a549 100644 --- a/adminer/static/editing.js +++ b/adminer/static/editing.js @@ -7,56 +7,58 @@ let autocompleter; // set in adminer.inc.php * @param [string] */ function syntaxHighlighting(version, vendor) { - if (window.jush) { - jush.create_links = 'target="_blank" rel="noreferrer noopener"'; - if (version) { - for (let key in jush.urls) { - let obj = jush.urls; - if (typeof obj[key] != 'string') { - obj = obj[key]; - key = 0; - if (vendor == 'maria') { - for (let i = 1; i < obj.length; i++) { - obj[i] = obj[i] - .replace('.html', '/') - .replace('-type-syntax', '-data-types') - .replace(/numeric-(data-types)/, '$1-$&') - .replace(/replication-options-(master|binary-log)\//, 'replication-and-binary-log-system-variables/') - .replace('server-options/', 'server-system-variables/') - .replace('innodb-parameters/', 'innodb-system-variables/') - .replace(/#(statvar|sysvar|option_mysqld)_(.*)/, '#$2') - .replace(/#sysvar_(.*)/, '#$1') - ; + addEventListener('DOMContentLoaded', () => { + if (window.jush) { + jush.create_links = 'target="_blank" rel="noreferrer noopener"'; + if (version) { + for (let key in jush.urls) { + let obj = jush.urls; + if (typeof obj[key] != 'string') { + obj = obj[key]; + key = 0; + if (vendor == 'maria') { + for (let i = 1; i < obj.length; i++) { + obj[i] = obj[i] + .replace('.html', '/') + .replace('-type-syntax', '-data-types') + .replace(/numeric-(data-types)/, '$1-$&') + .replace(/replication-options-(master|binary-log)\//, 'replication-and-binary-log-system-variables/') + .replace('server-options/', 'server-system-variables/') + .replace('innodb-parameters/', 'innodb-system-variables/') + .replace(/#(statvar|sysvar|option_mysqld)_(.*)/, '#$2') + .replace(/#sysvar_(.*)/, '#$1') + ; + } } } - } - obj[key] = (vendor == 'maria' ? obj[key].replace('dev.mysql.com/doc/mysql', 'mariadb.com/kb') : obj[key]) // MariaDB - .replace('/doc/mysql', '/doc/refman/' + version) // MySQL - ; - if (vendor != 'cockroach') { - obj[key] = obj[key].replace('/docs/current', '/docs/' + version); // PostgreSQL + obj[key] = (vendor == 'maria' ? obj[key].replace('dev.mysql.com/doc/mysql', 'mariadb.com/kb') : obj[key]) // MariaDB + .replace('/doc/mysql', '/doc/refman/' + version) // MySQL + ; + if (vendor != 'cockroach') { + obj[key] = obj[key].replace('/docs/current', '/docs/' + version); // PostgreSQL + } + } + } + if (window.jushLinks) { + jush.custom_links = jushLinks; + } + jush.highlight_tag('code', 0); + adminerHighlighter = els => jush.highlight_tag(els, 0); + for (const tag of qsa('textarea')) { + if (/(^|\s)jush-/.test(tag.className)) { + const pre = jush.textarea(tag, autocompleter); + if (pre) { + setupSubmitHighlightInput(pre); + tag.onchange = () => { + pre.textContent = tag.value; + pre.oninput(); + }; + } } } } - if (window.jushLinks) { - jush.custom_links = jushLinks; - } - jush.highlight_tag('code', 0); - adminerHighlighter = els => jush.highlight_tag(els, 0); - for (const tag of qsa('textarea')) { - if (/(^|\s)jush-/.test(tag.className)) { - const pre = jush.textarea(tag, autocompleter); - if (pre) { - setupSubmitHighlightInput(pre); - tag.onchange = () => { - pre.textContent = tag.value; - pre.oninput(); - }; - } - } - } - } + }); } /** Get value of dynamically created form field diff --git a/compile.php b/compile.php index 2f6b8feb..7b57f0a2 100755 --- a/compile.php +++ b/compile.php @@ -334,7 +334,7 @@ if ($_SESSION["lang"]) { $file = str_replace('', $_SESSION["lang"], $file); } $file = str_replace('echo script_src("static/editing.js");' . "\n", "", $file); // merged into functions.js -$file = preg_replace('~\s+echo script_src\("\.\./externals/jush/modules/jush-(autocomplete-sql|textarea|txt|js|" \. JUSH \. ")\.js"\);~', '', $file); // merged into jush.js +$file = preg_replace('~\s+echo script_src\("\.\./externals/jush/modules/jush-(autocomplete-sql|textarea|txt|js|" \. JUSH \. ")\.js", true\);~', '', $file); // merged into jush.js $file = preg_replace('~echo .*/jush(-dark)?.css\'>.*~', '', $file); // merged into default.css or dark.css if (function_exists('stripTypes')) { $file = stripTypes($file);