]> git.joonet.de Git - adminer.git/commitdiff
Generic AJAX links
authorJakub Vrana <jakub@vrana.cz>
Mon, 22 Nov 2010 15:52:54 +0000 (16:52 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 22 Nov 2010 17:00:53 +0000 (18:00 +0100)
adminer/include/adminer.inc.php
adminer/include/design.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
adminer/static/functions.js

index ce8ec73a9c0317e6711e06aba390647351f87329..97b5e1d14ad2df7b52717c1dbca1fb0fea653744 100644 (file)
@@ -139,7 +139,7 @@ document.getElementById('username').focus();
        */
        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
index 7b9bcd939148c1f4013eda084290bc9aed6f4424..8f94806443046f1e6d520af10ef7eae2d75a1093 100644 (file)
@@ -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>
 
index fff0a69f175f7dff13a3c577bd7586294356edd2..58ef4fd1cd4f3b4a41c08da21cd30a3ecc633191 100644 (file)
@@ -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
index a3e15538f8829af0ba1115e6d72adba06fe6f6ef..053c1d85268b08cf30a6b6885a65edd350817bc7 100644 (file)
@@ -263,7 +263,7 @@ if (!$columns) {
                                        $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 @@ if (!$columns) {
                                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";
                        
index 9c19046fffe3d9bb3fe4c9d5d666866a34463a5e..436d827e3c81c83a04a7f1b601558a898520c4cc 100644 (file)
@@ -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;
+               }
+       }
+}