Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/marionette/App.50-keyboard-shortcuts.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:493bcb69166c |
---|---|
1 "use strict"; | |
2 | |
3 App.addInitializer(function(options){ | |
4 var _this = this; | |
5 | |
6 /* ========================================================================= | |
7 * Global key shortcuts | |
8 */ | |
9 var $document = $(document); | |
10 | |
11 var aPopupIsOpen = function() { | |
12 return App.helpIsShowing(); | |
13 }; | |
14 var askToClosePopups = function() { | |
15 }; | |
16 | |
17 $document.bind("keydown", "esc", function(event) { | |
18 if (App.helpIsShowing()) { | |
19 App.hideHelp(); | |
20 } | |
21 }); | |
22 $document.bind("keydown", "h", function(event) { | |
23 if (App.helpIsShowing()) { | |
24 App.hideHelp(); | |
25 } else { | |
26 App.showHelp(); | |
27 } | |
28 }); | |
29 $document.bind("keydown", "f", function(event) { | |
30 if (aPopupIsOpen()) { | |
31 return false; | |
32 } | |
33 var state = App.context.get("state"); | |
34 state.set("musicRecordingsGridIsShown", !state.get("musicRecordingsGridIsShown")); | |
35 }); | |
36 | |
37 $document.bind("keydown", App.keyboardMappings.ctrl + "+z", function(event) { | |
38 if (aPopupIsOpen()) { | |
39 askToClosePopups(); | |
40 return false; | |
41 } | |
42 App.undo(); | |
43 }); | |
44 | |
45 $document.bind("keydown", App.keyboardMappings.ctrlShift + "+z", function(event) { | |
46 if (aPopupIsOpen()) { | |
47 askToClosePopups(); | |
48 return false; | |
49 } | |
50 App.redo(); | |
51 }); | |
52 | |
53 var moveConfig = function(dimension, offset) { | |
54 var state = App.context.get("state"); | |
55 var configGrid = state.get(state.get("musicRecordingsGridIsShown") ? "musicRecordingGrid" : "musicCollectionGrid"); | |
56 var configs = null; | |
57 if (dimension == "entity") { | |
58 configs = configGrid.get("entityConfigs"); | |
59 var selectedConfig = configGrid.getSelectedEntityConfig(); | |
60 if (selectedConfig) { | |
61 var configToInsertBefore; | |
62 if (offset == 1) { | |
63 configToInsertBefore = configGrid.getNextEntityNeighbour(selectedConfig); | |
64 if (configToInsertBefore) { | |
65 configToInsertBefore = configGrid.getNextEntityNeighbour(configToInsertBefore); | |
66 } | |
67 } else { | |
68 configToInsertBefore = configGrid.getPrevEntityNeighbour(selectedConfig); | |
69 if (!configToInsertBefore) { | |
70 return; | |
71 } | |
72 } | |
73 configGrid.relocateEntityConfig(selectedConfig, configToInsertBefore ? configToInsertBefore : null); | |
74 } | |
75 } else { | |
76 configs = configGrid.get("viewConfigs"); | |
77 var selectedConfig = configGrid.getSelectedViewConfig(); | |
78 if (selectedConfig) { | |
79 var configToInsertBefore; | |
80 if (offset == 1) { | |
81 configToInsertBefore = configGrid.getNextViewNeighbour(selectedConfig); | |
82 if (configToInsertBefore) { | |
83 configToInsertBefore = configGrid.getNextViewNeighbour(configToInsertBefore); | |
84 } | |
85 } else { | |
86 configToInsertBefore = configGrid.getPrevViewNeighbour(selectedConfig); | |
87 if (!configToInsertBefore) { | |
88 return; | |
89 } | |
90 } | |
91 configGrid.relocateViewConfig(selectedConfig, configToInsertBefore ? configToInsertBefore : null); | |
92 } | |
93 } | |
94 }; | |
95 | |
96 $document.bind("keydown", "alt+left", function(event) { | |
97 if (aPopupIsOpen()) { | |
98 askToClosePopups(); | |
99 return false; | |
100 } | |
101 moveConfig("entity", -1); | |
102 event.preventDefault(); | |
103 return false; | |
104 }); | |
105 | |
106 $document.bind("keydown", "alt+right", function(event) { | |
107 if (aPopupIsOpen()) { | |
108 askToClosePopups(); | |
109 return false; | |
110 } | |
111 moveConfig("entity", 1); | |
112 event.preventDefault(); | |
113 return false; | |
114 }); | |
115 | |
116 $document.bind("keydown", "alt+up", function(event) { | |
117 if (aPopupIsOpen()) { | |
118 askToClosePopups(); | |
119 return false; | |
120 } | |
121 moveConfig("view", -1); | |
122 event.preventDefault(); | |
123 return false; | |
124 }); | |
125 $document.bind("keydown", "alt+down", function(event) { | |
126 if (aPopupIsOpen()) { | |
127 askToClosePopups(); | |
128 return false; | |
129 } | |
130 moveConfig("view", 1); | |
131 event.preventDefault(); | |
132 return false; | |
133 }); | |
134 | |
135 }); |