Skip to content

Commit

Permalink
rename liszt: chosen: and add JUI hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
brianteeman committed Aug 24, 2016
1 parent 535bea0 commit 8611671
Showing 1 changed file with 68 additions and 10 deletions.
78 changes: 68 additions & 10 deletions media/jui/js/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ Version 1.6.2
Full source at https://github.com/harvesthq/chosen
Copyright (c) 2011-2016 Harvest http://getharvest.com
MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
This file is generated by `grunt build`, do not edit it by hand.
*/
//
// Modified for Joomla! UI:
// - fix zero width, based on https://github.com/harvesthq/chosen/pull/1439
// - allow to add a custom value on fly, based on https://github.com/harvesthq/chosen/pull/749
//
(function() {
var $, AbstractChosen, Chosen, SelectParser, _ref,
Expand Down Expand Up @@ -145,6 +147,10 @@ This file is generated by `grunt build`, do not edit it by hand.
this.mouse_on_container = false;
this.results_showing = false;
this.result_highlighted = null;
/*<JUI>*/
/* Original: not exist */
this.allow_custom_value = false;
/*</JUI>*/
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.disable_search = this.options.disable_search || false;
Expand All @@ -169,6 +175,10 @@ This file is generated by `grunt build`, do not edit it by hand.
} else {
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
}
/*<JUI>*/
/* Original: not exist */
this.custom_group_text = this.form_field.getAttribute("data-custom_group_text") || this.options.custom_group_text || "Custom Value";
/*</JUI>*/
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
};

Expand Down Expand Up @@ -495,7 +505,12 @@ This file is generated by `grunt build`, do not edit it by hand.
if (this.options.width != null) {
return this.options.width;
} else {
/*<JUI>*/
/* Original:
return "" + this.form_field.offsetWidth + "px";
*/
return this.form_field_jq.css("width") || "" + this.form_field.offsetWidth + "px";
/*</JUI>*/
}
};

Expand Down Expand Up @@ -561,7 +576,7 @@ This file is generated by `grunt build`, do not edit it by hand.
$ = jQuery;

$.fn.extend({
liszt: function(options) {
chosen: function(options) {
if (!AbstractChosen.browser_is_supported()) {
return this;
}
Expand Down Expand Up @@ -593,6 +608,10 @@ This file is generated by `grunt build`, do not edit it by hand.
Chosen.prototype.setup = function() {
this.form_field_jq = $(this.form_field);
this.current_selectedIndex = this.form_field.selectedIndex;
/*<JUI>*/
/* Original: not exist */
this.allow_custom_value = this.form_field_jq.hasClass("chzn-custom-value") || this.options.allow_custom_value;
/*</JUI>*/
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
};

Expand Down Expand Up @@ -640,7 +659,7 @@ This file is generated by `grunt build`, do not edit it by hand.

Chosen.prototype.on_ready = function() {
return this.form_field_jq.trigger("liszt:ready", {
liszt: this
chosen: this
});
};

Expand Down Expand Up @@ -884,7 +903,7 @@ This file is generated by `grunt build`, do not edit it by hand.
Chosen.prototype.results_show = function() {
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
this.form_field_jq.trigger("liszt:maxselected", {
liszt: this
chosen: this
});
return false;
}
Expand All @@ -894,7 +913,7 @@ This file is generated by `grunt build`, do not edit it by hand.
this.search_field.val(this.search_field.val());
this.winnow_results();
return this.form_field_jq.trigger("liszt:showing_dropdown", {
liszt: this
chosen: this
});
};

Expand All @@ -907,7 +926,7 @@ This file is generated by `grunt build`, do not edit it by hand.
this.result_clear_highlight();
this.container.removeClass("chzn-with-drop");
this.form_field_jq.trigger("liszt:hiding_dropdown", {
liszt: this
chosen: this
});
}
return this.results_showing = false;
Expand Down Expand Up @@ -1037,7 +1056,7 @@ This file is generated by `grunt build`, do not edit it by hand.
this.result_clear_highlight();
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
this.form_field_jq.trigger("liszt:maxselected", {
liszt: this
chosen: this
});
return false;
}
Expand Down Expand Up @@ -1069,7 +1088,46 @@ This file is generated by `grunt build`, do not edit it by hand.
evt.preventDefault();
return this.search_field_scale();
}
/*<JUI>*/
/* Original: not exist */
else if ((!this.is_multiple) && this.allow_custom_value) {
value = this.search_field.val();
group = this.add_unique_custom_group();
option = $('<option value="' + value + '">' + value + '</option>');
group.append(option);
this.form_field_jq.append(group);
this.form_field.options[this.form_field.options.length - 1].selected = true;
if (!evt.metaKey) {
this.results_hide();
}
return this.results_build();
}
/*</JUI>*/
};

/*<JUI>*/
/* Original: not exist */
Chosen.prototype.find_custom_group = function() {
var found, group, _i, _len, _ref;
_ref = $('optgroup', this.form_field);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
group = _ref[_i];
if (group.getAttribute('label') === this.custom_group_text) {
found = group;
}
}
return found;
};

Chosen.prototype.add_unique_custom_group = function() {
var group;
group = this.find_custom_group();
if (!group) {
group = $('<optgroup label="' + this.custom_group_text + '"></optgroup>');
}
return $(group);
};
/*</JUI>*/

Chosen.prototype.single_set_selected_text = function(text) {
if (text == null) {
Expand Down Expand Up @@ -1134,7 +1192,7 @@ This file is generated by `grunt build`, do not edit it by hand.
no_results_html.find("span").first().html(terms);
this.search_results.append(no_results_html);
return this.form_field_jq.trigger("liszt:no_results", {
liszt: this
chosen: this
});
};

Expand Down

0 comments on commit 8611671

Please sign in to comment.