Skip to content

Commit

Permalink
add documented js hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
brianteeman committed Aug 24, 2016
1 parent c68c275 commit 0ef056d
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion media/jui/js/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*<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 @@ -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;
}
/*<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 @@ -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 {
/*<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 @@ -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;
/*<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 @@ -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;
/*<JUI>*/
/* Original:
var high, item, selected_index;
*/
var group, high, high_id, item, option, position, value;
/*</JUI>*/

if (this.result_highlight) {
high = this.result_highlight;
this.result_clear_highlight();
Expand Down Expand Up @@ -1074,7 +1097,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

0 comments on commit 0ef056d

Please sign in to comment.