-
Notifications
You must be signed in to change notification settings - Fork 9
/
controllers.ts
106 lines (100 loc) · 2.91 KB
/
controllers.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Created by jsinai on 2/16/16.
*/
/// <reference path="app.ts"/>
/// <reference path="layouts.ts"/>
bsApp.controller('bsController', function ($scope, $filter, $translate, bsState, bsLayouts) {
$scope.getKeys = function (row) {
return bsLayouts.getKeys(row);
};
$scope.getKey = function (key) {
if (key.length > 1) {
return $filter('translate')(key);
} else {
return key;
}
};
$scope.getClasses = function (key) {
switch (key) {
case 'enter':
case 'accept':
return 'active btn-primary';
case 'cancel':
return 'active btn-warning';
case 'space':
return 'ui-keyboard-space btn-default';
default:
return 'btn-default';
}
};
$scope.clickMe = function (key) {
switch (key) {
case 'space':
bsState.sendKey(' ');
break;
case 'enter':
bsState.sendKey('ENTER');
$scope.upper = false;
$scope.loadLayout();
break;
case 'bksp':
bsState.sendKey('BACKSPACE');
break;
case 'alt':
$scope.alt = !$scope.alt;
$scope.loadLayout();
break;
case 'shift':
$scope.upper = !$scope.upper;
$scope.loadLayout();
break;
case 'cancel':
$scope.upper = false;
$scope.loadLayout();
bsState.hide();
break;
case 'accept':
bsState.sendKey('ENTER');
bsState.hide();
break;
default:
bsState.sendKey(key);
}
};
$scope.loadLayout = function () {
var layout = $scope.upper ? ($scope.alt ? 'alt-shift' : 'shift') : ($scope.alt ? 'alt' : 'normal');
$scope.rows = bsLayouts.getLayout($scope.lang, layout);
};
$scope.setLang = function (lang) {
$scope.lang = lang;
$translate.use($scope.lang);
$scope.loadLayout();
};
bsState.loadConfig().then(function (ret) {
$scope.config = ret.data;
$scope.langs = $scope.config.languages;
});
$scope.lang = 'en';
$scope.upper = false;
$scope.alt = false;
var portraitMode = $(window).width() < $(window).height();
var screenSize;
if (portraitMode) {
screenSize = $(window).height();
} else {
screenSize = $(window).width();
}
var textSize;
switch (screenSize) {
case 1920:
textSize = "1.6em";
break;
case 1280:
textSize = "1.2em";
break;
default:
textSize = "1em";
}
$scope.keyboardSize = {'font-size' : textSize};
$scope.setLang($scope.lang);
});