From 6a23b8335dd9e0786cf2c6ea90c8574ac0c6f28f Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sun, 21 Jun 2009 19:33:40 +0000 Subject: Bug 463598: Improve the performance of the JavaScript that adjusts field values based on the value of another field Patch by Max Kanat-Alexander r=wicked, a=mkanat --- js/field.js | 117 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 43 deletions(-) (limited to 'js') diff --git a/js/field.js b/js/field.js index 629fb8a23..700c1de8d 100644 --- a/js/field.js +++ b/js/field.js @@ -389,40 +389,52 @@ function handleVisControllerValueChange(e, args) { } } -function showValueWhen(controlled_field_id, controlled_value, - controller_field_id, controller_value) +function showValueWhen(controlled_field_id, controlled_value_ids, + controller_field_id, controller_value_id) { var controller_field = document.getElementById(controller_field_id); // Note that we don't get an object for the controlled field here, // because it might not yet exist in the DOM. We just pass along its id. YAHOO.util.Event.addListener(controller_field, 'change', - handleValControllerChange, [controlled_field_id, controlled_value, - controller_field, controller_value]); + handleValControllerChange, [controlled_field_id, controlled_value_ids, + controller_field, controller_value_id]); } function handleValControllerChange(e, args) { var controlled_field = document.getElementById(args[0]); - var controlled_value = args[1]; + var controlled_value_ids = args[1]; var controller_field = args[2]; - var controller_value = args[3]; - - var item = getPossiblyHiddenOption(controlled_field, controlled_value); - if (bz_valueSelected(controller_field, controller_value)) { - showOptionInIE(item, controlled_field); - YAHOO.util.Dom.removeClass(item, 'bz_hidden_option'); - item.disabled = false; - } - else if (!item.disabled) { - YAHOO.util.Dom.addClass(item, 'bz_hidden_option'); - if (item.selected) { - item.selected = false; - bz_fireEvent(controlled_field, 'change'); + var controller_value_id = args[3]; + + var controller_item = document.getElementById( + _value_id(controller_field.id, controller_value_id)); + + for (var i = 0; i < controlled_value_ids.length; i++) { + var item = getPossiblyHiddenOption(controlled_field, + controlled_value_ids[i]); + if (item.disabled && controller_item && controller_item.selected) { + item = showOptionInIE(item, controlled_field); + YAHOO.util.Dom.removeClass(item, 'bz_hidden_option'); + item.disabled = false; + } + else if (!item.disabled) { + YAHOO.util.Dom.addClass(item, 'bz_hidden_option'); + if (item.selected) { + item.selected = false; + bz_fireEvent(controlled_field, 'change'); + } + item.disabled = true; + hideOptionInIE(item, controlled_field); } - item.disabled = true; - hideOptionInIE(item, controlled_field); } } +// A convenience function to generate the "id" tag of an