From d0763a37c683feb3f3148a6dad877402421ab61d Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 27 May 2012 12:37:35 -0400 Subject: [PATCH] Fix #11823. Remove webkitConvertPointFromNodeToPage. Closes gh-796. --- build/jshint-check.js | 3 +- grunt.js | 1 - src/offset.js | 68 +++++++++++++++++-------------------------- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/build/jshint-check.js b/build/jshint-check.js index b33beaad5..259453931 100644 --- a/build/jshint-check.js +++ b/build/jshint-check.js @@ -12,8 +12,7 @@ smarttabs: true, predef: [ "define", - "DOMParser", - "WebKitPoint" + "DOMParser" ], maxerr: 100 }; diff --git a/grunt.js b/grunt.js index fa96f8336..2313bb27a 100644 --- a/grunt.js +++ b/grunt.js @@ -84,7 +84,6 @@ module.exports = function( grunt ) { predef: [ "define", "DOMParser", - "WebKitPoint", "__dirname" ], maxerr: 100 diff --git a/src/offset.js b/src/offset.js index 1288b79ff..728777621 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,43 +1,6 @@ (function( jQuery ) { -var getOffset, - rroot = /^(?:body|html)$/i; - -if ( "getBoundingClientRect" in document.documentElement ) { - getOffset = function( elem, doc, docElem ) { - var box; - - try { - box = elem.getBoundingClientRect(); - } catch(e) {} - - // Make sure we're not dealing with a disconnected DOM node - if ( !box || !jQuery.contains( docElem, elem ) ) { - return box ? { top: box.top, left: box.left } : { top: 0, left: 0 }; - } - - var body = doc.body, - win = getWindow( doc ), - clientTop = docElem.clientTop || body.clientTop || 0, - clientLeft = docElem.clientLeft || body.clientLeft || 0, - scrollTop = win.pageYOffset || docElem.scrollTop, - scrollLeft = win.pageXOffset || docElem.scrollLeft, - top = box.top + scrollTop - clientTop, - left = box.left + scrollLeft - clientLeft; - - return { top: top, left: left }; - }; - -} else { - getOffset = function( elem, doc, docElem ) { - if ( !jQuery.contains( docElem, elem ) ) { - return { top: 0, left: 0 }; - } - var point = getWindow( doc ).webkitConvertPointFromNodeToPage( elem, new WebKitPoint( 0, 0 ) ); - return { top: point.y, left: point.x }; - - }; -} +var rroot = /^(?:body|html)$/i; jQuery.fn.offset = function( options ) { if ( arguments.length ) { @@ -48,18 +11,39 @@ jQuery.fn.offset = function( options ) { }); } - var elem = this[0], + var docElem, body, win, clientTop, clientLeft, scrollTop, scrollLeft, top, left, + box = {}, + elem = this[ 0 ], doc = elem && elem.ownerDocument; if ( !doc ) { return null; } - if ( elem === doc.body ) { + if ( (body = doc.body) === elem ) { return jQuery.offset.bodyOffset( elem ); } - return getOffset( elem, doc, doc.documentElement ); + docElem = doc.documentElement; + + try { + box = elem.getBoundingClientRect(); + } catch(e) {} + + // Make sure we're not dealing with a disconnected DOM node + if ( !box.top || !jQuery.contains( docElem, elem ) ) { + return { top: box.top || 0, left: box.left || 0 }; + } + + win = getWindow( doc ); + clientTop = docElem.clientTop || body.clientTop || 0; + clientLeft = docElem.clientLeft || body.clientLeft || 0; + scrollTop = win.pageYOffset || docElem.scrollTop; + scrollLeft = win.pageXOffset || docElem.scrollLeft; + top = box.top + scrollTop - clientTop; + left = box.left + scrollLeft - clientLeft; + + return { top: top, left: left }; }; jQuery.offset = { @@ -201,4 +185,4 @@ function getWindow( elem ) { false; } -})( jQuery ); +})( jQuery ); \ No newline at end of file