Alright, before anyone tells me to do a search...
I have...
I want to have a javascript file(s) included for my Module to use...
How do I make sure that each page that uses the module, also includes "xyz.js"
Do I just create a folder called "includes" or "javascript" and it auto-includes them? Do I create a special function that is called by pnadmin or pnuser?
I am lost...
If you can help? Please do...
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 07:01 AM
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 06:41 AM
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 06:27 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
- damon responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
How do I include a javascript file in my module
-
- Rank: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
-
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
Are you templating your module with pnRender, or using pnHTML or what?
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
- Rank: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
I am using the new pnRender...
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink -
- Rank: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
Bloody tree rats are everywhere...
You gotta love em... Rats with great P.R.
What's with them? That's a secret they hold tighter than their cheeks...
But, uh, back to my question...
If I am designing a Module and I want it to include a Javascript File, HOW do I accomplish this? Is there a special way of including via pnRender?
Help me Mr. Popeil, I'm in trouble...
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
Using .7x you need to added an element to the global additional_header array. i.e
Code
$GLOBALS['additional_header'][] = '<script src="....." ....></script>';
-Mark
--
Visit My homepage and Zikula themes. -
- Rank: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
Thank you VERY MUCH Mr. Mark West...
Now a stupid question.
WHERE do I make this call...?
I have my module layout pretty much setup...
It is basically the 7.5 Example Module (modified of course).
So where do I add this line...
ALSO...
On a side-note.
Is there a pnRender way of doing this?
I assumed that whatever function needed this javascript file? I would add a line to THAT function that did something like $pnRender->addHeader( 'javascript', blah blah blah );
Or something like that...
Help Me Mr. Popeil...
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
You add to this global variable wherever you need to in your code..... This will change with .8x where we'll have the concept of page variables that can control addition to the header.
-Mark
--
Visit My homepage and Zikula themes. -
- Rank: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
Alrighty boys and girls...
I have a work-around that is VERY nice... and personally, it should make it easier once they fix this situation with the next upgrade.
What I did to include a file, as needed, to a module ( or I believe it would work with a theme as well (haven't started learning the new theming process yet) ) is I created a new FUNCTION...
In your Module's FILE STRUCTURE you will want to do the following:
create a folder HERE:
modules/yourmodulename/pnincludes
Put the files you want to include inside the pnincludes folder.
create your FUNCTION and put it HERE:
modules/yourmodulename/pntemplates/plugins/
Then... I named mine the following:
function.eng_additionalheaders.php
Here is the code I use...
Code
//*******************************************************************************
//* Smarty Function::Engineering Additional Headers *
//*******************************************************************************
//* smarty_function_eng_additionalheaders:: *
//* Smarty Function used to add additional headers to a page for including *
//* files that may be needed. *
//*******************************************************************************
//* Argument(Req/Opt) Basic Description *
//* ***************** *************************************************
//* $params All attributes passed to this function from the *
//* template *
//* &$smarty Reference to the Smarty object *
//*******************************************************************************
//* Special Use Instructions *
//* *********************************************************************** *
//* Inside a SMARTY template ( i.e., engineering_admin_new.htm ) you will *
//* call this function by using the following command: *
//* *********************************************************************** *
//*
//* <!--[eng_additionalheaders nameOfFile="example.css" typeOfFile="css"]-->
//* --- or ---
//* <!--[eng_additionalheaders nameOfFile="example.js" typeOfFile="javascript"]-->
//*
//*******************************************************************************
function smarty_function_eng_additionalheaders( $params, &$smarty )
{
extract( $params );
unset( $params );
$modName = pnModGetName();
$GLOBALS['additional_header'][] =
"<script type=\"text/" . $typeOfFile . "\" src=\"modules/" . $modName . "/pnincludes/" . $nameOfFile . "\"></script>";
}
I believe that should cover it...
Very simple... Very easy...
Any questions?
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 413
Do you guys know of anyway of testing to ensure the function is even getting called?? I tried doing a simple print and then die but that didn't work any idea how I might do that???
-SUNADMN
- Moderated by:
- Support
