Bug Tracker

Ticket #10996 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Simplify offset()

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

Description (last modified by rwaldron) (diff)

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

Change History

comment:1 Changed 3 years ago by dmethvin

  • Keywords 1.8-discuss added
  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to offset
  • Milestone changed from None to 1.8

Proposed in the 1.8 suggestion box.

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

comment:2 Changed 3 years ago by jzaefferer

  • Description modified (diff)

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

comment:3 Changed 3 years ago by rwaldron

  • Description modified (diff)

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

comment:4 Changed 3 years ago by jaubourg

  • Description modified (diff)

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

comment:5 Changed 3 years ago by dmethvin

  • Description modified (diff)

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

comment:6 Changed 3 years ago by mikesherov

  • 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:7 Changed 3 years ago by timmywil

+1, if it works, great!

comment:8 Changed 3 years ago by rwaldron

  • Description modified (diff)

+1

comment:9 Changed 3 years ago by mikesherov

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 3 years ago by mikesherov

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:11 Changed 3 years ago by addyosmani

+1

comment:12 Changed 3 years ago by mikesherov

  • Owner set to mikesherov
  • Status changed from open to assigned

comment:13 Changed 3 years ago by Mike Sherov

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1

Note: See TracTickets for help on using tickets.