1 /*global areasDefinitions, onFrameClick */
4 * @module HomescreenApplication
7 * Allows to select radial menu items and start selected application by keyboard. Following keys are intecepted:
8 * * A - Previous application
9 * * D - Next application
10 * * Enter - Launch application
11 * * 1 - 7 - Launch application 1-7 from radial menu starting from 12 o'clock application in clockwise direction
17 * Define selected sector (pie, app).
18 * @property homeScreenselectedIndex
22 homeScreenselectedIndex: 1,
24 * Indicate if some sector is selected.
25 * @property sectionHighlited
29 sectionHighlited: false,
31 * Timer for reset highlited pie after predefined timer interval in timerInteval property.
38 * Define interval for unhighlight and unselect selected sector if keyboard is inactive more than defined interval.
39 * @property timerIterval
45 * Provides changing of selected sector, highlights it and unhighlight previous higlighted. Also provides setting of timer.
47 * @param direction {string} Could be 'prev', 'next' for change highigting for prev or next sector and 'null' only for unhighligting sector
49 changeIndex: function (direction) {
52 for (i = 0; i < areasDefinitions.length; i++) {
53 if (areasDefinitions[i].sectorId !== null) {
54 $('.sector' + areasDefinitions[i].sectorId).removeClass('selected');
57 if (direction !== null) {
58 if (KeyControl.sectionHighlited) {
59 clearTimeout(KeyControl.timer);
60 KeyControl.timer = setTimeout(function() { KeyControl.changeIndex(); }, KeyControl.timerIterval);
63 KeyControl.prevIndex();
66 KeyControl.nextIndex();
69 $('.sector' + KeyControl.homeScreenselectedIndex).addClass('selected');
71 KeyControl.sectionHighlited = true;
72 $('.sector' + KeyControl.homeScreenselectedIndex).addClass('selected');
73 KeyControl.timer = setTimeout(function() { KeyControl.changeIndex(); }, KeyControl.timerIterval);
76 KeyControl.sectionHighlited = false;
80 * Provides changing index of selected sector to next one in circle.
83 nextIndex: function () {
85 KeyControl.homeScreenselectedIndex++;
86 if (KeyControl.homeScreenselectedIndex > 7) {
87 KeyControl.homeScreenselectedIndex = 1;
91 * Provides changing index of selected sector to previous one in circle.
94 prevIndex: function () {
96 KeyControl.homeScreenselectedIndex--;
97 if (KeyControl.homeScreenselectedIndex < 1) {
98 KeyControl.homeScreenselectedIndex = 7;
102 * Provides start of app by confirmation of selected sector with keyboard.
105 confirmed: function () {
107 if (KeyControl.sectionHighlited) {
108 switch (KeyControl.homeScreenselectedIndex) {
110 onFrameClick(areasDefinitions[1]);
113 onFrameClick(areasDefinitions[2]);
116 onFrameClick(areasDefinitions[3]);
119 onFrameClick(areasDefinitions[4]);
122 onFrameClick(areasDefinitions[5]);
125 onFrameClick(areasDefinitions[6]);
128 onFrameClick(areasDefinitions[7]);
136 * Provides catching and sorting of keyboard events.
137 * @method $(document).keypress
138 * @param callback {function} For calling functions on specific key press.
141 $(document).keypress(function (event) {
143 switch (event.keyCode) {
145 KeyControl.changeIndex('prev'); // a
148 KeyControl.changeIndex('next'); // d
151 KeyControl.confirmed();