Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 05:47 pm EST
Geeklog Forums
setJavaScript() set JavaScript file in footer
Status: offline
ivy
Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
scripts.class.php:
setJavaScript() set JavaScript file in footer.
But some jQuery needs to be set in header.
Geeklog Japan https://www.geeklog.jp
setJavaScript() set JavaScript file in footer.
But some jQuery needs to be set in header.
Geeklog Japan https://www.geeklog.jp
13
14
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
True.
There is a feature request for it here:
http://project.geeklog.net/tracking/view.php?id=1459
One of the Geeklog Core Developers.
There is a feature request for it here:
http://project.geeklog.net/tracking/view.php?id=1459
One of the Geeklog Core Developers.
11
17
Quote
Status: offline
ivy
Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
Thanks!
Geeklog Japan https://www.geeklog.jp
Geeklog Japan https://www.geeklog.jp
10
13
Quote
Status: offline
ivy
Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
Anyway, pages display fast by setting JavaScript files in footer.
Geeklog Japan https://www.geeklog.jp
Geeklog Japan https://www.geeklog.jp
14
16
Quote
Status: offline
Armitage
Forum User
Junior
Registered: 12/10/04
Posts: 15
Location:D.C.
Is there a temporary work-around for this? I've started migrating my ancient 1.4.1 installation to 1.8.1 on a dev server and some of my static pages require jQuery and additional .js libraries to be loaded in advance such that a $(document).ready(function() within the staticpage can begin the process of dynamically refreshing content. In the past, I just included all the .js I needed in my theme's header.thtml file.
Thanks!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
Thanks!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
17
11
Quote
Status: offline
ivy
Forum User
Full Member
Registered: 11/25/04
Posts: 314
Location:Tokyo Japan
function setJavaScript prepare JavaScript for header or footer by using $footer.
public function setJavaScript($script, $wrap = false, $footer = true, $constant = false)
Geeklog Japan https://www.geeklog.jp
public function setJavaScript($script, $wrap = false, $footer = true, $constant = false)
Geeklog Japan https://www.geeklog.jp
14
17
Quote
Status: offline
Armitage
Forum User
Junior
Registered: 12/10/04
Posts: 15
Location:D.C.
I have successfully worked around my current problem by adding my jQuery and .js to my header. However, the jQuery that gets placed at the footer of the page conflicts with mine and causes things not to work. As a quick-and-dirty fix I commented out the {plg_footercode} from my footer.thtml which fixed the immediate problem. Doing this, however, causes other problems when additional .js are loaded such as in the configuration page.
Is there a way I can hack Geeklog to not include only specific scripts (such as jquery.min.js) but allow it to dynamically load the extra ones it needs that I am not loading in the header?
Thanks!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
Is there a way I can hack Geeklog to not include only specific scripts (such as jquery.min.js) but allow it to dynamically load the extra ones it needs that I am not loading in the header?
Thanks!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
14
15
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
This is something we will definitely fix for Geeklog 2.0.1 but in the mean time you could modify the system/classes/scripts.class.php file.
Take a look at the getFooter function and replace it with this one:
public function getFooter() {
global $_CONF, $_USER;
$footercode = '';
// Do we need to set JavaScript
if ($this->javascript_set) {
// Add Core JavaScript global variables
if ($_CONF['advanced_editor'] && $_USER['advanced_editor']) {
$footercode .= '<script type="text/javascript">' . LB;
$footercode .= 'var geeklogEditorBaseUrl = "' . $_CONF['site_url'] . '";' . LB;
// Setup editor path for FCKeditor JS Functions
$footercode .= 'var geeklogEditorBasePath = "' . $_CONF['site_url'] . '/fckeditor/";' . LB;
$footercode .= '</script>' . LB;
}
// Now load in the rest of the libraries
foreach ($this->library_files as $file) {
if ($file['load']) {
$footercode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . '/' . $file['file'] . '"></script>' . LB;
}
}
// Set JavaScript (do this before file incase variables are needed)
if (isset($this->scripts['footer'])) {
foreach ($this->scripts['footer'] as $script) {
$footercode .= $script . LB;
}
}
// Set JavaScript Files
foreach ($this->script_files as $file) {
if ($file['footer']) {
$footercode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . $file['file'] . '"></script>' . LB;
}
}
}
return $footercode;
}
This code is not tested but I beleive things should work as long as you hardcode jquery in the header. All I did to the above function is remove the setting of the jquery files.
Let us know if it works.
Thanks
Tom
One of the Geeklog Core Developers.
Take a look at the getFooter function and replace it with this one:
Text Formatted Code
public function getFooter() {
global $_CONF, $_USER;
$footercode = '';
// Do we need to set JavaScript
if ($this->javascript_set) {
// Add Core JavaScript global variables
if ($_CONF['advanced_editor'] && $_USER['advanced_editor']) {
$footercode .= '<script type="text/javascript">' . LB;
$footercode .= 'var geeklogEditorBaseUrl = "' . $_CONF['site_url'] . '";' . LB;
// Setup editor path for FCKeditor JS Functions
$footercode .= 'var geeklogEditorBasePath = "' . $_CONF['site_url'] . '/fckeditor/";' . LB;
$footercode .= '</script>' . LB;
}
// Now load in the rest of the libraries
foreach ($this->library_files as $file) {
if ($file['load']) {
$footercode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . '/' . $file['file'] . '"></script>' . LB;
}
}
// Set JavaScript (do this before file incase variables are needed)
if (isset($this->scripts['footer'])) {
foreach ($this->scripts['footer'] as $script) {
$footercode .= $script . LB;
}
}
// Set JavaScript Files
foreach ($this->script_files as $file) {
if ($file['footer']) {
$footercode .= '<script type="text/javascript" src="' . $_CONF['site_url'] . $file['file'] . '"></script>' . LB;
}
}
}
return $footercode;
}
This code is not tested but I beleive things should work as long as you hardcode jquery in the header. All I did to the above function is remove the setting of the jquery files.
Let us know if it works.
Thanks
Tom
One of the Geeklog Core Developers.
16
15
Quote
Status: offline
Armitage
Forum User
Junior
Registered: 12/10/04
Posts: 15
Location:D.C.
Hi Tom, thanks for the reply! I applied the code change you provided above but noticed after my site failed to load that my original function isn't 100% the same (it lacks the bit about " // Setup editor path for FCKeditor JS Functions" ). I restored the original and then manually deleted the lines you had removed in the above example.
After making the change (and even restarting apache for good measure) I didn't observe any difference in my footer. The only one I don't want there is the jquery.min.js:
<script type="text/javascript" src="http://dev.armitunes.com/javascript/common.js"></script>
<script type="text/javascript" src="http://dev.armitunes.com/javascript/jquery.min.js"></script>
<script type="text/javascript" src="http://dev.armitunes.com/javascript/fix_tooltips.js"></script>
Here's the diff for the changes I made:
441d440
< $footercode = '';
448,471d446
< // Set JavaScript Library files first incase other scripts need them
< if ($this->jquery_cdn) {
< $footercode .= '<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) {
< $footercode .= '<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
< $footercode .= '<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
< $footercode .= '<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;
< }
< }
< }
I will continue to play with this in case I missed anything. Thank you for your help!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
After making the change (and even restarting apache for good measure) I didn't observe any difference in my footer. The only one I don't want there is the jquery.min.js:
Text Formatted Code
<script type="text/javascript" src="http://dev.armitunes.com/javascript/common.js"></script>
<script type="text/javascript" src="http://dev.armitunes.com/javascript/jquery.min.js"></script>
<script type="text/javascript" src="http://dev.armitunes.com/javascript/fix_tooltips.js"></script>
Here's the diff for the changes I made:
Text Formatted Code
441d440
< $footercode = '';
448,471d446
< // Set JavaScript Library files first incase other scripts need them
< if ($this->jquery_cdn) {
< $footercode .= '<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) {
< $footercode .= '<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
< $footercode .= '<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
< $footercode .= '<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;
< }
< }
< }
I will continue to play with this in case I missed anything. Thank you for your help!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
12
9
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
Okay lets approach this a little differently then since you just want to remove jquery and not the ui stuff. Put the getfooter function back to normal and then modify the setJavaScriptLibrary function in the same file:
public function setJavaScriptLibrary($name) {
global $_CONF;
$name = strtolower($name);
if (isset($this->library_files[$name])) {
if (!$this->library_files[$name]['load']) {
$this->library_files[$name]['load'] = true;
// If name is subset of jQuery. make sure all Core UI libraries are loaded
if (substr($name, 0, 7) == 'jquery.' && !$this->jquery_ui_cdn) {
// Check that file exists, if not use Google version
if (!file_exists($_CONF['path_html'] . $this->library_files[$name]['file'])) {
$this->jquery_ui_cdn = false;
$this->css_files['jquery.ui']['load'] = true;
$this->css_files['jquery.ui.all']['load'] = false;
} else {
$this->css_files['jquery.ui.all']['load'] = true;
}
$this->css_files['jquery.ui.geeklog']['load'] = true;
$this->library_files['jquery']['load'] = false;
$this->library_files['jquery.ui.core']['load'] = true;
$this->library_files['jquery.ui.widget']['load'] = true;
$this->library_files['jquery.ui.position']['load'] = true;
$this->library_files['jquery.ui.mouse']['load'] = true;
if ($_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
$this->jquery_ui_cdn = true;
}
} elseif ($name == 'jquery' && $_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
}
}
$this->javascript_set = true;
return true;
} else {
return false;
}
}
All I did here was set jquery for loading to false. This should work but I haven't tested it :-)
Tom
One of the Geeklog Core Developers.
Text Formatted Code
public function setJavaScriptLibrary($name) {
global $_CONF;
$name = strtolower($name);
if (isset($this->library_files[$name])) {
if (!$this->library_files[$name]['load']) {
$this->library_files[$name]['load'] = true;
// If name is subset of jQuery. make sure all Core UI libraries are loaded
if (substr($name, 0, 7) == 'jquery.' && !$this->jquery_ui_cdn) {
// Check that file exists, if not use Google version
if (!file_exists($_CONF['path_html'] . $this->library_files[$name]['file'])) {
$this->jquery_ui_cdn = false;
$this->css_files['jquery.ui']['load'] = true;
$this->css_files['jquery.ui.all']['load'] = false;
} else {
$this->css_files['jquery.ui.all']['load'] = true;
}
$this->css_files['jquery.ui.geeklog']['load'] = true;
$this->library_files['jquery']['load'] = false;
$this->library_files['jquery.ui.core']['load'] = true;
$this->library_files['jquery.ui.widget']['load'] = true;
$this->library_files['jquery.ui.position']['load'] = true;
$this->library_files['jquery.ui.mouse']['load'] = true;
if ($_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
$this->jquery_ui_cdn = true;
}
} elseif ($name == 'jquery' && $_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
}
}
$this->javascript_set = true;
return true;
} else {
return false;
}
}
All I did here was set jquery for loading to false. This should work but I haven't tested it :-)
Tom
One of the Geeklog Core Developers.
14
15
Quote
Status: offline
Armitage
Forum User
Junior
Registered: 12/10/04
Posts: 15
Location:D.C.
I implemented your changes but jquery.min.js was still loading. I further tweaked the load values to "false" until I got the result I was looking for. With the below configuration both my staticpages and the configuration pages work as expected!
public function setJavaScriptLibrary($name) {
global $_CONF;
$name = strtolower($name);
if (isset($this->library_files[$name])) {
if (!$this->library_files[$name]['load']) {
$this->library_files[$name]['load'] = false;
// If name is subset of jQuery. make sure all Core UI libraries are loaded
if (substr($name, 0, 7) == 'jquery.' && !$this->jquery_ui_cdn) {
// Check that file exists, if not use Google version
if (!file_exists($_CONF['path_html'] . $this->library_files[$name]['file'])) {
$this->jquery_ui_cdn = false;
$this->css_files['jquery.ui']['load'] = false;
$this->css_files['jquery.ui.all']['load'] = false;
} else {
$this->css_files['jquery.ui.all']['load'] = false;
}
$this->css_files['jquery.ui.geeklog']['load'] = false;
$this->library_files['jquery']['load'] = false;
$this->library_files['jquery.ui.core']['load'] = false;
$this->library_files['jquery.ui.widget']['load'] = true;
$this->library_files['jquery.ui.position']['load'] = true;
$this->library_files['jquery.ui.mouse']['load'] = true;
if ($_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
$this->jquery_ui_cdn = false;
}
} elseif ($name == 'jquery' && $_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
}
}
$this->javascript_set = true;
return true;
} else {
return false;
}
}
Thanks for all of your help! I'm almost ready to deploy 1.8.1 to my live site which is an upgrade it desperately needs!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
Text Formatted Code
public function setJavaScriptLibrary($name) {
global $_CONF;
$name = strtolower($name);
if (isset($this->library_files[$name])) {
if (!$this->library_files[$name]['load']) {
$this->library_files[$name]['load'] = false;
// If name is subset of jQuery. make sure all Core UI libraries are loaded
if (substr($name, 0, 7) == 'jquery.' && !$this->jquery_ui_cdn) {
// Check that file exists, if not use Google version
if (!file_exists($_CONF['path_html'] . $this->library_files[$name]['file'])) {
$this->jquery_ui_cdn = false;
$this->css_files['jquery.ui']['load'] = false;
$this->css_files['jquery.ui.all']['load'] = false;
} else {
$this->css_files['jquery.ui.all']['load'] = false;
}
$this->css_files['jquery.ui.geeklog']['load'] = false;
$this->library_files['jquery']['load'] = false;
$this->library_files['jquery.ui.core']['load'] = false;
$this->library_files['jquery.ui.widget']['load'] = true;
$this->library_files['jquery.ui.position']['load'] = true;
$this->library_files['jquery.ui.mouse']['load'] = true;
if ($_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
$this->jquery_ui_cdn = false;
}
} elseif ($name == 'jquery' && $_CONF['cdn_hosted']) {
$this->jquery_cdn = false;
}
}
$this->javascript_set = true;
return true;
} else {
return false;
}
}
Thanks for all of your help! I'm almost ready to deploy 1.8.1 to my live site which is an upgrade it desperately needs!
---
Matthew R. Demicco (matt@demicco.net) - armitunes.com
15
18
Quote
All times are EST. The time is now 05:47 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content