Skip to main content

Bug Tracker

Side navigation

#10996 closed enhancement (fixed)

Opened December 10, 2011 07:38PM UTC

Closed May 16, 2012 06:04PM UTC

Simplify offset()

Reported by: dmethvin Owned by: mikesherov
Priority: low Milestone: 1.8
Component: offset Version: 1.7.1
Keywords: 1.8-discuss Cc:
Blocked by: Blocking:
Description

On behalf of morris.johns (lastspottedat) timefiler.com

When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).

For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :

    getXY : function() {
        // @FEATUREDETECT
        var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));
        return [point.x, point.y];
    },

    getOffsetsTo : function(el){
        var o = this.getXY(),
            e = Ext.fly(el, '_internal').getXY();
        return [o[0]-e[0],o[1]-e[1]];
    },

I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."

http://stackoverflow.com/a/4758996/436776

Attachments (0)
Change History (13)

Changed December 10, 2011 07:39PM UTC by dmethvin comment:1

component: unfiledoffset
keywords: → 1.8-discuss
milestone: None1.8
priority: undecidedlow
status: newopen

Proposed in the 1.8 suggestion box.

P.S. Who you callin' *ugly*?

Changed December 13, 2011 02:49PM UTC by jzaefferer comment:2

description: \ On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \ \ On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\

+1, Sounds like one workaround can be replaced with a simpler workaround.

Changed December 13, 2011 02:55PM UTC by rwaldron comment:3

description: \ On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\ On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \

+1, I'm in favor of simplifying offset(), if we avoid using vendor prefixed functions

Changed December 13, 2011 04:26PM UTC by jaubourg comment:4

description: On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \ On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\

+1, if it is simpler and works, why not?

Changed December 13, 2011 05:24PM UTC by dmethvin comment:5

description: On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\ On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \

+1, Sounds like a great way to trim some code if it works!

Changed December 14, 2011 02:01PM UTC by mikesherov comment:6

description: On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \ On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\

+1, window.webkitConvertPointFromNodeToPage is only available in safari 4+ http://developer.apple.com/library/safari/#documentation/DataManagement/Reference/DOMWindowAdditionsReference/DOMWindowAdditions/DOMWindowAdditions.html . If we're willing to drop safari 3 support, we can get rid of that large block of ugly code and use this proprietary hack instead. It would also mean that we can eliminate 4 ugly support tests!

Changed December 14, 2011 04:13PM UTC by timmywil comment:7

+1, if it works, great!

Changed December 19, 2011 05:35PM UTC by rwaldron comment:8

description: On behalf of morris.johns (lastspottedat) timefiler.com\ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible).\ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js :\ {{{\ getXY : function() {\ // @FEATUREDETECT\ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0));\ return [point.x, point.y];\ },\ \ getOffsetsTo : function(el){\ var o = this.getXY(),\ e = Ext.fly(el, '_internal').getXY();\ return [o[0]-e[0],o[1]-e[1]];\ },\ }}}\ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers."\ \ http://stackoverflow.com/a/4758996/436776\ On behalf of morris.johns (lastspottedat) timefiler.com \ \ When getBoundingClientRect() is not available, jQuery.offset has a large block of ugly code that depends upon other ugly feature sniffs that exist only for use by the offset() function (such as jQuery.support.subtractsBorderForOverflowNotVisible). \ \ For older versions of Safari (or older mobile safari) it seems simpler to calculate offset using window.webkitConvertPointFromNodeToPage(). For example, the Sencha Touch codebase uses webkitConvertPointFromNodeToPage() - see sencha-touch-1.1.1\\src\\core\\Element.position.js : \ {{{ \ getXY : function() { \ // @FEATUREDETECT \ var point = window.webkitConvertPointFromNodeToPage(this.dom, new WebKitPoint(0, 0)); \ return [point.x, point.y]; \ }, \ \ getOffsetsTo : function(el){ \ var o = this.getXY(), \ e = Ext.fly(el, '_internal').getXY(); \ return [o[0]-e[0],o[1]-e[1]]; \ }, \ }}} \ I have used a function similar to the code given in the stack overflow link for our own proprietary ajax library, supporting a variety of current and obsolete desktop browsers." \ \ http://stackoverflow.com/a/4758996/436776 \

+1

Changed December 20, 2011 12:41AM UTC by mikesherov comment:9

More info: jquerymobile currently only supports iOS3.2+, so this would not be a breaking change for them. Again, if we drop safari 3.0 support (which at least according to jquery.com we do), this change should be safe.

Changed December 22, 2011 01:20PM UTC by mikesherov comment:10

All of the desktop browsers jQuery supports: http://docs.jquery.com/Browser_Compatibility (which is actually out of sync with the jQuery.com homepage) have support for getBoundingClientRect().

What mobile browsers does jQuery support? Do they all support either getBoundingClientRect() or window.webkitConvertPointFromNodeToPage?

Changed December 24, 2011 04:13PM UTC by addyosmani comment:11

+1

Changed December 25, 2011 11:51PM UTC by mikesherov comment:12

owner: → mikesherov
status: openassigned

Changed May 16, 2012 06:04PM UTC by Mike Sherov comment:13

resolution: → fixed
status: assignedclosed

Fix #10996, simplify offset code by forsaking ancient browsers.

Changeset: 77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1