From 93cd38af7dc7a361af488478c31e946a0c5ea10c Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 09 May 2014 07:35:15 -0400
Subject: [PATCH] Avoid scrolling when list gets back focus (on invisible focus element)

---
 program/js/list.js |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/program/js/list.js b/program/js/list.js
index 6a0c5b3..fa37353 100644
--- a/program/js/list.js
+++ b/program/js/list.js
@@ -115,7 +115,7 @@
       // this helps to maintain the natural tab order when moving focus with keyboard
       this.focus_elem = $('<a>')
         .attr('tabindex', '0')
-        .attr('style', 'display:block; width:1px; height:1px; line-height:1px; overflow:hidden; position:absolute; top:-1000px')
+        .attr('style', 'display:block; width:1px; height:1px; line-height:1px; overflow:hidden; position:fixed; top:-1000px')
         .html('Select List')
         .insertAfter(this.list)
         .on('focus', function(e){ me.focus(e); })
@@ -186,9 +186,9 @@
 
     if (this.fixed_header) {  // copy (modified) fixed header back to the actual table
       $(this.list.tHead).replaceWith($(this.fixed_header).find('thead').clone());
-      $(this.list.tHead).find('tr td').attr('style', '').find('a.sortcol').attr('tabindex', '-1');  // remove fixed widths
+      $(this.list.tHead).find('tr td').attr('style', '').find('a').attr('tabindex', '-1');  // remove fixed widths
     }
-    else if (!bw.touch && this.list.className.indexOf('fixedheader') >= 0 && 0) {
+    else if (!bw.touch && this.list.className.indexOf('fixedheader') >= 0) {
       this.init_fixed_header();
     }
 
@@ -408,7 +408,7 @@
   // Un-focus already focused elements (#1487123, #1487316, #1488600, #1488620)
   if (this.focus_elem) {
     // We now fix this by explicitly assigning focus to a dedicated link element
-    this.focus_elem.focus();
+    this.focus_noscroll(this.focus_elem);
   }
   else {
     // It looks that window.focus() does the job for all browsers, but not Firefox (#1489058)
@@ -441,6 +441,16 @@
   $(this.list).removeClass('focus');
 },
 
+/**
+ * Focus the given element without scrolling the list container
+ */
+focus_noscroll: function(elem)
+{
+  var y = this.frame.scrollTop || this.frame.scrollY;
+  elem.focus();
+  this.frame.scrollTop = y;
+},
+
 
 /**
  * Set/unset the given column as hidden

--
Gitblit v1.9.1