4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
19 </span> * @class Ext.Element
21 Ext.override(Ext.Element, {
22 <span id='Ext-Element-method-isScrollable'> /**
23 </span> * Returns true if this element is scrollable.
26 isScrollable : function(){
28 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
31 <span id='Ext-Element-method-getScroll'> /**
32 </span> * Returns the current scroll position of the element.
33 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
35 getScroll : function() {
39 docElement = doc.documentElement,
44 if (d == doc || d == body) {
45 if (Ext.isIE && Ext.isStrict) {
46 l = docElement.scrollLeft;
47 t = docElement.scrollTop;
49 l = window.pageXOffset;
50 t = window.pageYOffset;
53 left: l || (body ? body.scrollLeft : 0),
54 top : t || (body ? body.scrollTop : 0)
66 <span id='Ext-Element-method-scrollTo'> /**
67 </span> * 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().
68 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
69 * @param {Number} value The new scroll value
70 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
71 * @return {Ext.Element} this
73 scrollTo : function(side, value, animate) {
74 //check if we're scrolling top or left
75 var top = /top/i.test(side),
80 if (!animate || !me.anim) {
81 // just setting the value, so grab the direction
82 prop = 'scroll' + (top ? 'Top' : 'Left');
86 if (!Ext.isObject(animate)) {
89 obj['scroll' + (top ? 'Top' : 'Left')] = value;
90 me.animate(Ext.applyIf({
97 <span id='Ext-Element-method-scrollIntoView'> /**
98 </span> * Scrolls this element into view within the passed container.
99 * @param {String/HTMLElement/Ext.Element} container (optional) The container element to scroll (defaults to document.body). Should be a
100 * string (id), dom node, or Ext.Element.
101 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
102 * @return {Ext.Element} this
104 scrollIntoView : function(container, hscroll) {
105 container = Ext.getDom(container) || Ext.getBody().dom;
107 offsets = this.getOffsetsTo(container),
109 left = offsets[0] + container.scrollLeft,
110 top = offsets[1] + container.scrollTop,
111 bottom = top + el.offsetHeight,
112 right = left + el.offsetWidth,
114 ctClientHeight = container.clientHeight,
115 ctScrollTop = parseInt(container.scrollTop, 10),
116 ctScrollLeft = parseInt(container.scrollLeft, 10),
117 ctBottom = ctScrollTop + ctClientHeight,
118 ctRight = ctScrollLeft + container.clientWidth;
120 if (el.offsetHeight > ctClientHeight || top < ctScrollTop) {
121 container.scrollTop = top;
122 } else if (bottom > ctBottom) {
123 container.scrollTop = bottom - ctClientHeight;
125 // corrects IE, other browsers will ignore
126 container.scrollTop = container.scrollTop;
128 if (hscroll !== false) {
129 if (el.offsetWidth > container.clientWidth || left < ctScrollLeft) {
130 container.scrollLeft = left;
132 else if (right > ctRight) {
133 container.scrollLeft = right - container.clientWidth;
135 container.scrollLeft = container.scrollLeft;
141 scrollChildIntoView : function(child, hscroll) {
142 Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
145 <span id='Ext-Element-method-scroll'> /**
146 </span> * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
147 * within this element's scrollable range.
148 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
149 * @param {Number} distance How far to scroll the element in pixels
150 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
151 * @return {Boolean} Returns true if a scroll was triggered or false if the element
152 * was scrolled as far as it could go.
154 scroll : function(direction, distance, animate) {
155 if (!this.isScrollable()) {
159 l = el.scrollLeft, t = el.scrollTop,
160 w = el.scrollWidth, h = el.scrollHeight,
161 cw = el.clientWidth, ch = el.clientHeight,
164 l: Math.min(l + distance, w-cw),
165 r: v = Math.max(l - distance, 0),
166 t: Math.max(t - distance, 0),
167 b: Math.min(t + distance, h-ch)
172 direction = direction.substr(0, 1);
173 if ((v = hash[direction]) > -1) {
175 this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate));