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
/
MultiSelectionDrawControl.js
90 lines (72 loc) · 3.13 KB
/
MultiSelectionDrawControl.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @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 AppInit = brackets.getModule("utils/AppInit");
var SelectionUtility = require("SelectionUtility");
var topLeftPoint,
bottomRightPoint,
$preMultiselectionArea;
function _initMultiSelect(event,element,point){
topLeftPoint = point;
$preMultiselectionArea
.css('left',point.x+23)
.css('top',point.y+23)
.css('width',0)
.css('height',0)
.show();
$(window).on('keyup',_cleanUp);
}
function _drawMultiSelectRect(event,element,point){
if(topLeftPoint){
if(point.x < topLeftPoint.x){
$preMultiselectionArea.css('left',point.x+23);
$preMultiselectionArea.css('width', (topLeftPoint.x - point.x));
} else {
$preMultiselectionArea.css('width', (point.x - topLeftPoint.x));
}
if(point.y < topLeftPoint.y){
$preMultiselectionArea.css('top',point.y+23);
$preMultiselectionArea.css('height', (topLeftPoint.y - point.y));
} else {
$preMultiselectionArea.css('height', (point.y - topLeftPoint.y));
}
}
}
function _cleanUp(){
if(event.which === 17){
$preMultiselectionArea.hide();
topLeftPoint = null;
$(window).off('keyup',_cleanUp);
}
}
function _doMultiSelect(event,element,point){
bottomRightPoint = point;
if(topLeftPoint && bottomRightPoint){
//swap the points if drawn in reverse
if(bottomRightPoint.x < topLeftPoint.x ){
bottomRightPoint = topLeftPoint;
topLeftPoint = point;
}
var content = $(document.getElementById('htmldesignerIframe').contentWindow.document.body).children();
var elements = SelectionUtility.getElementInRect( content
,topLeftPoint.x,topLeftPoint.y
,bottomRightPoint.x,bottomRightPoint.y
);
$preMultiselectionArea.hide();
if(elements.length > 0){
$("#html-design-editor").trigger("multiselection.done",[elements]);
}
topLeftPoint = null;
}
}
$(document).on("multiselectmousedown","#html-design-editor", _initMultiSelect);
$(document).on("multiselectmousemove targetdom.element.mousemove","#html-design-editor", _drawMultiSelectRect);
$(document).on("multiselectmouseup multiselectmouseout multiselectmouseleave targetdom.element.mouseup targetdom.element.mouseout targetdom.element.mouseleave","#html-design-editor",_doMultiSelect);
AppInit.appReady(function () {
$preMultiselectionArea = $(".preMultiSelectionArea");
});
});