Fix arrow up/down behavior without relying on buggy intersect method.
This commit is contained in:
parent
d16cf5f3da
commit
465eb61eb6
2 changed files with 29 additions and 59 deletions
|
@ -22,7 +22,7 @@
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
*/ var $, Chosen, OptionsParser, first_intersect, get_side_border_padding, root;
|
*/ var $, Chosen, OptionsParser, get_side_border_padding, root;
|
||||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||||
root = typeof exports !== "undefined" && exports !== null ? exports : this;
|
root = typeof exports !== "undefined" && exports !== null ? exports : this;
|
||||||
$ = jQuery;
|
$ = jQuery;
|
||||||
|
@ -541,33 +541,30 @@
|
||||||
return this.search_results.find(".no-results").remove();
|
return this.search_results.find(".no-results").remove();
|
||||||
};
|
};
|
||||||
Chosen.prototype.keydown_arrow = function() {
|
Chosen.prototype.keydown_arrow = function() {
|
||||||
var actives, next, sibs;
|
var first_active, next_sib;
|
||||||
actives = this.search_results.find("li.active-result");
|
if (!this.result_highlight) {
|
||||||
if (actives.length) {
|
first_active = this.search_results.find("li.active-result").first();
|
||||||
if (!this.result_highlight) {
|
if (first_active) {
|
||||||
this.result_do_highlight($(actives[0]));
|
this.result_do_highlight($(first_active));
|
||||||
} else if (this.results_showing) {
|
|
||||||
sibs = this.result_highlight.nextAll();
|
|
||||||
next = first_intersect(sibs, actives);
|
|
||||||
if (next) {
|
|
||||||
this.result_do_highlight($(next));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!this.results_showing) {
|
} else if (this.results_showing) {
|
||||||
return this.results_show();
|
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
||||||
|
if (next_sib) {
|
||||||
|
this.result_do_highlight(next_sib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!this.results_showing) {
|
||||||
|
return this.results_show();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Chosen.prototype.keyup_arrow = function() {
|
Chosen.prototype.keyup_arrow = function() {
|
||||||
var actives, prev, sibs;
|
var prev_sibs;
|
||||||
if (!this.results_showing && !this.is_multiple) {
|
if (!this.results_showing && !this.is_multiple) {
|
||||||
return this.results_show();
|
return this.results_show();
|
||||||
} else if (this.result_highlight) {
|
} else if (this.result_highlight) {
|
||||||
sibs = this.result_highlight.prevAll();
|
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
||||||
actives = this.search_results.find("li.active-result");
|
if (prev_sibs.length) {
|
||||||
prev = first_intersect(sibs, actives);
|
return this.result_do_highlight(prev_sibs.first());
|
||||||
if (prev) {
|
|
||||||
return this.result_do_highlight($(prev));
|
|
||||||
} else {
|
} else {
|
||||||
if (this.choices > 0) {
|
if (this.choices > 0) {
|
||||||
this.results_hide();
|
this.results_hide();
|
||||||
|
@ -677,17 +674,6 @@
|
||||||
return side_border_padding = elmt.outerWidth() - elmt.width();
|
return side_border_padding = elmt.outerWidth() - elmt.width();
|
||||||
};
|
};
|
||||||
root.get_side_border_padding = get_side_border_padding;
|
root.get_side_border_padding = get_side_border_padding;
|
||||||
first_intersect = function(a1, a2) {
|
|
||||||
var element, _i, _len;
|
|
||||||
for (_i = 0, _len = a1.length; _i < _len; _i++) {
|
|
||||||
element = a1[_i];
|
|
||||||
if ($.inArray(element, a2)) {
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
root.first_intersect = first_intersect;
|
|
||||||
OptionsParser = (function() {
|
OptionsParser = (function() {
|
||||||
function OptionsParser() {
|
function OptionsParser() {
|
||||||
this.group_index = 0;
|
this.group_index = 0;
|
||||||
|
|
|
@ -486,26 +486,22 @@ class Chosen
|
||||||
@search_results.find(".no-results").remove()
|
@search_results.find(".no-results").remove()
|
||||||
|
|
||||||
keydown_arrow: ->
|
keydown_arrow: ->
|
||||||
actives = @search_results.find "li.active-result"
|
if not @result_highlight
|
||||||
if actives.length
|
first_active = @search_results.find("li.active-result").first()
|
||||||
if not @result_highlight
|
this.result_do_highlight $(first_active) if first_active
|
||||||
this.result_do_highlight $(actives[0])
|
else if @results_showing
|
||||||
else if @results_showing
|
next_sib = @result_highlight.nextAll("li.active-result").first()
|
||||||
sibs = @result_highlight.nextAll()
|
this.result_do_highlight next_sib if next_sib
|
||||||
next = first_intersect sibs, actives
|
this.results_show() if not @results_showing
|
||||||
this.result_do_highlight $(next) if next
|
|
||||||
this.results_show() if not @results_showing
|
|
||||||
|
|
||||||
keyup_arrow: ->
|
keyup_arrow: ->
|
||||||
if not @results_showing and not @is_multiple
|
if not @results_showing and not @is_multiple
|
||||||
this.results_show()
|
this.results_show()
|
||||||
else if @result_highlight
|
else if @result_highlight
|
||||||
sibs = @result_highlight.prevAll()
|
prev_sibs = @result_highlight.prevAll("li.active-result")
|
||||||
actives = @search_results.find "li.active-result"
|
|
||||||
prev = first_intersect sibs, actives
|
if prev_sibs.length
|
||||||
|
this.result_do_highlight prev_sibs.first()
|
||||||
if prev
|
|
||||||
this.result_do_highlight ($ prev)
|
|
||||||
else
|
else
|
||||||
this.results_hide() if @choices > 0
|
this.results_hide() if @choices > 0
|
||||||
this.result_clear_highlight()
|
this.result_clear_highlight()
|
||||||
|
@ -591,18 +587,6 @@ get_side_border_padding = (elmt) ->
|
||||||
|
|
||||||
root.get_side_border_padding = get_side_border_padding
|
root.get_side_border_padding = get_side_border_padding
|
||||||
|
|
||||||
first_intersect = (a1, a2) ->
|
|
||||||
# TODO for some reason, up arrow doesn't find the first
|
|
||||||
#console.log a2
|
|
||||||
for element in a1
|
|
||||||
#console.log element
|
|
||||||
#console.log $.inArray element, a2
|
|
||||||
return element if $.inArray element, a2
|
|
||||||
|
|
||||||
return null
|
|
||||||
|
|
||||||
root.first_intersect = first_intersect
|
|
||||||
|
|
||||||
class OptionsParser
|
class OptionsParser
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue