Skip to content

Commit

Permalink
Moved choices_click into AbstractChosen
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Earley committed Apr 29, 2013
1 parent fd1a7a3 commit 9969a46
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 62 deletions.
82 changes: 56 additions & 26 deletions chosen/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
var SelectParser;

SelectParser = (function() {

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

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,6 +79,7 @@

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 @@ -91,7 +92,6 @@
this.SelectParser = SelectParser;

}).call(this);

/*
Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
Expand All @@ -104,7 +104,6 @@ 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 @@ -122,6 +121,7 @@ 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,6 +165,7 @@ 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 @@ -180,6 +181,7 @@ 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 @@ -190,6 +192,7 @@ 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 @@ -235,8 +238,16 @@ Copyright (c) 2011 by Harvest
}
};

AbstractChosen.prototype.choices_click = function(evt) {
evt.preventDefault();
if (!this.results_showing) {
return this.results_show();
}
};

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 @@ -273,20 +284,23 @@ 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 @@ -296,6 +310,7 @@ 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 @@ -315,15 +330,14 @@ 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, root,
var $, Chosen, root, _ref,
__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 @@ -338,6 +352,7 @@ 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 @@ -347,11 +362,11 @@ Copyright (c) 2011 by Harvest
});

Chosen = (function(_super) {

__extends(Chosen, _super);

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

Chosen.prototype.setup = function() {
Expand All @@ -366,6 +381,7 @@ Copyright (c) 2011 by Harvest

Chosen.prototype.set_up_html = function() {
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 Down Expand Up @@ -411,6 +427,7 @@ 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 @@ -521,9 +538,10 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.search_results_mousewheel_ff = function(evt) {
var bottom_overflow, delta, target, top_overflow, _ref;
var bottom_overflow, delta, target, top_overflow, _ref1;

target = evt.currentTarget;
delta = ((_ref = evt.originalEvent) != null ? _ref.wheelDelta : void 0) || -evt.detail;
delta = ((_ref1 = evt.originalEvent) != null ? _ref1.wheelDelta : void 0) || -evt.detail;
bottom_overflow = target.scrollTop + $(target).outerHeight() - target.scrollHeight >= 0;
top_overflow = target.scrollTop <= 0;
if (target.scrollHeight > $(target).outerHeight() && ((delta < 0 && bottom_overflow) || (delta > 0 && top_overflow))) {
Expand Down Expand Up @@ -564,7 +582,8 @@ Copyright (c) 2011 by Harvest
};

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

this.parsing = true;
this.results_data = root.SelectParser.select_to_array(this.form_field);
if (this.is_multiple && this.choices > 0) {
Expand All @@ -579,9 +598,9 @@ Copyright (c) 2011 by Harvest
}
}
content = '';
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
_ref1 = this.results_data;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
data = _ref1[_i];
if (data.group) {
content += this.result_add_group(data);
} else if (!data.empty) {
Expand Down Expand Up @@ -614,6 +633,7 @@ 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,6 +688,7 @@ 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 @@ -677,6 +698,7 @@ Copyright (c) 2011 by Harvest

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

this.form_field_label = this.form_field_jq.parents("label");
if (!this.form_field_label.length && this.form_field.id.length) {
this.form_field_label = $("label[for=" + this.form_field.id + "]");
Expand Down Expand Up @@ -704,6 +726,7 @@ 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 @@ -714,6 +737,7 @@ 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 @@ -726,16 +750,10 @@ Copyright (c) 2011 by Harvest
}
};

Chosen.prototype.choices_click = function(evt) {
evt.preventDefault();
if (!this.results_showing) {
return this.results_show();
}
};

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 @@ -797,6 +815,7 @@ 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 @@ -845,6 +864,7 @@ 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 @@ -870,16 +890,17 @@ 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, _ref;
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref1;

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');
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
_ref1 = this.results_data;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
option = _ref1[_i];
if (!option.disabled && !option.empty) {
if (option.group) {
$('#' + option.dom_id).css('display', 'none');
Expand Down Expand Up @@ -933,6 +954,7 @@ 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 @@ -952,6 +974,7 @@ 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 @@ -963,6 +986,7 @@ 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 @@ -974,6 +998,7 @@ 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 @@ -992,6 +1017,7 @@ 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 @@ -1009,6 +1035,7 @@ 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 @@ -1033,8 +1060,9 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.keydown_checker = function(evt) {
var stroke, _ref;
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
var stroke, _ref1;

stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
this.search_field_scale();
if (stroke !== 8 && this.pending_backstroke) {
this.clear_backstroke();
Expand Down Expand Up @@ -1064,6 +1092,7 @@ 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 @@ -1094,6 +1123,7 @@ 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 Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9969a46

Please # to comment.