[geeklog-hg] geeklog: Script Libraries can now be loaded in the header. A pri...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Jul 22 21:37:27 EDT 2013
changeset 9227:d1f86bebc8a0
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/d1f86bebc8a0
user: Tom <websitemaster at cogeco.net>
date: Mon Jul 22 21:36:27 2013 -0400
description:
Script Libraries can now be loaded in the header. A priority for loading can be set for Javascript Files and CSS Files (feature request #0001459)
diffstat:
public_html/layout/denim/functions.php | 15 ++-
public_html/layout/modern_curve/functions.php | 30 +++-
public_html/layout/professional/functions.php | 5 +-
public_html/layout/professional_css/functions.php | 18 ++-
public_html/lib-common.php | 22 ++-
system/classes/scripts.class.php | 127 +++++++++++++++------
6 files changed, 157 insertions(+), 60 deletions(-)
diffs (truncated from 436 to 300 lines):
diff -r c3e050a577d6 -r d1f86bebc8a0 public_html/layout/denim/functions.php
--- a/public_html/layout/denim/functions.php Mon Jul 22 22:11:56 2013 +0900
+++ b/public_html/layout/denim/functions.php Mon Jul 22 21:36:27 2013 -0400
@@ -71,7 +71,12 @@
*/
function theme_js_libs_denim()
{
- return array('jquery');
+ return array(
+ array(
+ 'library' => 'jquery',
+ 'footer' => true // Not requred, default = true
+ )
+ );
}
/**
@@ -82,8 +87,12 @@
global $_CONF;
return array(
- '/layout/' . $_CONF['theme'] . '/javascript/script.js'
- );
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/script.js',
+ 'footer' => true, // Not requred, default = true
+ 'priority' => 100 // Not requred, default = 100
+ )
+ );
}
/**
diff -r c3e050a577d6 -r d1f86bebc8a0 public_html/layout/modern_curve/functions.php
--- a/public_html/layout/modern_curve/functions.php Mon Jul 22 22:11:56 2013 +0900
+++ b/public_html/layout/modern_curve/functions.php Mon Jul 22 21:36:27 2013 -0400
@@ -57,10 +57,14 @@
function theme_css_modern_curve()
{
global $_CONF, $LANG_DIRECTION;
+
return array(
- array(
- 'file' => '/layout/' . $_CONF['theme'] . '/style.css.php?dir=' . $LANG_DIRECTION
- )
+ array(
+ 'name' => 'theme', // Not required but if set to theme then will always be loaded first
+ 'file' => '/layout/' . $_CONF['theme'] . '/style.css.php?dir=' . $LANG_DIRECTION,
+ 'attributes' => array('media' => 'all'), // Not requred
+ 'priority' => 100 // Not requred, default = 100
+ )
);
}
@@ -70,7 +74,10 @@
function theme_js_libs_modern_curve()
{
return array(
- 'jquery'
+ array(
+ 'library' => 'jquery',
+ 'footer' => true // Not requred, default = true
+ )
);
}
@@ -80,10 +87,19 @@
function theme_js_files_modern_curve()
{
global $_CONF;
+
return array(
- '/layout/' . $_CONF['theme'] . '/javascript/fix_html.js',
- '/layout/' . $_CONF['theme'] . '/javascript/confirm.js',
- '/layout/' . $_CONF['theme'] . '/javascript/search.js'
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/fix_html.js',
+ 'footer' => true, // Not requred, default = true
+ 'priority' => 100 // Not requred, default = 100
+ ),
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/confirm.js',
+ ),
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/search.js',
+ )
);
}
diff -r c3e050a577d6 -r d1f86bebc8a0 public_html/layout/professional/functions.php
--- a/public_html/layout/professional/functions.php Mon Jul 22 22:11:56 2013 +0900
+++ b/public_html/layout/professional/functions.php Mon Jul 22 21:36:27 2013 -0400
@@ -69,7 +69,10 @@
function theme_js_libs_professional()
{
return array(
- 'jquery'
+ array(
+ 'library' => 'jquery',
+ 'footer' => true // Not requred, default = true
+ )
);
}
diff -r c3e050a577d6 -r d1f86bebc8a0 public_html/layout/professional_css/functions.php
--- a/public_html/layout/professional_css/functions.php Mon Jul 22 22:11:56 2013 +0900
+++ b/public_html/layout/professional_css/functions.php Mon Jul 22 21:36:27 2013 -0400
@@ -70,7 +70,10 @@
function theme_js_libs_professional_css()
{
return array(
- 'jquery'
+ array(
+ 'library' => 'jquery',
+ 'footer' => true // Not requred, default = true
+ )
);
}
@@ -80,10 +83,17 @@
function theme_js_files_professional_css()
{
global $_CONF;
+
return array(
- '/layout/' . $_CONF['theme'] . '/javascript/confirm.js',
- '/layout/' . $_CONF['theme'] . '/javascript/fix_html.js'
- );
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/fix_html.js',
+ 'footer' => true, // Not requred, default = true
+ 'priority' => 100 // Not requred, default = 100
+ ),
+ array(
+ 'file' => '/layout/' . $_CONF['theme'] . '/javascript/confirm.js',
+ )
+ );
}
/**
diff -r c3e050a577d6 -r d1f86bebc8a0 public_html/lib-common.php
--- a/public_html/lib-common.php Mon Jul 22 22:11:56 2013 +0900
+++ b/public_html/lib-common.php Mon Jul 22 21:36:27 2013 -0400
@@ -440,22 +440,32 @@
if (function_exists($func)) {
foreach ($func() as $info) {
$file = $info['file'];
- $name = md5($file);
+ $name = (!empty($info['name'])) ? $info['name'] : md5($file);
+ $priority = (!empty($info['priority'])) ? $info['priority'] : 100;
$constant = (!empty($info['constant'])) ? $info['constant'] : true;
$attributes = (!empty($info['attributes'])) ? $info['attributes'] : array();
- $_SCRIPTS->setCssFile($name, $file, $constant, $attributes);
+ $_SCRIPTS->setCssFile($name, $file, $priority, $constant, $attributes);
}
}
$func = "theme_js_libs_" . $_CONF['theme'];
if (function_exists($func)) {
- foreach ($func() as $name) {
- $_SCRIPTS->setJavaScriptLibrary($name);
+ foreach ($func() as $info) {
+ $footer = true;
+ if (isset($info['footer']) && !$info['footer']) {
+ $footer = false;
+ }
+ $_SCRIPTS->setJavaScriptLibrary($info['library'], $footer);
}
}
$func = "theme_js_files_" . $_CONF['theme'];
if (function_exists($func)) {
- foreach ($func() as $file) {
- $_SCRIPTS->setJavaScriptFile(md5($file), $file);
+ foreach ($func() as $info) {
+ $footer = true;
+ if (isset($info['footer']) && !$info['footer']) {
+ $footer = false;
+ }
+ $priority = (!empty($info['priority'])) ? $info['priority'] : 100;
+ $_SCRIPTS->setJavaScriptFile(md5($info['file']), $info['file'], $footer, $priority);
}
}
$func = "theme_init_" . $_CONF['theme'];
diff -r c3e050a577d6 -r d1f86bebc8a0 system/classes/scripts.class.php
--- a/system/classes/scripts.class.php Mon Jul 22 22:11:56 2013 +0900
+++ b/system/classes/scripts.class.php Mon Jul 22 21:36:27 2013 -0400
@@ -39,6 +39,7 @@
class scripts {
private $library_files; // Array of available jQuery library files that can be loaded
+ private $library_files_footer; // Location of loading library files
private $jquery_cdn; // Flag to use jQuery file from CDN-hosted source (Google)
private $jquery_cdn_file; // Location of jQuery file at Google
@@ -68,6 +69,7 @@
global $_CONF, $_USER;
$this->library_files = array();
+ $this->library_files_footer = true;
$this->jquery_ui_cdn = false;
$this->script_files = array();
$this->css_files = array();
@@ -104,7 +106,6 @@
$theme_path = '/layout/' . $_CONF['theme'];
-
// Add Geeklog Specific JavaScript files. Treat them as library files since other plugins may try to load them
$name = 'common';
$this->library_files[$name]['file'] = 'javascript/common.js';
@@ -177,20 +178,26 @@
$this->library_files[$name]['load'] = false;
}
}
-
+
/**
* Set JavaScript Libraries to load
*
* @param $name name of JavaScript library to flag for loading
+ * @param $footer set to true to include script in footer, else script placed in header
* @access public
* @return boolean
*
*/
- public function setJavaScriptLibrary($name) {
+ public function setJavaScriptLibrary($name, $footer = true) {
global $_CONF;
$name = strtolower($name);
+
+ if (!$footer) {
+ // If something wants a library in the header then all in the header
+ $this->library_files_footer = false;
+ }
if (isset($this->library_files[$name])) {
if (!$this->library_files[$name]['load']) {
@@ -230,6 +237,53 @@
return false;
}
}
+
+ /**
+ * Set Libraries file to load. Used only by class.
+ *
+ * @access private
+ * @return boolean
+ *
+ */
+ private function setJavaScriptLibraries() {
+
+ global $_CONF;
+
+ $librarycode = '';
+
+ if ($this->jquery_cdn) {
+ $librarycode .= '<script type="text/javascript" src="' . $this->jquery_cdn_file . '"></script>' . LB;
+ $this->library_files['jquery']['load'] = false; // Set to false so not reloaded
+ if ($this->jquery_ui_cdn) {
+ $librarycode .= '<script type="text/javascript" src="' . $this->jquery_ui_cdn_file . '"></script>' . LB;
+ // Since using CDN file reset loading of jQuery UI
+ foreach ($this->library_files as $key => &$file) {
+ if (substr($key, 0, 7) == 'jquery.') {
+ $file['load'] = false;
+ }
+ }
+ }
+ } elseif ($this->jquery_ui_cdn) { // This might happen if a jQuery UI file is not found
+ $librarycode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . '/' . $this->library_files['jquery']['file'] . '"></script>' . LB;
+ $this->library_files['jquery']['load'] = false; // Set to false so not reloaded
+ $librarycode .= '<script type="text/javascript" src="' . $this->jquery_ui_cdn_file . '"></script>' . LB;
+ // Since using CDN file reset loading of jQuery UI
+ foreach ($this->library_files as $key => &$file) {
+ if (substr($key, 0, 7) == 'jquery.') {
+ $file['load'] = false;
+ }
+ }
+ }
+
+ // Now load in the rest of the libraries
+ foreach ($this->library_files as $file) {
+ if ($file['load']) {
+ $librarycode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . '/' . $file['file'] . '"></script>' . LB;
+ }
+ }
+
+ return $librarycode;
+ }
/**
* Set JavaScript to load
@@ -237,12 +291,11 @@
* @param $script script to include in page
* @param $wrap set to true to place script tags around contents of $script
* @param $footer set to true to include script in footer, else script placed in header
- * @param $constant Future use. Set to true if script is planned to be loaded all the time (Caching/Compression)
* @access public
* @return boolean
*
*/
More information about the geeklog-cvs
mailing list