Skip to content
Browse files

Generic AJAX links

  • Loading branch information...
1 parent 8ad4809 commit 6585b23ba87307fecf512d020e670e6da8d1bc32 @vrana committed Nov 22, 2010
View
2 adminer/include/adminer.inc.php
@@ -139,7 +139,7 @@ function backwardKeysPrint($backwardKeys, $row) {
*/
function selectQuery($query) {
global $jush;
- return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Last page') . "' onclick='return !ajaxMain(this.href, undefined, event);'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
+ return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Last page') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
}
/** Description of a row in a table
View
2 adminer/include/design.inc.php
@@ -26,7 +26,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<link rel="stylesheet" type="text/css" href="adminer.css">
<?php } ?>
-<body class="<?php echo lang('ltr'); ?>" onload="bodyLoad('<?php echo (is_object($connection) ? substr($connection->server_info, 0, 3) : ""); ?>', '<?php echo $protocol; ?>');<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verifyVersion('$protocol');"); ?>">
+<body class="<?php echo lang('ltr'); ?>" onclick="return bodyClick(event<?php echo (isset($_GET["username"]) ? ", '" . js_escape(DB) . "'" : ""); ?>);" onload="bodyLoad('<?php echo (is_object($connection) ? substr($connection->server_info, 0, 3) : ""); ?>', '<?php echo $protocol; ?>');<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verifyVersion('$protocol');"); ?>">
<script type="text/javascript" src="../adminer/static/functions.js"></script>
<script type="text/javascript" src="static/editing.js"></script>
View
2 adminer/include/functions.inc.php
@@ -462,7 +462,7 @@ function remove_from_uri($param = "") {
* @return string
*/
function pagination($page, $current) {
- return " " . ($page == $current ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '" onclick="return !ajaxMain(this.href, undefined, event);">' . ($page + 1) . "</a>");
+ return " " . ($page == $current ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
}
/** Get file contents from $_FILES
View
4 adminer/select.inc.php
@@ -263,7 +263,7 @@
$rank++;
$names[$key] = $name;
$column = idf_escape($key);
- echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($order[0] == $column || $order[0] == $key || (!$order && $group[0] == $column) ? '&desc%5B0%5D=1' : '')) . '" onclick="return !ajaxMain(this.href, undefined, event);">' . apply_sql_function($val["fun"], $name) . "</a>"; // $order[0] == $key - COUNT(*) //! columns looking like functions
+ echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($order[0] == $column || $order[0] == $key || (!$order && $group[0] == $column) ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; // $order[0] == $key - COUNT(*) //! columns looking like functions
}
$functions[$key] = $val["fun"];
next($select);
@@ -386,7 +386,7 @@
for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
echo pagination($i, $page);
}
- echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '" onclick="return !ajaxMain(this.href, undefined, event);">' . lang('last') . "</a>");
+ echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
}
echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
View
36 adminer/static/functions.js
@@ -115,7 +115,7 @@ function setHtml(id, html) {
function pageClick(href, page, event) {
if (!isNaN(page) && page) {
href += (page != 1 ? '&page=' + (page - 1) : '');
- if (!ajaxMain(href, undefined, event)) {
+ if (!ajaxMain(href, '', event)) {
location.href = href;
}
}
@@ -250,7 +250,7 @@ function ajaxSend(url, data) {
* @return XMLHttpRequest or false in case of an error
*/
function ajaxMain(url, data, event) {
- if (!history.pushState || (event && event.ctrlKey)) {
+ if (!history.pushState || (event && (event.ctrlKey || event.shiftKey || event.metaKey))) {
return false;
}
history.pushState(data, '', url);
@@ -286,9 +286,8 @@ function ajaxForm(form, data) {
}
if (form.method == 'post') {
return ajaxMain((/\?/.test(form.action) ? form.action : location.href), params.join('&')); // ? - always part of Adminer URL
- } else {
- return ajaxMain((form.action || location.pathname) + '?' + params.join('&'));
}
+ return ajaxMain((form.action || location.pathname) + '?' + params.join('&'));
}
@@ -341,3 +340,32 @@ function selectDblClick(td, event, text) {
range.select();
}
}
+
+
+
+/** Load link by AJAX
+* @param MouseEvent
+* @param [string]
+* @return bool
+*/
+function bodyClick(event, db) {
+ var el = event.target || event.srcElement;
+ if (/^a$/i.test(el.parentNode.tagName)) {
+ el = el.parentNode;
+ }
+ if (/^a$/i.test(el.tagName) && !/^https?:/i.test(el.getAttribute('href')) && !el.onclick && /[&?]username=/.exec(el.href)) {
+ var match = /&db=([^&]*)/.exec(el.href);
+ if (db === (match ? match[1] : '') && ajaxMain(el.href, '', event)) {
+ var as = document.getElementById('menu').getElementsByTagName('a');
+ for (var i=0; i < as.length; i++) {
+ if (as[i].className == 'active') {
+ as[i].className = '';
+ } else if (el.href == as[i].href) {
+ as[i].className = 'active';
+ }
+ }
+ //! modify Export link
+ return false;
+ }
+ }
+}

0 comments on commit 6585b23

Please sign in to comment.
Something went wrong with that request. Please try again.