forked from swmitra/html-designer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionUtility.js
More file actions
43 lines (35 loc) · 1.39 KB
/
SelectionUtility.js
File metadata and controls
43 lines (35 loc) · 1.39 KB
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
/**
* @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);
}
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(element, x1, y1, x2, y2) {
var elements = [];
_getContainedChildrens(element, x1, y1, x2, y2,elements);
return elements;
}
exports.getElementInRect = _elementsInRect;
});