-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelements.js
71 lines (59 loc) · 1.44 KB
/
elements.js
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
$(document).ready(function(){
createHandlersForElements($('.element'));
});
function createHandlersForElements(els){
checkIfIsInCanvas = canvas().checkIfIsInCanvas;
els.draggable({
drag: elementDragHandler,
revert: elementDropHandler
});
els.resizable({
autoHide:true,
containment: $('.canvas'),
resize: textBlockResizeHandler
});
els.find('.content').draggable({
containment:"parent"
});
els.find('.image').resizable({
autoHide:true,
containment:"parent"
});
els.find('.content').on('dblclick', function(){
var handler = getContentClass($(this)).getEditHandler();
handler.call(this);
});
function textBlockResizeHandler(event, ui){
var innerText = ui.element[0].getElementsByClassName('content')[0];
var minWidth = innerText.clientWidth + innerText.offsetLeft;
var minHeight = innerText.clientHeight + innerText.offsetTop;
if(ui.size.width < minWidth) {
ui.size.width = minWidth;
}
if(ui.size.height < minHeight) {
ui.size.height = minHeight;
}
}
function elementDragHandler(event, ui){
if(!checkIfIsInCanvas(ui.offset)){
$(this).addClass("redmask");
}
else{
$(this).removeClass("redmask");
}
}
function elementDropHandler(){
if(!checkIfIsInCanvas($(this).offset())){
if(confirm("Really delete this element?")){
$(this).remove();
}
else{
//Smoothly return back
$(this).removeClass("redmask");
return true;
}
}
return false;
}
}
var checkIfIsInCanvas;