Skip to content

Commit

Permalink
Merge pull request #37 from kangax/master
Browse files Browse the repository at this point in the history
sync to master
  • Loading branch information
asturur committed Oct 12, 2015
2 parents f468134 + 0623c02 commit f112514
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 75 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "4"
- "0.12"
- "0.11"
- "0.10"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"istanbul": "0.3.x"
},
"engines": {
"node": ">=0.4.0 && <1.0.0"
"node": ">=0.4.0"
},
"main": "./dist/fabric.js"
}
1 change: 0 additions & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@
if (obj &&
obj.visible &&
obj.evented &&
obj.selectable &&
this.containsPoint(e, obj)){
if ((this.perPixelTargetFind || obj.perPixelTargetFind) && !obj.isEditing) {
var isTransparent = this.isTargetTransparent(obj, pointer.x, pointer.y);
Expand Down
8 changes: 4 additions & 4 deletions src/filters/mask_filter.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
i,
iLen = imageData.width * imageData.height * 4;

maskCanvasEl.width = maskEl.width;
maskCanvasEl.height = maskEl.height;
maskCanvasEl.width = canvasEl.width;
maskCanvasEl.height = canvasEl.height;

maskCanvasEl.getContext('2d').drawImage(maskEl, 0, 0, maskEl.width, maskEl.height);
maskCanvasEl.getContext('2d').drawImage(maskEl, 0, 0, canvasEl.width, canvasEl.height);

var maskImageData = maskCanvasEl.getContext('2d').getImageData(0, 0, maskEl.width, maskEl.height),
var maskImageData = maskCanvasEl.getContext('2d').getImageData(0, 0, canvasEl.width, canvasEl.height),
maskData = maskImageData.data;

for (i = 0; i < iLen; i += 4) {
Expand Down
3 changes: 2 additions & 1 deletion src/gradient.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
coords: this.coords,
colorStops: this.colorStops,
offsetX: this.offsetX,
offsetY: this.offsetY
offsetY: this.offsetY,
gradientTransform: this.gradientTransform ? this.gradientTransform.concat() : this.gradientTransform
};
},

Expand Down
11 changes: 3 additions & 8 deletions src/mixins/canvas_dataurl_exporter.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
*/
__toDataURL: function(format, quality, cropping) {

this.renderAll(true);
this.renderAll();

var canvasEl = this.upperCanvasEl || this.lowerCanvasEl,
var canvasEl = this.lowerCanvasEl,
croppedCanvasEl = this.__getCroppedCanvas(canvasEl, cropping);

// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
Expand All @@ -71,9 +71,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
? (croppedCanvasEl || canvasEl).toDataURL('image/' + format, quality)
: (croppedCanvasEl || canvasEl).toDataURL('image/' + format);

this.contextTop && this.clearContext(this.contextTop);
this.renderAll();

if (croppedCanvasEl) {
croppedCanvasEl = null;
}
Expand Down Expand Up @@ -119,7 +116,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
activeObject = this.getActiveObject(),
activeGroup = this.getActiveGroup(),

ctx = this.contextTop || this.contextContainer;
ctx = this.contextContainer;

if (multiplier > 1) {
this.setWidth(scaledWidth).setHeight(scaledHeight);
Expand Down Expand Up @@ -153,8 +150,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
this.deactivateAll();
}

this.renderAll(true);

var data = this.__toDataURL(format, quality, cropping);

// restoring width, height for `renderAll` to draw
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/canvas_grouping.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
_shouldGroup: function(e, target) {
var activeObject = this.getActiveObject();
return e.shiftKey &&
return e.shiftKey && target && target.selectable &&
(this.getActiveGroup() || (activeObject && activeObject !== target))
&& this.selection;
},
Expand Down
24 changes: 12 additions & 12 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,35 +703,35 @@
lineIndex = cursorLocation.lineIndex,
charIndex = cursorLocation.charIndex;

if (isBeginningOfLine) {
this._removeStyleObject(isBeginningOfLine, cursorLocation, lineIndex, charIndex);
},

_getTextOnPreviousLine: function(lIndex) {
return this._textLines[lIndex - 1];
},

_removeStyleObject: function(isBeginningOfLine, cursorLocation, lineIndex, charIndex) {

var textOnPreviousLine = this._textLines[lineIndex - 1],
newCharIndexOnPrevLine = textOnPreviousLine
? textOnPreviousLine.length
: 0;
if (isBeginningOfLine) {
var textOnPreviousLine = this._getTextOnPreviousLine(cursorLocation.lineIndex),
newCharIndexOnPrevLine = textOnPreviousLine ? textOnPreviousLine.length : 0;

if (!this.styles[lineIndex - 1]) {
this.styles[lineIndex - 1] = {};
}

for (charIndex in this.styles[lineIndex]) {
this.styles[lineIndex - 1][parseInt(charIndex, 10) + newCharIndexOnPrevLine]
= this.styles[lineIndex][charIndex];
}

this.shiftLineStyles(lineIndex, -1);

this.shiftLineStyles(cursorLocation.lineIndex, -1);
}
else {
var currentLineStyles = this.styles[lineIndex];

if (currentLineStyles) {
delete currentLineStyles[charIndex];
//console.log('deleting', lineIndex, charIndex + offset);
}

var currentLineStylesCloned = clone(currentLineStyles);

// shift all styles by 1 backwards
for (var i in currentLineStylesCloned) {
var numericIndex = parseInt(i, 10);
Expand Down
9 changes: 5 additions & 4 deletions src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Event} e Event object
*/
onInput: function(e) {
if (!this.isEditing || this._cancelOnInput) {
this._cancelOnInput = false;
if (!this.isEditing) {
return;
}
var offset = this.selectionStart || 0,
offsetEnd = this.selectionEnd || 0,
textLength = this.text.length,
newTextLength = this.hiddenTextarea.value.length,
diff = newTextLength - textLength,
diff = newTextLength - textLength + offsetEnd - offset,
charsToInsert = this.hiddenTextarea.value.slice(offset, offset + diff);
this.insertChars(charsToInsert);
e.stopPropagation();
Expand Down Expand Up @@ -149,7 +149,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
if (copiedText) {
this.insertChars(copiedText, useCopiedStyle);
}
this._cancelOnInput = true;
e.stopImmediatePropagation();
e.preventDefault();
},

/**
Expand Down
37 changes: 1 addition & 36 deletions src/mixins/textbox_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,42 +142,7 @@
map = this._styleMap[cursorLocation.lineIndex],
lineIndex = map.line,
charIndex = map.offset + cursorLocation.charIndex;

if (isBeginningOfLine) {
var textOnPreviousLine = this._getTextOnPreviousLine(cursorLocation.lineIndex),
newCharIndexOnPrevLine = textOnPreviousLine ? textOnPreviousLine.length : 0;

if (!this.styles[lineIndex - 1]) {
this.styles[lineIndex - 1] = {};
}

for (charIndex in this.styles[lineIndex]) {
this.styles[lineIndex - 1][parseInt(charIndex, 10) + newCharIndexOnPrevLine]
= this.styles[lineIndex][charIndex];
}

this.shiftLineStyles(cursorLocation.lineIndex, -1);

}
else {
var currentLineStyles = this.styles[lineIndex];

if (currentLineStyles) {
delete currentLineStyles[charIndex];
//console.log('deleting', lineIndex, charIndex + offset);
}

var currentLineStylesCloned = clone(currentLineStyles);

// shift all styles by 1 backwards
for (var i in currentLineStylesCloned) {
var numericIndex = parseInt(i, 10);
if (numericIndex >= charIndex && numericIndex !== 0) {
currentLineStyles[numericIndex - 1] = currentLineStylesCloned[numericIndex];
delete currentLineStyles[numericIndex];
}
}
}
this._removeStyleObject(isBeginningOfLine, cursorLocation, lineIndex, charIndex);
}
});
})();
8 changes: 3 additions & 5 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,15 @@
* @return {fabric.Canvas} instance
* @chainable
*/
renderAll: function (allOnTop) {
var canvasToDrawOn = this[(allOnTop === true && this.interactive) ? 'contextTop' : 'contextContainer'],
renderAll: function () {
var canvasToDrawOn = this.contextContainer,
activeGroup = this.getActiveGroup();

if (this.contextTop && this.selection && !this._groupSelector) {
this.clearContext(this.contextTop);
}

if (!allOnTop) {
this.clearContext(canvasToDrawOn);
}
this.clearContext(canvasToDrawOn);

this.fire('before:render');

Expand Down
4 changes: 2 additions & 2 deletions test/unit/gradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

test('toObject linearGradient', function() {
var gradient = createLinearGradient();

gradient.gradientTransform = [1, 0, 0, 1, 50, 50];
ok(typeof gradient.toObject == 'function');

var object = gradient.toObject();
Expand All @@ -103,7 +103,7 @@
equal(object.coords.y2, gradient.coords.y2);

equal(object.type, gradient.type);

deepEqual(object.gradientTransform, gradient.gradientTransform);
equal(object.colorStops, gradient.colorStops);
});

Expand Down

0 comments on commit f112514

Please sign in to comment.