diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 4390bc0c..1d23d12c 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -64,7 +64,7 @@ if ($_POST["save"]) { } ?> -
" method="post" enctype="multipart/form-data"> + \n"; @@ -106,8 +106,5 @@ if ($fields) { if ($update) { echo "\n"; } -if (isset($_GET["select"])) { - echo "" . lang('Cancel') . "\n"; -} ?>
diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index a24b1ba8..b9bb39cb 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -130,7 +130,7 @@ document.getElementById('username').focus(); */ function selectQuery($query) { global $jush; - return "

>> " . h(str_replace("\n", " ", $query)) . " " . lang('Edit') . "" . (is_ajax() ? " #" : "") . "\n"; + return "

>> " . h(str_replace("\n", " ", $query)) . " " . lang('Edit') . "\n"; } /** Description of a row in a table diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 36ba8916..550fd999 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -361,10 +361,14 @@ function redirect($location, $message = null) { $_SESSION["messages"][] = $message; } if (isset($location)) { + if ($location == "") { + $location = "."; + } if (!is_ajax()) { - header("Location: " . ($location != "" ? $location : ".")); + header("Location: $location"); exit; } + header("X-AJAX-Redirect: $location"); $_POST = array(); } } diff --git a/adminer/lang/cs.inc.php b/adminer/lang/cs.inc.php index a80e0dac..f2cd1048 100644 --- a/adminer/lang/cs.inc.php +++ b/adminer/lang/cs.inc.php @@ -289,6 +289,4 @@ $translations = array( // function translation used in Editor 'now' => 'teď', - - 'Cancel' => 'Storno', ); diff --git a/adminer/select.inc.php b/adminer/select.inc.php index cbb2ac89..a4473995 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -231,7 +231,7 @@ if (!$columns) { $result->seek($limit * $page); } $email_fields = array(); - echo "

\n"; // $_SERVER["REQUEST_URI"] is required for sending the form after an AJAX request + echo "\n"; $rows = array(); while ($row = $result->fetch_assoc()) { $rows[] = $row; diff --git a/adminer/static/functions.js b/adminer/static/functions.js index c04e9bde..dd161f23 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -172,13 +172,17 @@ function textareaKeydown(target, event, tab, button) { function ajax(url, callback, data) { var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false)); if (xmlhttp) { - xmlhttp.open((data === undefined ? 'GET' : 'POST'), url); + xmlhttp.open((data ? 'POST' : 'GET'), url); if (data) { xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xmlhttp.onreadystatechange = function (text) { if (xmlhttp.readyState == 4) { + var redirect = xmlhttp.getResponseHeader('X-AJAX-Redirect'); + if (redirect && history.replaceState) { + history.replaceState(null, '', redirect); + } callback(xmlhttp.responseText); } }; @@ -203,16 +207,12 @@ function ajaxSetHtml(url) { var ajaxState = 0; var ajaxTimeout; -/** Load content to #main +/** Safely load content to #main * @param string * @param [string] -* @param [MouseEvent] * @return XMLHttpRequest or false in case of an error */ -function ajaxMain(url, data, event) { - if (event && event.ctrlKey) { - return false; - } +function ajaxSend(url, data) { var currentState = ++ajaxState; clearTimeout(ajaxTimeout); ajaxTimeout = setTimeout(function () { @@ -230,6 +230,29 @@ function ajaxMain(url, data, event) { }, data); } +/** Load content to #main +* @param string +* @param [string] +* @param [MouseEvent] +* @return XMLHttpRequest or false in case of an error +*/ +function ajaxMain(url, data, event) { + if (!history.pushState || (event && event.ctrlKey)) { + return false; + } + history.pushState(data, '', url); + return ajaxSend(url, data); +} + +/** Revive page from history +* @param PopStateEvent +*/ +window.onpopstate = function (event) { + if (ajaxState || event.state) { + ajaxSend(location.href, event.state); + } +} + /** Send form by AJAX GET * @param HTMLFormElement * @param [string] @@ -239,7 +262,9 @@ function ajaxForm(form, data) { var params = [ ]; for (var i=0; i < form.elements.length; i++) { var el = form.elements[i]; - if (el.name && (!/checkbox|radio|submit|file/i.test(el.type) || el.checked)) { + if (/file/i.test(el.type) && el.value) { + return false; + } else if (el.name && (!/checkbox|radio|submit|file/i.test(el.type) || el.checked)) { params.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value)); } }