Work on toggleables

This commit is contained in:
Flavio Copes
2015-08-04 19:28:42 +02:00
parent c0b3064a08
commit dd150f67f7
8 changed files with 178 additions and 38 deletions

View File

@@ -30,6 +30,70 @@
var el = $(this),
type = el.data(form.dataIndicator);
if (type == 'textarea' || type == 'toggleable' || type == 'datetime') {
var processSpan = function processSpan(element, toggleable) {
var on = true;
if (!toggleable) {
on = $(element).find('input').is(':checked');
}
$(element).find('label').css('opacity', on ? 1 : 0.7);
$(element).siblings('label').css('opacity', on ? 1 : 0.7);
if (!on) {
$(element).find('input').attr('checked', false).prop('value', 0);
} else {
$(element).find('input').attr('checked', true).prop('value', 1);
}
$(element).parent().siblings('.form-data').css('opacity', on ? 1 : 0.6);
$(element).parent().siblings('.form-data').find('textarea').css('opacity', on ? 1 : 0.6);
$(element).parent().siblings('.form-data').find('input').css('opacity', on ? 1 : 0.6);
};
var processToggleables = function processToggleables(element) {
var elType = $(element)[0].tagName.toLowerCase();
if (elType == 'checkbox') {
var on = $(element).is(':checked');
$(element).siblings('label').css('opacity', on ? 1 : 0.7);
$(element).parent().siblings('label').css('opacity', on ? 1 : 0.7);
if (!on) {
$(element).attr('checked', false).prop('value', 0);
} else {
$(element).attr('checked', true).prop('value', 1);
}
$(element).parent().parent().siblings('.form-data').css('opacity', on ? 1 : 0.6);
$(element).parent().parent().siblings('.form-data').find('textarea').css('opacity', on ? 1 : 0.6);
$(element).parent().parent().siblings('.form-data').find('input').css('opacity', on ? 1 : 0.6);
}
if (elType == 'span') {
processSpan(element);
}
};
el.on('change input propertychange', function() {
processToggleables(this);
});
el.find('input').on('change', function() {
processToggleables(this);
});
if ($(el)[0].className == 'checkboxes toggleable') {
var toggles = $(el).parent().siblings('.form-data').find('label');
toggles.on('click', function() {
processSpan(el, true);
});
}
processToggleables(this);
}
if (form.types[type]) {
var factory = form.factories[form.types[type]],
element = new factory(el, form),
@@ -70,6 +134,9 @@
element.disabled(!on);
if (!on) {
element.reset();
element.el.attr('checked', false).prop('value', 0);
} else {
element.el.attr('checked', true).prop('value', 1);
}
});
@@ -79,6 +146,12 @@
if (!on) {
element.reset();
}
if (!on) {
element.el.attr('checked', false).prop('value', 0);
} else {
element.el.attr('checked', true).prop('value', 1);
}
}
var Form = function (el, options) {