Skip to content

Commit

Permalink
add comment and some code style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed May 12, 2015
1 parent 92136c7 commit 746b87d
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@
* Constructor
* @param {Object} objects Group objects
* @param {Object} [options] Options object
* @param {Boolean} [alreadyGrouped] if true, objects have been grouped already.
* @return {Object} thisArg
*/
initialize: function(objects, options, skipPropagation) {
initialize: function(objects, options, alreadyGrouped) {
options = options || { };

this._objects = [];
skipPropagation && this.callSuper('initialize', options);
// if objects enclosed in a group have been grouped already,
// we cannot change properties of objects.
// Thus we need to set options to group without objects,
// because delegatedProperties propagate to objects.
alreadyGrouped && this.callSuper('initialize', options);

this._objects = objects || [];
for (var i = this._objects.length; i--; ) {
Expand All @@ -74,44 +79,49 @@
this.originY = options.originY;
}

if (!skipPropagation) {
if (alreadyGrouped) {
// do not change coordinate of objects enclosed in a group,
// because objects coordinate system have been group coodinate system already.
this._updateObjectsCoords(true);
}
else {
this._calcBounds();
this._updateObjectsCoords();
this.callSuper('initialize', options);
}
else {
for (i = this._objects.length; i--; ) {
this._objects[i].setCoords();
this._objects[i].__origHasControls = this._objects[i].hasControls;
this._objects[i].hasControls = false;
}
}

this.setCoords();
this.saveCoords();
},

/**
* @private
* @param {Boolean} [unchangeCoords] if true, coordinates of objects enclosed in a group do not change
*/
_updateObjectsCoords: function() {
this.forEachObject(this._updateObjectCoords, this);
_updateObjectsCoords: function(unchangeCoords) {
for (var i = this._objects.length; i--; ){
this._updateObjectCoords(this._objects[i], unchangeCoords);
}
},

/**
* @private
*/
_updateObjectCoords: function(object) {
var objectLeft = object.getLeft(),
objectTop = object.getTop(),
center = this.getCenterPoint();

object.set({
originalLeft: objectLeft,
originalTop: objectTop,
left: objectLeft - center.x,
top: objectTop - center.y
});
* @param {Object} object
* @param {Boolean} [unchangeCoords] if true, coordinates of object dose not change
*/
_updateObjectCoords: function(object, unchangeCoords) {
if (!unchangeCoords) {
var objectLeft = object.getLeft(),
objectTop = object.getTop(),
center = this.getCenterPoint();

object.set({
originalLeft: objectLeft,
originalTop: objectTop,
left: objectLeft - center.x,
top: objectTop - center.y
});
}

object.setCoords();

Expand Down

0 comments on commit 746b87d

Please sign in to comment.