1
1
import windowWatcherUtil from "../utils/window_watchers" ;
2
- import { i18n } from "../localization" ;
3
2
4
3
const css_dark = [
5
4
'/css/dark-theme.css' ,
@@ -43,10 +42,6 @@ let gimbalElems;
43
42
let sliderElems ;
44
43
let enableTX = false ;
45
44
46
- // NOTE: import should be enough right?
47
- // This is a hack to get the i18n var of the parent, but the localizePage not works
48
- // const i18n = opener.i18n;
49
-
50
45
const watchers = {
51
46
darkTheme : ( val ) => {
52
47
if ( val ) {
@@ -57,17 +52,6 @@ const watchers = {
57
52
} ,
58
53
} ;
59
54
60
- $ ( document ) . ready ( function ( ) {
61
- $ ( '[i18n]:not(.i18n-replaced)' ) . each ( function ( ) {
62
- const element = $ ( this ) ;
63
-
64
- element . html ( i18n . getMessage ( element . attr ( 'i18n' ) ) ) ;
65
- element . addClass ( 'i18n-replaced' ) ;
66
- } ) ;
67
-
68
- windowWatcherUtil . bindWatchers ( window , watchers ) ;
69
- } ) ;
70
-
71
55
function transmitChannels ( ) {
72
56
const channelValues = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
73
57
@@ -107,10 +91,10 @@ function updateControlPositions() {
107
91
gimbalSize = $ ( gimbalElem ) . width ( ) ,
108
92
stickElem = $ ( ".control-stick" , gimbalElem ) ;
109
93
110
- if ( gimbal [ 0 ] == stickName ) {
94
+ if ( gimbal [ 0 ] === stickName ) {
111
95
stickElem . css ( 'top' , `${ ( 1.0 - channelValueToStickPortion ( stickValue ) ) * gimbalSize } px` ) ;
112
96
break ;
113
- } else if ( gimbal [ 1 ] == stickName ) {
97
+ } else if ( gimbal [ 1 ] === stickName ) {
114
98
stickElem . css ( 'left' , `${ channelValueToStickPortion ( stickValue ) * gimbalSize } px` ) ;
115
99
break ;
116
100
}
@@ -129,6 +113,15 @@ function handleGimbalMouseDrag(e) {
129
113
updateControlPositions ( ) ;
130
114
}
131
115
116
+ function localizePage ( ) {
117
+ $ ( '[i18n]:not(.i18n-replaced)' ) . each ( function ( ) {
118
+ const element = $ ( this ) ;
119
+
120
+ element . html ( i18n . getMessage ( element . attr ( 'i18n' ) ) ) ;
121
+ element . addClass ( 'i18n-replaced' ) ;
122
+ } ) ;
123
+ }
124
+
132
125
function localizeAxisNames ( ) {
133
126
for ( const gimbalIndex in gimbals ) {
134
127
const gimbal = gimbalElems . get ( gimbalIndex ) ;
@@ -150,65 +143,70 @@ function applyNormalTheme() {
150
143
css_dark . forEach ( ( el ) => $ ( `link[href="${ el } "]` ) . prop ( 'disabled' , true ) ) ;
151
144
}
152
145
153
- $ ( document ) . ready ( function ( ) {
154
- $ ( ".button-enable .btn" ) . click ( function ( ) {
155
- const shrinkHeight = $ ( ".warning" ) . height ( ) ;
146
+ $ ( ".button-enable .btn" ) . on ( "click" , function ( ) {
147
+ const shrinkHeight = $ ( ".warning" ) . height ( ) ;
156
148
157
- $ ( ".warning" ) . slideUp ( "short" , function ( ) {
158
- chrome . app . window . current ( ) . innerBounds . minHeight -= shrinkHeight ;
159
- chrome . app . window . current ( ) . innerBounds . height -= shrinkHeight ;
160
- chrome . app . window . current ( ) . innerBounds . maxHeight -= shrinkHeight ;
161
- } ) ;
162
-
163
- enableTX = true ;
149
+ $ ( ".warning" ) . slideUp ( "short" , function ( ) {
150
+ chrome . app . window . current ( ) . innerBounds . minHeight -= shrinkHeight ;
151
+ chrome . app . window . current ( ) . innerBounds . height -= shrinkHeight ;
152
+ chrome . app . window . current ( ) . innerBounds . maxHeight -= shrinkHeight ;
164
153
} ) ;
165
154
166
- gimbalElems = $ ( ".control-gimbal" ) ;
167
- sliderElems = $ ( ".control-slider" ) ;
155
+ enableTX = true ;
156
+ } ) ;
168
157
169
- gimbalElems . each ( function ( gimbalIndex ) {
170
- $ ( this ) . on ( 'mousedown' , { gimbalIndex : gimbalIndex } , function ( e ) {
171
- if ( e . which == 1 ) { // Only move sticks on left mouse button
172
- handleGimbalMouseDrag ( e ) ;
158
+ gimbalElems = $ ( ".control-gimbal" ) ;
159
+ sliderElems = $ ( ".control-slider" ) ;
173
160
174
- $ ( window ) . on ( 'mousemove' , { gimbalIndex : gimbalIndex } , handleGimbalMouseDrag ) ;
175
- }
176
- } ) ;
161
+ gimbalElems . each ( function ( gimbalIndex ) {
162
+ $ ( this ) . on ( 'mousedown' , { gimbalIndex : gimbalIndex } , function ( e ) {
163
+ if ( e . button === 0 ) { // Only move sticks on left mouse button
164
+ handleGimbalMouseDrag ( e ) ;
165
+
166
+ $ ( window ) . on ( 'mousemove' , { gimbalIndex : gimbalIndex } , handleGimbalMouseDrag ) ;
167
+ }
177
168
} ) ;
169
+ } ) ;
178
170
179
- $ ( ".slider" , sliderElems ) . each ( function ( sliderIndex ) {
180
- const initialValue = stickValues [ `Aux${ sliderIndex + 1 } ` ] ;
171
+ $ ( ".slider" , sliderElems ) . each ( function ( sliderIndex ) {
172
+ const initialValue = stickValues [ `Aux${ sliderIndex + 1 } ` ] ;
181
173
182
- $ ( this )
183
- . noUiSlider ( {
184
- start : initialValue ,
185
- range : {
186
- min : CHANNEL_MIN_VALUE ,
187
- max : CHANNEL_MAX_VALUE ,
188
- } ,
189
- } ) . on ( 'slide change set' , function ( e , value ) {
190
- value = Math . round ( parseFloat ( value ) ) ;
174
+ $ ( this )
175
+ . noUiSlider ( {
176
+ start : initialValue ,
177
+ range : {
178
+ min : CHANNEL_MIN_VALUE ,
179
+ max : CHANNEL_MAX_VALUE ,
180
+ } ,
181
+ } ) . on ( 'slide change set' , function ( e , value ) {
182
+ value = Math . round ( parseFloat ( value ) ) ;
191
183
192
- stickValues [ `Aux${ ( sliderIndex + 1 ) } ` ] = value ;
184
+ stickValues [ `Aux${ ( sliderIndex + 1 ) } ` ] = value ;
193
185
194
- $ ( ".tooltip" , this ) . text ( value ) ;
195
- } ) ;
186
+ $ ( ".tooltip" , this ) . text ( value ) ;
187
+ } ) ;
196
188
197
- $ ( this ) . append ( '<div class="tooltip"></div>' ) ;
189
+ $ ( this ) . append ( '<div class="tooltip"></div>' ) ;
198
190
199
- $ ( ".tooltip" , this ) . text ( initialValue ) ;
200
- } ) ;
191
+ $ ( ".tooltip" , this ) . text ( initialValue ) ;
192
+ } ) ;
201
193
202
- /*
203
- * Mouseup handler needs to be bound to the window in order to receive mouseup if mouse leaves window.
204
- */
205
- $ ( window ) . mouseup ( function ( e ) {
206
- $ ( this ) . off ( 'mousemove' , handleGimbalMouseDrag ) ;
207
- } ) ;
194
+ /*
195
+ * Mouseup handler needs to be bound to the window in order to receive mouseup if mouse leaves window.
196
+ */
197
+ $ ( window ) . on ( "mouseup" , function ( e ) {
198
+ $ ( this ) . off ( 'mousemove' , handleGimbalMouseDrag ) ;
199
+ } ) ;
208
200
209
- localizeAxisNames ( ) ;
201
+ windowWatcherUtil . bindWatchers ( window , watchers ) ;
210
202
211
- updateControlPositions ( ) ;
203
+ // This is a hack to get the i18n var of the parent, but the i18n.localizePage not works
204
+ // It seems than when node opens a new window, the module "context" is different, so the i18n var is not initialized
205
+ const i18n = opener . i18n ;
212
206
213
- setInterval ( transmitChannels , 50 ) ;
214
- } ) ;
207
+ localizePage ( ) ;
208
+ localizeAxisNames ( ) ;
209
+
210
+ updateControlPositions ( ) ;
211
+
212
+ setInterval ( transmitChannels , 50 ) ;
0 commit comments