- add vim modeline
- remove tab characters
This commit is contained in:
69
js/config.js
69
js/config.js
@@ -1,3 +1,4 @@
|
|||||||
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||||
/**
|
/**
|
||||||
* Functions used in configuration forms and on user preferences pages
|
* Functions used in configuration forms and on user preferences pages
|
||||||
*/
|
*/
|
||||||
@@ -14,9 +15,9 @@ var PMA_messages = {};
|
|||||||
* @param {Element} field
|
* @param {Element} field
|
||||||
*/
|
*/
|
||||||
function getFieldType(field) {
|
function getFieldType(field) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
var tagName = field.attr('tagName');
|
var tagName = field.attr('tagName');
|
||||||
if (tagName == 'INPUT') {
|
if (tagName == 'INPUT') {
|
||||||
return field.attr('type');
|
return field.attr('type');
|
||||||
} else if (tagName == 'SELECT') {
|
} else if (tagName == 'SELECT') {
|
||||||
return 'select';
|
return 'select';
|
||||||
@@ -40,7 +41,7 @@ function getFieldType(field) {
|
|||||||
* @param {String|Boolean} [value]
|
* @param {String|Boolean} [value]
|
||||||
*/
|
*/
|
||||||
function setFieldValue(field, field_type, value) {
|
function setFieldValue(field, field_type, value) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
switch (field_type) {
|
switch (field_type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
field.attr('value', (value != undefined ? value : field.attr('defaultValue')));
|
field.attr('value', (value != undefined ? value : field.attr('defaultValue')));
|
||||||
@@ -50,14 +51,14 @@ function setFieldValue(field, field_type, value) {
|
|||||||
break;
|
break;
|
||||||
case 'select':
|
case 'select':
|
||||||
var options = field.attr('options');
|
var options = field.attr('options');
|
||||||
var i, imax = options.length;
|
var i, imax = options.length;
|
||||||
if (value == undefined) {
|
if (value == undefined) {
|
||||||
for (i = 0; i < imax; i++) {
|
for (i = 0; i < imax; i++) {
|
||||||
options[i].selected = options[i].defaultSelected;
|
options[i].selected = options[i].defaultSelected;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < imax; i++) {
|
for (i = 0; i < imax; i++) {
|
||||||
options[i].selected = (value.indexOf(options[i].value) != -1);
|
options[i].selected = (value.indexOf(options[i].value) != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -78,14 +79,14 @@ function setFieldValue(field, field_type, value) {
|
|||||||
* @type Boolean|String|String[]
|
* @type Boolean|String|String[]
|
||||||
*/
|
*/
|
||||||
function getFieldValue(field, field_type) {
|
function getFieldValue(field, field_type) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
switch (field_type) {
|
switch (field_type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
return field.attr('value');
|
return field.attr('value');
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
return field.attr('checked');
|
return field.attr('checked');
|
||||||
case 'select':
|
case 'select':
|
||||||
var options = field.attr('options');
|
var options = field.attr('options');
|
||||||
var i, imax = options.length, items = [];
|
var i, imax = options.length, items = [];
|
||||||
for (i = 0; i < imax; i++) {
|
for (i = 0; i < imax; i++) {
|
||||||
if (options[i].selected) {
|
if (options[i].selected) {
|
||||||
@@ -354,7 +355,7 @@ function displayErrors(error_list) {
|
|||||||
* @param {Object} errors
|
* @param {Object} errors
|
||||||
*/
|
*/
|
||||||
function validate_fieldset(fieldset, isKeyUp, errors) {
|
function validate_fieldset(fieldset, isKeyUp, errors) {
|
||||||
fieldset = $(fieldset);
|
fieldset = $(fieldset);
|
||||||
if (fieldset.length && typeof validators._fieldset[fieldset.attr('id')] != 'undefined') {
|
if (fieldset.length && typeof validators._fieldset[fieldset.attr('id')] != 'undefined') {
|
||||||
var fieldset_errors = validators._fieldset[fieldset.attr('id')].apply(fieldset[0], [isKeyUp]);
|
var fieldset_errors = validators._fieldset[fieldset.attr('id')].apply(fieldset[0], [isKeyUp]);
|
||||||
for (var field_id in fieldset_errors) {
|
for (var field_id in fieldset_errors) {
|
||||||
@@ -377,8 +378,8 @@ function validate_fieldset(fieldset, isKeyUp, errors) {
|
|||||||
* @param {Object} errors
|
* @param {Object} errors
|
||||||
*/
|
*/
|
||||||
function validate_field(field, isKeyUp, errors) {
|
function validate_field(field, isKeyUp, errors) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
var field_id = field.attr('id');
|
var field_id = field.attr('id');
|
||||||
errors[field_id] = [];
|
errors[field_id] = [];
|
||||||
var functions = getFieldValidators(field_id, isKeyUp);
|
var functions = getFieldValidators(field_id, isKeyUp);
|
||||||
for (var i = 0; i < functions.length; i++) {
|
for (var i = 0; i < functions.length; i++) {
|
||||||
@@ -389,7 +390,7 @@ function validate_field(field, isKeyUp, errors) {
|
|||||||
var result = functions[i][0].apply(field[0], args);
|
var result = functions[i][0].apply(field[0], args);
|
||||||
if (result !== true) {
|
if (result !== true) {
|
||||||
if (typeof result == 'string') {
|
if (typeof result == 'string') {
|
||||||
result = [result];
|
result = [result];
|
||||||
}
|
}
|
||||||
$.merge(errors[field_id], result);
|
$.merge(errors[field_id], result);
|
||||||
}
|
}
|
||||||
@@ -403,7 +404,7 @@ 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);
|
field = $(field);
|
||||||
var errors = {};
|
var errors = {};
|
||||||
validate_field(field, isKeyUp, errors);
|
validate_field(field, isKeyUp, errors);
|
||||||
validate_fieldset(field.closest('fieldset'), isKeyUp, errors);
|
validate_fieldset(field.closest('fieldset'), isKeyUp, errors);
|
||||||
@@ -416,7 +417,7 @@ function validate_field_and_fieldset(field, isKeyUp) {
|
|||||||
* @param {Element} field
|
* @param {Element} field
|
||||||
*/
|
*/
|
||||||
function markField(field) {
|
function markField(field) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
var type = getFieldType(field);
|
var type = getFieldType(field);
|
||||||
var isDefault = checkFieldDefault(field, type);
|
var isDefault = checkFieldDefault(field, type);
|
||||||
|
|
||||||
@@ -439,7 +440,7 @@ function setRestoreDefaultBtn(field, display) {
|
|||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// register validators and mark custom values
|
// register validators and mark custom values
|
||||||
var elements = $('input[id], select[id], textarea[id]');
|
var elements = $('input[id], select[id], textarea[id]');
|
||||||
$('input[id], select[id], textarea[id]').each(function(){
|
$('input[id], select[id], textarea[id]').each(function(){
|
||||||
markField(this);
|
markField(this);
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
@@ -450,35 +451,35 @@ $(function() {
|
|||||||
var tagName = el.attr('tagName');
|
var tagName = el.attr('tagName');
|
||||||
// text fields can be validated after each change
|
// text fields can be validated after each change
|
||||||
if (tagName == 'INPUT' && el.attr('type') == 'text') {
|
if (tagName == 'INPUT' && el.attr('type') == 'text') {
|
||||||
el.keyup(function() {
|
el.keyup(function() {
|
||||||
validate_field_and_fieldset(el, true);
|
validate_field_and_fieldset(el, true);
|
||||||
markField(el);
|
markField(el);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// disable textarea spellcheck
|
// disable textarea spellcheck
|
||||||
if (tagName == 'TEXTAREA') {
|
if (tagName == 'TEXTAREA') {
|
||||||
el.attr('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.length == 0 || check_page_refresh.val() == '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.length; 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(){
|
$('fieldset').each(function(){
|
||||||
validate_fieldset(this, false, errors);
|
validate_fieldset(this, false, errors);
|
||||||
});
|
});
|
||||||
|
|
||||||
displayErrors(errors);
|
displayErrors(errors);
|
||||||
} else if (check_page_refresh) {
|
} else if (check_page_refresh) {
|
||||||
check_page_refresh.val('1');
|
check_page_refresh.val('1');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user