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
/
SelectionUtility.js
57 lines (47 loc) · 1.84 KB
/
SelectionUtility.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
/**
* @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";
function _getContainedChildrens(element, x1, y1, x2, y2,elementArray){
var boundingRect = element.getBoundingClientRect();
var topLeftX = boundingRect.left;
var topLeftY = boundingRect.top;
var bottomRightX = boundingRect.right;
var bottomRightY = boundingRect.bottom;
if (topLeftX >= x1
&& topLeftY >= y1
&& bottomRightX <= x2
&& bottomRightY <= y2) {
// this element fits inside the selection rectangle
elementArray.push(element);
}
if(elementArray.length === 0){
var elementsSet = $(element).children();
elementsSet.each(function() {
_getContainedChildrens(this, x1, y1, x2, y2,elementArray);
});
}
}
// x1, y1 would be top-left corner
// x2, y2 would be bottom-right corner
// all coordinates are considered relative to the document
function _elementsInRect(elementSet, x1, y1, x2, y2) {
var elements = [];
elementSet.each(function() {
_getContainedChildrens(this, x1, y1, x2, y2,elements);
});
if(elements.length === 1){
elementSet = $(elements[0]).children();
elements = [];
elementSet.each(function() {
_getContainedChildrens(this, x1, y1, x2, y2,elements);
});
}
//_getContainedChildrens(element, x1, y1, x2, y2,elements);
return elements;
}
exports.getElementInRect = _elementsInRect;
});