@@ -115,9 +115,9 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
115115 var decodedHeader = window . decode ( parts [ 0 ] ) ;
116116
117117 try {
118- selectDetectedAlgorithm ( JSON . parse ( decodedHeader . result ) . alg ) ;
118+ selectDetectedAlgorithm ( JSON . parse ( decodedHeader . result ) . alg ) ;
119119 } catch ( e ) {
120- console . log ( 'Invalid header decoded' ) ;
120+ console . error ( 'Invalid header decoded' ) ;
121121 }
122122
123123 var selector = $ ( '.jwt-header' ) ;
@@ -130,12 +130,10 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
130130 }
131131
132132 function selectDetectedAlgorithm ( alg ) {
133+ var $algRadio = $ ( '.algorithm input[value="' + alg + '"]' ) ;
134+ $algRadio . prop ( 'checked' , true ) ;
133135
134- var $algRadio = $ ( '.algorithm input[value="' + alg + '"]' ) ;
135- $algRadio . prop ( 'checked' , true ) ;
136-
137- fireEvent ( $algRadio . get ( 0 ) ) ;
138-
136+ fireEvent ( $algRadio . get ( 0 ) ) ;
139137 }
140138
141139 function saveToStorage ( jwt ) {
@@ -149,20 +147,19 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
149147 }
150148
151149 function refreshTokenEditor ( instance ) {
152-
153150 tokenEditor . off ( 'change' , tokenEditorOnChangeListener ) ;
154151
155152 var algorithm = getAlgorithm ( ) ;
156153 var secretElement = document . getElementsByName ( 'secret' ) [ 0 ] ;
157154 var isBase64EncodedElement = document . getElementsByName ( 'is-base64-encoded' ) [ 0 ] ;
158155
159156 var signResult = window . sign (
160- algorithm ,
161- headerEditor . getValue ( ) ,
162- payloadEditor . getValue ( ) ,
163- getKey ( algorithm , 'sign' ) ,
164- isBase64EncodedElement . checked ) ;
165-
157+ algorithm ,
158+ headerEditor . getValue ( ) ,
159+ payloadEditor . getValue ( ) ,
160+ getKey ( algorithm , 'sign' ) ,
161+ isBase64EncodedElement . checked
162+ ) ;
166163
167164 if ( signResult . error ) {
168165 tokenEditor . setValue ( '' ) ;
@@ -217,7 +214,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
217214 var isBase64EncodedElement = document . getElementsByName ( 'is-base64-encoded' ) [ 0 ] ;
218215
219216 function updateSignature ( ) {
220-
221217 var algorithm = getAlgorithm ( ) ;
222218 var signatureElement = getFirstElementByClassName ( 'js-signature' ) ;
223219 var signatureContainerElement = getFirstElementByClassName ( 'jwt-signature' ) ;
@@ -235,10 +231,11 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
235231 }
236232
237233 var result = window . verify (
238- algorithm ,
239- value ,
240- getKey ( algorithm , 'verify' ) ,
241- isBase64 ) ;
234+ algorithm ,
235+ value ,
236+ getKey ( algorithm , 'verify' ) ,
237+ isBase64
238+ ) ;
242239
243240
244241 var error = result . error ;
@@ -254,27 +251,23 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
254251 }
255252 }
256253
257- function getKey ( algorithm , action ) {
258-
259- var secretElement = $ ( 'input[name="secret"]' ) ,
260- privateKeyElement = $ ( 'textarea[name="private-key"]' ) ,
261- publicKeyElement = $ ( 'textarea[name="public-key"]' ) ;
254+ function getKey ( algorithm , action ) {
255+ var secretElement = $ ( 'input[name="secret"]' ) ;
256+ var privateKeyElement = $ ( 'textarea[name="private-key"]' ) ;
257+ var publicKeyElement = $ ( 'textarea[name="public-key"]' ) ;
262258
263- if ( algorithm === 'HS256' ) {
259+ if ( algorithm === 'HS256' ) {
264260 return secretElement . val ( ) ;
265- } else {
261+ } else {
266262 return action === 'sign' ? privateKeyElement . val ( ) : publicKeyElement . val ( ) ;
267263 }
268-
269264 }
270265
271- function getAlgorithm ( ) {
272-
266+ function getAlgorithm ( ) {
273267 return algorithmRadios . filter ( ':checked' ) . val ( ) ;
274268 }
275269
276270 function updateAlgorithm ( ) {
277-
278271 var algorithm = algorithmRadios . filter ( ':checked' ) . val ( ) ;
279272
280273 $ ( '.js-input' ) . attr ( 'data-alg' , algorithm ) ;
@@ -285,33 +278,47 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
285278 . show ( ) ;
286279
287280 if ( getTrimmedValue ( tokenEditor ) === DEFAULT_HS_TOKEN &&
288- algorithm === 'RS256' ) {
281+ algorithm === 'RS256' ) {
289282 setDefaultsForRSA ( ) ;
290283 } else if ( getTrimmedValue ( tokenEditor ) === DEFAULT_RS_TOKEN &&
291- algorithm === 'HS256' ) {
284+ algorithm === 'HS256' ) {
292285 setDefaultsForHMAC ( ) ;
293286 }
294-
295287 }
296288
297- function setDefaultsForRSA ( ) {
298-
299- tokenEditor . setValue ( DEFAULT_RS_TOKEN ) ;
289+ function setDefaultsForRSA ( ) {
290+ tokenEditor . setValue ( DEFAULT_RS_TOKEN ) ;
300291
301- $ ( '.jwt-signature textarea[name=public-key]' ) . val ( DEFAULT_PUBLIC_RSA ) ;
302- $ ( '.jwt-signature textarea[name=private-key]' ) . val ( DEFAULT_PRIVATE_RSA ) ;
292+ $ ( '.jwt-signature textarea[name=public-key]' ) . val ( DEFAULT_PUBLIC_RSA ) ;
293+ $ ( '.jwt-signature textarea[name=private-key]' ) . val ( DEFAULT_PRIVATE_RSA ) ;
303294 }
304295
305296 function setDefaultsForHMAC ( ) {
297+ tokenEditor . setValue ( DEFAULT_HS_TOKEN ) ;
298+ }
299+
300+ function validateKey ( ) {
301+ var $textarea = $ ( this ) ;
302+ var valid ;
303+
304+ if ( $textarea . prop ( 'name' ) === 'public-key' ) {
305+ valid = / - - - - - B E G I N ( P U B L I C K E Y | C E R T I F I C A T E ) - - - - - ( .| \n ) * - - - - - E N D ( P U B L I C K E Y | C E R T I F I C A T E ) - - - - - / . test ( $textarea . val ( ) ) ;
306+ } else {
307+ valid = / - - - - - B E G I N R S A P R I V A T E K E Y - - - - - ( .| \n ) * - - - - - E N D R S A P R I V A T E K E Y - - - - - / . test ( $textarea . val ( ) ) ;
308+ }
306309
307- tokenEditor . setValue ( DEFAULT_HS_TOKEN ) ;
310+ if ( valid ) {
311+ $textarea . removeClass ( 'error' ) ;
312+ } else {
313+ $textarea . addClass ( 'error' ) ;
314+ }
308315 }
309316
310317 updateAlgorithm ( ) ;
311318
312319 algorithmRadios . on ( 'change' , function ( ) {
313- updateAlgorithm ( ) ;
314- updateSignature ( ) ;
320+ updateAlgorithm ( ) ;
321+ updateSignature ( ) ;
315322 } ) ;
316323
317324 $ ( '.jwt-signature textarea' ) . on ( 'change' , updateSignature , false ) ;
@@ -322,25 +329,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
322329 secretElement . addEventListener ( 'keyup' , updateSignature , false ) ;
323330 isBase64EncodedElement . addEventListener ( 'change' , updateSignature , false ) ;
324331
325- function validateKey ( ) {
326-
327- $textarea = $ ( this ) ;
328- var valid ;
329-
330- if ( $textarea . prop ( 'name' ) === 'public-key' ) {
331- valid = / - - - - - B E G I N ( P U B L I C K E Y | C E R T I F I C A T E ) - - - - - ( .| \n ) * - - - - - E N D ( P U B L I C K E Y | C E R T I F I C A T E ) - - - - - / . test ( $textarea . val ( ) ) ;
332- } else {
333- valid = / - - - - - B E G I N R S A P R I V A T E K E Y - - - - - ( .| \n ) * - - - - - E N D R S A P R I V A T E K E Y - - - - - / . test ( $textarea . val ( ) ) ;
334- }
335-
336- if ( valid ) {
337- $textarea . removeClass ( 'error' ) ;
338- } else {
339- $textarea . addClass ( 'error' ) ;
340- }
341-
342- }
343-
344332 if ( document . location . search ) {
345333 var qs = document . location . search . slice ( 1 ) ;
346334 var d = { } ;
@@ -364,11 +352,10 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
364352 }
365353
366354 loadFromStorage ( function ( jwt ) {
367-
368355 lastRestoredToken = jwt || DEFAULT_HS_TOKEN ;
369356
370357 tokenEditor . setValue (
371- lastRestoredToken
358+ lastRestoredToken
372359 ) ;
373360 } ) ;
374361
@@ -385,26 +372,23 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
385372 } , 1000 ) ;
386373} ) . call ( this ) ;
387374
388-
389375//Inizialize bootstrap widgets
390376$ ( '[data-toggle="tooltip"]' ) . tooltip ( ) ;
391377
392378// Fetch stargazers count for each repo from GitHub's API
393379$ ( '.stars' ) . each ( function ( idx , element ) {
394-
395380 var $el = $ ( element ) ;
396381 var repo = $el . attr ( 'data-repo' ) ;
397382
398383 if ( repo ) {
399- $ . getJSON ( 'http://api.github.com/repos/' + repo , function ( repoData ) {
400-
401- var $count = $ ( '<span>' ) ;
402- $count . text ( repoData . stargazers_count ) ;
384+ $ . getJSON ( 'http://api.github.com/repos/' + repo , function ( repoData ) {
385+ var $count = $ ( '<span>' ) ;
386+ $count . text ( repoData . stargazers_count ) ;
403387
404- $el . find ( 'i' ) . after ( $count ) ;
388+ $el . find ( 'i' ) . after ( $count ) ;
405389
406- $el . show ( ) ;
407- } ) ;
390+ $el . show ( ) ;
391+ } ) ;
408392 }
409393} ) ;
410394
0 commit comments