Created
November 10, 2015 04:27
-
-
Save klebervirgilio/299caa8e9eaa67160d99 to your computer and use it in GitHub Desktop.
Adds the ability to render html in the list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = jQuery; | |
$.fn.extend({ | |
chosenDataHtml: function(options) { | |
return this.each(function(input_field) { | |
var $this = $(this), | |
formatSelection = options['formatSelection'] || function(e, data) { | |
var chosen = data.chosen, | |
selected = chosen.form_field_jq.find("option:enabled[value!='']:selected:first"), | |
html = selected.data('html'); | |
if ( html ) { | |
chosen.container.find('.chosen-single').find('> span:first').html(html); | |
if ( selected.length ) | |
chosen.container.find('.chosen-single').removeClass('chosen-default') | |
} | |
}, | |
formatList = options['formatList'] || function(e, data) { | |
var chosen = data.chosen, | |
options = chosen.form_field.options, | |
isFirstEmpty = options[0].value === '' ? 1 | |
: 0 ; | |
return $(chosen.container).find('.chosen-drop ul .group-option').each(function(index){ | |
$(this).html($(options[index + isFirstEmpty]).data('html') || $(this).html()) | |
}); | |
}; | |
if ( options !== "destroy") { | |
$this | |
.on("chosen:ready", formatSelection) | |
.on("chosen:hiding_dropdown", formatSelection) | |
.on("chosen:showing_dropdown", formatList); | |
} | |
return $this.chosen(options); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment