-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextBox.js
More file actions
executable file
·82 lines (73 loc) · 2.16 KB
/
Copy pathtextBox.js
File metadata and controls
executable file
·82 lines (73 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
$(document).ready(function(){
$(".addTextbox").click(function(){
var text = new fabric.IText('write here',{left: 50 , top :50});
canvas.add(text);
canvas.setActiveObject(text);
text.enterEditing();
text.selectAll();
$(".layersRight").append("<div><span class='layer' id='"+k+"'>"+k+"</span>Layer<button class='delete'>Delete this</button></div>");
k = k + 1;
});
function setStyle(object, styleName, value) {
if (object.setSelectionStyles && object.isEditing) {
var style = { };
style[styleName] = value;
object.setSelectionStyles(style);
}
else {
object[styleName] = value;
}
}
function getStyle(object, styleName) {
return (object.getSelectionStyles && object.isEditing)
? object.getSelectionStyles()[styleName]
: object[styleName];
}
function addHandler(id, fn, eventName) {
document.getElementById(id)[eventName || 'onclick'] = function() {
var el = this;
if (obj = canvas.getActiveObject()) {
fn.call(el, obj);
canvas.renderAll();
}
};
}
addHandler('underline', function(obj) {
var isUnderline = (getStyle(obj, 'textDecoration') || '').indexOf('underline') > -1;
setStyle(obj, 'textDecoration', isUnderline ? '' : 'underline');
});
addHandler('bold', function(obj) {
var isBold = getStyle(obj, 'fontWeight') === 'bold';
setStyle(obj, 'fontWeight', isBold ? '' : 'bold');
});
addHandler('italic', function() {
var isItalic = getStyle(obj, 'fontStyle') === 'italic';
setStyle(obj, 'fontStyle', isItalic ? '' : 'italic');
});
addHandler('color', function(obj) {
setStyle(obj, 'fill', this.value);
}, 'onchange');
addHandler('size', function(obj) {
setStyle(obj, 'fontSize', parseInt(this.value, 10));
}, 'onchange');
addHandler('font-control',function(obj){
setStyle(obj,'fontFamily',$('#font-control').val());
},'onchange');
// showing hiding for textbox options
canvas.on('mouse:down', function(options) {
if (options.target) {
if(options.target.type == "i-text")
{
$("#forTextBox").show();
}
else
{
$("#forTextBox").hide();
}
}
else
{
$("#forTextBox").hide();
}
});
});