3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 Ext.Element.addMethods({
\r
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().
\r
13 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
\r
14 * @param {Number} value The new scroll value
\r
15 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
16 * @return {Element} this
\r
18 scrollTo : function(side, value, animate){
\r
19 var top = /top/i.test(side), //check if we're scrolling top or left
\r
23 if (!animate || !me.anim) {
\r
24 prop = 'scroll' + (top ? 'Top' : 'Left'), // just setting the value, so grab the direction
\r
27 prop = 'scroll' + (top ? 'Left' : 'Top'), // if scrolling top, we need to grab scrollLeft, if left, scrollTop
\r
28 me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}},
\r
29 me.preanim(arguments, 2), 'scroll');
\r
35 * Scrolls this element into view within the passed container.
\r
36 * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
\r
37 * string (id), dom node, or Ext.Element.
\r
38 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
\r
39 * @return {Ext.Element} this
\r
41 scrollIntoView : function(container, hscroll){
\r
42 var c = Ext.getDom(container) || Ext.getBody().dom,
\r
44 o = this.getOffsetsTo(c),
\r
45 l = o[0] + c.scrollLeft,
\r
46 t = o[1] + c.scrollTop,
\r
47 b = t + el.offsetHeight,
\r
48 r = l + el.offsetWidth,
\r
49 ch = c.clientHeight,
\r
50 ct = parseInt(c.scrollTop, 10),
\r
51 cl = parseInt(c.scrollLeft, 10),
\r
53 cr = cl + c.clientWidth;
\r
55 if (el.offsetHeight > ch || t < ct) {
\r
60 c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore
\r
62 if(hscroll !== false){
\r
63 if(el.offsetWidth > c.clientWidth || l < cl){
\r
66 c.scrollLeft = r - c.clientWidth;
\r
68 c.scrollLeft = c.scrollLeft;
\r
74 scrollChildIntoView : function(child, hscroll){
\r
75 Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
\r
79 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
\r
80 * within this element's scrollable range.
\r
81 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
\r
82 * @param {Number} distance How far to scroll the element in pixels
\r
83 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
84 * @return {Boolean} Returns true if a scroll was triggered or false if the element
\r
85 * was scrolled as far as it could go.
\r
87 scroll : function(direction, distance, animate){
\r
88 if(!this.isScrollable()){
\r
92 l = el.scrollLeft, t = el.scrollTop,
\r
93 w = el.scrollWidth, h = el.scrollHeight,
\r
94 cw = el.clientWidth, ch = el.clientHeight,
\r
95 scrolled = false, v,
\r
97 l: Math.min(l + distance, w-cw),
\r
98 r: v = Math.max(l - distance, 0),
\r
99 t: Math.max(t - distance, 0),
\r
100 b: Math.min(t + distance, h-ch)
\r
105 direction = direction.substr(0, 1);
\r
106 if((v = hash[direction]) > -1){
\r
108 this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));
\r