@@ -132,10 +132,12 @@ $(function(){
132
132
submit . removeAttr ( 'disabled' ) ;
133
133
reset . show ( ) ;
134
134
headers = parseHeaders ( headers ) ;
135
+ resource . data ( "jsondata" , "" ) ;
135
136
136
137
if ( headers [ 'content-type' ] . indexOf ( 'application/json' ) > - 1 || headers [ 'content-type' ] . indexOf ( 'text/json' ) > - 1 || headers [ 'content-type' ] . indexOf ( 'application/vnd.api+json' ) > - 1 ) {
137
138
//indentation!
138
139
if ( body . length ) {
140
+ resource . data ( "jsondata" , JSON . parse ( body ) ) ;
139
141
body = JSON . stringify ( JSON . parse ( body ) , null , 3 ) ;
140
142
// only do syntax highlighting if hljs is defined
141
143
if ( typeof hljs === 'undefined' ) {
@@ -166,13 +168,30 @@ $(function(){
166
168
headerRow . append ( '<div class="row"><div class="col-md-5 headerName">' + sortable [ h ] + ':</div><div class="col-md-7 headerVal">' + headers [ sortable [ h ] ] + '</div></div>' ) ;
167
169
}
168
170
169
- response . find ( '.responseTime' ) . html ( 'Request took ' + timeSpent + 'ms' ) ;
171
+ // only display dump button if jQuery dump is available
172
+ var renderBtn = "" ;
173
+ if ( typeof $ . dump === "undefined" ) {
174
+ /* nothing */
175
+ } else if ( resource . data ( "jsondata" ) ) {
176
+ renderBtn = "<span class=\"dumpBtn label label-default\" style=\"cursor:pointer;\">CLICK TO DUMP</span> " ;
177
+ }
178
+
179
+ response . find ( '.responseTime' ) . html ( renderBtn + 'Request took ' + timeSpent + 'ms' ) ;
170
180
response . find ( '.responseStatus' ) . html ( status ) ;
171
181
response . find ( '.responseBody' ) . html ( body ) ;
172
182
} ) ;
173
183
174
184
} ) ;
175
185
186
+ $ ( "body" ) . on ( "click" , ".dumpBtn" , function ( e ) {
187
+ var data = $ ( this ) . closest ( ".resource" ) . data ( "jsondata" ) || 0 ;
188
+ if ( data ) {
189
+ $ . dump ( data , false , true , true ) ;
190
+ } else {
191
+ alert ( "Unable to dump API response" ) ;
192
+ }
193
+ } ) ;
194
+
176
195
$ ( ".resetRequest" ) . click ( function ( ) {
177
196
var reset = $ ( this )
178
197
, resource = reset . closest ( '.resource' )
0 commit comments