X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/core/Element.scroll-more.js..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/src/core/src/dom/Element.scroll.js diff --git a/src/core/Element.scroll-more.js b/src/core/src/dom/Element.scroll.js similarity index 51% rename from src/core/Element.scroll-more.js rename to src/core/src/dom/Element.scroll.js index c3acb02a..e0fdb1c5 100644 --- a/src/core/Element.scroll-more.js +++ b/src/core/src/dom/Element.scroll.js @@ -1,13 +1,51 @@ -/*! - * Ext JS Library 3.3.1 - * Copyright(c) 2006-2010 Sencha Inc. - * licensing@sencha.com - * http://www.sencha.com/license - */ /** - * @class Ext.Element + * @class Ext.core.Element */ -Ext.Element.addMethods({ +Ext.override(Ext.core.Element, { + /** + * Returns true if this element is scrollable. + * @return {Boolean} + */ + isScrollable : function(){ + var dom = this.dom; + return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth; + }, + + /** + * Returns the current scroll position of the element. + * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)} + */ + getScroll : function() { + var d = this.dom, + doc = document, + body = doc.body, + docElement = doc.documentElement, + l, + t, + ret; + + if (d == doc || d == body) { + if (Ext.isIE && Ext.isStrict) { + l = docElement.scrollLeft; + t = docElement.scrollTop; + } else { + l = window.pageXOffset; + t = window.pageYOffset; + } + ret = { + left: l || (body ? body.scrollLeft : 0), + top : t || (body ? body.scrollTop : 0) + }; + } else { + ret = { + left: d.scrollLeft, + top : d.scrollTop + }; + } + + return ret; + }, + /** * 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(). * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values. @@ -20,6 +58,7 @@ Ext.Element.addMethods({ var top = /top/i.test(side), me = this, dom = me.dom, + obj = {}, prop; if (!animate || !me.anim) { // just setting the value, so grab the direction @@ -27,51 +66,56 @@ Ext.Element.addMethods({ dom[prop] = value; } else { - // if scrolling top, we need to grab scrollLeft, if left, scrollTop - prop = 'scroll' + (top ? 'Left' : 'Top'); - me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}}, me.preanim(arguments, 2), 'scroll'); + if (!Ext.isObject(animate)) { + animate = {}; + } + obj['scroll' + (top ? 'Top' : 'Left')] = value; + me.animate(Ext.applyIf({ + to: obj + }, animate)); } return me; }, - + /** * Scrolls this element into view within the passed container. * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a - * string (id), dom node, or Ext.Element. + * string (id), dom node, or Ext.core.Element. * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true) - * @return {Ext.Element} this + * @return {Ext.core.Element} this */ scrollIntoView : function(container, hscroll) { - var c = Ext.getDom(container) || Ext.getBody().dom, - el = this.dom, - o = this.getOffsetsTo(c), - l = o[0] + c.scrollLeft, - t = o[1] + c.scrollTop, - b = t + el.offsetHeight, - r = l + el.offsetWidth, - ch = c.clientHeight, - ct = parseInt(c.scrollTop, 10), - cl = parseInt(c.scrollLeft, 10), - cb = ct + ch, - cr = cl + c.clientWidth; + container = Ext.getDom(container) || Ext.getBody().dom; + var el = this.dom, + offsets = this.getOffsetsTo(container), + // el's box + left = offsets[0] + container.scrollLeft, + top = offsets[1] + container.scrollTop, + bottom = top + el.offsetHeight, + right = left + el.offsetWidth, + // ct's box + ctClientHeight = container.clientHeight, + ctScrollTop = parseInt(container.scrollTop, 10), + ctScrollLeft = parseInt(container.scrollLeft, 10), + ctBottom = ctScrollTop + ctClientHeight, + ctRight = ctScrollLeft + container.clientWidth; - if (el.offsetHeight > ch || t < ct) { - c.scrollTop = t; - } - else if (b > cb) { - c.scrollTop = b-ch; + if (el.offsetHeight > ctClientHeight || top < ctScrollTop) { + container.scrollTop = top; + } else if (bottom > ctBottom) { + container.scrollTop = bottom - ctClientHeight; } // corrects IE, other browsers will ignore - c.scrollTop = c.scrollTop; + container.scrollTop = container.scrollTop; if (hscroll !== false) { - if (el.offsetWidth > c.clientWidth || l < cl) { - c.scrollLeft = l; + if (el.offsetWidth > container.clientWidth || left < ctScrollLeft) { + container.scrollLeft = left; } - else if (r > cr) { - c.scrollLeft = r - c.clientWidth; + else if (right > ctRight) { + container.scrollLeft = right - container.clientWidth; } - c.scrollLeft = c.scrollLeft; + container.scrollLeft = container.scrollLeft; } return this; }, @@ -80,7 +124,7 @@ Ext.Element.addMethods({ scrollChildIntoView : function(child, hscroll) { Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll); }, - + /** * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is * within this element's scrollable range. @@ -107,11 +151,11 @@ Ext.Element.addMethods({ }; hash.d = hash.b; hash.u = hash.t; - + direction = direction.substr(0, 1); if ((v = hash[direction]) > -1) { scrolled = true; - this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2)); + this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate)); } return scrolled; }