Setup script: migrate MooTools code to jQuery

This commit is contained in:
Crack
2010-04-08 19:30:20 +02:00
committed by Michal Čihař
parent 1fc253e19e
commit 5603e1a683
5 changed files with 238 additions and 184 deletions

31
js/jquery/jquery.json-2.2.min.js vendored Normal file
View File

@@ -0,0 +1,31 @@
(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);

View File

@@ -34,8 +34,9 @@ require './libraries/header_http.inc.php';
<link href="../favicon.ico" rel="icon" type="image/x-icon" /> <link href="../favicon.ico" rel="icon" type="image/x-icon" />
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon" /> <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="styles.css" rel="stylesheet" type="text/css" /> <link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/mootools.js"></script> <script type="text/javascript" src="../js/jquery/jquery-1.4.2-min.js"></script>
<script type="text/javascript" src="../js/mootools-more.js"></script> <script type="text/javascript" src="../js/jquery/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.json-2.2.min.js"></script>
<script type="text/javascript" src="scripts.js"></script> <script type="text/javascript" src="scripts.js"></script>
</head> </head>
<body> <body>

View File

@@ -227,10 +227,10 @@ class FormDisplay
: filter_input($GLOBALS["str$str"]); // null if not set : filter_input($GLOBALS["str$str"]); // null if not set
$js_lang[] = "'$str': '" . PMA_jsFormat($lang, false) . '\''; $js_lang[] = "'$str': '" . PMA_jsFormat($lang, false) . '\'';
} }
$js[] = '$extend(PMA_messages, {' . implode(",\n\t", $js_lang) . '})'; $js[] = '$.extend(PMA_messages, {' . implode(",\n\t", $js_lang) . '})';
} }
$js[] = '$extend(defaultValues, {' . implode(",\n\t", $js_default) . '})'; $js[] = '$.extend(defaultValues, {' . implode(",\n\t", $js_default) . '})';
display_js($js); display_js($js);
} }

View File

@@ -21,11 +21,13 @@ var PMA_messages = {};
* @param Element field * @param Element field
*/ */
function getFieldType(field) { function getFieldType(field) {
if (field.tagName == 'INPUT') { field = $(field);
return field.getProperty('type'); var tagName = field.attr('tagName');
} else if (field.tagName == 'SELECT') { if (tagName == 'INPUT') {
return field.attr('type');
} else if (tagName == 'SELECT') {
return 'select'; return 'select';
} else if (field.tagName == 'TEXTAREA') { } else if (tagName == 'TEXTAREA') {
return 'text'; return 'text';
} }
return ''; return '';
@@ -36,31 +38,33 @@ function getFieldType(field) {
* *
* value must be of type: * value must be of type:
* o undefined (omitted) - restore default value (form default, not PMA default) * o undefined (omitted) - restore default value (form default, not PMA default)
* o String - if type is 'text' * o String - if field_type is 'text'
* o boolean - if type is 'checkbox' * o boolean - if field_type is 'checkbox'
* o Array of values - if type is 'select' * o Array of values - if field_type is 'select'
* *
* @param Element field * @param Element field
* @param String field_type see getFieldType * @param String field_type see getFieldType
* @param mixed value * @param mixed value
*/ */
function setFieldValue(field, field_type, value) { function setFieldValue(field, field_type, value) {
field = $(field);
switch (field_type) { switch (field_type) {
case 'text': case 'text':
field.value = $defined(value) ? value : field.defaultValue; field.attr('value', (value != undefined ? value : field.attr('defaultValue')));
break; break;
case 'checkbox': case 'checkbox':
field.checked = $defined(value) ? value : field.defaultChecked; field.attr('checked', (value != undefined ? value : field.attr('defaultChecked')));
break; break;
case 'select': case 'select':
var i, imax = field.options.length; var options = field.attr('options');
if (!$defined(value)) { var i, imax = options.length;
if (value == undefined) {
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
field.options[i].selected = field.options[i].defaultSelected; options[i].selected = options[i].defaultSelected;
} }
} else { } else {
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
field.options[i].selected = (value.indexOf(field.options[i].value) != -1); options[i].selected = (value.indexOf(options[i].value) != -1);
} }
} }
break; break;
@@ -81,16 +85,18 @@ function setFieldValue(field, field_type, value) {
* @return mixed * @return mixed
*/ */
function getFieldValue(field, field_type) { function getFieldValue(field, field_type) {
field = $(field);
switch (field_type) { switch (field_type) {
case 'text': case 'text':
return field.value; return field.attr('value');
case 'checkbox': case 'checkbox':
return field.checked; return field.attr('checked');
case 'select': case 'select':
var i, imax = field.options.length, items = []; var options = field.attr('options');
var i, imax = options.length, items = [];
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
if (field.options[i].selected) { if (options[i].selected) {
items.push(field.options[i].value); items.push(options[i].value);
} }
} }
return items; return items;
@@ -101,8 +107,8 @@ function getFieldValue(field, field_type) {
* Returns values for all fields in fieldsets * Returns values for all fields in fieldsets
*/ */
function getAllValues() { function getAllValues() {
var elements = $$('fieldset input, fieldset select, fieldset textarea'); var elements = $('fieldset input, fieldset select, fieldset textarea');
var values = {} var values = {};
var type, value; var type, value;
for (var i = 0; i < elements.length; i++) { for (var i = 0; i < elements.length; i++) {
type = getFieldType(elements[i]); type = getFieldType(elements[i]);
@@ -126,21 +132,23 @@ function getAllValues() {
* @return boolean * @return boolean
*/ */
function checkFieldDefault(field, type) { function checkFieldDefault(field, type) {
if (!$defined(defaultValues[field.id])) { field = $(field);
var field_id = field.attr('id');
if (typeof defaultValues[field_id] == 'undefined') {
return true; return true;
} }
var isDefault = true var isDefault = true;
var currentValue = getFieldValue(field, type); var currentValue = getFieldValue(field, type);
if (type != 'select') { if (type != 'select') {
isDefault = currentValue == defaultValues[field.id]; isDefault = currentValue == defaultValues[field_id];
} else { } else {
// compare arrays, will work for our representation of select values // compare arrays, will work for our representation of select values
if (currentValue.length != defaultValues[field.id].length) { if (currentValue.length != defaultValues[field_id].length) {
isDefault = false; isDefault = false;
} }
else { else {
for (var i = 0; i < currentValue.length; i++) { for (var i = 0; i < currentValue.length; i++) {
if (currentValue[i] != defaultValues[field.id][i]) { if (currentValue[i] != defaultValues[field_id][i]) {
isDefault = false; isDefault = false;
break; break;
} }
@@ -155,7 +163,7 @@ function checkFieldDefault(field, type) {
* @param Element element * @param Element element
*/ */
function getIdPrefix(element) { function getIdPrefix(element) {
return element.id.replace(/[^-]+$/, ''); return $(element).attr('id').replace(/[^-]+$/, '');
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@@ -165,22 +173,22 @@ function getIdPrefix(element) {
// stores hidden message ids // stores hidden message ids
var hiddenMessages = []; var hiddenMessages = [];
window.addEvent('domready', function() { $(function() {
var hidden = hiddenMessages.length; var hidden = hiddenMessages.length;
for (var i = 0; i < hidden; i++) { for (var i = 0; i < hidden; i++) {
$(hiddenMessages[i]).style.display = 'none'; $('#'+hiddenMessages[i]).css('display', 'none');
} }
if (hidden > 0) { if (hidden > 0) {
var link = $('show_hidden_messages'); var link = $('#show_hidden_messages');
link.addEvent('click', function(e) { link.click(function(e) {
e.stop(); e.preventDefault();
for (var i = 0; i < hidden; i++) { for (var i = 0; i < hidden; i++) {
$(hiddenMessages[i]).style.display = ''; $('#'+hiddenMessages[i]).show(500);
} }
this.dispose(); $(this).remove();
}); });
link.set('html', link.get('html').replace('#MSG_COUNT', hidden)); link.html(link.html().replace('#MSG_COUNT', hidden));
link.style.display = ''; link.css('display', '');
} }
}); });
@@ -197,13 +205,15 @@ var validate = {};
// form validator list // form validator list
var validators = { var validators = {
// regexp: numeric value
_regexp_numeric: new RegExp('^[0-9]*$'),
/** /**
* Validates positive number * Validates positive number
* *
* @param boolean isKeyUp * @param boolean isKeyUp
*/ */
validate_positive_number: function (isKeyUp) { validate_positive_number: function (isKeyUp) {
var result = this.value.test('^[0-9]*$') && this.value != '0'; var result = this.value != '0' && validators._regexp_numeric.test(this.value);
return result ? true : PMA_messages['error_nan_p']; return result ? true : PMA_messages['error_nan_p'];
}, },
/** /**
@@ -212,7 +222,7 @@ var validators = {
* @param boolean isKeyUp * @param boolean isKeyUp
*/ */
validate_non_negative_number: function (isKeyUp) { validate_non_negative_number: function (isKeyUp) {
var result = this.value.test('^[0-9]*$'); var result = validators._regexp_numeric.test(this.value);
return result ? true : PMA_messages['error_nan_nneg']; return result ? true : PMA_messages['error_nan_nneg'];
}, },
/** /**
@@ -221,7 +231,7 @@ var validators = {
* @param boolean isKeyUp * @param boolean isKeyUp
*/ */
validate_port_number: function(isKeyUp) { validate_port_number: function(isKeyUp) {
var result = this.value.test('^[0-9]*$') && this.value != '0'; var result = validators._regexp_numeric.test(this.value) && this.value != '0';
if (!result || this.value > 65536) { if (!result || this.value > 65536) {
result = PMA_messages['error_incorrect_port']; result = PMA_messages['error_incorrect_port'];
} }
@@ -254,7 +264,7 @@ var validators = {
ajaxValidate(this, 'TrustedProxies', data); ajaxValidate(this, 'TrustedProxies', data);
} }
return true; return true;
}, }
}, },
// fieldset validators // fieldset validators
_fieldset: { _fieldset: {
@@ -275,7 +285,7 @@ var validators = {
* @param boolean isKeyUp * @param boolean isKeyUp
*/ */
Server_login_options: function(isKeyUp) { Server_login_options: function(isKeyUp) {
return validators._fieldset.Server.bind(this)(isKeyUp); return validators._fieldset.Server.apply(this, [isKeyUp]);
}, },
/** /**
* Validates Server_pmadb fieldset * Validates Server_pmadb fieldset
@@ -287,8 +297,8 @@ var validators = {
return true; return true;
} }
var prefix = getIdPrefix(this.getElement('input')); var prefix = getIdPrefix($(this).find('input'));
var pmadb_active = $(prefix + 'pmadb').value != ''; var pmadb_active = $('#' + prefix + 'pmadb').val() != '';
if (pmadb_active) { if (pmadb_active) {
ajaxValidate(this, 'Server_pmadb', getAllValues()); ajaxValidate(this, 'Server_pmadb', getAllValues());
} }
@@ -296,7 +306,7 @@ var validators = {
return true; return true;
} }
} }
} };
/** /**
* Calls server-side validation procedures * Calls server-side validation procedures
@@ -306,45 +316,50 @@ var validators = {
* @param Object values values hash (element_id: value) * @param Object values values hash (element_id: value)
*/ */
function ajaxValidate(parent, id, values) { function ajaxValidate(parent, id, values) {
parent = $(parent);
// ensure that parent is a fieldset // ensure that parent is a fieldset
if (parent.tagName != 'FIELDSET') { if (parent.attr('tagName') != 'FIELDSET') {
parent = parent.getParent('fieldset'); parent = parent.closest('fieldset');
if (!parent) { if (parent.length == 0) {
return false; return false;
} }
} }
// ensure that we have a Request object
if (typeof parent.request == 'undefined') { if (parent.data('ajax') != null) {
parent.validate = { parent.data('ajax').abort();
request: new Request.JSON({
url: 'validate.php',
autoCancel: true,
onSuccess: function(response) {
if (response == null) {
return;
}
var error = {};
if ($type(response) != 'object') {
error[parent.id] = [response];
} else if (typeof response['error'] != 'undefined') {
error[parent.id] = [response['error']];
} else {
$each(response, function(value, key) {
error[key] = $type(value) == 'array' ? value : [value];
});
}
displayErrors(error);
}}),
token: parent.getParent('form').token.value
};
} }
parent.validate.request.send({ parent.data('ajax', $.ajax({
url: 'validate.php',
cache: false,
type: 'POST',
data: { data: {
token: parent.validate.token, token: parent.closest('form').find('input[name=token]').val(),
id: id, id: id,
values: JSON.encode(values)} values: $.toJSON(values)
}); },
success: function(response) {
if (response == null) {
return;
}
var error = {};
if (typeof response != 'object') {
error[parent.id] = [response];
} else if (typeof response['error'] != 'undefined') {
error[parent.id] = [response['error']];
} else {
for (key in response) {
var value = response[key];
error[key] = jQuery.isArray(value) ? value : [value];
}
}
displayErrors(error);
},
complete: function() {
parent.removeData('ajax');
}
}));
return true; return true;
} }
@@ -404,32 +419,29 @@ function getFieldValidators(field_id, onKeyUpOnly) {
* *
* @param Object error list (key: field id, value: error array) * @param Object error list (key: field id, value: error array)
*/ */
function displayErrors(errors) { function displayErrors(error_list) {
$each(errors, function(errors, field_id) { for (field_id in error_list) {
var field = $(field_id); var errors = error_list[field_id];
var isFieldset = field.tagName == 'FIELDSET'; var field = $('#'+field_id);
var isFieldset = field.attr('tagName') == 'FIELDSET';
var errorCnt = isFieldset var errorCnt = isFieldset
? field.getElement('dl.errors') ? field.find('dl.errors')
: field.getNext('.inline_errors'); : field.siblings('.inline_errors');
// remove empty errors (used to clear error list) // remove empty errors (used to clear error list)
errors = errors.filter(function(item) { errors = $.grep(errors, function(item) {
return item != ''; return item != '';
}); });
if (errors.length) { if (errors.length) {
// if error container doesn't exist, create it // if error container doesn't exist, create it
if (errorCnt === null) { if (errorCnt.length == 0) {
if (isFieldset) { if (isFieldset) {
errorCnt = new Element('dl', { errorCnt = $('<dl class="errors" />');
'class': 'errors' field.find('table').before(errorCnt);
});
errorCnt.inject(field.getElement('table'), 'before');
} else { } else {
errorCnt = new Element('dl', { errorCnt = $('<dl class="inline_errors" />');
'class': 'inline_errors' field.closest('td').append(errorCnt);
});
errorCnt.inject(field.getParent('td'), 'bottom');
} }
} }
@@ -437,12 +449,12 @@ function displayErrors(errors) {
for (var i = 0, imax = errors.length; i < imax; i++) { for (var i = 0, imax = errors.length; i < imax; i++) {
html += '<dd>' + errors[i] + '</dd>'; html += '<dd>' + errors[i] + '</dd>';
} }
errorCnt.set('html', html); errorCnt.html(html);
} else if (errorCnt !== null) { } else if (errorCnt !== null) {
// remove useless error container // remove useless error container
errorCnt.dispose(); errorCnt.remove();
} }
}); }
} }
/** /**
@@ -453,14 +465,18 @@ function displayErrors(errors) {
* @param Object errors * @param Object errors
*/ */
function validate_fieldset(fieldset, isKeyUp, errors) { function validate_fieldset(fieldset, isKeyUp, errors) {
if (fieldset && typeof validators._fieldset[fieldset.id] != 'undefined') { fieldset = $(fieldset);
var fieldset_errors = validators._fieldset[fieldset.id].bind(fieldset)(isKeyUp); if (fieldset.length && typeof validators._fieldset[fieldset.attr('id')] != 'undefined') {
$each(fieldset_errors, function(field_errors, field_id) { var fieldset_errors = validators._fieldset[fieldset.attr('id')].apply(fieldset[0], [isKeyUp]);
for (field_id in fieldset_errors) {
if (typeof errors[field_id] == 'undefined') { if (typeof errors[field_id] == 'undefined') {
errors[field_id] = []; errors[field_id] = [];
} }
errors[field_id][$type(field_errors) == 'array' ? 'extend' : 'push'](field_errors); if (typeof fieldset_errors[field_id] == 'string') {
}); fieldset_errors[field_id] = [fieldset_errors[field_id]];
}
$.merge(errors[field_id], fieldset_errors[field_id]);
}
} }
} }
@@ -472,12 +488,17 @@ function validate_fieldset(fieldset, isKeyUp, errors) {
* @param Object errors * @param Object errors
*/ */
function validate_field(field, isKeyUp, errors) { function validate_field(field, isKeyUp, errors) {
errors[field.id] = []; field = $(field);
var functions = getFieldValidators(field.id, isKeyUp); var field_id = field.attr('id');
errors[field_id] = [];
var functions = getFieldValidators(field_id, isKeyUp);
for (var i = 0; i < functions.length; i++) { for (var i = 0; i < functions.length; i++) {
var result = functions[i][0].bind(field)(isKeyUp, functions[i][1]); var result = functions[i][0].apply(field[0], [isKeyUp, functions[i][1]]);
if (result !== true) { if (result !== true) {
errors[field.id][$type(result) == 'array' ? 'extend' : 'push'](result); if (typeof result == 'string') {
result = [result];
}
$.merge(errors[field_id], result);
} }
} }
} }
@@ -489,9 +510,10 @@ function validate_field(field, isKeyUp, errors) {
* @param boolean isKeyUp * @param boolean isKeyUp
*/ */
function validate_field_and_fieldset(field, isKeyUp) { function validate_field_and_fieldset(field, isKeyUp) {
field = $(field);
var errors = {}; var errors = {};
validate_field(field, isKeyUp, errors); validate_field(field, isKeyUp, errors);
validate_fieldset(field.getParent('fieldset'), isKeyUp, errors); validate_fieldset(field.closest('fieldset'), isKeyUp, errors);
displayErrors(errors); displayErrors(errors);
} }
@@ -501,11 +523,12 @@ function validate_field_and_fieldset(field, isKeyUp) {
* @param Element field * @param Element field
*/ */
function markField(field) { function markField(field) {
field = $(field);
var type = getFieldType(field); var type = getFieldType(field);
var isDefault = checkFieldDefault(field, type); var isDefault = checkFieldDefault(field, type);
// checkboxes uses parent <span> for marking // checkboxes uses parent <span> for marking
var fieldMarker = (type == 'checkbox') ? field.getParent() : field; var fieldMarker = (type == 'checkbox') ? field.parent() : field;
setRestoreDefaultBtn(field, !isDefault); setRestoreDefaultBtn(field, !isDefault);
fieldMarker[isDefault ? 'removeClass' : 'addClass']('custom'); fieldMarker[isDefault ? 'removeClass' : 'addClass']('custom');
} }
@@ -517,55 +540,51 @@ function markField(field) {
* @param bool display * @param bool display
*/ */
function setRestoreDefaultBtn(field, display) { function setRestoreDefaultBtn(field, display) {
var td = field.getParent('td'); var el = $(field).closest('td').find('.restore-default');
if (!td) return; el.css('display', (el.css('display') ? '' : 'none'));
var el = td.getElement('.restore-default');
if (!el) return;
el.style.display = (display ? '' : 'none');
} }
window.addEvent('domready', function() { $(function() {
var elements = $$('input[id], select[id], textarea[id]');
var elements_count = elements.length;
// register validators and mark custom values // register validators and mark custom values
for (var i = 0; i < elements_count; i++) { var elements = $('input[id], select[id], textarea[id]');
var el = elements[i]; $('input[id], select[id], textarea[id]').each(function(){
markField(el); markField(this);
el.addEvent('change', function(e) { var el = $(this);
el.bind('change', function() {
validate_field_and_fieldset(this, false); validate_field_and_fieldset(this, false);
markField(this); markField(this);
}); });
var tagName = el.attr('tagName');
// text fields can be validated after each change // text fields can be validated after each change
if (el.tagName == 'INPUT' && el.type == 'text') { if (tagName == 'INPUT' && el.attr('type') == 'text') {
el.addEvent('keyup', function(e) { el.keyup(function() {
validate_field_and_fieldset(this, true); validate_field_and_fieldset(el, true);
markField(el); markField(el);
}); });
} }
// disable textarea spellcheck // disable textarea spellcheck
if (el.tagName == 'TEXTAREA') { if (tagName == 'TEXTAREA') {
el.setProperty('spellcheck', false) el.attr('spellcheck', false);
} }
} });
// check whether we've refreshed a page and browser remembered modified // check whether we've refreshed a page and browser remembered modified
// form values // form values
var check_page_refresh = $('check_page_refresh'); var check_page_refresh = $('#check_page_refresh');
if (!check_page_refresh || check_page_refresh.value == '1') { if (check_page_refresh.length == 0 || check_page_refresh.val() == '1') {
// run all field validators // run all field validators
var errors = {}; var errors = {};
for (var i = 0; i < elements_count; i++) { for (var i = 0; i < elements.length; i++) {
validate_field(elements[i], false, errors); validate_field(elements[i], false, errors);
} }
// run all fieldset validators // run all fieldset validators
$$('fieldset').each(function(el){ $('fieldset').each(function(){
validate_fieldset(el, false, errors); validate_fieldset(this, false, errors);
}); });
displayErrors(errors); displayErrors(errors);
} else if (check_page_refresh) { } else if (check_page_refresh) {
check_page_refresh.value = '1'; check_page_refresh.val('1');
} }
}); });
@@ -583,37 +602,38 @@ window.addEvent('domready', function() {
* @param Element tab_link * @param Element tab_link
*/ */
function setTab(tab_link) { function setTab(tab_link) {
var tabs_menu = tab_link.getParent('.tabs'); var tabs_menu = $(tab_link).closest('.tabs');
var links = tabs_menu.getElements('a'); var links = tabs_menu.find('a');
var contents; var contents, link;
for (var i = 0, imax = links.length; i < imax; i++) { for (var i = 0, imax = links.length; i < imax; i++) {
contents = $(links[i].getProperty('href').substr(1)); link = $(links[i]);
contents = $(link.attr('href'));
if (links[i] == tab_link) { if (links[i] == tab_link) {
links[i].addClass('active'); link.addClass('active');
contents.style.display = 'block'; contents.css('display', 'block');
} else { } else {
links[i].removeClass('active'); link.removeClass('active');
contents.style.display = 'none'; contents.css('display', 'none');
} }
} }
location.hash = 'tab_' + tab_link.getProperty('href').substr(1); location.hash = 'tab_' + $(tab_link).attr('href').substr(1);
} }
window.addEvent('domready', function() { $(function() {
var tabs = $$('.tabs'); var tabs = $('.tabs');
var url_tab = location.hash.match(/^#tab_.+/) var url_tab = location.hash.match(/^#tab_.+/)
? $$('a[href$="' + location.hash.substr(5) + '"]') : null; ? $('a[href$="' + location.hash.substr(5) + '"]') : null;
if (url_tab) { if (url_tab) {
url_tab = url_tab[0]; url_tab = url_tab[0];
} }
// add tabs events and activate one tab (the first one or indicated by location hash) // add tabs events and activate one tab (the first one or indicated by location hash)
for (var i = 0, imax = tabs.length; i < imax; i++) { for (var i = 0, imax = tabs.length; i < imax; i++) {
var links = tabs[i].getElements('a'); var links = $(tabs[i]).find('a');
var selected_tab = links[0]; var selected_tab = links[0];
for (var j = 0, jmax = links.length; j < jmax; j++) { for (var j = 0, jmax = links.length; j < jmax; j++) {
links[j].addEvent('click', function(e) { $(links[j]).click(function(e) {
e.stop(); e.preventDefault();
setTab(this); setTab(this);
}); });
if (links[j] == url_tab) { if (links[j] == url_tab) {
@@ -625,16 +645,16 @@ window.addEvent('domready', function() {
// tab links handling, check each 200ms // tab links handling, check each 200ms
// (works with history in FF, further browser support here would be an overkill) // (works with history in FF, further browser support here would be an overkill)
var prev_hash = location.hash; var prev_hash = location.hash;
(function() { setInterval(function() {
if (location.hash != prev_hash) { if (location.hash != prev_hash) {
prev_hash = location.hash; prev_hash = location.hash;
var url_tab = location.hash.match(/^#tab_.+/) var url_tab = location.hash.match(/^#tab_.+/)
? $$('a[href$="' + location.hash.substr(5) + '"]') : null; ? $('a[href$="' + location.hash.substr(5) + '"]') : null;
if (url_tab) { if (url_tab) {
setTab(url_tab[0]); setTab(url_tab[0]);
} }
} }
}).periodical(200); }, 200);
}); });
// //
@@ -645,16 +665,13 @@ window.addEvent('domready', function() {
// Form reset buttons // Form reset buttons
// //
window.addEvent('domready', function() { $(function() {
var buttons = $$('input[type=button]'); $('input[type=button]').click(function(e) {
for (var i = 0, imax = buttons.length; i < imax; i++) { var fields = $(this).closest('fieldset').find('input, select, textarea');
buttons[i].addEvent('click', function(e) { for (var i = 0, imax = fields.length; i < imax; i++) {
var fields = this.getParent('fieldset').getElements('input, select, textarea'); setFieldValue(fields[i], getFieldType(fields[i]));
for (var i = 0, imax = fields.length; i < imax; i++) { }
setFieldValue(fields[i], getFieldType(fields[i])); });
}
});
}
}); });
// //
@@ -671,45 +688,40 @@ window.addEvent('domready', function() {
* @param String field_id * @param String field_id
*/ */
function restoreField(field_id) { function restoreField(field_id) {
var field = $(field_id); var field = $('#'+field_id);
if (!field || !$defined(defaultValues[field_id])) { if (field.length == 0 || defaultValues[field_id] == undefined) {
return; return;
} }
setFieldValue(field, getFieldType(field), defaultValues[field_id]); setFieldValue(field, getFieldType(field), defaultValues[field_id]);
} }
window.addEvent('domready', function() { $(function() {
var buttons = $$('.restore-default, .set-value'); $('.restore-default, .set-value').each(function() {
var fixIE = Browser.Engine.name == 'trident' && Browser.Engine.version == 4; var link = $(this);
for (var i = 0, imax = buttons.length; i < imax; i++) { link.css('opacity', 0.25);
buttons[i].set('opacity', 0.25); if (!link.hasClass('restore-default')) {
if (!buttons[i].hasClass('restore-default')) {
// restore-default is handled by markField // restore-default is handled by markField
buttons[i].style.display = ''; link.css('display', '');
} }
buttons[i].addEvents({ link.bind({
mouseenter: function(e) {this.set('opacity', 1);}, mouseenter: function() {$(this).css('opacity', 1);},
mouseleave: function(e) {this.set('opacity', 0.25);}, mouseleave: function() {$(this).css('opacity', 0.25);},
click: function(e) { click: function(e) {
e.stop(); e.preventDefault();
var href = this.getProperty('href').substr(1); var href = $(this).attr('href').substr(1);
var field_id; var field_id;
if (this.hasClass('restore-default')) { if ($(this).hasClass('restore-default')) {
field_id = href; field_id = href;
restoreField(field_id); restoreField(field_id);
} else { } else {
field_id = href.match(/^[^=]+/)[0]; field_id = href.match(/^[^=]+/)[0];
var value = href.match(/=(.+)$/)[1]; var value = href.match(/=(.+)$/)[1];
setFieldValue($(field_id), 'text', value); setFieldValue($('#'+field_id), 'text', value);
} }
$(field_id).fireEvent('change'); $('#'+field_id).trigger('change');
} }
}); });
// fix IE showing <img> alt text instead of link title });
if (fixIE) {
buttons[i].getChildren('img')[0].alt = buttons[i].title;
}
}
}); });
// //

View File

@@ -111,6 +111,15 @@ div.notice h4 {
border-color: #FFD700; border-color: #FFD700;
} }
div.notice[id^=version_check] {
border-color: #002DFF;
background-color: #EEF;
}
div.notice[id^=version_check] h4 {
border-color: #002DFF;
}
div.warning { div.warning {
border-color: #C00; border-color: #C00;
background-color: #FFC; background-color: #FFC;
@@ -229,6 +238,7 @@ fieldset .inline_errors { /* field error list */
padding: 0; padding: 0;
list-style: none; list-style: none;
color: #9A0000; color: #9A0000;
font-size: small;
} }
fieldset table { fieldset table {