Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing reference to container element instead of reselecting. #1151

Merged
merged 2 commits into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 22 additions & 52 deletions chosen/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var SelectParser;

SelectParser = (function() {

function SelectParser() {
this.options_index = 0;
this.parsed = [];
Expand All @@ -26,7 +27,6 @@

SelectParser.prototype.add_group = function(group) {
var group_position, option, _i, _len, _ref, _results;

group_position = this.parsed.length;
this.parsed.push({
array_index: group_position,
Expand Down Expand Up @@ -79,7 +79,6 @@

SelectParser.select_to_array = function(select) {
var child, parser, _i, _len, _ref;

parser = new SelectParser();
_ref = select.childNodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
Expand All @@ -92,6 +91,7 @@
this.SelectParser = SelectParser;

}).call(this);

/*
Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
Expand All @@ -104,6 +104,7 @@ Copyright (c) 2011 by Harvest
root = this;

AbstractChosen = (function() {

function AbstractChosen(form_field, options) {
this.form_field = form_field;
this.options = options != null ? options : {};
Expand All @@ -121,7 +122,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.set_default_values = function() {
var _this = this;

this.click_test_action = function(evt) {
return _this.test_active_click(evt);
};
Expand Down Expand Up @@ -165,7 +165,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.input_focus = function(evt) {
var _this = this;

if (this.is_multiple) {
if (!this.active_field) {
return setTimeout((function() {
Expand All @@ -181,7 +180,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.input_blur = function(evt) {
var _this = this;

if (!this.mouse_on_container) {
this.active_field = false;
return setTimeout((function() {
Expand All @@ -192,7 +190,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.result_add_option = function(option) {
var classes, style;

if (!option.disabled) {
option.dom_id = this.container_id + "_o_" + option.array_index;
classes = option.selected && this.is_multiple ? [] : ["active-result"];
Expand Down Expand Up @@ -240,7 +237,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.keyup_checker = function(evt) {
var stroke, _ref;

stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
this.search_field_scale();
switch (stroke) {
Expand Down Expand Up @@ -277,23 +273,20 @@ Copyright (c) 2011 by Harvest

AbstractChosen.prototype.generate_field_id = function() {
var new_id;

new_id = this.generate_random_id();
this.form_field.id = new_id;
return new_id;
};

AbstractChosen.prototype.generate_random_char = function() {
var chars, newchar, rand;

chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
rand = Math.floor(Math.random() * chars.length);
return newchar = chars.substring(rand, rand + 1);
};

AbstractChosen.prototype.container_width = function() {
var width;

if (this.options.width != null) {
return this.options.width;
}
Expand All @@ -303,7 +296,6 @@ Copyright (c) 2011 by Harvest

AbstractChosen.browser_is_supported = function() {
var _ref;

if (window.navigator.appName === "Microsoft Internet Explorer") {
return (null !== (_ref = document.documentMode) && _ref >= 8);
}
Expand All @@ -323,14 +315,15 @@ Copyright (c) 2011 by Harvest
root.AbstractChosen = AbstractChosen;

}).call(this);

/*
Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
*/


(function() {
var $, Chosen, get_side_border_padding, root, _ref,
var $, Chosen, get_side_border_padding, root,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

Expand All @@ -345,7 +338,6 @@ Copyright (c) 2011 by Harvest
}
return this.each(function(input_field) {
var $this;

$this = $(this);
if (!$this.hasClass("chzn-done")) {
return $this.data('chosen', new Chosen(this, options));
Expand All @@ -355,11 +347,11 @@ Copyright (c) 2011 by Harvest
});

Chosen = (function(_super) {

__extends(Chosen, _super);

function Chosen() {
_ref = Chosen.__super__.constructor.apply(this, arguments);
return _ref;
return Chosen.__super__.constructor.apply(this, arguments);
}

Chosen.prototype.setup = function() {
Expand All @@ -373,8 +365,7 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.set_up_html = function() {
var container_classes, container_div, container_props;

var container_classes, container_props;
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
this.container_id += "_chzn";
container_classes = ["chzn-container"];
Expand All @@ -391,14 +382,13 @@ Copyright (c) 2011 by Harvest
'style': "width: " + (this.container_width()) + ";",
'title': this.form_field.title
};
container_div = $("<div />", container_props);
this.container = $("<div />", container_props);
if (this.is_multiple) {
container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
this.container.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
} else {
container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
this.container.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
}
this.form_field_jq.hide().after(container_div);
this.container = $('#' + this.container_id);
this.form_field_jq.hide().after(this.container);
this.dropdown = this.container.find('div.chzn-drop').first();
this.search_field = this.container.find('input').first();
this.search_results = this.container.find('ul.chzn-results').first();
Expand All @@ -420,7 +410,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.register_observers = function() {
var _this = this;

this.container.mousedown(function(evt) {
_this.container_mousedown(evt);
});
Expand Down Expand Up @@ -552,8 +541,7 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.results_build = function() {
var content, data, _i, _len, _ref1;

var content, data, _i, _len, _ref;
this.parsing = true;
this.results_data = root.SelectParser.select_to_array(this.form_field);
if (this.is_multiple && this.choices > 0) {
Expand All @@ -568,9 +556,9 @@ Copyright (c) 2011 by Harvest
}
}
content = '';
_ref1 = this.results_data;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
data = _ref1[_i];
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
if (data.group) {
content += this.result_add_group(data);
} else if (!data.empty) {
Expand Down Expand Up @@ -603,7 +591,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.result_do_highlight = function(el) {
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;

if (el.length) {
this.result_clear_highlight();
this.result_highlight = el;
Expand Down Expand Up @@ -668,7 +655,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.set_tab_index = function(el) {
var ti;

if (this.form_field_jq.attr("tabindex")) {
ti = this.form_field_jq.attr("tabindex");
this.form_field_jq.attr("tabindex", -1);
Expand All @@ -688,7 +674,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.search_results_mouseup = function(evt) {
var target;

target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target.length) {
this.result_highlight = target;
Expand All @@ -699,7 +684,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.search_results_mouseover = function(evt) {
var target;

target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target) {
return this.result_do_highlight(target);
Expand All @@ -722,7 +706,6 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.choice_build = function(item) {
var choice_id, html, link,
_this = this;

if (this.is_multiple && this.max_selected_options <= this.choices) {
this.form_field_jq.trigger("liszt:maxselected", {
chosen: this
Expand Down Expand Up @@ -784,7 +767,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.result_select = function(evt) {
var high, high_id, item, position;

if (this.result_highlight) {
high = this.result_highlight;
high_id = high.attr("id");
Expand Down Expand Up @@ -833,7 +815,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.result_deselect = function(pos) {
var result, result_data;

result_data = this.results_data[pos];
if (!this.form_field.options[result_data.options_index].disabled) {
result_data.selected = false;
Expand All @@ -859,17 +840,16 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref1;

var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
results = 0;
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
regexAnchor = this.search_contains ? "" : "^";
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
_ref1 = this.results_data;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
option = _ref1[_i];
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
if (!option.disabled && !option.empty) {
if (option.group) {
$('#' + option.dom_id).css('display', 'none');
Expand Down Expand Up @@ -923,7 +903,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.winnow_results_clear = function() {
var li, lis, _i, _len, _results;

this.search_field.val("");
lis = this.search_results.find("li");
_results = [];
Expand All @@ -943,7 +922,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.winnow_results_set_highlight = function() {
var do_high, selected_results;

if (!this.result_highlight) {
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
Expand All @@ -955,7 +933,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.no_results = function(terms) {
var no_results_html;

no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
no_results_html.find("span").first().html(terms);
return this.search_results.append(no_results_html);
Expand All @@ -967,7 +944,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.keydown_arrow = function() {
var first_active, next_sib;

if (!this.result_highlight) {
first_active = this.search_results.find("li.active-result").first();
if (first_active) {
Expand All @@ -986,7 +962,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.keyup_arrow = function() {
var prev_sibs;

if (!this.results_showing && !this.is_multiple) {
return this.results_show();
} else if (this.result_highlight) {
Expand All @@ -1004,7 +979,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.keydown_backstroke = function() {
var next_available_destroy;

if (this.pending_backstroke) {
this.choice_destroy(this.pending_backstroke.find("a").first());
return this.clear_backstroke();
Expand All @@ -1029,9 +1003,8 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.keydown_checker = function(evt) {
var stroke, _ref1;

stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
var stroke, _ref;
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
this.search_field_scale();
if (stroke !== 8 && this.pending_backstroke) {
this.clear_backstroke();
Expand Down Expand Up @@ -1061,7 +1034,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.search_field_scale = function() {
var div, h, style, style_block, styles, w, _i, _len;

if (this.is_multiple) {
h = 0;
w = 0;
Expand Down Expand Up @@ -1092,7 +1064,6 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.generate_random_id = function() {
var string;

string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
while ($("#" + string).length > 0) {
string += this.generate_random_char();
Expand All @@ -1108,7 +1079,6 @@ Copyright (c) 2011 by Harvest

get_side_border_padding = function(elmt) {
var side_border_padding;

return side_border_padding = elmt.outerWidth() - elmt.width();
};

Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

Loading