(function($, undefined) { /* -------------------------------- * LIMIT SELECTS BASED ON OBJECT * --------------------------------*/ $.fn.selimit = function(mapping, selector_child, selector_group) { if (!selector_group) { selector_group = 'body'; } var limit = function() { var $this = $(this); var parent_sel = $this.find('option:selected'); var $children = $this.closest(selector_group).find(selector_child); $children.xeach(function() { var child = this; var $child = $(child); if (parent_sel.length > 0) { sel = parent_sel[0].value if (sel == '') { sel = -1; } } if (sel == -1) { $child.attr('disabled', 'disabled'); $child.val(''); return false; } else { $child.removeAttr('disabled'); } var parents = mapping[sel]; var allowed = {} $(parents).xeach(function() { allowed[this] = true; }); var selected = $child.find('option:selected')[0]; if (!allowed[selected.value]) { $child.val(''); } $child.find('option').xeach(function() { if (allowed[this.value]) { this.style.display = 'inline'; } else { this.style.display = 'none'; } }); }); } this.xeach(limit); this.xeach(function() { $(this).on('change', limit); }) }; /* -------------------------------- * FAST EACHTING * --------------------------------*/ $.fn.xeach = function(callback) { for(var i=0,len=this.length; value=this[i], i', { class: type, }); jQuery('