Comparing version 1.0.9 to 1.0.10
121
lib/index.js
@@ -8,4 +8,12 @@ /** | ||
var utils = require('./utils'); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _utils = require('./utils'); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
// http://yiminghe.iteye.com/blog/1124720 | ||
@@ -18,8 +26,8 @@ | ||
function getAlignOffset(region, align) { | ||
var V = align.charAt(0), | ||
H = align.charAt(1), | ||
w = region.width, | ||
h = region.height, | ||
x, | ||
y; | ||
var V = align.charAt(0); | ||
var H = align.charAt(1); | ||
var w = region.width; | ||
var h = region.height; | ||
var x = undefined; | ||
var y = undefined; | ||
@@ -67,7 +75,7 @@ x = region.left; | ||
// 统一的 offsetParent 方法 | ||
var doc = element.ownerDocument, | ||
body = doc.body, | ||
parent, | ||
positionStyle = utils.css(element, 'position'), | ||
skipStatic = positionStyle === 'fixed' || positionStyle === 'absolute'; | ||
var doc = element.ownerDocument; | ||
var body = doc.body; | ||
var parent = undefined; | ||
var positionStyle = _utils2['default'].css(element, 'position'); | ||
var skipStatic = positionStyle === 'fixed' || positionStyle === 'absolute'; | ||
@@ -79,3 +87,3 @@ if (!skipStatic) { | ||
for (parent = element.parentNode; parent && parent !== body; parent = parent.parentNode) { | ||
positionStyle = utils.css(parent, 'position'); | ||
positionStyle = _utils2['default'].css(parent, 'position'); | ||
if (positionStyle !== 'static') { | ||
@@ -98,11 +106,11 @@ return parent; | ||
bottom: Infinity | ||
}, | ||
el = element, | ||
scrollX, | ||
scrollY, | ||
winSize, | ||
doc = element.ownerDocument, | ||
win = doc.defaultView || doc.parentWindow, | ||
body = doc.body, | ||
documentElement = doc.documentElement; | ||
}; | ||
var el = element; | ||
var scrollX = undefined; | ||
var scrollY = undefined; | ||
var winSize = undefined; | ||
var doc = element.ownerDocument; | ||
var win = doc.defaultView || doc.parentWindow; | ||
var body = doc.body; | ||
var documentElement = doc.documentElement; | ||
@@ -113,4 +121,8 @@ // Determine the size of the visible rect by climbing the dom accounting for | ||
// clientWidth is zero for inline block elements in ie. | ||
if ((navigator.userAgent.indexOf('MSIE') === -1 || el.clientWidth !== 0) && (el !== body && el !== documentElement && utils.css(el, 'overflow') !== 'visible')) { | ||
var pos = utils.offset(el); | ||
if ((navigator.userAgent.indexOf('MSIE') === -1 || el.clientWidth !== 0) && ( | ||
// body may have overflow set on it, yet we still get the entire | ||
// viewport. In some browsers, el.offsetParent may be | ||
// document.documentElement, so check for that too. | ||
el !== body && el !== documentElement && _utils2['default'].css(el, 'overflow') !== 'visible')) { | ||
var pos = _utils2['default'].offset(el); | ||
// add border | ||
@@ -132,9 +144,9 @@ pos.left += el.clientLeft; | ||
// Clip by window's viewport. | ||
scrollX = utils.getWindowScrollLeft(win); | ||
scrollY = utils.getWindowScrollTop(win); | ||
scrollX = _utils2['default'].getWindowScrollLeft(win); | ||
scrollY = _utils2['default'].getWindowScrollTop(win); | ||
visibleRect.left = Math.max(visibleRect.left, scrollX); | ||
visibleRect.top = Math.max(visibleRect.top, scrollY); | ||
winSize = { | ||
width: utils.viewportWidth(win), | ||
height: utils.viewportHeight(win) | ||
width: _utils2['default'].viewportWidth(win), | ||
height: _utils2['default'].viewportHeight(win) | ||
}; | ||
@@ -147,3 +159,6 @@ visibleRect.right = Math.min(visibleRect.right, scrollX + winSize.width); | ||
function getElFuturePos(elRegion, refNodeRegion, points, offset) { | ||
var xy, diff, p1, p2; | ||
var xy = undefined; | ||
var diff = undefined; | ||
var p1 = undefined; | ||
var p2 = undefined; | ||
@@ -175,4 +190,4 @@ xy = { | ||
function adjustForViewport(elFuturePos, elRegion, visibleRect, overflow) { | ||
var pos = utils.clone(elFuturePos), | ||
size = { | ||
var pos = _utils2['default'].clone(elFuturePos); | ||
var size = { | ||
width: elRegion.width, | ||
@@ -213,3 +228,3 @@ height: elRegion.height | ||
return utils.mix(pos, size); | ||
return _utils2['default'].mix(pos, size); | ||
} | ||
@@ -219,3 +234,3 @@ | ||
var ret = []; | ||
utils.each(points, function (p) { | ||
_utils2['default'].each(points, function (p) { | ||
ret.push(p.replace(reg, function (m) { | ||
@@ -234,15 +249,17 @@ return map[m]; | ||
function getRegion(node) { | ||
var offset, w, h; | ||
if (!utils.isWindow(node) && node.nodeType !== 9) { | ||
offset = utils.offset(node); | ||
w = utils.outerWidth(node); | ||
h = utils.outerHeight(node); | ||
var offset = undefined; | ||
var w = undefined; | ||
var h = undefined; | ||
if (!_utils2['default'].isWindow(node) && node.nodeType !== 9) { | ||
offset = _utils2['default'].offset(node); | ||
w = _utils2['default'].outerWidth(node); | ||
h = _utils2['default'].outerHeight(node); | ||
} else { | ||
var win = utils.getWindow(node); | ||
var win = _utils2['default'].getWindow(node); | ||
offset = { | ||
left: utils.getWindowScrollLeft(win), | ||
top: utils.getWindowScrollTop(win) | ||
left: _utils2['default'].getWindowScrollLeft(win), | ||
top: _utils2['default'].getWindowScrollTop(win) | ||
}; | ||
w = utils.viewportWidth(win); | ||
h = utils.viewportHeight(win); | ||
w = _utils2['default'].viewportWidth(win); | ||
h = _utils2['default'].viewportHeight(win); | ||
} | ||
@@ -284,3 +301,3 @@ offset.width = w; | ||
// 当前节点将要所处的区域 | ||
var newElRegion = utils.merge(elRegion, elFuturePos); | ||
var newElRegion = _utils2['default'].merge(elRegion, elFuturePos); | ||
@@ -320,3 +337,3 @@ // 如果可视区域不能完全放置当前节点时允许调整 | ||
elFuturePos = getElFuturePos(elRegion, refNodeRegion, points, offset); | ||
utils.mix(newElRegion, elFuturePos); | ||
_utils2['default'].mix(newElRegion, elFuturePos); | ||
} | ||
@@ -340,11 +357,11 @@ | ||
// 例如 <div 'relative'><el absolute></div> | ||
utils.offset(el, { left: newElRegion.left, top: newElRegion.top }); | ||
_utils2['default'].offset(el, { left: newElRegion.left, top: newElRegion.top }); | ||
// need judge to in case set fixed with in css on height auto element | ||
if (newElRegion.width !== elRegion.width) { | ||
utils.css(el, 'width', el.width() + newElRegion.width - elRegion.width); | ||
_utils2['default'].css(el, 'width', el.width() + newElRegion.width - elRegion.width); | ||
} | ||
if (newElRegion.height !== elRegion.height) { | ||
utils.css(el, 'height', el.height() + newElRegion.height - elRegion.height); | ||
_utils2['default'].css(el, 'height', el.height() + newElRegion.height - elRegion.height); | ||
} | ||
@@ -363,3 +380,4 @@ | ||
module.exports = domAlign; | ||
exports['default'] = domAlign; | ||
/** | ||
@@ -373,5 +391,2 @@ * 2012-04-26 yiminghe@gmail.com | ||
**/ | ||
// body may have overflow set on it, yet we still get the entire | ||
// viewport. In some browsers, el.offsetParent may be | ||
// document.documentElement, so check for that too. | ||
module.exports = exports['default']; |
169
lib/utils.js
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var RE_NUM = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source; | ||
var getComputedStyleX; | ||
var getComputedStyleX = undefined; | ||
function css(el, name, value) { | ||
function css(el, name, v) { | ||
var value = v; | ||
if (typeof name === 'object') { | ||
for (var i in name) { | ||
css(el, i, name[i]); | ||
if (name.hasOwnProperty(i)) { | ||
css(el, i, name[i]); | ||
} | ||
} | ||
@@ -20,9 +26,10 @@ return undefined; | ||
return undefined; | ||
} else { | ||
return getComputedStyleX(el, name); | ||
} | ||
return getComputedStyleX(el, name); | ||
} | ||
function getClientPosition(elem) { | ||
var box, x, y; | ||
var box = undefined; | ||
var x = undefined; | ||
var y = undefined; | ||
var doc = elem.ownerDocument; | ||
@@ -72,6 +79,6 @@ var body = doc.body; | ||
var d = w.document; | ||
//ie6,7,8 standard mode | ||
// ie6,7,8 standard mode | ||
ret = d.documentElement[method]; | ||
if (typeof ret !== 'number') { | ||
//quirks mode | ||
// quirks mode | ||
ret = d.body[method]; | ||
@@ -99,3 +106,4 @@ } | ||
} | ||
function _getComputedStyle(elem, name, computedStyle) { | ||
function _getComputedStyle(elem, name, cs) { | ||
var computedStyle = cs; | ||
var val = ''; | ||
@@ -113,7 +121,7 @@ var d = elem.ownerDocument; | ||
var _RE_NUM_NO_PX = new RegExp('^(' + RE_NUM + ')(?!px)[a-z%]+$', 'i'); | ||
var RE_POS = /^(top|right|bottom|left)$/, | ||
CURRENT_STYLE = 'currentStyle', | ||
RUNTIME_STYLE = 'runtimeStyle', | ||
LEFT = 'left', | ||
PX = 'px'; | ||
var RE_POS = /^(top|right|bottom|left)$/; | ||
var CURRENT_STYLE = 'currentStyle'; | ||
var RUNTIME_STYLE = 'runtimeStyle'; | ||
var LEFT = 'left'; | ||
var PX = 'px'; | ||
@@ -137,5 +145,5 @@ function _getComputedStyleIE(elem, name) { | ||
// Remember the original values | ||
var style = elem.style, | ||
left = style[LEFT], | ||
rsLeft = elem[RUNTIME_STYLE][LEFT]; | ||
var style = elem.style; | ||
var left = style[LEFT]; | ||
var rsLeft = elem[RUNTIME_STYLE][LEFT]; | ||
@@ -176,5 +184,7 @@ // prevent flashing of content | ||
var ret = {}; | ||
var key; | ||
var key = undefined; | ||
for (key in offset) { | ||
ret[key] = preset + offset[key] - old[key]; | ||
if (offset.hasOwnProperty(key)) { | ||
ret[key] = preset + offset[key] - old[key]; | ||
} | ||
} | ||
@@ -194,17 +204,19 @@ css(elem, ret); | ||
var BOX_MODELS = ['margin', 'border', 'padding'], | ||
CONTENT_INDEX = -1, | ||
PADDING_INDEX = 2, | ||
BORDER_INDEX = 1, | ||
MARGIN_INDEX = 0; | ||
var BOX_MODELS = ['margin', 'border', 'padding']; | ||
var CONTENT_INDEX = -1; | ||
var PADDING_INDEX = 2; | ||
var BORDER_INDEX = 1; | ||
var MARGIN_INDEX = 0; | ||
function swap(elem, options, callback) { | ||
var old = {}, | ||
style = elem.style, | ||
name; | ||
var old = {}; | ||
var style = elem.style; | ||
var name = undefined; | ||
// Remember the old values, and insert the new ones | ||
for (name in options) { | ||
old[name] = style[name]; | ||
style[name] = options[name]; | ||
if (options.hasOwnProperty(name)) { | ||
old[name] = style[name]; | ||
style[name] = options[name]; | ||
} | ||
} | ||
@@ -216,3 +228,5 @@ | ||
for (name in options) { | ||
style[name] = old[name]; | ||
if (options.hasOwnProperty(name)) { | ||
style[name] = old[name]; | ||
} | ||
} | ||
@@ -222,6 +236,6 @@ } | ||
function getPBMWidth(elem, props, which) { | ||
var value = 0, | ||
prop, | ||
j, | ||
i; | ||
var value = 0; | ||
var prop = undefined; | ||
var j = undefined; | ||
var i = undefined; | ||
for (j = 0; j < props.length; j++) { | ||
@@ -231,3 +245,3 @@ prop = props[j]; | ||
for (i = 0; i < which.length; i++) { | ||
var cssProp; | ||
var cssProp = undefined; | ||
if (prop === 'border') { | ||
@@ -251,4 +265,4 @@ cssProp = prop + which[i] + 'Width'; | ||
// must use == for ie8 | ||
/*eslint eqeqeq:0*/ | ||
return obj != null && obj == obj.window; | ||
/* eslint eqeqeq:0 */ | ||
return obj !== null && obj !== undefined && obj == obj.window; | ||
} | ||
@@ -262,6 +276,6 @@ | ||
return Math.max( | ||
//firefox chrome documentElement.scrollHeight< body.scrollHeight | ||
//ie standard mode : documentElement.scrollHeight> body.scrollHeight | ||
// firefox chrome documentElement.scrollHeight< body.scrollHeight | ||
// ie standard mode : documentElement.scrollHeight> body.scrollHeight | ||
d.documentElement['scroll' + name], | ||
//quirks : documentElement.scrollHeight 最大等于可视窗口多一点? | ||
// quirks : documentElement.scrollHeight 最大等于可视窗口多一点? | ||
d.body['scroll' + name], domUtils['viewport' + name](d)); | ||
@@ -272,7 +286,7 @@ }; | ||
// pc browser includes scrollbar in window.innerWidth | ||
var prop = 'client' + name, | ||
doc = win.document, | ||
body = doc.body, | ||
documentElement = doc.documentElement, | ||
documentElementProp = documentElement[prop]; | ||
var prop = 'client' + name; | ||
var doc = win.document; | ||
var body = doc.body; | ||
var documentElement = doc.documentElement; | ||
var documentElementProp = documentElement[prop]; | ||
// 标准模式取 documentElement | ||
@@ -292,3 +306,4 @@ // backcompat 取 body | ||
*/ | ||
function getWH(elem, name, extra) { | ||
function getWH(elem, name, ex) { | ||
var extra = ex; | ||
if (isWindow(elem)) { | ||
@@ -299,12 +314,12 @@ return name === 'width' ? domUtils.viewportWidth(elem) : domUtils.viewportHeight(elem); | ||
} | ||
var which = name === 'width' ? ['Left', 'Right'] : ['Top', 'Bottom'], | ||
borderBoxValue = name === 'width' ? elem.offsetWidth : elem.offsetHeight; | ||
var which = name === 'width' ? ['Left', 'Right'] : ['Top', 'Bottom']; | ||
var borderBoxValue = name === 'width' ? elem.offsetWidth : elem.offsetHeight; | ||
var computedStyle = getComputedStyleX(elem); | ||
var isBorderBox = isBorderBoxFn(elem, computedStyle); | ||
var cssBoxValue = 0; | ||
if (borderBoxValue == null || borderBoxValue <= 0) { | ||
if (borderBoxValue === null || borderBoxValue === undefined || borderBoxValue <= 0) { | ||
borderBoxValue = undefined; | ||
// Fall back to computed then un computed css if necessary | ||
cssBoxValue = getComputedStyleX(elem, name); | ||
if (cssBoxValue == null || Number(cssBoxValue) < 0) { | ||
if (cssBoxValue === null || cssBoxValue === undefined || Number(cssBoxValue) < 0) { | ||
cssBoxValue = elem.style[name] || 0; | ||
@@ -323,10 +338,11 @@ } | ||
return val - getPBMWidth(elem, ['border', 'padding'], which, computedStyle); | ||
} else { | ||
return cssBoxValue; | ||
} | ||
return cssBoxValue; | ||
} else if (borderBoxValueOrIsBorderBox) { | ||
return val + (extra === BORDER_INDEX ? 0 : extra === PADDING_INDEX ? -getPBMWidth(elem, ['border'], which, computedStyle) : getPBMWidth(elem, ['margin'], which, computedStyle)); | ||
} else { | ||
return cssBoxValue + getPBMWidth(elem, BOX_MODELS.slice(extra), which, computedStyle); | ||
if (extra === BORDER_INDEX) { | ||
return val; | ||
} | ||
return val + (extra === PADDING_INDEX ? -getPBMWidth(elem, ['border'], which, computedStyle) : getPBMWidth(elem, ['margin'], which, computedStyle)); | ||
} | ||
return cssBoxValue + getPBMWidth(elem, BOX_MODELS.slice(extra), which, computedStyle); | ||
} | ||
@@ -337,5 +353,9 @@ | ||
// fix #119 : https://github.com/kissyteam/kissy/issues/119 | ||
function getWHIgnoreDisplay(elem) { | ||
var val, | ||
args = arguments; | ||
function getWHIgnoreDisplay() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var val = undefined; | ||
var elem = args[0]; | ||
// in case elem is window | ||
@@ -360,3 +380,4 @@ // elem.offsetWidth === undefined | ||
domUtils[name] = function (elem, val) { | ||
domUtils[name] = function (elem, v) { | ||
var val = v; | ||
if (val !== undefined) { | ||
@@ -379,3 +400,5 @@ if (elem) { | ||
for (var i in from) { | ||
to[i] = from[i]; | ||
if (from.hasOwnProperty(i)) { | ||
to[i] = from[i]; | ||
} | ||
} | ||
@@ -385,3 +408,3 @@ return to; | ||
var utils = module.exports = { | ||
var utils = { | ||
getWindow: function getWindow(node) { | ||
@@ -405,6 +428,8 @@ if (node && node.document && node.setTimeout) { | ||
clone: function clone(obj) { | ||
var i; | ||
var i = undefined; | ||
var ret = {}; | ||
for (i in obj) { | ||
ret[i] = obj[i]; | ||
if (obj.hasOwnProperty(i)) { | ||
ret[i] = obj[i]; | ||
} | ||
} | ||
@@ -414,3 +439,5 @@ var overflow = obj.overflow; | ||
for (i in obj) { | ||
ret.overflow[i] = obj.overflow[i]; | ||
if (obj.hasOwnProperty(i)) { | ||
ret.overflow[i] = obj.overflow[i]; | ||
} | ||
} | ||
@@ -429,5 +456,10 @@ } | ||
var ret = {}; | ||
for (var i = 0; i < arguments.length; i++) { | ||
utils.mix(ret, arguments[i]); | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
utils.mix(ret, args[i]); | ||
} | ||
return ret; | ||
@@ -439,2 +471,5 @@ }, | ||
mix(utils, domUtils); | ||
mix(utils, domUtils); | ||
exports['default'] = utils; | ||
module.exports = exports['default']; |
{ | ||
"name": "dom-align", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Align DOM Node Flexibly ", | ||
@@ -10,3 +10,6 @@ "keywords": [ | ||
"homepage": "http://github.com/yiminghe/dom-align", | ||
"main":"lib/index", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/index", | ||
"author": "yiminghe@gmail.com", | ||
@@ -26,8 +29,7 @@ "repository": { | ||
"build": "rc-tools run build", | ||
"precommit": "rc-tools run precommit", | ||
"less": "rc-tools run less", | ||
"gh-pages": "rc-tools run gh-pages", | ||
"start": "node --harmony node_modules/.bin/rc-server", | ||
"publish": "rc-tools run tag", | ||
"pub": "rc-tools run pub", | ||
"lint": "rc-tools run lint", | ||
"karma": "rc-tools run karma", | ||
"saucelabs": "node --harmony node_modules/.bin/rc-tools run saucelabs", | ||
@@ -42,8 +44,8 @@ "browser-test": "node --harmony node_modules/.bin/rc-tools run browser-test", | ||
"rc-server": "3.x", | ||
"rc-tools": "3.x", | ||
"rc-tools": "4.x", | ||
"react": "^0.13.0" | ||
}, | ||
"precommit": [ | ||
"precommit" | ||
"lint" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30148
719