diff --git a/cck_select_other.js b/cck_select_other.js index bf49576..51f4c91 100644 --- a/cck_select_other.js +++ b/cck_select_other.js @@ -1,4 +1,3 @@ -//$Id$ /** * @file * cck_select_other javascript file @@ -8,6 +7,8 @@ Drupal.behaviors.cckSelectOther = { attach: function (context, settings) { + var ActionBind = this.getActionBind(); + // Prevent errors if (typeof settings.CCKSelectOther != 'object') return; @@ -22,18 +23,31 @@ $(document).ready( function() { // We need to go up further up the element chain to work around 'add another item' - $('select#edit-' + select_id).change(function() { + $('select#edit-' + select_id).bind(ActionBind, function() { // Add parent() to hide input wrapper $(this).children(':selected').each(function() { - if($(this).val() == 'other'){ + if($(this).val() === 'other'){ $('input#edit-' + text_id).parent().show(); } else{ $('input#edit-' + text_id).parent().hide(); } }); - }).trigger('change'); + }).trigger(ActionBind); }); }); + }, + /** + * Provides a backwards-compatible way of supporting Drupal 7 core jQuery, + * and contemporary versions of jQuery without browser detection support. + * + * @returns {string} + */ + getActionBind: function() { + var action = 'change'; + if (undefined !== $.browser && $.browser.msie === true) { + action = 'click'; + } + return action; } } })(jQuery);