Opened 11 years ago
Closed 11 years ago
#10996 closed enhancement (fixed)
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 (last modified by )
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."
Change History (13)
comment:1 Changed 11 years ago by
Component: | unfiled → offset |
---|---|
Keywords: | 1.8-discuss added |
Milestone: | None → 1.8 |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 11 years ago by
Description: | modified (diff) |
---|
+1, Sounds like one workaround can be replaced with a simpler workaround.
comment:3 Changed 11 years ago by
Description: | modified (diff) |
---|
+1, I'm in favor of simplifying offset(), if we avoid using vendor prefixed functions
comment:4 Changed 11 years ago by
Description: | modified (diff) |
---|
+1, if it is simpler and works, why not?
comment:5 Changed 11 years ago by
Description: | modified (diff) |
---|
+1, Sounds like a great way to trim some code if it works!
comment:6 Changed 11 years ago by
Description: | modified (diff) |
---|
+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!
comment:9 Changed 11 years ago by
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.
comment:10 Changed 11 years ago by
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?
comment:12 Changed 11 years ago by
Owner: | set to mikesherov |
---|---|
Status: | open → assigned |
comment:13 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fix #10996, simplify offset code by forsaking ancient browsers.
Changeset: 77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1
Proposed in the 1.8 suggestion box.
P.S. Who you callin' *ugly*?