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
/
ElementDeleteHandler.js
56 lines (43 loc) · 1.57 KB
/
ElementDeleteHandler.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
/**
* @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 lastSelectedElement;
$(document).on("element.selected","#html-design-editor",function(event,element){
lastSelectedElement = element;
});
$(document).on("deselect.all","#html-design-editor",function(event){
//lastSelectedElement = null;
});
$(document).on("multiselection.done","#html-design-editor", function(event,elements){
lastSelectedElement = elements;
});
function _handleDelete(){
if(lastSelectedElement){
$("#html-design-editor")
.trigger(
"design.editor.event"
,['delete.element'
,{ element : lastSelectedElement},'html']
);
$("#html-design-editor").trigger('groupdeselect.all');
$("#html-design-editor").trigger('deselect.all');
}
}
$(document).on("delete-element","#html-design-editor", function(event){
_handleDelete();
});
function _handleElementDeletion(event){
if($("#html-design-template").is(':visible')){
if(event.which === 46){
if($("input:focus").length === 0 && $("textarea:focus").length === 0){
_handleDelete();
}
}
}
}
$(window).on('keydown',_handleElementDeletion);
});