summaryrefslogtreecommitdiff
path: root/public_html
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-07-02 10:50:05 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-07-02 10:50:05 (GMT)
commit5ce6595a60ad67281da58cf7c06fecb4b158d199 (patch)
tree73ba8a85dd7648126525c831ba4f80fa75ab0e99 /public_html
parentfb228487d825af1d9e9b6bdff4a47171601e8928 (diff)
downloadkolab-wap-5ce6595a60ad67281da58cf7c06fecb4b158d199.tar.gz
Fix infinite loop in domain selector when rollower list contains
one element, small improvements in Up/Down arrow keys handling (Bug #2005)
Diffstat (limited to 'public_html')
-rw-r--r--public_html/js/kolab_admin.js60
1 files changed, 34 insertions, 26 deletions
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index f3281fd..b5bc376 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1030,6 +1030,12 @@ function kolab_admin()
if (e.which == 13)
e.preventDefault();
})
+ .keydown(function(e) {
+ // block Up/Down arrow keys,
+ // in Firefox Up arrow moves cursor left
+ if (e.which == 38 || e.which == 40)
+ e.preventDefault();
+ })
.keyup(function(e) {
// filtering
var s = this.value,
@@ -1048,36 +1054,38 @@ function kolab_admin()
// UP/Down arrows
else if (e.which == 38 || e.which == 40) {
options = options.not(':hidden');
- var selected = options.filter('.selected');
-
- if (!selected.length) {
- if (e.which == 40) // Down key
- options.first().addClass('selected').parent().get(0).scrollTop = 0;
- }
- else {
- var focused = selected[e.which == 40 ? 'next' : 'prev']();
- while (focused.length && focused.is(':hidden'))
- focused = selected[e.which == 40 ? 'next' : 'prev']();
+ if (options.length <= 1)
+ return;
- if (!focused.length)
- focused = options[e.which == 40 ? 'first' : 'last']();
+ var focused,
+ selected = options.filter('.selected'),
+ index = options.index(selected);
- if (focused.length) {
- selected.removeClass('selected');
- focused.addClass('selected');
-
- var parent = focused.parent(),
- parent_height = parent.height(),
- parent_top = parent.get(0).scrollTop,
- top = focused.offset().top - parent.offset().top,
- height = focused.height();
+ if (e.which == 40) {
+ if (!(focused = options.get(index+1)))
+ focused = options.get(index-1);
+ }
+ else {
+ if (!(focused = options.get(index-1)))
+ focused = options.get(index+1);
+ }
- if (top < 0)
- parent.get(0).scrollTop = 0;
- else if (top >= parent_height)
- parent.get(0).scrollTop = top - parent_height + height + parent_top;
- }
+ if (focused) {
+ focused = $(focused);
+ selected.removeClass('selected');
+ focused.addClass('selected');
+
+ var parent = focused.parent(),
+ parent_height = parent.height(),
+ parent_top = parent.get(0).scrollTop,
+ top = focused.offset().top - parent.offset().top,
+ height = focused.height();
+
+ if (top < 0)
+ parent.get(0).scrollTop = 0;
+ else if (top >= parent_height)
+ parent.get(0).scrollTop = top - parent_height + height + parent_top;
}
return;