Added event-triggers for dragged status

This commit is contained in:
Erik Tiekstra
2017-05-17 14:14:24 +02:00
parent 6ac64d18bd
commit ae9c75265d
4 changed files with 16 additions and 1 deletions
@@ -2,6 +2,7 @@
function ApertureHandler(canvas) { function ApertureHandler(canvas) {
var _items = {x: [], y: []}; var _items = {x: [], y: []};
var $document = $(document);
function init() { function init() {
var bounds = canvas; var bounds = canvas;
@@ -61,6 +62,7 @@ function ApertureHandler(canvas) {
this.getApertures().forEach(function (o) { this.getApertures().forEach(function (o) {
o.opacity = apply ? 0.7 : 1; o.opacity = apply ? 0.7 : 1;
}); });
canvas.renderAll(); canvas.renderAll();
return this; return this;
}; };
+3 -1
View File
@@ -22,8 +22,10 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
this.on('mouse:up', function () { this.on('mouse:up', function () {
if (this.getImage().__moved) { if (this.getImage().__moved) {
this.getApertures().setTransparent(false); this.getApertures().setTransparent(false);
// Trigger event to tell the image has been dragged.
$(document).trigger('PIE:dragged');
} }
$(this.upperCanvasEl).css('cursor', 'default');
this.renderAll(); this.renderAll();
}); });
}, },
@@ -129,6 +129,10 @@ function Viewport(canvas) {
canvas.getApertures().setTransparent(true); canvas.getApertures().setTransparent(true);
canvas.getImage().__moved = false; canvas.getImage().__moved = false;
canvas.getButtonMenu().bringToFront(); canvas.getButtonMenu().bringToFront();
// Trigger event to tell the image needs to be dragged.
$(document).trigger('PIE:needs-dragging');
}; };
/** /**
+7
View File
@@ -1,6 +1,7 @@
'use strict'; 'use strict';
(function() { (function() {
var $document = $(document);
// Inputs for the editor // Inputs for the editor
var $input = { var $input = {
w: $('#form-control input[name="w"]'), w: $('#form-control input[name="w"]'),
@@ -69,4 +70,10 @@
$input.mirror.on('change', Event.Mirror); $input.mirror.on('change', Event.Mirror);
$input.noCrop.on('change', Event.NoCrop); $input.noCrop.on('change', Event.NoCrop);
$input.border.on('change', Event.SetBorder); $input.border.on('change', Event.SetBorder);
$document.on('PIE:dragged', function() {
console.log('Now you can buy!');
});
$document.on('PIE:needs-dragging', function() {
console.log('You need to drag to be able to buy!');
});
}()); }());