Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 05:37 pm EST
Geeklog Forums
SCRIPTS class
Status: offline
Al262
Forum User
Junior
Registered: 10/19/10
Posts: 16
I am trying to set both a CSS file and include JS file in my plugin. Since it is a plugin, I opened up my functions.inc and added the $_SCRIPT->sets... When I view source after the page is displayed, I do not see a reference to either.
Guidance?
/**
* Return <head> items for this plugin
*
* @return html for <link>, <script>, <style>...
*
*/
function plugin_getheadercode_myplug()
{
global $_SCRIPTS;
$headerText = "\n<!-- Javascript and CSS includes -->\n";
$_SCRIPTS->setCSSFile('myplug', '/myplug/jquery-lightbox-0.5.css', false);
$_SCRIPTS->setJavaScriptFile('myplug', '/myplug/jquery-lightbox-0.5.js');
return $headerText;
}
Guidance?
Text Formatted Code
/**
* Return <head> items for this plugin
*
* @return html for <link>, <script>, <style>...
*
*/
function plugin_getheadercode_myplug()
{
global $_SCRIPTS;
$headerText = "\n<!-- Javascript and CSS includes -->\n";
$_SCRIPTS->setCSSFile('myplug', '/myplug/jquery-lightbox-0.5.css', false);
$_SCRIPTS->setJavaScriptFile('myplug', '/myplug/jquery-lightbox-0.5.js');
return $headerText;
}
14
17
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
Your code should work though it looks like your lightbox requires jQuery so you should make sure it is loaded as well by adding
$_SCRIPTS->setJavaScriptLibrary('jquery');
to tell Geeklog to include it if not already added by some other process. Also setJavaScriptFile by default will add the javascript to the footer not the header.
Tom
One of the Geeklog Core Developers.
Text Formatted Code
$_SCRIPTS->setJavaScriptLibrary('jquery');
to tell Geeklog to include it if not already added by some other process. Also setJavaScriptFile by default will add the javascript to the footer not the header.
Tom
One of the Geeklog Core Developers.
17
16
Quote
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
As sample, you can also look at the code of the jquery plugin or maps plugin.
Ben
I'm available to customise your themes or plugins for your Geeklog CMS
Ben
I'm available to customise your themes or plugins for your Geeklog CMS
11
16
Quote
Status: offline
Al262
Forum User
Junior
Registered: 10/19/10
Posts: 16
Thanks for the guidance. I added the $_SCRIPTS->setJavaScriptLibrary('jquery'; to the function.inc and the code below to my index.php. All appears to be in order.
// MAIN
global $_SCRIPTS;
$_SCRIPTS->setCSSFile('storygallery', '/storygallery/style.css', false);
$_SCRIPTS->setJavaScriptFile('storygallery', '/storygallery/jquery.tablesorter.min.js');
$js = "\n" . '$(document).ready(function()' . "\n";
$js .= '{' . "\n";
$js .= ' $("#storygallery").tablesorter( {sortList: [[0,0], [1,0]]} );' . "\n";
$js .= '}' . "\n";
$js .= ');' . "\n";
$_SCRIPTS->setJavaScript($js, true);
$display .= COM_siteHeader('menu', $LANG_STORYGALLERY_1['plugin_name']);
Text Formatted Code
// MAIN
global $_SCRIPTS;
$_SCRIPTS->setCSSFile('storygallery', '/storygallery/style.css', false);
$_SCRIPTS->setJavaScriptFile('storygallery', '/storygallery/jquery.tablesorter.min.js');
$js = "\n" . '$(document).ready(function()' . "\n";
$js .= '{' . "\n";
$js .= ' $("#storygallery").tablesorter( {sortList: [[0,0], [1,0]]} );' . "\n";
$js .= '}' . "\n";
$js .= ');' . "\n";
$_SCRIPTS->setJavaScript($js, true);
$display .= COM_siteHeader('menu', $LANG_STORYGALLERY_1['plugin_name']);
13
15
Quote
All times are EST. The time is now 05:37 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