} 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);
$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>";
}
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>";
}
}
}
: 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);
);
}
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 {
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
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
/** 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) : '');
}
}
/** Fill column in search field
* @param string
+* @return boolean false
*/
function selectSearch(name) {
var el = qs('#fieldset-search');
div.firstChild.onchange();
}
div.lastChild.focus();
+ return false;
}
/** Load and display next page in select
* @param number
* @param string
-* @return boolean
+* @return boolean false for success
* @this HTMLLinkElement
*/
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);