clean up config JavaScript
This commit is contained in:
105
js/config.js
105
js/config.js
@@ -94,6 +94,7 @@ function getFieldValue(field, field_type) {
|
|||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -491,62 +492,42 @@ $(function() {
|
|||||||
/**
|
/**
|
||||||
* Sets active tab
|
* Sets active tab
|
||||||
*
|
*
|
||||||
* @param {Element} tab_link
|
* @param {String} tab_id
|
||||||
*/
|
*/
|
||||||
function setTab(tab_link) {
|
function setTab(tab_id) {
|
||||||
var tabs_menu = $(tab_link).closest('.tabs');
|
$('.tabs a').removeClass('active').filter('[href=' + tab_id + ']').addClass('active');
|
||||||
|
$('.tabs_contents fieldset').hide().filter(tab_id).show();
|
||||||
var links = tabs_menu.find('a');
|
location.hash = 'tab_' + tab_id.substr(1);
|
||||||
var contents, link;
|
|
||||||
for (var i = 0, imax = links.length; i < imax; i++) {
|
|
||||||
link = $(links[i]);
|
|
||||||
contents = $(link.attr('href'));
|
|
||||||
if (links[i] == tab_link) {
|
|
||||||
link.addClass('active');
|
|
||||||
contents.css('display', 'block');
|
|
||||||
} else {
|
|
||||||
link.removeClass('active');
|
|
||||||
contents.css('display', 'none');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
location.hash = 'tab_' + $(tab_link).attr('href').substr(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
var tabs = $('.tabs');
|
var tabs = $('.tabs');
|
||||||
var url_tab = location.hash.match(/^#tab_.+/)
|
if (!tabs.length) {
|
||||||
? $('a[href$="' + location.hash.substr(5) + '"]') : null;
|
return;
|
||||||
if (url_tab) {
|
|
||||||
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++) {
|
tabs.find('a')
|
||||||
var links = $(tabs[i]).find('a');
|
.click(function(e) {
|
||||||
var selected_tab = links[0];
|
|
||||||
for (var j = 0, jmax = links.length; j < jmax; j++) {
|
|
||||||
$(links[j]).click(function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setTab(this);
|
setTab($(this).attr('href'));
|
||||||
});
|
})
|
||||||
if (links[j] == url_tab) {
|
.filter(':first')
|
||||||
selected_tab = links[j];
|
.addClass('active');
|
||||||
}
|
$('.tabs_contents fieldset').hide().filter(':first').show();
|
||||||
}
|
|
||||||
setTab(selected_tab);
|
|
||||||
}
|
|
||||||
// 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;
|
||||||
setInterval(function() {
|
var tab_check_fnc = 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_.+/)
|
if (location.hash.match(/^#tab_.+/) && $('#' + location.hash.substr(5)).length) {
|
||||||
? $('a[href$="' + location.hash.substr(5) + '"]') : null;
|
setTab('#' + location.hash.substr(5));
|
||||||
if (url_tab) {
|
|
||||||
setTab(url_tab[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 200);
|
};
|
||||||
|
tab_check_fnc();
|
||||||
|
setInterval(tab_check_fnc, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -558,7 +539,7 @@ $(function() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$('input[type=button]').click(function() {
|
$('input[type=button][name=submit_reset]').click(function() {
|
||||||
var fields = $(this).closest('fieldset').find('input, select, textarea');
|
var fields = $(this).closest('fieldset').find('input, select, textarea');
|
||||||
for (var i = 0, imax = fields.length; i < imax; i++) {
|
for (var i = 0, imax = fields.length; i < imax; i++) {
|
||||||
setFieldValue(fields[i], getFieldType(fields[i]));
|
setFieldValue(fields[i], getFieldType(fields[i]));
|
||||||
@@ -588,32 +569,26 @@ function restoreField(field_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$('.restore-default, .set-value').each(function() {
|
$('.tabs_contents')
|
||||||
var link = $(this);
|
.delegate('.restore-default, .set-value', 'mouseenter', function(){$(this).css('opacity', 1)})
|
||||||
// inline-block for IE so opacity inheritance works
|
.delegate('.restore-default, .set-value', 'mouseleave', function(){$(this).css('opacity', 0.25)})
|
||||||
link.css({display: 'inline-block', opacity: 0.25});
|
.delegate('.restore-default, .set-value', 'click', function(e) {
|
||||||
if (link.hasClass('restore-default')) {
|
|
||||||
// restore-default is handled by markField
|
|
||||||
}
|
|
||||||
link.bind({
|
|
||||||
mouseenter: function() {$(this).css('opacity', 1);},
|
|
||||||
mouseleave: function() {$(this).css('opacity', 0.25);},
|
|
||||||
click: function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var href = $(this).attr('href').substr(1);
|
var href = $(this).attr('href');
|
||||||
var field_id;
|
var field_sel;
|
||||||
if ($(this).hasClass('restore-default')) {
|
if ($(this).hasClass('restore-default')) {
|
||||||
field_id = href;
|
field_sel = href;
|
||||||
restoreField(field_id);
|
restoreField(field_sel.substr(1));
|
||||||
} else {
|
} else {
|
||||||
field_id = href.match(/^[^=]+/)[0];
|
field_sel = href.match(/^[^=]+/)[0];
|
||||||
var value = href.match(/=(.+)$/)[1];
|
var value = href.match(/=(.+)$/)[1];
|
||||||
setFieldValue($('#'+field_id), 'text', value);
|
setFieldValue($(field_sel), 'text', value);
|
||||||
}
|
}
|
||||||
$('#'+field_id).trigger('change');
|
$(field_sel).trigger('change');
|
||||||
}
|
})
|
||||||
});
|
.find('.restore-default, .set-value')
|
||||||
});
|
// inline-block for IE so opacity inheritance works
|
||||||
|
.css({display: 'inline-block', opacity: 0.25});
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -641,7 +616,7 @@ $(function() {
|
|||||||
? enable_id.replace(/local_storage$/, 'text_file')
|
? enable_id.replace(/local_storage$/, 'text_file')
|
||||||
: enable_id.replace(/text_file$/, 'local_storage');
|
: enable_id.replace(/text_file$/, 'local_storage');
|
||||||
$('#opts_'+disable_id).addClass('disabled').find('input').attr('disabled', true);
|
$('#opts_'+disable_id).addClass('disabled').find('input').attr('disabled', true);
|
||||||
$('#opts_'+enable_id).removeClass('disabled').find('input').attr('disabled', false);;
|
$('#opts_'+enable_id).removeClass('disabled').find('input').attr('disabled', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// detect localStorage state
|
// detect localStorage state
|
||||||
|
Reference in New Issue
Block a user