source: trunk/web/addons/job_monarch/lib/extjs-30/src/core/Element.scroll-more.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 4.2 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/**
8 * @class Ext.Element
9 */
10Ext.Element.addMethods({
11    /**
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
17     */
18    scrollTo : function(side, value, animate){
19        var tester = /top/i,
20                prop = "scroll" + (tester.test(side) ? "Top" : "Left"),
21                me = this,
22                dom = me.dom;
23        if (!animate || !me.anim) {
24            dom[prop] = value;
25        } else {
26            me.anim({scroll: {to: tester.test(prop) ? [dom[prop], value] : [value, dom[prop]]}},
27                         me.preanim(arguments, 2), 'scroll');
28        }
29        return me;
30    },
31   
32    /**
33     * Scrolls this element into view within the passed container.
34     * @param {Mixed} container (optional) The container element to scroll (defaults to document.body).  Should be a
35     * string (id), dom node, or Ext.Element.
36     * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
37     * @return {Ext.Element} this
38     */
39    scrollIntoView : function(container, hscroll){
40        var c = Ext.getDom(container) || Ext.getBody().dom,
41                el = this.dom,
42                o = this.getOffsetsTo(c),
43            l = o[0] + c.scrollLeft,
44            t = o[1] + c.scrollTop,
45            b = t + el.offsetHeight,
46            r = l + el.offsetWidth,
47                ch = c.clientHeight,
48                ct = parseInt(c.scrollTop, 10),
49                cl = parseInt(c.scrollLeft, 10),
50                cb = ct + ch,
51                cr = cl + c.clientWidth;
52
53        if (el.offsetHeight > ch || t < ct) {
54                c.scrollTop = t;
55        } else if (b > cb){
56            c.scrollTop = b-ch;
57        }
58        c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore
59
60        if(hscroll !== false){
61                        if(el.offsetWidth > c.clientWidth || l < cl){
62                c.scrollLeft = l;
63            }else if(r > cr){
64                c.scrollLeft = r - c.clientWidth;
65            }
66            c.scrollLeft = c.scrollLeft;
67        }
68        return this;
69    },
70
71    // private
72    scrollChildIntoView : function(child, hscroll){
73        Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
74    },
75   
76    /**
77     * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
78     * within this element's scrollable range.
79     * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
80     * @param {Number} distance How far to scroll the element in pixels
81     * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
82     * @return {Boolean} Returns true if a scroll was triggered or false if the element
83     * was scrolled as far as it could go.
84     */
85     scroll : function(direction, distance, animate){
86         if(!this.isScrollable()){
87             return;
88         }
89         var el = this.dom,
90            l = el.scrollLeft, t = el.scrollTop,
91            w = el.scrollWidth, h = el.scrollHeight,
92            cw = el.clientWidth, ch = el.clientHeight,
93            scrolled = false, v,
94            hash = {
95                l: Math.min(l + distance, w-cw),
96                r: v = Math.max(l - distance, 0),
97                t: Math.max(t - distance, 0),
98                b: Math.min(t + distance, h-ch)
99            };
100            hash.d = hash.b;
101            hash.u = hash.t;
102           
103         direction = direction.substr(0, 1);
104         if((v = hash[direction]) > -1){
105            scrolled = true;
106            this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));
107         }
108         return scrolled;
109    }
110});
Note: See TracBrowser for help on using the repository browser.