BUGFIX: Allow use on frontend

'Chosen' plugin assumed, but on front-end this is not
a valid assumption.
This commit is contained in:
Luke Hudson 2015-06-19 17:44:35 +02:00
parent fb049075d4
commit 850e5a51b7
1 changed files with 16 additions and 10 deletions

View File

@ -9,22 +9,28 @@
* we'll see an extra field where there should be only one.
*/
$.fn.chosenDestroy = function () {
$(this)
.show() // The field needs to be visible so Select2 evaluates the width correctly.
.removeClass('chzn-done')
.removeClass('has-chzn')
.next()
.remove();
return $(this);
var $this = $(this);
if ($this.siblings('.chzn-container').length) {
$this
.show() // The field needs to be visible so Select2 evaluates the width correctly.
.removeClass('chzn-done')
.removeClass('has-chzn')
.next()
.remove();
}
return $this;
};
$.entwine('ss', function ($) {
$('.ss-tag-field + .chzn-container').entwine({
$('.ss-tag-field.has-chzn + .chzn-container, .ss-tag-field:not(.has-chzn)').entwine({
applySelect2: function () {
var self = this,
$select = $(this).prev();
$select = $(this);
if ($select.prev().hasClass('ss-tag-field')) {
$select = $select.prev();
}
// There is a race condition where Select2 might not
// be bound to jQuery yet. So here we make sure Select2