clean up config JavaScript

This commit is contained in:
Crack
2010-07-26 22:34:13 +02:00
parent edaf7ce86c
commit 9d62971e11

View File

@@ -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]; e.preventDefault();
for (var j = 0, jmax = links.length; j < jmax; j++) { setTab($(this).attr('href'));
$(links[j]).click(function(e) { })
e.preventDefault(); .filter(':first')
setTab(this); .addClass('active');
}); $('.tabs_contents fieldset').hide().filter(':first').show();
if (links[j] == url_tab) {
selected_tab = links[j];
}
}
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')) { e.preventDefault();
// restore-default is handled by markField var href = $(this).attr('href');
} var field_sel;
link.bind({ if ($(this).hasClass('restore-default')) {
mouseenter: function() {$(this).css('opacity', 1);}, field_sel = href;
mouseleave: function() {$(this).css('opacity', 0.25);}, restoreField(field_sel.substr(1));
click: function(e) { } else {
e.preventDefault(); field_sel = href.match(/^[^=]+/)[0];
var href = $(this).attr('href').substr(1); var value = href.match(/=(.+)$/)[1];
var field_id; setFieldValue($(field_sel), 'text', value);
if ($(this).hasClass('restore-default')) {
field_id = href;
restoreField(field_id);
} else {
field_id = href.match(/^[^=]+/)[0];
var value = href.match(/=(.+)$/)[1];
setFieldValue($('#'+field_id), '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});
}); });
// //
@@ -640,9 +615,9 @@ $(function() {
var disable_id = enable_id.match(/local_storage$/) var disable_id = enable_id.match(/local_storage$/)
? 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
var ls_supported = window.localStorage || false; var ls_supported = window.localStorage || false;