diff --git a/chosen.js b/chosen.js index e0a6406..3280956 100644 --- a/chosen.js +++ b/chosen.js @@ -8,6 +8,36 @@ attach: function(context, settings) { settings.chosen = settings.chosen || Drupal.settings.chosen; + // Temporal workaround while https://github.com/harvesthq/chosen/issues/515 + // is fixed. This fix was taken from: + // https://github.com/harvesthq/chosen/issues/515#issuecomment-104602031 + $.fn.oldChosen = $.fn.chosen; + $.fn.chosen = function(options) { + + var select = $(this) + , is_creating_chosen = !!options; + + if (is_creating_chosen && select.css('position') === 'absolute') { + // if we are creating a chosen and the select already has the appropriate styles added + // we remove those (so that the select hasn't got a crazy width), then create the chosen + // then we re-add them later + select.removeAttr('style'); + + } + + var ret = select.oldChosen(options); + + // only act if the select has display: none, otherwise chosen is unsupported (iPhone, etc) + if (is_creating_chosen && select.css('display') === 'none') { + // https://github.com/harvesthq/chosen/issues/515#issuecomment-33214050 + // only do this if we are initializing chosen (no params, or object params) not calling a method + select.attr('style','display:visible; position:absolute; width:0px; height:0px; clip:rect(0,0,0,0)'); + select.attr('tabindex', -1); + } + return ret; + }; + + // Prepare selector and add unwantend selectors. var selector = settings.chosen.selector;