diff --git a/class-RegisterCSS.php b/class-RegisterCSS.php
index e3285ef..a81c5a1 100644
--- a/class-RegisterCSS.php
+++ b/class-RegisterCSS.php
@@ -1,96 +1,96 @@
.
class RegisterCSS {
/**
* Stylesheets
*/
private $css = [];
/**
* Get the singleton instance
*
* @return self
*/
public static function instance() {
static $me = false;
if( ! $me ) {
$me = new self();
}
return $me;
}
/**
- * Register a new style name
+ * Register a new stylesheet
*
* @param string $name CSS name, like: "jquery-ui".
* @param string $url CSS url, like "http://example.org/styles/jquery-ui.css".
*/
public function register( $uid, $url ) {
$this->css[ $uid ] = new CSS( $url );
}
/**
- * Enqueue a previously registered CSS name
+ * Enqueue a previously registered stylesheet
*
* @param string $uid CSS name
* @param boolean $report_errors In case of errors, report the error?
*/
public function enqueue( $uid, $report_errors = true ) {
if( empty( $this->css[ $uid ] ) ) {
if( $report_errors ) {
error( "unknown stylesheet $uid" );
}
} else {
$this->css[ $uid ]->enqueue = true;
}
}
/**
* Enqueue all registered style that are not registered as private use
*/
public function printAll( $force = false ) {
foreach( $this->css as $uid => $css ) {
if( $css->enqueue && !$css->enqueued ) {
self::link( $css->url, $uid );
$this->css[ $uid ]->enqueued = true;
}
}
}
/**
* Print the CSS link tag
*/
public static function link( $url, $uid ) {
$url = site_page( $url );
if( CACHE_BUSTER ) {
$url .= false === strpos( $url, '?' ) ? '?' : '&';
$url .= CACHE_BUSTER;
}
echo "\n\t";
}
}
class CSS {
public $url;
public $enqueue = false;
public $enqueued = false;
public function __construct( $url ) {
$this->url = $url;
}
}
diff --git a/class-RegisterJS.php b/class-RegisterJS.php
index 0747fb5..7fefb30 100644
--- a/class-RegisterJS.php
+++ b/class-RegisterJS.php
@@ -1,190 +1,198 @@
.
/**
* Register and enqueue JS libraries
*/
class RegisterJS {
/**
* Default position
*/
public static $DEFAULT = 'header';
/**
* Script names
*/
private $js = [];
/**
* Get the singleton instance
*
* @return self
*/
public static function instance() {
static $me = false;
if( ! $me ) {
$me = new self();
}
return $me;
}
/**
* Register a new script name
*
* @param string $name Script name, like: "jquery"
* @param mixed $url Script url, like "http://example.org/lib/jquery.js"
* @param string $position header|footer
* @param array $dependencies Dependent script names
*/
public function register( $uid, $url, $position = null, $dependencies = [] ) {
if( ! $position ) {
$position = self::$DEFAULT;
}
$this->js[ $uid ] = new JS( $uid, $url, $position, $dependencies );
}
/**
* Register an inline script
*
* @param string $uid Script name, like: "jquery"
* @param array $data Inline JavaScript content (without ";
if( DEBUG ) {
echo "";
}
}
}
/**
* Print the normal JS inclusion
*
* @param $glue string
*/
public function printNormal( $glue ) {
$url = $this->url;
$url = site_page( $url );
if( CACHE_BUSTER ) {
$url .= false === strpos( $url, '?' ) ? '?' : '&';
$url .= CACHE_BUSTER;
}
echo "$glue";
if( DEBUG ) {
echo "";
}
}
}