}
?>
-<form action="<?php echo h($_SERVER["REQUEST_URI"]); // required for sending the form after an AJAX request ?>" method="post" enctype="multipart/form-data">
+<form action="" method="post" enctype="multipart/form-data">
<?php
if ($fields) {
echo "<table cellspacing='0'>\n";
if ($update) {
echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "')" . (isset($_GET["select"]) ? " && !ajaxForm(this.form, 'delete=1')" : "") . ";\">\n";
}
-if (isset($_GET["select"])) {
- echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "' onclick='return !ajaxMain(this.href, undefined, event);'>" . lang('Cancel') . "</a>\n";
-}
?>
</form>
*/
function selectQuery($query) {
global $jush;
- return "<p><a href='" . h(remove_from_uri("page")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "' onclick='return !ajaxMain(this.href, undefined, event);'>>></a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" . (is_ajax() ? " <a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>" : "") . "\n";
+ return "<p><a href='" . h(remove_from_uri("page")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "' onclick='return !ajaxMain(this.href, undefined, event);'>>></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
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);
}
};
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 () {
}, 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]
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));
}
}