This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
ContextMenuHandler.js
64 lines (52 loc) · 1.92 KB
/
ContextMenuHandler.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
/**
* @author Swagatam Mitra
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, document, console, brackets, $, Mustache */
define(function (require, exports, module) {
"use strict";
var selectionArea;
function _isContextOnSelection(point){
if(selectionArea){
if( point.x >= selectionArea.left && point.x <= selectionArea.right
&& point.y >= selectionArea.top && point.y <= selectionArea.bottom){
return true;
} else {
return false;
}
} else {
return false;
}
}
function _hideContextMenu(){
$("#designer-context-menu-cont")
.removeClass('open')
.hide();
}
$(document).on("targetdom.contextmenu","#html-design-editor", function(e,elem,point){
if(_isContextOnSelection(point)){
$("#context-delete-element").parent().removeClass("disabledli");
}else {
$("#context-delete-element").parent().addClass("disabledli");
}
$("#designer-context-menu-cont")
.css('top',point.y)
.css('left',point.x)
.addClass('open')
.show();
});
$(document).on("element.selected","#html-design-editor",function(event,element){
selectionArea = element.getBoundingClientRect();
_hideContextMenu();
});
$(document).on("multiselectarea.computed","#html-design-editor",function(event,unionArea){
selectionArea = unionArea;
});
$(document).on("deselect.all","#html-design-editor",function(event){
selectionArea = null;
_hideContextMenu();
});
$(document).on("hide.contextmenu","#html-design-editor",function(event){
_hideContextMenu();
});
});