summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-05-27 17:30:56 +0200
committerThomas Bruederli <thomas@roundcube.net>2014-05-27 17:30:56 +0200
commitf5de03208e80bec1a9be689b55c93d4faade2de0 (patch)
treefcfae1c39e82c55229bdabfeec14f3d1fe9d3847
parentd4d62ac414a3ba706fb65c581581c419a90d5ac9 (diff)
Replace Array.prototype.last() with jQuery.last to avoid side-effects in array iterations
-rw-r--r--program/js/app.js12
-rw-r--r--program/js/common.js4
2 files changed, 7 insertions, 9 deletions
diff --git a/program/js/app.js b/program/js/app.js
index 4bd6442b3..658f3c569 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -6597,10 +6597,8 @@ function rcube_webmail()
this.treelist.select(name);
}
else if (this.gui_objects.folderlist) {
- $('li.selected', this.gui_objects.folderlist)
- .removeClass('selected').addClass('unfocused');
- $(this.get_folder_li(name, prefix, encode))
- .removeClass('unfocused').addClass('selected');
+ $('li.selected', this.gui_objects.folderlist).removeClass('selected');
+ $(this.get_folder_li(name, prefix, encode)).addClass('selected');
// trigger event hook
this.triggerEvent('selectfolder', { folder:name, prefix:prefix });
@@ -6976,8 +6974,8 @@ function rcube_webmail()
this.hide_menu(this.menu_stack[i]);
}
if (stack && this.menu_stack.length) {
- obj.data('parent', this.menu_stack.last());
- obj.css('z-index', ($('#'+this.menu_stack.last()).css('z-index') || 0) + 1);
+ obj.data('parent', $.last(this.menu_stack));
+ obj.css('z-index', ($('#'+$.last(this.menu_stack)).css('z-index') || 0) + 1);
}
else if (!stack && this.menu_stack.length) {
this.hide_menu(this.menu_stack[0], event);
@@ -7027,7 +7025,7 @@ function rcube_webmail()
// focus previous menu in stack
if (this.menu_stack.length && keyboard) {
this.menu_keyboard_active = true;
- this.focused_menu = this.menu_stack.last();
+ this.focused_menu = $.last(this.menu_stack);
if (!obj || !obj.data('opener'))
$('#'+this.focused_menu).find('a,input:not(:disabled)').not('[aria-disabled=true]').first().focus();
}
diff --git a/program/js/common.js b/program/js/common.js
index b532c36c1..ee38c3528 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -607,8 +607,8 @@ if (!String.prototype.startsWith) {
}
// array utility function
-Array.prototype.last = function() {
- return this[this.length-1];
+jQuery.last = function(arr) {
+ return arr && arr.length ? arr[arr.length-1] : undefined;
}
// jQuery plugin to emulate HTML5 placeholder attributes on input elements