-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
.wp-env.json export-ignore | ||
assets-lazy-loader.php export-ignore | ||
package.json export-ignore | ||
test.js export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Kunoichi\AssetsLazyLoader\Pattern; | ||
|
||
/** | ||
* Handle detector | ||
* | ||
* @package assets-lazy-loader | ||
* @property-read string[] $exclude | ||
* @property-read string[] $include | ||
*/ | ||
abstract class HandleDetector extends Singleton { | ||
|
||
/** | ||
* Add extra arguments. | ||
* | ||
* @param array $args | ||
* @return array | ||
*/ | ||
protected function parse_args( $args ) { | ||
return array_merge( [ | ||
'exclude' => [], | ||
'include' => [], | ||
], parent::parse_args( $args ) ); | ||
} | ||
|
||
/** | ||
* Check if handle is avilable. | ||
* | ||
* @param string $handle | ||
* @return bool | ||
*/ | ||
protected function is_valid_handle( $handle ) { | ||
if ( ( ! $this->in_admin ) && is_admin() ) { | ||
// If not in admin, skip. | ||
return false; | ||
} | ||
if ( ( ! $this->in_login ) && $this->is_login() ) { | ||
// If not in login, skip. | ||
return false; | ||
} | ||
if ( $this->include ) { | ||
// Allow list exists, check if it's included. | ||
return in_array( $handle, (array) $this->include, true ); | ||
} elseif ( $this->exclude ) { | ||
// Deny list exists, check if it's included. | ||
return ! in_array( $handle, (array) $this->exclude, true ); | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*! | ||
* Description | ||
*/ | ||
|
||
console.log( 'Assets Lazy Loader' ); |