Remove all left-overs of call chaining, except for where it's in use.

This commit is contained in:
Jürg Lehni 2013-03-05 20:39:07 -08:00
parent 0e72dbd2e0
commit 1d1e6425fa
9 changed files with 27 additions and 40 deletions

View file

@ -182,7 +182,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
point = Point.read(arguments); point = Point.read(arguments);
this.x = point.x; this.x = point.x;
this.y = point.y; this.y = point.y;
return this;
}, },
@ -201,7 +200,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
size = Size.read(arguments); size = Size.read(arguments);
this.width = size.width; this.width = size.width;
this.height = size.height; this.height = size.height;
return this;
}, },
/** /**
@ -220,7 +218,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setLeft: function(left) { setLeft: function(left) {
this.width -= left - this.x; this.width -= left - this.x;
this.x = left; this.x = left;
return this;
}, },
/** /**
@ -237,7 +234,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setTop: function(top) { setTop: function(top) {
this.height -= top - this.y; this.height -= top - this.y;
this.y = top; this.y = top;
return this;
}, },
/** /**
@ -253,7 +249,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setRight: function(right) { setRight: function(right) {
this.width = right - this.x; this.width = right - this.x;
return this;
}, },
/** /**
@ -269,7 +264,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setBottom: function(bottom) { setBottom: function(bottom) {
this.height = bottom - this.y; this.height = bottom - this.y;
return this;
}, },
/** /**
@ -285,7 +279,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setCenterX: function(x) { setCenterX: function(x) {
this.x = x - this.width * 0.5; this.x = x - this.width * 0.5;
return this;
}, },
/** /**
@ -301,7 +294,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setCenterY: function(y) { setCenterY: function(y) {
this.y = y - this.height * 0.5; this.y = y - this.height * 0.5;
return this;
}, },
/** /**
@ -319,7 +311,11 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
setCenter: function(point) { setCenter: function(point) {
point = Point.read(arguments); point = Point.read(arguments);
return this.setCenterX(point.x).setCenterY(point.y); this.setCenterX(point.x);
this.setCenterY(point.y);
// A special setter where we allow chaining, because it comes in handy
// in a couple of places in core.
return this;
}, },
/** /**
@ -736,8 +732,8 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
}; };
this[set] = function(point) { this[set] = function(point) {
point = Point.read(arguments); point = Point.read(arguments);
// Note: call chaining happens here. this[setX](point.x);
return this[setX](point.x)[setY](point.y); this[setY](point.y);
}; };
}, {}); }, {});
}); });
@ -810,7 +806,6 @@ var LinkedRectangle = Rectangle.extend({
proto[name].apply(this, arguments); proto[name].apply(this, arguments);
delete this._dontNotify; delete this._dontNotify;
this._owner[this._setter](this); this._owner[this._setter](this);
return this;
}; };
}, { }, {
/** /**

View file

@ -337,7 +337,6 @@ var Color = this.Color = Base.extend(new function() {
// All other values are 0..1 // All other values are 0..1
: Math.min(Math.max(value, 0), 1); : Math.min(Math.max(value, 0), 1);
this._changed(); this._changed();
return this;
}; };
}, src); }, src);
} }
@ -434,7 +433,6 @@ var Color = this.Color = Base.extend(new function() {
setAlpha: function(alpha) { setAlpha: function(alpha) {
this._alpha = alpha == null ? null : Math.min(Math.max(alpha, 0), 1); this._alpha = alpha == null ? null : Math.min(Math.max(alpha, 0), 1);
this._changed(); this._changed();
return this;
}, },
/** /**

View file

@ -107,7 +107,6 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
stop.setRampPoint(i / (l - 1)); stop.setRampPoint(i / (l - 1));
} }
this._changed(); this._changed();
return this;
}, },
/** /**

View file

@ -147,7 +147,6 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
if (this._destination) if (this._destination)
this._radius = this._destination.getDistance(this._origin); this._radius = this._destination.getDistance(this._origin);
this._changed(); this._changed();
return this;
}, },
/** /**
@ -189,7 +188,6 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
this._destination = destination; this._destination = destination;
this._radius = this._destination.getDistance(this._origin); this._radius = this._destination.getDistance(this._origin);
this._changed(); this._changed();
return this;
}, },
/** /**
@ -234,7 +232,6 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
this._hilite = hilite; this._hilite = hilite;
} }
this._changed(); this._changed();
return this;
}, },
toCanvasStyle: function(ctx) { toCanvasStyle: function(ctx) {

View file

@ -18,31 +18,32 @@ var Callback = {
attach: function(type, func) { attach: function(type, func) {
// If an object literal is passed, attach all callbacks defined in it // If an object literal is passed, attach all callbacks defined in it
if (typeof type !== 'string') { if (typeof type !== 'string') {
return Base.each(type, function(value, key) { Base.each(type, function(value, key) {
this.attach(key, value); this.attach(key, value);
}, this); }, this);
return;
} }
var entry = this._eventTypes[type]; var entry = this._eventTypes[type];
if (!entry) if (entry) {
return this; var handlers = this._handlers = this._handlers || {};
var handlers = this._handlers = this._handlers || {}; handlers = handlers[type] = handlers[type] || [];
handlers = handlers[type] = handlers[type] || []; if (handlers.indexOf(func) == -1) { // Not added yet, add it now
if (handlers.indexOf(func) == -1) { // Not added yet, add it now handlers.push(func);
handlers.push(func); // See if this is the first handler that we're attaching, and
// See if this is the first handler that we're attaching, and // call install if defined.
// call install if defined. if (entry.install && handlers.length == 1)
if (entry.install && handlers.length == 1) entry.install.call(this, type);
entry.install.call(this, type); }
} }
return this;
}, },
detach: function(type, func) { detach: function(type, func) {
// If an object literal is passed, detach all callbacks defined in it // If an object literal is passed, detach all callbacks defined in it
if (typeof type !== 'string') { if (typeof type !== 'string') {
return Base.each(type, function(value, key) { Base.each(type, function(value, key) {
this.detach(key, value); this.detach(key, value);
}, this); }, this);
return;
} }
var entry = this._eventTypes[type], var entry = this._eventTypes[type],
handlers = this._handlers && this._handlers[type], handlers = this._handlers && this._handlers[type],
@ -60,7 +61,6 @@ var Callback = {
handlers.splice(index, 1); handlers.splice(index, 1);
} }
} }
return this;
}, },
fire: function(type, event) { fire: function(type, event) {

View file

@ -116,7 +116,6 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
var child = this.getFirstChild(); var child = this.getFirstChild();
if (child) if (child)
child.setClipMask(clipped); child.setClipMask(clipped);
return this;
}, },
draw: function(ctx, param) { draw: function(ctx, param) {

View file

@ -2089,6 +2089,7 @@ var Item = this.Item = Base.extend(Callback, {
// Transform position as well. // Transform position as well.
this._position = matrix._transformPoint(position, position); this._position = matrix._transformPoint(position, position);
} }
// Allow chaining here, since transform() is related to Matrix functions
return this; return this;
}, },

View file

@ -118,13 +118,12 @@ var Style = Base.extend({
return style; return style;
}; };
// Style-getters and setters for owner class: // Style-getters and setters for owner class:
owner[set] = function(value) {
this[styleKey][set](value);
return this;
};
owner[get] = function() { owner[get] = function() {
return this[styleKey][get](); return this[styleKey][get]();
}; };
owner[set] = function(value) {
this[styleKey][set](value);
};
}); });
src._owner.inject(owner); src._owner.inject(owner);
// Pass on to base() // Pass on to base()

View file

@ -22,17 +22,16 @@ var Event = this.Event = Base.extend(/** @lends Event# */{
preventDefault: function() { preventDefault: function() {
this._prevented = true; this._prevented = true;
DomEvent.preventDefault(this.event); DomEvent.preventDefault(this.event);
return this;
}, },
stopPropagation: function() { stopPropagation: function() {
this._stopped = true; this._stopped = true;
DomEvent.stopPropagation(this.event); DomEvent.stopPropagation(this.event);
return this;
}, },
stop: function() { stop: function() {
return this.stopPropagation().preventDefault(); this.stopPropagation();
this.preventDefault();
}, },
// DOCS: Document Event#modifiers // DOCS: Document Event#modifiers