define(["./core", "./core/access", "./var/document", "./var/documentElement", "./css/var/rnumnonpx", "./css/curCSS", "./css/addGetHookIf", "./css/support", "./core/init", "./css", "./selector"] , function (jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support){ function getWindow(elem){ return jQuery.isWindow(elem)? elem: elem.nodeType === 9 && elem.defaultView; } jQuery.offset = { setOffset: function (elem, options, i){ var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition, position = jQuery.css(elem, "position"), curElem = jQuery(elem), props = { } ; if (position === "static") { elem.style.position = "relative"; } curOffset = curElem.offset(); curCSSTop = jQuery.css(elem, "top"); curCSSLeft = jQuery.css(elem, "left"); calculatePosition = (position === "absolute" || position === "fixed") && (curCSSTop + curCSSLeft).indexOf("auto") > -1; if (calculatePosition) { curPosition = curElem.position(); curTop = curPosition.top; curLeft = curPosition.left; } else { curTop = parseFloat(curCSSTop) || 0; curLeft = parseFloat(curCSSLeft) || 0; } if (jQuery.isFunction(options)) { options = options.call(elem, i, jQuery.extend({ } , curOffset)); } if (options.top != null ) { props.top = (options.top - curOffset.top) + curTop; } if (options.left != null ) { props.left = (options.left - curOffset.left) + curLeft; } if ("using" in options) { options.using.call(elem, props); } else { curElem.css(props); } } } ; jQuery.fn.extend({ offset: function (options){ if (arguments.length) { return options === undefined? this: this.each(function (i){ jQuery.offset.setOffset(this, options, i); } ); } var docElem, win, rect, doc, elem = this[0]; if (!elem) { return ; } if (!_AN_Read_length("length", elem.getClientRects())) { return { top: 0, left: 0} ; } rect = elem.getBoundingClientRect(); if (rect.width || rect.height) { doc = elem.ownerDocument; win = getWindow(doc); docElem = doc.documentElement; return { top: rect.top + win.pageYOffset - docElem.clientTop, left: rect.left + win.pageXOffset - docElem.clientLeft} ; } return rect; } , position: function (){ if (!this[0]) { return ; } var offsetParent, offset, elem = this[0], parentOffset = { top: 0, left: 0} ; if (jQuery.css(elem, "position") === "fixed") { offset = elem.getBoundingClientRect(); } else { offsetParent = this.offsetParent(); offset = this.offset(); if (!jQuery.nodeName(offsetParent[0], "html")) { parentOffset = offsetParent.offset(); } parentOffset.top += jQuery.css(offsetParent[0], "borderTopWidth", true ) - offsetParent.scrollTop(); parentOffset.left += jQuery.css(offsetParent[0], "borderLeftWidth", true ) - offsetParent.scrollLeft(); } return { top: offset.top - parentOffset.top - jQuery.css(elem, "marginTop", true ), left: offset.left - parentOffset.left - jQuery.css(elem, "marginLeft", true )} ; } , offsetParent: function (){ return this.map(function (){ var offsetParent = this.offsetParent; while (offsetParent && jQuery.css(offsetParent, "position") === "static"){ offsetParent = offsetParent.offsetParent; } return offsetParent || documentElement; } ); } } ); jQuery.each({ scrollLeft: "pageXOffset", scrollTop: "pageYOffset"} , function (method, prop){ var top = "pageYOffset" === prop; jQuery.fn[method] = function (val){ return access(this, function (elem, method, val){ var win = getWindow(elem); if (val === undefined) { return win? win[prop]: elem[method]; } if (win) { win.scrollTo(!top? val: win.pageXOffset, top? val: win.pageYOffset); } else { elem[method] = val; } } , method, val, _AN_Read_length("length", arguments), null ); } ; } ); jQuery.each(["top", "left"] , function (i, prop){ jQuery.cssHooks[prop] = addGetHookIf(support.pixelPosition, function (elem, computed){ if (computed) { computed = curCSS(elem, prop); return rnumnonpx.test(computed)? jQuery(elem).position()[prop] + "px": computed; } } ); } ); return jQuery; } );