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
/
PrecisionPositionHandler.js
72 lines (56 loc) · 2 KB
/
PrecisionPositionHandler.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
/**
* @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 layout;
//handle precision movement by 1px increments/decrements
function _moveLeft(){
layout.changeX(1);
}
function _moveRight(){
layout.changeX(-1);
}
function _moveUp(){
layout.changeY(1);
}
function _moveDown(){
layout.changeY(-1);
}
function _handlePresicisonMovement(event){
var LEFT = 37,
UP = 38,
RIGHT = 39,
DOWN = 40;
if(layout && $("#html-design-template").is(':visible')){
if(event.shiftKey === false && event.altKey === false && event.ctrlKey === false
&& (event.which === LEFT || event.which === RIGHT || event.which === UP || event.which === DOWN)){
if($("input:focus").length === 0 && $("textarea:focus").length === 0){
layout.open();
switch(event.which){
case LEFT: _moveLeft();break;
case RIGHT: _moveRight();break;
case UP: _moveUp();break;
case DOWN: _moveDown();break;
}
layout.close();
layout.refresh();
event.preventDefault();
event.stopPropagation();
}
}
}
}
$(document).on("layout.decision","#html-design-editor", function(event,layoutObj){
layout = layoutObj;
});
$(document).on("grouplayout.decision","#html-design-editor", function(event,layoutObj){
layout = layoutObj;
});
$(document).on('deselect.all',"#html-design-editor",function(){
layout = null;
});
$(window).on('keydown',_handlePresicisonMovement);
});