Permalink
Browse files

Added scroll position restore to Table and Tree widgets (in WebKit)

after having been hidden.
  • Loading branch information...
1 parent 84c4795 commit 2e875203c6c0b55379cf5f926439d8270ae9b4d2 @cederberg committed May 8, 2012
@@ -533,6 +533,7 @@
* Table Style
*/
div.widgetTable {
+ position: relative;
overflow-x: hidden;
overflow-y: auto;
}
@@ -659,6 +660,7 @@ th.widgetTableColumn.sortDesc {
* Tree Style
*/
.widgetTree {
+ position: relative;
overflow: auto;
border: 1px solid #ccc;
background: white;
@@ -47,11 +47,11 @@ RapidContext.Widget = RapidContext.Widget || { Classes: {}};
RapidContext.Widget.Table = function (attrs/*, ...*/) {
var thead = MochiKit.DOM.THEAD({}, MochiKit.DOM.TR());
var tbody = MochiKit.DOM.TBODY();
- tbody.resizeContent = MochiKit.Base.noop;
var table = MochiKit.DOM.TABLE({ "class": "widgetTable" }, thead, tbody);
var o = MochiKit.DOM.DIV({}, table);
RapidContext.Widget._widgetMixin(o, arguments.callee);
o.addClass("widgetTable");
+ o.resizeContent = o._resizeContent;
o._rows = [];
o._data = null;
o._keyField = null;
@@ -656,3 +656,21 @@ RapidContext.Widget.Table.prototype._unmarkSelection = function (indexOrNull) {
MochiKit.DOM.removeElementClass(tr, "selected");
}
};
+
+/**
+ * Called when table content should be resized. This method is also called when
+ * the widget is made visible in a container after being hidden.
+ */
+RapidContext.Widget.Table.prototype._resizeContent = function () {
+ // Work-around to restore scrollTop for WebKit browsers
+ if (this.scrollTop == 0 && this._selected.length > 0) {
+ var index = this._selected[0];
+ var tbody = this.firstChild.lastChild;
+ var tr = tbody.childNodes[index];
+ var h = this.clientHeight;
+ var y = tr.offsetTop + tr.offsetHeight;
+ this.scrollTop = Math.round(y - h / 2);
+ }
+ var thead = this.firstChild.firstChild;
+ RapidContext.Util.resizeElements(thead);
+};
@@ -35,7 +35,7 @@ RapidContext.Widget.Tree = function (attrs/*, ...*/) {
var o = MochiKit.DOM.DIV(attrs);
RapidContext.Widget._widgetMixin(o, arguments.callee);
o.addClass("widgetTree");
- o.resizeContent = MochiKit.Base.noop;
+ o.resizeContent = o._resizeContent;
o.selectedPath = null;
o.setAttrs(attrs);
o.addAll(MochiKit.Base.extend(null, arguments, 1));
@@ -252,3 +252,17 @@ RapidContext.Widget.Tree.prototype.addPath = function (path) {
}
return node;
};
+
+/**
+ * Called when tree content should be resized. This method is also called when
+ * the widget is made visible in a container after being hidden.
+ */
+RapidContext.Widget.Tree.prototype._resizeContent = function () {
+ // Work-around to restore scrollTop for WebKit browsers
+ if (this.scrollTop == 0 && this.selectedPath) {
+ var node = this.selectedChild();
+ var h = this.clientHeight;
+ var y = node.offsetTop + node.offsetHeight;
+ this.scrollTop = Math.round(y - h / 2);
+ }
+};

0 comments on commit 2e87520

Please sign in to comment.