frontend-picker.min.js
2 years ago
index.php
12 years ago
public.js
11 years ago
ready-queue.js
4 years ago
ready-queue.min.js
4 years ago
ready.js
4 years ago
ready.min.js
4 years ago
ready.js
27 lines
| 1 | /** |
| 2 | * Wait for the page to be ready before firing JS. |
| 3 | * |
| 4 | * @param {function} callback - A callable function to be executed. |
| 5 | * @param {string} [requestedState=complete] - document.readyState to wait for. Defaults to 'complete', can be 'interactive'. |
| 6 | */ |
| 7 | window.advanced_ads_ready = function ( callback, requestedState ) { |
| 8 | requestedState = requestedState || 'complete'; |
| 9 | var checkState = function ( state ) { |
| 10 | return requestedState === 'interactive' ? state !== 'loading' : state === 'complete'; |
| 11 | }; |
| 12 | |
| 13 | // If we have reached the correct state, fire the callback. |
| 14 | if ( checkState( document.readyState ) ) { |
| 15 | callback(); |
| 16 | return; |
| 17 | } |
| 18 | // We are not yet in the correct state, attach an event handler, only fire once if the requested state is 'interactive'. |
| 19 | document.addEventListener( 'readystatechange', function ( event ) { |
| 20 | if ( checkState( event.target.readyState ) ) { |
| 21 | callback(); |
| 22 | } |
| 23 | }, {once: requestedState === 'interactive'} ); |
| 24 | }; |
| 25 | |
| 26 | window.advanced_ads_ready_queue = window.advanced_ads_ready_queue || []; |
| 27 |