@@ -39,17 +39,17 @@ function prefetcher(url) {
3939}
4040
4141/**
42- * Determine if the anchor tag can be prefetched.
42+ * Determine if the anchor tag should be prefetched.
4343 * A filter can be a RegExp, Function, or Array of both.
4444 * - Function receives `node.href, node` arguments
4545 * - RegExp receives `node.href` only (the full URL)
4646 * @param {Element } node The anchor (<a>) tag.
4747 * @param {Mixed } filter The custom filter(s)
48- * @return {Boolean } If true, then it was allowed.
48+ * @return {Boolean } If true, then it should be ignored
4949 */
50- function isAllowed ( node , filter ) {
50+ function isIgnored ( node , filter ) {
5151 return Array . isArray ( filter )
52- ? filter . every ( x => isAllowed ( node , x ) )
52+ ? filter . some ( x => isIgnored ( node , x ) )
5353 : ( filter . test || filter ) ( node . href , node ) ;
5454}
5555
@@ -64,7 +64,7 @@ function isAllowed(node, filter) {
6464 * @param {Object } options.el - DOM element to prefetch in-viewport links of
6565 * @param {Boolean } options.priority - Attempt higher priority fetch (low or high)
6666 * @param {Array } options.origins - Allowed origins to prefetch (empty allows all)
67- * @param {Array|RegExp|Function } options.filter - Custom filter(s) that run after origin checks
67+ * @param {Array|RegExp|Function } options.ignores - Custom filter(s) that run after origin checks
6868 * @param {Number } options.timeout - Timeout after which prefetching will occur
6969 * @param {Function } options.timeoutFn - Custom timeout function
7070 */
@@ -79,7 +79,7 @@ export default function (options) {
7979 observer . priority = options . priority ;
8080
8181 const allowed = options . origins || [ location . hostname ] ;
82- const filter = options . filter ;
82+ const ignores = options . ignores || [ ] ;
8383
8484 options . timeoutFn ( ( ) => {
8585 // If URLs are given, prefetch them.
@@ -92,8 +92,8 @@ export default function (options) {
9292 // If the anchor matches a permitted origin
9393 // ~> A `[]` or `true` means everything is allowed
9494 if ( ! allowed . length || allowed . includes ( link . hostname ) ) {
95- // If there are any filters, they must also return true
96- if ( ! filter || isAllowed ( link , filter ) ) toPrefetch . add ( link . href ) ;
95+ // If there are any filters, the link must not match any of them
96+ isIgnored ( link , ignores ) || toPrefetch . add ( link . href ) ;
9797 }
9898 } ) ;
9999 }
0 commit comments