@@ -145,26 +145,35 @@ $(document).on('ready turbolinks:load', function () {
145145 } ) ;
146146
147147 // Highlight
148- $ ( 'pre.highlight code' ) . on ( 'dblclick' , function ( ) {
149- let code = $ ( this ) ;
148+ $ ( 'pre.highlight code' )
149+ . on ( 'click' , function ( ) {
150+ let code = $ ( this ) ;
150151
151- if ( code . closest ( 'tr' ) . hasClass ( "hightlight" ) ) {
152- code .
153- removeClass ( )
154- . html ( code . data ( 'raw' ) )
155- . closest ( 'tr' )
156- . removeClass ( "hightlight" )
157- } else {
158- code . data ( 'raw' , code . html ( ) ) ;
152+ if ( ! code . closest ( 'tr' ) . hasClass ( "hightlight" ) ) {
153+ code . data ( 'raw' , code . html ( ) ) ;
159154
160- try {
161- let json = JSON . parse ( code . html ( ) ) ;
162- code . html ( JSON . stringify ( json , null , 2 ) ) ;
163- } catch ( e ) { }
155+ try {
156+ let json = JSON . parse ( code . html ( ) ) ;
157+ code . html ( JSON . stringify ( json , null , 2 ) ) ;
158+ } catch ( e ) { }
164159
165- hljs . highlightBlock ( code [ 0 ] ) ;
160+ hljs . highlightBlock ( code [ 0 ] ) ;
166161
167- code . closest ( 'tr' ) . addClass ( "hightlight" ) ;
168- }
169- } ) ;
162+ code . closest ( 'tr' ) . addClass ( "hightlight" ) ;
163+ code . closest ( 'td' ) . find ( 'button.close' ) . toggleClass ( 'd-none' ) ;
164+ }
165+ } )
166+ . closest ( 'td' )
167+ . find ( 'button.close' )
168+ . on ( 'click' , function ( ) {
169+ $ ( this ) . toggleClass ( 'd-none' ) ;
170+
171+ let code = $ ( this ) . parent ( ) . find ( 'code' ) ;
172+ $ ( this ) . parent ( ) . find ( 'code' )
173+ . removeClass ( )
174+ . html ( code . data ( 'raw' ) )
175+ . closest ( 'tr' )
176+ . removeClass ( "hightlight" )
177+ } )
178+ ;
170179} ) ;
0 commit comments