Fabricjs trigger
HTML
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<canvas id="c" width="300" height="200"></canvas>
<a id="testClick" href="javascript:">Deselect</a>
JavaScript
var canvas = new fabric.Canvas("c");
var test = jQuery(".canvas-container");
test.on("mousedown", function (){
alert("you clicked me mmm");
canvas.renderAll();
});
canvas.on({"mouse:down": function() {
alert("you clicked me too");
}});
$("#testClick").click(function() {
var e = jQuery.Event("mousedown", {
pageX: 10,
pageY: 10
});
jQuery(test).trigger(e);
canvas.trigger("mouse:down");
});
/*************** TEXT ****************/
var text = new fabric.IText('FaBric.js', {
fontSize: 40,
textAlign: 'center',
fontWeight: 'bold',
left: 128,
top: 128,
angle: 30,
originX: 'center',
originY: 'center',
shadow: 'blue -5px 6px 5px',
styles: {
0: {
0: {
fontSize: 60,
fontFamily: 'Impact',
fontWeight: 'normal',
fill: 'orange'
}
}
}
});
text.setSelectionStyles({
fontStyle: 'italic',
fill: '',
stroke: 'red',
strokeWidth: 2
}, 1, 5);
canvas.add(text);
canvas.setActiveObject(text);