diff --git a/class-RegisterJS.php b/class-RegisterJS.php
index 7fefb30..50360d5 100644
--- a/class-RegisterJS.php
+++ b/class-RegisterJS.php
@@ -1,198 +1,212 @@
.
/**
* 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"
+ * This will not automatically enqueue it (normally).
+ *
+ * @param string $name Script name, like: "jquery" (or just true for whatever, to enqueue it)
* @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 ) {
+
+ // assume the default position
+ if( !$position ) {
$position = self::$DEFAULT;
}
- $this->js[ $uid ] = new JS( $uid, $url, $position, $dependencies );
+
+ // create the object
+ $js = new JS( $uid, $url, $position, $dependencies );
+
+ // if the UID is just true, automatically enqueue
+ if( $uid === true ) {
+ $js->enqueue = true;
+ }
+
+ // append
+ $this->js[ $uid ] = $js;
}
/**
* 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 "";
}
}
}