@@ -100,7 +100,12 @@ var Tabs = {
100100 console . warn ( 'plotly.js reloaded at ' + reloadTime ) ;
101101 reloaded . textContent = 'last reload at ' + reloadTime ;
102102
103- Tabs . onReload ( ) ;
103+ var interval = setInterval ( function ( ) {
104+ if ( window . Plotly ) {
105+ clearInterval ( interval ) ;
106+ Tabs . onReload ( ) ;
107+ }
108+ } , 100 ) ;
104109 }
105110} ;
106111
@@ -129,7 +134,24 @@ var searchBar = document.getElementById('mocks-search');
129134var mocksList = document . getElementById ( 'mocks-list' ) ;
130135var plotArea = document . getElementById ( 'plots' ) ;
131136
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 ) {
133155
134156 // Clear results.
135157 while ( mocksList . firstChild ) {
@@ -157,4 +179,4 @@ searchBar.addEventListener('keyup', function(e) {
157179 var plotAreaWidth = Math . floor ( window . innerWidth - listWidth ) ;
158180 plotArea . setAttribute ( 'style' , 'width: ' + plotAreaWidth + 'px;' ) ;
159181 } ) ;
160- } ) ;
182+ }
0 commit comments