2009-05-29 16:51:21 +00:00
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Toggle visibility
|
|
|
|
* @param string
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-05-29 16:14:54 +00:00
|
|
|
function toggle(id) {
|
|
|
|
var el = document.getElementById(id);
|
|
|
|
el.className = (el.className == 'hidden' ? '' : 'hidden');
|
|
|
|
return true;
|
2009-06-03 18:32:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 16:22:54 +00:00
|
|
|
/** Set permanent cookie
|
|
|
|
* @param string
|
|
|
|
* @param number
|
|
|
|
* @param string optional
|
|
|
|
*/
|
2011-02-08 19:58:31 +00:00
|
|
|
function cookie(assign, days) {
|
2010-03-05 16:22:54 +00:00
|
|
|
var date = new Date();
|
|
|
|
date.setDate(date.getDate() + days);
|
2011-02-08 19:58:31 +00:00
|
|
|
document.cookie = assign + '; expires=' + date;
|
2010-03-05 16:22:54 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Verify current Adminer version
|
|
|
|
*/
|
2011-02-15 17:11:24 +00:00
|
|
|
function verifyVersion() {
|
2010-03-05 16:22:54 +00:00
|
|
|
cookie('adminer_version=0', 1);
|
2009-07-29 15:07:57 +00:00
|
|
|
var script = document.createElement('script');
|
2011-02-15 17:11:24 +00:00
|
|
|
script.src = location.protocol + '//www.adminer.org/version.php';
|
2009-07-29 15:07:57 +00:00
|
|
|
document.body.appendChild(script);
|
2009-07-29 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 23:51:56 +00:00
|
|
|
/** Get value of select
|
|
|
|
* @param HTMLSelectElement
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function selectValue(select) {
|
2011-02-28 14:57:37 +00:00
|
|
|
var selected = select.options[select.selectedIndex];
|
|
|
|
return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
|
2010-10-16 23:51:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Check all elements matching given name
|
|
|
|
* @param HTMLInputElement
|
|
|
|
* @param RegExp
|
|
|
|
*/
|
2009-12-17 13:22:28 +00:00
|
|
|
function formCheck(el, name) {
|
2009-05-29 16:14:54 +00:00
|
|
|
var elems = el.form.elements;
|
|
|
|
for (var i=0; i < elems.length; i++) {
|
2009-06-01 13:06:11 +00:00
|
|
|
if (name.test(elems[i].name)) {
|
2009-05-29 16:14:54 +00:00
|
|
|
elems[i].checked = el.checked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Uncheck single element
|
|
|
|
* @param string
|
|
|
|
*/
|
2009-12-17 13:22:28 +00:00
|
|
|
function formUncheck(id) {
|
2009-06-01 13:06:11 +00:00
|
|
|
document.getElementById(id).checked = false;
|
|
|
|
}
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Get number of checked elements matching given name
|
|
|
|
* @param HTMLInputElement
|
|
|
|
* @param RegExp
|
|
|
|
* @return number
|
|
|
|
*/
|
2009-12-17 13:22:28 +00:00
|
|
|
function formChecked(el, name) {
|
2009-09-23 12:21:14 +00:00
|
|
|
var checked = 0;
|
|
|
|
var elems = el.form.elements;
|
|
|
|
for (var i=0; i < elems.length; i++) {
|
|
|
|
if (name.test(elems[i].name) && elems[i].checked) {
|
|
|
|
checked++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return checked;
|
|
|
|
}
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Select clicked row
|
|
|
|
* @param MouseEvent
|
|
|
|
*/
|
2009-12-17 13:22:28 +00:00
|
|
|
function tableClick(event) {
|
2009-08-26 13:43:17 +00:00
|
|
|
var el = event.target || event.srcElement;
|
2009-08-25 12:21:03 +00:00
|
|
|
while (!/^tr$/i.test(el.tagName)) {
|
2010-04-26 16:19:59 +00:00
|
|
|
if (/^(table|a|input|textarea)$/i.test(el.tagName)) {
|
2009-08-25 10:25:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-25 12:21:03 +00:00
|
|
|
el = el.parentNode;
|
2009-08-25 10:25:56 +00:00
|
|
|
}
|
2009-08-25 12:21:03 +00:00
|
|
|
el = el.firstChild.firstChild;
|
|
|
|
el.click && el.click();
|
|
|
|
el.onclick && el.onclick();
|
2009-08-25 10:25:56 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 12:01:32 +00:00
|
|
|
/** Set HTML code of an element
|
|
|
|
* @param string
|
|
|
|
* @param string undefined to set parentNode to
|
|
|
|
*/
|
|
|
|
function setHtml(id, html) {
|
|
|
|
var el = document.getElementById(id);
|
|
|
|
if (el) {
|
|
|
|
if (html == undefined) {
|
|
|
|
el.parentNode.innerHTML = ' ';
|
|
|
|
} else {
|
2011-01-31 10:57:35 +00:00
|
|
|
el.innerHTML = html.replace(/<noscript>.*<\/noscript>/i, ''); // required for Google Chrome // hopes that there will be only one <noscript> on each line
|
2010-04-21 12:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:13:57 +00:00
|
|
|
/** Find node position
|
|
|
|
* @param Node
|
|
|
|
* @return number
|
|
|
|
*/
|
|
|
|
function nodePosition(el) {
|
|
|
|
var pos = 0;
|
|
|
|
while (el = el.previousSibling) {
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2010-11-12 16:31:18 +00:00
|
|
|
/** Go to the specified page
|
|
|
|
* @param string
|
|
|
|
* @param string
|
|
|
|
* @param [MouseEvent]
|
|
|
|
*/
|
|
|
|
function pageClick(href, page, event) {
|
|
|
|
if (!isNaN(page) && page) {
|
|
|
|
href += (page != 1 ? '&page=' + (page - 1) : '');
|
2011-03-16 12:08:46 +00:00
|
|
|
if (!ajaxSend(href)) {
|
2010-11-12 16:31:18 +00:00
|
|
|
location.href = href;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-29 16:51:21 +00:00
|
|
|
|
|
|
|
|
2009-12-17 14:53:26 +00:00
|
|
|
/** Add row in select fieldset
|
|
|
|
* @param HTMLSelectElement
|
|
|
|
*/
|
2009-12-17 13:22:28 +00:00
|
|
|
function selectAddRow(field) {
|
2010-10-18 23:06:30 +00:00
|
|
|
field.onchange = function () { };
|
2009-05-29 16:14:54 +00:00
|
|
|
var row = field.parentNode.cloneNode(true);
|
|
|
|
var selects = row.getElementsByTagName('select');
|
|
|
|
for (var i=0; i < selects.length; i++) {
|
2010-10-22 22:02:24 +00:00
|
|
|
selects[i].name = selects[i].name.replace(/[a-z]\[\d+/, '$&1');
|
2009-05-29 16:14:54 +00:00
|
|
|
selects[i].selectedIndex = 0;
|
|
|
|
}
|
|
|
|
var inputs = row.getElementsByTagName('input');
|
|
|
|
if (inputs.length) {
|
2010-10-22 22:02:24 +00:00
|
|
|
inputs[0].name = inputs[0].name.replace(/[a-z]\[\d+/, '$&1');
|
2009-05-29 16:14:54 +00:00
|
|
|
inputs[0].value = '';
|
|
|
|
inputs[0].className = '';
|
|
|
|
}
|
|
|
|
field.parentNode.parentNode.appendChild(row);
|
|
|
|
}
|
2010-04-23 15:26:59 +00:00
|
|
|
|
2010-04-26 16:19:59 +00:00
|
|
|
|
|
|
|
|
2011-03-21 12:53:48 +00:00
|
|
|
/** Handle Tab and Esc in textarea
|
2010-10-17 05:16:32 +00:00
|
|
|
* @param HTMLTextAreaElement
|
|
|
|
* @param KeyboardEvent
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2011-03-21 12:53:48 +00:00
|
|
|
function textareaKeydown(target, event) {
|
|
|
|
if (!event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
2011-03-18 08:12:31 +00:00
|
|
|
if (event.keyCode == 9) { // 9 - Tab
|
2011-03-08 12:46:37 +00:00
|
|
|
// inspired by http://pallieter.org/Projects/insertTab/
|
|
|
|
if (target.setSelectionRange) {
|
|
|
|
var start = target.selectionStart;
|
2011-03-10 17:06:48 +00:00
|
|
|
var scrolled = target.scrollTop;
|
2011-03-08 12:46:37 +00:00
|
|
|
target.value = target.value.substr(0, start) + '\t' + target.value.substr(target.selectionEnd);
|
|
|
|
target.setSelectionRange(start + 1, start + 1);
|
2011-03-10 17:06:48 +00:00
|
|
|
target.scrollTop = scrolled;
|
2011-03-08 12:46:37 +00:00
|
|
|
return false; //! still loses focus in Opera, can be solved by handling onblur
|
|
|
|
} else if (target.createTextRange) {
|
|
|
|
document.selection.createRange().text = '\t';
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-10 17:06:48 +00:00
|
|
|
}
|
2011-03-18 08:12:31 +00:00
|
|
|
if (event.keyCode == 27) { // 27 - Esc
|
2011-03-08 12:46:37 +00:00
|
|
|
var els = target.form.elements;
|
|
|
|
for (var i=1; i < els.length; i++) {
|
|
|
|
if (els[i-1] == target) {
|
|
|
|
els[i].focus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-21 12:53:48 +00:00
|
|
|
return false;
|
2010-10-17 05:16:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-07-13 16:18:47 +00:00
|
|
|
|
2011-05-04 09:42:46 +00:00
|
|
|
/** Send form by Ctrl+Enter on <select> and <textarea>
|
2011-03-18 16:24:29 +00:00
|
|
|
* @param KeyboardEvent
|
2011-05-04 09:42:46 +00:00
|
|
|
* @param [string]
|
2011-03-21 11:15:38 +00:00
|
|
|
* @return boolean
|
2011-03-18 16:24:29 +00:00
|
|
|
*/
|
2011-05-04 09:42:46 +00:00
|
|
|
function bodyKeydown(event, button) {
|
2011-03-18 16:24:29 +00:00
|
|
|
var target = event.target || event.srcElement;
|
2011-05-04 09:42:46 +00:00
|
|
|
if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey && /select|textarea|input/i.test(target.tagName)) { // 13|10 - Enter, shiftKey allowed
|
2011-03-21 11:15:38 +00:00
|
|
|
target.blur();
|
2011-05-04 09:42:46 +00:00
|
|
|
if ((!target.form.onsubmit || target.form.onsubmit() !== false) && !ajaxForm(target.form, (button ? button + '=1' : ''))) {
|
|
|
|
if (button) {
|
|
|
|
target.form[button].click();
|
|
|
|
} else {
|
|
|
|
target.form.submit();
|
|
|
|
}
|
2011-03-21 11:15:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
2011-03-18 16:24:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-17 05:55:58 +00:00
|
|
|
|
|
|
|
|
2011-01-25 16:13:57 +00:00
|
|
|
/** Change focus by Ctrl+Up or Ctrl+Down
|
|
|
|
* @param KeyboardEvent
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function editingKeydown(event) {
|
2011-03-18 08:12:31 +00:00
|
|
|
if ((event.keyCode == 40 || event.keyCode == 38) && event.ctrlKey && !event.altKey && !event.metaKey) { // 40 - Down, 38 - Up, shiftKey allowed
|
2011-01-25 16:13:57 +00:00
|
|
|
var target = event.target || event.srcElement;
|
|
|
|
var sibling = (event.keyCode == 40 ? 'nextSibling' : 'previousSibling');
|
|
|
|
var el = target.parentNode.parentNode[sibling];
|
|
|
|
if (el && (/^tr$/i.test(el.tagName) || (el = el[sibling])) && /^tr$/i.test(el.tagName) && (el = el.childNodes[nodePosition(target.parentNode)]) && (el = el.childNodes[nodePosition(target)])) {
|
|
|
|
el.focus();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:06:05 +00:00
|
|
|
/** Disable maxlength for functions
|
|
|
|
* @param HTMLSelectElement
|
|
|
|
*/
|
|
|
|
function functionChange(select) {
|
|
|
|
var input = select.form[select.name.replace(/^function/, 'fields')];
|
|
|
|
if (selectValue(select)) {
|
|
|
|
if (input.origMaxLength === undefined) {
|
|
|
|
input.origMaxLength = input.maxLength;
|
|
|
|
}
|
|
|
|
input.removeAttribute('maxlength');
|
|
|
|
} else if (input.origMaxLength >= 0) {
|
|
|
|
input.maxLength = input.origMaxLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:13:57 +00:00
|
|
|
|
|
|
|
|
2010-10-16 23:51:56 +00:00
|
|
|
/** Create AJAX request
|
|
|
|
* @param string
|
2011-03-11 23:33:06 +00:00
|
|
|
* @param function (XMLHttpRequest)
|
2010-10-17 21:54:41 +00:00
|
|
|
* @param [string]
|
2010-10-16 23:51:56 +00:00
|
|
|
* @return XMLHttpRequest or false in case of an error
|
|
|
|
*/
|
2010-10-18 11:57:22 +00:00
|
|
|
function ajax(url, callback, data) {
|
2010-10-17 05:19:01 +00:00
|
|
|
var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false));
|
|
|
|
if (xmlhttp) {
|
2010-11-12 16:09:30 +00:00
|
|
|
xmlhttp.open((data ? 'POST' : 'GET'), url);
|
2010-10-18 11:57:22 +00:00
|
|
|
if (data) {
|
2010-10-17 05:50:40 +00:00
|
|
|
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
}
|
2010-10-17 05:19:01 +00:00
|
|
|
xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
2011-01-03 15:42:08 +00:00
|
|
|
xmlhttp.onreadystatechange = function () {
|
2010-10-18 11:57:22 +00:00
|
|
|
if (xmlhttp.readyState == 4) {
|
2011-03-11 23:33:06 +00:00
|
|
|
callback(xmlhttp);
|
2010-10-16 23:51:56 +00:00
|
|
|
}
|
2010-10-17 05:19:01 +00:00
|
|
|
};
|
2010-10-17 05:50:40 +00:00
|
|
|
xmlhttp.send(data);
|
2010-10-17 05:19:01 +00:00
|
|
|
}
|
2010-10-16 23:51:56 +00:00
|
|
|
return xmlhttp;
|
|
|
|
}
|
|
|
|
|
2010-10-18 23:40:49 +00:00
|
|
|
/** Use setHtml(key, value) for JSON response
|
|
|
|
* @param string
|
|
|
|
* @return XMLHttpRequest or false in case of an error
|
|
|
|
*/
|
|
|
|
function ajaxSetHtml(url) {
|
2011-03-11 23:33:06 +00:00
|
|
|
return ajax(url, function (xmlhttp) {
|
|
|
|
if (xmlhttp.status) {
|
|
|
|
var data = eval('(' + xmlhttp.responseText + ')');
|
|
|
|
for (var key in data) {
|
|
|
|
setHtml(key, data[key]);
|
|
|
|
}
|
2010-10-18 23:40:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-03 15:17:26 +00:00
|
|
|
var originalFavicon = (document.getElementById('favicon') || {}).href;
|
|
|
|
|
2011-03-11 22:21:54 +00:00
|
|
|
/** Replace favicon
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
function replaceFavicon(href) {
|
|
|
|
var favicon = document.getElementById('favicon');
|
2011-04-03 15:17:26 +00:00
|
|
|
if (favicon) {
|
|
|
|
favicon.href = href;
|
|
|
|
favicon.parentNode.appendChild(favicon); // to replace the icon in Firefox
|
|
|
|
}
|
2011-03-11 22:21:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 15:47:37 +00:00
|
|
|
var ajaxState = 0;
|
2010-10-18 11:57:22 +00:00
|
|
|
|
2010-11-18 11:17:06 +00:00
|
|
|
/** Safely load content to #content
|
2010-10-18 11:57:22 +00:00
|
|
|
* @param string
|
|
|
|
* @param [string]
|
2011-03-11 15:47:37 +00:00
|
|
|
* @param [boolean]
|
2010-10-18 11:57:22 +00:00
|
|
|
* @return XMLHttpRequest or false in case of an error
|
|
|
|
*/
|
2011-03-11 15:47:37 +00:00
|
|
|
function ajaxSend(url, data, popState) {
|
2011-03-16 12:08:46 +00:00
|
|
|
if (!history.pushState) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-18 11:57:22 +00:00
|
|
|
var currentState = ++ajaxState;
|
2011-03-15 11:58:04 +00:00
|
|
|
onblur = function () {
|
|
|
|
replaceFavicon('../adminer/static/loader.gif');
|
|
|
|
};
|
2011-03-11 15:47:37 +00:00
|
|
|
setHtml('loader', '<img src="../adminer/static/loader.gif" alt="">');
|
2011-03-11 23:33:06 +00:00
|
|
|
return ajax(url, function (xmlhttp) {
|
2010-10-18 11:57:22 +00:00
|
|
|
if (currentState == ajaxState) {
|
2011-03-11 23:33:06 +00:00
|
|
|
var title = xmlhttp.getResponseHeader('X-AJAX-Title');
|
|
|
|
if (title) {
|
|
|
|
document.title = decodeURIComponent(title);
|
|
|
|
}
|
|
|
|
var redirect = xmlhttp.getResponseHeader('X-AJAX-Redirect');
|
|
|
|
if (redirect) {
|
2011-03-16 12:08:46 +00:00
|
|
|
return ajaxSend(redirect, '', popState);
|
2011-03-11 23:33:06 +00:00
|
|
|
}
|
2011-03-15 11:58:04 +00:00
|
|
|
onblur = function () { };
|
2011-04-03 15:17:26 +00:00
|
|
|
replaceFavicon(originalFavicon);
|
2011-03-11 23:33:06 +00:00
|
|
|
if (!xmlhttp.status) {
|
2011-03-11 21:09:54 +00:00
|
|
|
setHtml('loader', '');
|
|
|
|
} else {
|
|
|
|
if (!popState) {
|
2011-03-11 23:16:56 +00:00
|
|
|
if (data || url != location.href) {
|
|
|
|
history.pushState(data, '', url);
|
|
|
|
}
|
2011-03-11 21:09:54 +00:00
|
|
|
scrollTo(0, 0);
|
|
|
|
}
|
2011-03-11 23:33:06 +00:00
|
|
|
setHtml('content', xmlhttp.responseText);
|
2011-03-11 21:09:54 +00:00
|
|
|
var content = document.getElementById('content');
|
|
|
|
var scripts = content.getElementsByTagName('script');
|
|
|
|
var length = scripts.length; // required to avoid infinite loop
|
|
|
|
for (var i=0; i < length; i++) {
|
|
|
|
var script = document.createElement('script');
|
|
|
|
script.text = scripts[i].text;
|
|
|
|
content.appendChild(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
var as = document.getElementById('menu').getElementsByTagName('a');
|
|
|
|
var href = location.href.replace(/(&(sql=|dump=|(select|table)=[^&]*)).*/, '$1');
|
|
|
|
for (var i=0; i < as.length; i++) {
|
|
|
|
if (href == as[i].href) {
|
|
|
|
as[i].className = 'active';
|
|
|
|
} else if (as[i].className == 'active') {
|
|
|
|
as[i].className = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var dump = document.getElementById('dump');
|
|
|
|
if (dump) {
|
|
|
|
var match = /&(select|table)=([^&]+)/.exec(href);
|
|
|
|
dump.href = dump.href.replace(/[^=]+$/, '') + (match ? match[2] : '');
|
|
|
|
}
|
|
|
|
//! modify Change database hidden fields
|
|
|
|
|
|
|
|
if (window.jush) {
|
|
|
|
jush.highlight_tag('code', 0);
|
2010-11-23 10:50:53 +00:00
|
|
|
}
|
2010-10-18 11:57:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, data);
|
|
|
|
}
|
|
|
|
|
2010-11-12 16:09:30 +00:00
|
|
|
/** Revive page from history
|
2011-03-11 23:20:27 +00:00
|
|
|
* @param PopStateEvent|history
|
2010-11-12 16:09:30 +00:00
|
|
|
*/
|
2011-03-15 11:58:04 +00:00
|
|
|
onpopstate = function (event) {
|
2011-04-25 19:06:42 +00:00
|
|
|
if ((ajaxState || event.state) && !/#/.test(location.href)) {
|
2011-03-24 07:39:35 +00:00
|
|
|
ajaxSend(location.href, (event.state && confirm(areYouSure) ? event.state : ''), 1); // 1 - disable pushState
|
2011-03-24 07:24:57 +00:00
|
|
|
} else {
|
|
|
|
ajaxState++;
|
2011-03-16 12:07:44 +00:00
|
|
|
}
|
2011-04-25 19:06:42 +00:00
|
|
|
};
|
2010-11-12 16:09:30 +00:00
|
|
|
|
2010-10-16 23:51:56 +00:00
|
|
|
/** Send form by AJAX GET
|
|
|
|
* @param HTMLFormElement
|
2010-10-17 21:54:41 +00:00
|
|
|
* @param [string]
|
2010-10-16 23:51:56 +00:00
|
|
|
* @return XMLHttpRequest or false in case of an error
|
|
|
|
*/
|
2010-10-17 21:54:41 +00:00
|
|
|
function ajaxForm(form, data) {
|
2011-03-21 11:15:38 +00:00
|
|
|
if (/&(database|scheme|create|view|sql|user|dump|call)=/.test(location.href) && !/\./.test(data)) { // . - type="image"
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-16 23:51:56 +00:00
|
|
|
var params = [ ];
|
|
|
|
for (var i=0; i < form.elements.length; i++) {
|
|
|
|
var el = form.elements[i];
|
2010-11-12 16:09:30 +00:00
|
|
|
if (/file/i.test(el.type) && el.value) {
|
|
|
|
return false;
|
|
|
|
} else if (el.name && (!/checkbox|radio|submit|file/i.test(el.type) || el.checked)) {
|
2010-10-17 05:50:40 +00:00
|
|
|
params.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
|
2010-10-16 23:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-17 21:54:41 +00:00
|
|
|
if (data) {
|
|
|
|
params.push(data);
|
|
|
|
}
|
2010-10-17 05:50:40 +00:00
|
|
|
if (form.method == 'post') {
|
2011-03-16 12:08:46 +00:00
|
|
|
return ajaxSend((/\?/.test(form.action) ? form.action : location.href), params.join('&')); // ? - always part of Adminer URL
|
2010-10-17 05:50:40 +00:00
|
|
|
}
|
2011-03-16 12:08:46 +00:00
|
|
|
return ajaxSend((form.action || location.href).replace(/\?.*/, '') + '?' + params.join('&'));
|
2010-10-16 23:51:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 16:18:47 +00:00
|
|
|
|
|
|
|
|
2010-04-26 16:19:59 +00:00
|
|
|
/** Display edit field
|
|
|
|
* @param HTMLElement
|
|
|
|
* @param MouseEvent
|
2010-10-18 11:57:22 +00:00
|
|
|
* @param number display textarea instead of input, 2 - load long text
|
2010-04-26 16:19:59 +00:00
|
|
|
*/
|
2010-04-23 15:26:59 +00:00
|
|
|
function selectDblClick(td, event, text) {
|
2010-10-18 23:06:30 +00:00
|
|
|
td.ondblclick = function () { };
|
2010-04-23 15:26:59 +00:00
|
|
|
var pos = event.rangeOffset;
|
2010-11-18 11:09:05 +00:00
|
|
|
var value = (td.firstChild.alt ? td.firstChild.alt : (td.textContent ? td.textContent : td.innerText));
|
2010-04-23 15:26:59 +00:00
|
|
|
var input = document.createElement(text ? 'textarea' : 'input');
|
2010-10-17 14:00:29 +00:00
|
|
|
input.style.width = Math.max(td.clientWidth - 14, 20) + 'px'; // 14 = 2 * (td.border + td.padding + input.border)
|
2010-04-23 15:26:59 +00:00
|
|
|
if (text) {
|
|
|
|
var rows = 1;
|
|
|
|
value.replace(/\n/g, function () {
|
|
|
|
rows++;
|
|
|
|
});
|
|
|
|
input.rows = rows;
|
|
|
|
}
|
2011-03-21 13:35:58 +00:00
|
|
|
if (value == '\u00A0' || td.getElementsByTagName('i').length) { // or i - NULL
|
|
|
|
value = '';
|
|
|
|
}
|
2010-04-23 15:26:59 +00:00
|
|
|
if (document.selection) {
|
|
|
|
var range = document.selection.createRange();
|
2011-02-08 20:41:57 +00:00
|
|
|
range.moveToPoint(event.clientX, event.clientY);
|
2010-04-23 15:26:59 +00:00
|
|
|
var range2 = range.duplicate();
|
|
|
|
range2.moveToElementText(td);
|
|
|
|
range2.setEndPoint('EndToEnd', range);
|
|
|
|
pos = range2.text.length;
|
|
|
|
}
|
|
|
|
td.innerHTML = '';
|
|
|
|
td.appendChild(input);
|
|
|
|
input.focus();
|
2010-10-18 11:57:22 +00:00
|
|
|
if (text == 2) { // long text
|
2011-03-11 23:33:06 +00:00
|
|
|
return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (xmlhttp) {
|
|
|
|
if (xmlhttp.status) {
|
|
|
|
input.value = xmlhttp.responseText;
|
|
|
|
input.name = td.id;
|
|
|
|
}
|
2010-10-18 11:57:22 +00:00
|
|
|
});
|
|
|
|
}
|
2010-11-28 15:40:11 +00:00
|
|
|
input.value = value;
|
2010-10-18 22:57:37 +00:00
|
|
|
input.name = td.id;
|
2010-04-23 15:26:59 +00:00
|
|
|
input.selectionStart = pos;
|
|
|
|
input.selectionEnd = pos;
|
|
|
|
if (document.selection) {
|
|
|
|
var range = document.selection.createRange();
|
2010-11-19 14:50:09 +00:00
|
|
|
range.moveEnd('character', -input.value.length + pos);
|
2010-04-23 15:26:59 +00:00
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|
2010-11-22 15:52:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Load link by AJAX
|
|
|
|
* @param MouseEvent
|
2010-11-26 09:26:08 +00:00
|
|
|
* @param string
|
2010-11-28 16:58:35 +00:00
|
|
|
* @param string
|
2010-11-22 15:52:54 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2010-11-28 16:58:35 +00:00
|
|
|
function bodyClick(event, db, ns) {
|
2011-03-16 12:08:46 +00:00
|
|
|
if (event.button || event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) {
|
2010-12-06 00:13:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-12-03 12:40:37 +00:00
|
|
|
if (event.getPreventDefault ? event.getPreventDefault() : event.returnValue === false) {
|
2010-11-23 10:50:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-22 15:52:54 +00:00
|
|
|
var el = event.target || event.srcElement;
|
|
|
|
if (/^a$/i.test(el.parentNode.tagName)) {
|
|
|
|
el = el.parentNode;
|
|
|
|
}
|
2011-04-25 19:06:42 +00:00
|
|
|
if (/^a$/i.test(el.tagName) && !/:|#|&download=/i.test(el.getAttribute('href')) && /[&?]username=/.test(el.href)) {
|
2010-11-22 15:52:54 +00:00
|
|
|
var match = /&db=([^&]*)/.exec(el.href);
|
2010-11-28 16:58:35 +00:00
|
|
|
var match2 = /&ns=([^&]*)/.exec(el.href);
|
2011-03-16 12:08:46 +00:00
|
|
|
return !(db == (match ? match[1] : '') && ns == (match2 ? match2[1] : '') && ajaxSend(el.href));
|
2010-11-22 15:52:54 +00:00
|
|
|
}
|
2011-03-21 11:15:38 +00:00
|
|
|
if (/^input$/i.test(el.tagName) && /image|submit/.test(el.type)) {
|
2011-01-24 14:35:06 +00:00
|
|
|
return !ajaxForm(el.form, (el.name ? encodeURIComponent(el.name) + (el.type == 'image' ? '.x' : '') + '=1' : ''));
|
2010-11-23 10:50:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
2010-11-22 15:52:54 +00:00
|
|
|
}
|
2010-12-01 17:44:17 +00:00
|
|
|
|
|
|
|
/** Stop event propagation
|
|
|
|
* @param Event
|
|
|
|
*/
|
|
|
|
function eventStop(event) {
|
|
|
|
if (event.stopPropagation) {
|
|
|
|
event.stopPropagation();
|
|
|
|
} else {
|
|
|
|
event.cancelBubble = true;
|
|
|
|
}
|
|
|
|
}
|