3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
10 Ext.Element.addMethods({
12 * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
13 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
14 * @param {Number} value The new scroll value
15 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
16 * @return {Element} this
18 scrollTo : function(side, value, animate) {
19 //check if we're scrolling top or left
20 var top = /top/i.test(side),
24 if (!animate || !me.anim) {
25 // just setting the value, so grab the direction
26 prop = 'scroll' + (top ? 'Top' : 'Left');
30 // if scrolling top, we need to grab scrollLeft, if left, scrollTop
31 prop = 'scroll' + (top ? 'Left' : 'Top');
32 me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}}, me.preanim(arguments, 2), 'scroll');
38 * Scrolls this element into view within the passed container.
39 * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
40 * string (id), dom node, or Ext.Element.
41 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
42 * @return {Ext.Element} this
44 scrollIntoView : function(container, hscroll) {
45 var c = Ext.getDom(container) || Ext.getBody().dom,
47 o = this.getOffsetsTo(c),
48 l = o[0] + c.scrollLeft,
49 t = o[1] + c.scrollTop,
50 b = t + el.offsetHeight,
51 r = l + el.offsetWidth,
53 ct = parseInt(c.scrollTop, 10),
54 cl = parseInt(c.scrollLeft, 10),
56 cr = cl + c.clientWidth;
58 if (el.offsetHeight > ch || t < ct) {
64 // corrects IE, other browsers will ignore
65 c.scrollTop = c.scrollTop;
67 if (hscroll !== false) {
68 if (el.offsetWidth > c.clientWidth || l < cl) {
72 c.scrollLeft = r - c.clientWidth;
74 c.scrollLeft = c.scrollLeft;
80 scrollChildIntoView : function(child, hscroll) {
81 Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
85 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
86 * within this element's scrollable range.
87 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
88 * @param {Number} distance How far to scroll the element in pixels
89 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
90 * @return {Boolean} Returns true if a scroll was triggered or false if the element
91 * was scrolled as far as it could go.
93 scroll : function(direction, distance, animate) {
94 if (!this.isScrollable()) {
98 l = el.scrollLeft, t = el.scrollTop,
99 w = el.scrollWidth, h = el.scrollHeight,
100 cw = el.clientWidth, ch = el.clientHeight,
103 l: Math.min(l + distance, w-cw),
104 r: v = Math.max(l - distance, 0),
105 t: Math.max(t - distance, 0),
106 b: Math.min(t + distance, h-ch)
111 direction = direction.substr(0, 1);
112 if ((v = hash[direction]) > -1) {
114 this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));