@@ -100,7 +100,12 @@ var Tabs = {
100
100
console . warn ( 'plotly.js reloaded at ' + reloadTime ) ;
101
101
reloaded . textContent = 'last reload at ' + reloadTime ;
102
102
103
- Tabs . onReload ( ) ;
103
+ var interval = setInterval ( function ( ) {
104
+ if ( window . Plotly ) {
105
+ clearInterval ( interval ) ;
106
+ Tabs . onReload ( ) ;
107
+ }
108
+ } , 100 ) ;
104
109
}
105
110
} ;
106
111
@@ -129,7 +134,24 @@ var searchBar = document.getElementById('mocks-search');
129
134
var mocksList = document . getElementById ( 'mocks-list' ) ;
130
135
var plotArea = document . getElementById ( 'plots' ) ;
131
136
132
- searchBar . addEventListener ( 'keyup' , function ( e ) {
137
+ searchBar . addEventListener ( 'keyup' , debounce ( searchMocks , 250 ) ) ;
138
+
139
+ function debounce ( func , wait , immediate ) {
140
+ var timeout ;
141
+ return function ( ) {
142
+ var context = this , args = arguments ;
143
+ var later = function ( ) {
144
+ timeout = null ;
145
+ if ( ! immediate ) func . apply ( context , args ) ;
146
+ } ;
147
+ var callNow = immediate && ! timeout ;
148
+ clearTimeout ( timeout ) ;
149
+ timeout = setTimeout ( later , wait ) ;
150
+ if ( callNow ) func . apply ( context , args ) ;
151
+ } ;
152
+ }
153
+
154
+ function searchMocks ( e ) {
133
155
134
156
// Clear results.
135
157
while ( mocksList . firstChild ) {
@@ -157,4 +179,4 @@ searchBar.addEventListener('keyup', function(e) {
157
179
var plotAreaWidth = Math . floor ( window . innerWidth - listWidth ) ;
158
180
plotArea . setAttribute ( 'style' , 'width: ' + plotAreaWidth + 'px;' ) ;
159
181
} ) ;
160
- } ) ;
182
+ }
0 commit comments