]> git.joonet.de Git - adminer.git/commitdiff
Move inline event handlers to <script>
authorJakub Vrana <jakub@vrana.cz>
Fri, 12 Jan 2018 10:56:03 +0000 (11:56 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 12 Jan 2018 16:09:35 +0000 (17:09 +0100)
adminer/select.inc.php
adminer/static/default.css
adminer/static/functions.js

index 8ccaeeda8bcaaf6f74f77f114fd2abba28861510..6a8e95b95c88e39ddded233b158259a8b79f8615 100644 (file)
@@ -297,8 +297,9 @@ if (!$columns && support("table")) {
                } else {
                        $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
 
-                       echo "<table id='table' cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);' onkeydown='return editingKeydown(event);'>\n";
-                       echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck.call(this, /check/);' class='jsonly'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('Modify') . "</a>");
+                       echo "<table id='table' cellspacing='0' class='nowrap checkable'>";
+                       echo "<script>mixin(qs('#table'), {onclick: tableClick, ondblclick: partialArg(tableClick, true), onkeydown: editingKeydown});</script>\n";
+                       echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' class='jsonly'><script>qs('#all-page').onclick = partial(formCheck, /check/);</script> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('Modify') . "</a>");
                        $names = array();
                        $functions = array();
                        reset($select);
@@ -314,13 +315,14 @@ if (!$columns && support("table")) {
                                                $column = idf_escape($key);
                                                $href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key);
                                                $desc = "&desc%5B0%5D=1";
-                                               echo '<th onmouseover="columnMouse.call(this);" onmouseout="columnMouse.call(this, \' hidden\');">';
+                                               echo "<th><script>mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});</script>";
                                                echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
                                                echo apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
                                                echo "<span class='column hidden'>";
                                                echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
                                                if (!$val["fun"]) {
-                                                       echo '<a href="#fieldset-search" onclick="selectSearch(\'' . h(js_escape($key)) . '\'); return false;" title="' . lang('Search') . '" class="text jsonly"> =</a>';
+                                                       echo '<a href="#fieldset-search" title="' . lang('Search') . '" class="text jsonly"> =</a>';
+                                                       echo "<script>qsl('a').onclick = partial(selectSearch, '" . h(js_escape($key)) . "');</script>";
                                                }
                                                echo "</span>";
                                        }
@@ -419,7 +421,8 @@ if (!$columns && support("table")) {
                                                        echo "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>");
                                                } else {
                                                        $long = strpos($val, "<i>...</i>");
-                                                       echo "<td id='$id' onclick=\"selectClick.call(this, event, " . ($long ? 2 : ($text ? 1 : 0)) . ($editable ? "" : ", '" . h(lang('Use edit link to modify this value.')) . "'") . ");\">$val";
+                                                       echo "<td id='$id'>$val</td>";
+                                                       echo "<script>qsl('td').onclick = partialArg(selectClick, " . ($long ? 2 : ($text ? 1 : 0)) . ($editable ? "" : ", '" . h(lang('Use edit link to modify this value.')) . "'") . ");</script>";
                                                }
                                        }
                                }
@@ -461,7 +464,8 @@ if (!$columns && support("table")) {
                                        : floor(($found_rows - 1) / $limit)
                                );
                                if ($jush != "simpledb") {
-                                       echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
+                                       echo '<a href="' . h(remove_from_uri("page")) . '">' . lang('Page') . "</a>:";
+                                       echo "<script>qsl('a').onclick = function () { pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "')); return false; }</script>\n";
                                        echo pagination(0, $page) . ($page > 5 ? " ..." : "");
                                        for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
                                                echo pagination($i, $page);
@@ -474,7 +478,8 @@ if (!$columns && support("table")) {
                                                );
                                        }
                                        echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit
-                                               ? ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore.call(this, ' . (+$limit) . ', \'' . lang('Loading') . '...\');" class="loadmore">' . lang('Load more data') . '</a>'
+                                               ? ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" class="loadmore">' . lang('Load more data') . '</a>'
+                                                       . "<script>qsl('a').onclick = partial(selectLoadMore, " . (+$limit) . ", '" . lang('Loading') . "...');</script>"
                                                : ''
                                        );
                                } else {
index b1fae3b762c3d6351850c3931c5ed73af23f858f..63666550fa42faa4e5d04cae2b41b7c77c80b3c9 100644 (file)
@@ -11,7 +11,7 @@ h3 { font-weight: normal; font-size: 130%; margin: 1em 0 0; }
 form { margin: 0; }
 td table { width: 100%; margin: 0; }
 table { margin: 1em 20px 0 0; border: 0; border-top: 1px solid #999; border-left: 1px solid #999; font-size: 90%; }
-td, th { border: 0; border-right: 1px solid #999; border-bottom: 1px solid #999; padding: .2em .3em; }
+td, th {border: 0;border-right: 1px solid #999;border-bottom: 1px solid #999;padding: .2em .3em;}
 th { background: #eee; text-align: left; }
 thead th { text-align: center; padding: .2em .5em; }
 thead td, thead th { background: #ddf; }
index f43e3a9113e39c6d9c355c5579279e1d60fc0281..c1d9401be197f99069a67779916e8109c4581b01 100644 (file)
@@ -7,6 +7,15 @@ function qs(selector) {
        return document.querySelector(selector);
 }
 
+/** Get last element by selector
+* @param string
+* @return HTMLElement
+*/
+function qsl(selector) {
+       var els = qsa(selector, document);
+       return els[els.length - 1];
+}
+
 /** Get all elements by selector
 * @param string
 * @param HTMLElement
@@ -16,6 +25,41 @@ function qsa(selector, context) {
        return context.querySelectorAll(selector);
 }
 
+/** Return a function calling fn with the next arguments
+* @param function
+* @param ...
+* @return function with preserved this
+*/
+function partial(fn) {
+       var args = Array.apply(null, arguments).slice(1);
+       return function () {
+               return fn.apply(this, args);
+       };
+}
+
+/** Return a function calling fn with the first parameter and then the next arguments
+* @param function
+* @param ...
+* @return function with preserved this
+*/
+function partialArg(fn) {
+       var args = Array.apply(null, arguments);
+       return function (arg) {
+               args[0] = arg;
+               return fn.apply(this, args);
+       };
+}
+
+/** Assign values from source to target
+* @param Object
+* @param Object
+*/
+function mixin(target, source) {
+       for (var key in source) {
+               target[key] = source[key];
+       }
+}
+
 /** Add or remove CSS class
 * @param HTMLElement
 * @param string
@@ -279,12 +323,10 @@ function nodePosition(el) {
 /** Go to the specified page
 * @param string
 * @param string
-* @param [MouseEvent]
 */
-function pageClick(href, page, event) {
+function pageClick(href, page) {
        if (!isNaN(page) && page) {
-               href += (page != 1 ? '&page=' + (page - 1) : '');
-               location.href = href;
+               location.href = href + (page != 1 ? '&page=' + (page - 1) : '');
        }
 }
 
@@ -377,6 +419,7 @@ function columnMouse(className) {
 
 /** Fill column in search field
 * @param string
+* @return boolean false
 */
 function selectSearch(name) {
        var el = qs('#fieldset-search');
@@ -393,6 +436,7 @@ function selectSearch(name) {
                div.firstChild.onchange();
        }
        div.lastChild.focus();
+       return false;
 }
 
 
@@ -685,7 +729,7 @@ function selectClick(event, text, warning) {
 /** Load and display next page in select
 * @param number
 * @param string
-* @return boolean
+* @return boolean false for success
 * @this HTMLLinkElement
 */
 function selectLoadMore(limit, loading) {
@@ -695,7 +739,7 @@ function selectLoadMore(limit, loading) {
        a.innerHTML = loading;
        if (href) {
                a.removeAttribute('href');
-               return ajax(href, function (request) {
+               return !ajax(href, function (request) {
                        var tbody = document.createElement('tbody');
                        tbody.innerHTML = request.responseText;
                        qs('#table').appendChild(tbody);