Skip to content

Commit 1760a47

Browse files
author
Ken Earley
committed
Merge pull request #1155 from harvesthq/elasticsales-isolated-scroll
Isolated scroll
2 parents 37b64bc + 3f4e0fe commit 1760a47

6 files changed

+178
-39
lines changed

chosen/chosen.jquery.js

+70-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
var SelectParser;
1212

1313
SelectParser = (function() {
14-
1514
function SelectParser() {
1615
this.options_index = 0;
1716
this.parsed = [];
@@ -27,6 +26,7 @@
2726

2827
SelectParser.prototype.add_group = function(group) {
2928
var group_position, option, _i, _len, _ref, _results;
29+
3030
group_position = this.parsed.length;
3131
this.parsed.push({
3232
array_index: group_position,
@@ -79,6 +79,7 @@
7979

8080
SelectParser.select_to_array = function(select) {
8181
var child, parser, _i, _len, _ref;
82+
8283
parser = new SelectParser();
8384
_ref = select.childNodes;
8485
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -91,7 +92,6 @@
9192
this.SelectParser = SelectParser;
9293

9394
}).call(this);
94-
9595
/*
9696
Chosen source: generate output using 'cake build'
9797
Copyright (c) 2011 by Harvest
@@ -104,7 +104,6 @@ Copyright (c) 2011 by Harvest
104104
root = this;
105105

106106
AbstractChosen = (function() {
107-
108107
function AbstractChosen(form_field, options) {
109108
this.form_field = form_field;
110109
this.options = options != null ? options : {};
@@ -122,6 +121,7 @@ Copyright (c) 2011 by Harvest
122121

123122
AbstractChosen.prototype.set_default_values = function() {
124123
var _this = this;
124+
125125
this.click_test_action = function(evt) {
126126
return _this.test_active_click(evt);
127127
};
@@ -165,6 +165,7 @@ Copyright (c) 2011 by Harvest
165165

166166
AbstractChosen.prototype.input_focus = function(evt) {
167167
var _this = this;
168+
168169
if (this.is_multiple) {
169170
if (!this.active_field) {
170171
return setTimeout((function() {
@@ -180,6 +181,7 @@ Copyright (c) 2011 by Harvest
180181

181182
AbstractChosen.prototype.input_blur = function(evt) {
182183
var _this = this;
184+
183185
if (!this.mouse_on_container) {
184186
this.active_field = false;
185187
return setTimeout((function() {
@@ -190,6 +192,7 @@ Copyright (c) 2011 by Harvest
190192

191193
AbstractChosen.prototype.result_add_option = function(option) {
192194
var classes, style;
195+
193196
if (!option.disabled) {
194197
option.dom_id = this.container_id + "_o_" + option.array_index;
195198
classes = option.selected && this.is_multiple ? [] : ["active-result"];
@@ -237,6 +240,7 @@ Copyright (c) 2011 by Harvest
237240

238241
AbstractChosen.prototype.keyup_checker = function(evt) {
239242
var stroke, _ref;
243+
240244
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
241245
this.search_field_scale();
242246
switch (stroke) {
@@ -273,20 +277,23 @@ Copyright (c) 2011 by Harvest
273277

274278
AbstractChosen.prototype.generate_field_id = function() {
275279
var new_id;
280+
276281
new_id = this.generate_random_id();
277282
this.form_field.id = new_id;
278283
return new_id;
279284
};
280285

281286
AbstractChosen.prototype.generate_random_char = function() {
282287
var chars, newchar, rand;
288+
283289
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
284290
rand = Math.floor(Math.random() * chars.length);
285291
return newchar = chars.substring(rand, rand + 1);
286292
};
287293

288294
AbstractChosen.prototype.container_width = function() {
289295
var width;
296+
290297
if (this.options.width != null) {
291298
return this.options.width;
292299
}
@@ -296,6 +303,7 @@ Copyright (c) 2011 by Harvest
296303

297304
AbstractChosen.browser_is_supported = function() {
298305
var _ref;
306+
299307
if (window.navigator.appName === "Microsoft Internet Explorer") {
300308
return (null !== (_ref = document.documentMode) && _ref >= 8);
301309
}
@@ -315,15 +323,14 @@ Copyright (c) 2011 by Harvest
315323
root.AbstractChosen = AbstractChosen;
316324

317325
}).call(this);
318-
319326
/*
320327
Chosen source: generate output using 'cake build'
321328
Copyright (c) 2011 by Harvest
322329
*/
323330

324331

325332
(function() {
326-
var $, Chosen, get_side_border_padding, root,
333+
var $, Chosen, get_side_border_padding, root, _ref,
327334
__hasProp = {}.hasOwnProperty,
328335
__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; };
329336

@@ -338,6 +345,7 @@ Copyright (c) 2011 by Harvest
338345
}
339346
return this.each(function(input_field) {
340347
var $this;
348+
341349
$this = $(this);
342350
if (!$this.hasClass("chzn-done")) {
343351
return $this.data('chosen', new Chosen(this, options));
@@ -347,11 +355,11 @@ Copyright (c) 2011 by Harvest
347355
});
348356

349357
Chosen = (function(_super) {
350-
351358
__extends(Chosen, _super);
352359

353360
function Chosen() {
354-
return Chosen.__super__.constructor.apply(this, arguments);
361+
_ref = Chosen.__super__.constructor.apply(this, arguments);
362+
return _ref;
355363
}
356364

357365
Chosen.prototype.setup = function() {
@@ -366,6 +374,7 @@ Copyright (c) 2011 by Harvest
366374

367375
Chosen.prototype.set_up_html = function() {
368376
var container_classes, container_props;
377+
369378
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
370379
this.container_id += "_chzn";
371380
container_classes = ["chzn-container"];
@@ -411,6 +420,7 @@ Copyright (c) 2011 by Harvest
411420

412421
Chosen.prototype.register_observers = function() {
413422
var _this = this;
423+
414424
this.container.mousedown(function(evt) {
415425
_this.container_mousedown(evt);
416426
});
@@ -432,6 +442,12 @@ Copyright (c) 2011 by Harvest
432442
this.search_results.mouseout(function(evt) {
433443
_this.search_results_mouseout(evt);
434444
});
445+
this.search_results.bind('mousewheel', function(evt) {
446+
_this.search_results_mousewheel(evt);
447+
});
448+
this.search_results.bind('DOMMouseScroll', function(evt) {
449+
_this.search_results_mousewheel_ff(evt);
450+
});
435451
this.form_field_jq.bind("liszt:updated", function(evt) {
436452
_this.results_update_field(evt);
437453
});
@@ -509,6 +525,23 @@ Copyright (c) 2011 by Harvest
509525
}
510526
};
511527

528+
Chosen.prototype.search_results_mousewheel = function(evt) {
529+
this.search_results[0].scrollTop -= evt.wheelDelta;
530+
return evt.preventDefault();
531+
};
532+
533+
Chosen.prototype.search_results_mousewheel_ff = function(evt) {
534+
var bottom_overflow, delta, target, top_overflow, _ref1;
535+
536+
target = evt.currentTarget;
537+
delta = ((_ref1 = evt.originalEvent) != null ? _ref1.wheelDelta : void 0) || -evt.detail;
538+
bottom_overflow = target.scrollTop + $(target).outerHeight() - target.scrollHeight >= 0;
539+
top_overflow = target.scrollTop <= 0;
540+
if (target.scrollHeight > $(target).outerHeight() && ((delta < 0 && bottom_overflow) || (delta > 0 && top_overflow))) {
541+
return evt.preventDefault();
542+
}
543+
};
544+
512545
Chosen.prototype.blur_test = function(evt) {
513546
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
514547
return this.close_field();
@@ -542,7 +575,8 @@ Copyright (c) 2011 by Harvest
542575
};
543576

544577
Chosen.prototype.results_build = function() {
545-
var content, data, _i, _len, _ref;
578+
var content, data, _i, _len, _ref1;
579+
546580
this.parsing = true;
547581
this.results_data = root.SelectParser.select_to_array(this.form_field);
548582
if (this.is_multiple && this.choices > 0) {
@@ -557,9 +591,9 @@ Copyright (c) 2011 by Harvest
557591
}
558592
}
559593
content = '';
560-
_ref = this.results_data;
561-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
562-
data = _ref[_i];
594+
_ref1 = this.results_data;
595+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
596+
data = _ref1[_i];
563597
if (data.group) {
564598
content += this.result_add_group(data);
565599
} else if (!data.empty) {
@@ -592,6 +626,7 @@ Copyright (c) 2011 by Harvest
592626

593627
Chosen.prototype.result_do_highlight = function(el) {
594628
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
629+
595630
if (el.length) {
596631
this.result_clear_highlight();
597632
this.result_highlight = el;
@@ -646,6 +681,7 @@ Copyright (c) 2011 by Harvest
646681

647682
Chosen.prototype.set_tab_index = function(el) {
648683
var ti;
684+
649685
if (this.form_field_jq.attr("tabindex")) {
650686
ti = this.form_field_jq.attr("tabindex");
651687
this.form_field_jq.attr("tabindex", -1);
@@ -655,6 +691,7 @@ Copyright (c) 2011 by Harvest
655691

656692
Chosen.prototype.set_label_behavior = function() {
657693
var _this = this;
694+
658695
this.form_field_label = this.form_field_jq.parents("label");
659696
if (!this.form_field_label.length && this.form_field.id.length) {
660697
this.form_field_label = $("label[for=" + this.form_field.id + "]");
@@ -682,6 +719,7 @@ Copyright (c) 2011 by Harvest
682719

683720
Chosen.prototype.search_results_mouseup = function(evt) {
684721
var target;
722+
685723
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
686724
if (target.length) {
687725
this.result_highlight = target;
@@ -692,6 +730,7 @@ Copyright (c) 2011 by Harvest
692730

693731
Chosen.prototype.search_results_mouseover = function(evt) {
694732
var target;
733+
695734
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
696735
if (target) {
697736
return this.result_do_highlight(target);
@@ -714,6 +753,7 @@ Copyright (c) 2011 by Harvest
714753
Chosen.prototype.choice_build = function(item) {
715754
var choice_id, html, link,
716755
_this = this;
756+
717757
if (this.is_multiple && this.max_selected_options <= this.choices) {
718758
this.form_field_jq.trigger("liszt:maxselected", {
719759
chosen: this
@@ -775,6 +815,7 @@ Copyright (c) 2011 by Harvest
775815

776816
Chosen.prototype.result_select = function(evt) {
777817
var high, high_id, item, position;
818+
778819
if (this.result_highlight) {
779820
high = this.result_highlight;
780821
high_id = high.attr("id");
@@ -823,6 +864,7 @@ Copyright (c) 2011 by Harvest
823864

824865
Chosen.prototype.result_deselect = function(pos) {
825866
var result, result_data;
867+
826868
result_data = this.results_data[pos];
827869
if (!this.form_field.options[result_data.options_index].disabled) {
828870
result_data.selected = false;
@@ -848,16 +890,17 @@ Copyright (c) 2011 by Harvest
848890
};
849891

850892
Chosen.prototype.winnow_results = function() {
851-
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
893+
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref1;
894+
852895
this.no_results_clear();
853896
results = 0;
854897
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
855898
regexAnchor = this.search_contains ? "" : "^";
856899
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
857900
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
858-
_ref = this.results_data;
859-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
860-
option = _ref[_i];
901+
_ref1 = this.results_data;
902+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
903+
option = _ref1[_i];
861904
if (!option.disabled && !option.empty) {
862905
if (option.group) {
863906
$('#' + option.dom_id).css('display', 'none');
@@ -911,6 +954,7 @@ Copyright (c) 2011 by Harvest
911954

912955
Chosen.prototype.winnow_results_clear = function() {
913956
var li, lis, _i, _len, _results;
957+
914958
this.search_field.val("");
915959
lis = this.search_results.find("li");
916960
_results = [];
@@ -930,6 +974,7 @@ Copyright (c) 2011 by Harvest
930974

931975
Chosen.prototype.winnow_results_set_highlight = function() {
932976
var do_high, selected_results;
977+
933978
if (!this.result_highlight) {
934979
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
935980
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
@@ -941,6 +986,7 @@ Copyright (c) 2011 by Harvest
941986

942987
Chosen.prototype.no_results = function(terms) {
943988
var no_results_html;
989+
944990
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
945991
no_results_html.find("span").first().html(terms);
946992
return this.search_results.append(no_results_html);
@@ -952,6 +998,7 @@ Copyright (c) 2011 by Harvest
952998

953999
Chosen.prototype.keydown_arrow = function() {
9541000
var first_active, next_sib;
1001+
9551002
if (!this.result_highlight) {
9561003
first_active = this.search_results.find("li.active-result").first();
9571004
if (first_active) {
@@ -970,6 +1017,7 @@ Copyright (c) 2011 by Harvest
9701017

9711018
Chosen.prototype.keyup_arrow = function() {
9721019
var prev_sibs;
1020+
9731021
if (!this.results_showing && !this.is_multiple) {
9741022
return this.results_show();
9751023
} else if (this.result_highlight) {
@@ -987,6 +1035,7 @@ Copyright (c) 2011 by Harvest
9871035

9881036
Chosen.prototype.keydown_backstroke = function() {
9891037
var next_available_destroy;
1038+
9901039
if (this.pending_backstroke) {
9911040
this.choice_destroy(this.pending_backstroke.find("a").first());
9921041
return this.clear_backstroke();
@@ -1011,8 +1060,9 @@ Copyright (c) 2011 by Harvest
10111060
};
10121061

10131062
Chosen.prototype.keydown_checker = function(evt) {
1014-
var stroke, _ref;
1015-
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
1063+
var stroke, _ref1;
1064+
1065+
stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
10161066
this.search_field_scale();
10171067
if (stroke !== 8 && this.pending_backstroke) {
10181068
this.clear_backstroke();
@@ -1042,6 +1092,7 @@ Copyright (c) 2011 by Harvest
10421092

10431093
Chosen.prototype.search_field_scale = function() {
10441094
var div, h, style, style_block, styles, w, _i, _len;
1095+
10451096
if (this.is_multiple) {
10461097
h = 0;
10471098
w = 0;
@@ -1072,6 +1123,7 @@ Copyright (c) 2011 by Harvest
10721123

10731124
Chosen.prototype.generate_random_id = function() {
10741125
var string;
1126+
10751127
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
10761128
while ($("#" + string).length > 0) {
10771129
string += this.generate_random_char();
@@ -1087,6 +1139,7 @@ Copyright (c) 2011 by Harvest
10871139

10881140
get_side_border_padding = function(elmt) {
10891141
var side_border_padding;
1142+
10901143
return side_border_padding = elmt.outerWidth() - elmt.width();
10911144
};
10921145

0 commit comments

Comments
 (0)