Merge remote branch 'origin/master'

This commit is contained in:
Jonathan Puckey 2011-06-03 11:34:34 +02:00
commit 298c304660
3 changed files with 29 additions and 22 deletions

View file

@ -15,12 +15,15 @@
*/
var DomElement = new function() {
function cumulate(el, name, parent) {
function cumulate(el, name, parent, positioned) {
var left = name + 'Left',
top = name + 'Top',
x = 0,
y = 0;
while (el) {
// If we're asked to calculate positioned offset, stop at any
// parent element that has relative or absolute position.
while (el && (!positioned
|| !/^(relative|absolute)$/.test(el.style.position))) {
x += el[left] || 0;
y += el[top] || 0;
el = el[parent];
@ -29,8 +32,8 @@ var DomElement = new function() {
}
return {
getOffset: function(el, scroll) {
var point = cumulate(el, 'offset', 'offsetParent');
getOffset: function(el, positioned, scroll) {
var point = cumulate(el, 'offset', 'offsetParent', positioned);
return scroll
? point.subtract(cumulate(el, 'scroll', 'parentNode'))
: point;
@ -40,8 +43,8 @@ var DomElement = new function() {
return Size.create(el.offsetWidth, el.offsetHeight);
},
getBounds: function(el, scroll) {
return new Rectangle(DomElement.getOffset(el, scroll),
getBounds: function(el, positioned, scroll) {
return new Rectangle(DomElement.getOffset(el, positioned, scroll),
DomElement.getSize(el));
},
@ -59,7 +62,7 @@ var DomElement = new function() {
// See if the scrolled bounds intersect with the windows rectangle
// which always starts at 0, 0
return new Rectangle([0, 0], DomElement.getWindowSize())
.intersects(DomElement.getBounds(el, true));
.intersects(DomElement.getBounds(el, false, true));
}
};
};

View file

@ -128,19 +128,18 @@ var Item = this.Item = Base.extend({
*/
getPosition: function() {
// Cache position value
if (!this._position) {
// Center is a LinkedPoint as well, so we can use _x and _y
var center = this.getBounds().getCenter();
this._position = LinkedPoint.create(this, 'setPosition',
center._x, center._y);
}
return this._position;
var pos = this._position
|| (this._position = this.getBounds().getCenter());
// this._position is a LinkedPoint as well, so we can use _x and _y.
// Do not cache LinkedPoints directly, since we would not be able to
// use them to calculate the difference in #setPosition, as when it is
// modified, it would hold new values already and only then cause the
// calling of #setPosition.
return LinkedPoint.create(this, 'setPosition', pos._x, pos._y);
},
setPosition: function(point) {
point = Point.read(arguments);
if (point)
this.translate(point.subtract(this.getPosition()));
this.translate(Point.read(arguments).subtract(this.getPosition()));
},
/**

View file

@ -67,13 +67,18 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
* </pre>
*/
initialize: function(style) {
// Note: This relies on bean setters that get implicetly
// called when setting values on this[key].
// If the passed style object is a PathStyle, clone its clonable
// fields rather than simply copying them.
var clone = style instanceof PathStyle;
// Note: This relies on bean getters and setters that get implicetly
// called when getting from style[key] and setting on this[key].
for (var i = 0, l = style && keys.length; i < l; i++) {
var key = keys[i],
value = style[key];
if (value !== undefined)
this[key] = value;
if (value !== undefined) {
this[key] = value && clone && value.clone
? value.clone() : value;
}
}
},
@ -101,7 +106,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
} else {
var old = this['_' + key];
if (old != value && !(old && old.equals && old.equals(value))) {
this['_' + key] = value && value.clone ? value.clone() : value;
this['_' + key] = value;
if (this._item) {
this._item._changed(ChangeFlags.STYLE
| (strokeFlags[key] ? ChangeFlags.STROKE : 0));