File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,24 +52,20 @@ function prefetcher(url) {
5252 * @param {function } options.timeoutFn - Custom timeout function
5353 */
5454export default function ( options ) {
55- options = Object . assign ( {
56- timeout : 2e3 ,
57- timeoutFn : requestIdleCallback ,
58- el : document ,
59- } , options ) ;
55+ options = options || { } ;
6056
6157 observer . priority = ! ! options . priority ;
6258
63- options . timeoutFn ( ( ) => {
59+ ( options . timeoutFn || requestIdleCallback ) ( ( ) => {
6460 // If URLs are given, prefetch them.
6561 if ( options . urls ) {
6662 options . urls . forEach ( prefetcher ) ;
6763 } else {
6864 // If not, find all links and use IntersectionObserver.
69- Array . from ( options . el . querySelectorAll ( 'a' ) , link => {
65+ Array . from ( ( options . el || document ) . querySelectorAll ( 'a' ) , link => {
7066 observer . observe ( link ) ;
7167 toPrefetch . add ( link . href ) ;
7268 } ) ;
7369 }
74- } , { timeout : options . timeout } ) ;
70+ } , { timeout : options . timeout || 2e3 } ) ;
7571}
You can’t perform that action at this time.
0 commit comments