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,20 +52,25 @@ function prefetcher(url) {
5252 * @param {function } options.timeoutFn - Custom timeout function
5353 */
5454export default function ( options ) {
55- options = options || { } ;
55+ options = Object . assign ( {
56+ timeout : 2e3 ,
57+ priority : false ,
58+ timeoutFn : requestIdleCallback ,
59+ el : document ,
60+ } , options ) ;
5661
57- observer . priority = ! ! options . priority ;
62+ observer . priority = options . priority ;
5863
59- ( options . timeoutFn || requestIdleCallback ) ( ( ) => {
64+ options . timeoutFn ( ( ) => {
6065 // If URLs are given, prefetch them.
6166 if ( options . urls ) {
6267 options . urls . forEach ( prefetcher ) ;
6368 } else {
6469 // If not, find all links and use IntersectionObserver.
65- Array . from ( ( options . el || document ) . querySelectorAll ( 'a' ) , link => {
70+ Array . from ( options . el . querySelectorAll ( 'a' ) , link => {
6671 observer . observe ( link ) ;
6772 toPrefetch . add ( link . href ) ;
6873 } ) ;
6974 }
70- } , { timeout : options . timeout || 2e3 } ) ;
75+ } , { timeout : options . timeout } ) ;
7176}
You can’t perform that action at this time.
0 commit comments