From 0ef056d06609cab17b272aa7c37da4b0521199b6 Mon Sep 17 00:00:00 2001 From: Brian Teeman Date: Wed, 24 Aug 2016 17:59:55 +0100 Subject: [PATCH] add documented js hacks --- media/jui/js/chosen.jquery.js | 64 ++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/media/jui/js/chosen.jquery.js b/media/jui/js/chosen.jquery.js index dcd7c17180312..efc65967c594a 100755 --- a/media/jui/js/chosen.jquery.js +++ b/media/jui/js/chosen.jquery.js @@ -150,6 +150,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; + /**/ + /* Original: not exist */ + this.allow_custom_value = false; + /**/ 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; @@ -174,6 +178,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; } + /**/ + /* Original: not exist */ + this.custom_group_text = this.form_field.getAttribute("data-custom_group_text") || this.options.custom_group_text || "Custom Value"; + /**/ return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; }; @@ -500,7 +508,12 @@ This file is generated by `grunt build`, do not edit it by hand. if (this.options.width != null) { return this.options.width; } else { + /**/ + /* Original: return "" + this.form_field.offsetWidth + "px"; + */ + return this.form_field_jq.css("width") || "" + this.form_field.offsetWidth + "px"; + /**/ } }; @@ -598,6 +611,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; + /**/ + /* Original: not exist */ + this.allow_custom_value = this.form_field_jq.hasClass("chzn-custom-value") || this.options.allow_custom_value; + /**/ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); }; @@ -1036,7 +1053,13 @@ This file is generated by `grunt build`, do not edit it by hand. }; Chosen.prototype.result_select = function(evt) { - var high, item; + /**/ + /* Original: + var high, item, selected_index; + */ + var group, high, high_id, item, option, position, value; + /**/ + if (this.result_highlight) { high = this.result_highlight; this.result_clear_highlight(); @@ -1074,7 +1097,46 @@ This file is generated by `grunt build`, do not edit it by hand. evt.preventDefault(); return this.search_field_scale(); } + /**/ + /* Original: not exist */ + else if ((!this.is_multiple) && this.allow_custom_value) { + value = this.search_field.val(); + group = this.add_unique_custom_group(); + 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(); + } + /**/ + }; + + /**/ + /* 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 = $(''); + } + return $(group); }; + /**/ Chosen.prototype.single_set_selected_text = function(text) { if (text == null) {