forked from swmitra/html-designer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrecisionResizeHandler.js
69 lines (54 loc) · 1.87 KB
/
PrecisionResizeHandler.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
/**
* @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 = null;
//handle precision resize by 1px increments
function _increaseWidth(){
layout.changeWidth(1);
}
function _decreaseWidth(){
layout.changeWidth(-1);
}
function _increaseHeight(){
layout.changeHeight(1);
}
function _decreaseHeight(){
layout.changeHeight(-1);
}
function _handlePresicisonResize(event){
var LEFT = 37,
UP = 38,
RIGHT = 39,
DOWN = 40;
if(layout && $("#html-design-template").is(':visible')){
if(event.altKey === true
&& (event.which === LEFT || event.which === RIGHT || event.which === UP || event.which === DOWN)){
if($("input:focus").length === 0){
layout.open();
switch(event.which){
case LEFT: _decreaseWidth();break;
case RIGHT: _increaseWidth();break;
case UP: _decreaseHeight();break;
case DOWN: _increaseHeight();break;
}
layout.close();
layout.refresh();
}
}
}
}
$(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',_handlePresicisonResize);
});