1
1
// ****************************************************************
2
- // * EasyPI v1.3
2
+ // * EasyPI v1.3.3
3
3
// * Author: BarRaider
4
4
// *
5
5
// * JS library to simplify the communication between the
6
6
// * Stream Deck's Property Inspector and the plugin.
7
7
// *
8
8
// * Project page: https://github.com/BarRaider/streamdeck-easypi
9
9
// * Support: http://discord.barraider.com
10
+ // *
11
+ // * Initially forked from Elgato's common.js file
10
12
// ****************************************************************
11
13
12
14
var websocket = null ,
@@ -35,6 +37,7 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo,
35
37
document . dispatchEvent ( event ) ;
36
38
37
39
loadConfiguration ( actionInfo . payload . settings ) ;
40
+ initPropertyInspector ( ) ;
38
41
}
39
42
40
43
function websocketOnOpen ( ) {
@@ -52,16 +55,12 @@ function websocketOnMessage(evt) {
52
55
// Received message from Stream Deck
53
56
var jsonObj = JSON . parse ( evt . data ) ;
54
57
55
- if ( jsonObj . event === 'sendToPropertyInspector' ) {
56
- var payload = jsonObj . payload ;
57
- loadConfiguration ( payload ) ;
58
- }
59
- else if ( jsonObj . event === 'didReceiveSettings' ) {
58
+ if ( jsonObj . event === 'didReceiveSettings' ) {
60
59
var payload = jsonObj . payload ;
61
60
loadConfiguration ( payload . settings ) ;
62
61
}
63
62
else {
64
- console . log ( "Unhandled websocketOnMessage: " + jsonObj . event ) ;
63
+ console . log ( "Ignored websocketOnMessage: " + jsonObj . event ) ;
65
64
}
66
65
}
67
66
@@ -216,8 +215,31 @@ window.addEventListener('beforeunload', function (e) {
216
215
// Don't set a returnValue to the event, otherwise Chromium with throw an error.
217
216
} ) ;
218
217
218
+ function prepareDOMElements ( baseElement ) {
219
+ baseElement = baseElement || document ;
220
+
221
+ /**
222
+ * You could add a 'label' to a textares, e.g. to show the number of charactes already typed
223
+ * or contained in the textarea. This helper updates this label for you.
224
+ */
225
+ baseElement . querySelectorAll ( 'textarea' ) . forEach ( ( e ) => {
226
+ const maxl = e . getAttribute ( 'maxlength' ) ;
227
+ e . targets = baseElement . querySelectorAll ( `[for='${ e . id } ']` ) ;
228
+ if ( e . targets . length ) {
229
+ let fn = ( ) => {
230
+ for ( let x of e . targets ) {
231
+ x . textContent = maxl ? `${ e . value . length } /${ maxl } ` : `${ e . value . length } ` ;
232
+ }
233
+ } ;
234
+ fn ( ) ;
235
+ e . onkeyup = fn ;
236
+ }
237
+ } ) ;
238
+ }
239
+
219
240
function initPropertyInspector ( ) {
220
241
// Place to add functions
242
+ prepareDOMElements ( document ) ;
221
243
}
222
244
223
245
@@ -296,4 +318,4 @@ function fadeColor(col, amt) {
296
318
const g = min ( 255 , max ( ( num & 0x0000FF ) + amt , 0 ) ) ;
297
319
const b = min ( 255 , max ( ( ( num >> 8 ) & 0x00FF ) + amt , 0 ) ) ;
298
320
return '#' + ( g | ( b << 8 ) | ( r << 16 ) ) . toString ( 16 ) . padStart ( 6 , 0 ) ;
299
- }
321
+ }
0 commit comments