060 - Write a document describing how to add JavaScript to a Joomla template
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sat Dec 01, 2007 3:28 pm
060 - Write a document describing how to add JavaScript to a Joomla template
I have already wrote the docs but [email protected] posted that I need to use API call.
Where to put that command to? The template? Some component? or where?
Thank you.
Google Task
[me=AmyStephen]Changed subject slightly for sorting all threads to match against Google resource [/me]
Where to put that command to? The template? Some component? or where?
Thank you.
Google Task
[me=AmyStephen]Changed subject slightly for sorting all threads to match against Google resource [/me]
Last edited by AmyStephen on Mon Dec 10, 2007 3:12 am, edited 1 time in total.
- jlleblanc
- Joomla! Guru
- Posts: 963
- Joined: Fri Aug 19, 2005 12:37 am
- Location: Washington, DC / NoVA
- Contact:
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Yes, there are API calls you can use to put Javascript and CSS files in the head section of the document. These can be called from components, modules, or plugins. I do this very frequently for projects where I want to add styles and scripts to my components, but I still want to maintain valid HTML by keeping all CSS and JS references in the header.
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sat Dec 01, 2007 3:28 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
And in the tutorial, where I should put it?
I remembered it said that who that don't know PHP/JS can understand this howto so I think they must don't edit the component without PHP knowledge.
I remembered it said that who that don't know PHP/JS can understand this howto so I think they must don't edit the component without PHP knowledge.
- jlleblanc
- Joomla! Guru
- Posts: 963
- Joined: Fri Aug 19, 2005 12:37 am
- Location: Washington, DC / NoVA
- Contact:
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
The audience will need some very basic PHP knowledge, probably at the level where they could echo "Hello World!" within an if() statement. However, they won't need knowledge of object-oriented programming or complex array structures to accomplish this.
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
are you the same guy that claimed this task on the google webpage? because i only see another person that unclaimed it and after him i clamied the task. anyway i have a draft already going to upload to the google issue tracker. going to upload as html but i am not sure in what format to upload the file. heres the draft as a attachtment and the image that should go at the botton of the file. would like some feedback guys
You do not have the required permissions to view the files attached to this post.
Last edited by annerajb on Sun Dec 02, 2007 3:40 am, edited 1 time in total.
-
- Joomla! Champion
- Posts: 7018
- Joined: Wed Nov 22, 2006 3:35 pm
- Location: Nebraska
- Contact:
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
i would like to call for a final review as i dont see anything else that i could improve unless anyone has some feedback on things to add to it.
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
i fixed some stuff hopefully its better now i removed the image because i fell it wasnt needed but if somebody things its ok with a screenshot i will put it back . BTW: joomla is a great community
You do not have the required permissions to view the files attached to this post.
Last edited by annerajb on Tue Dec 04, 2007 12:24 am, edited 1 time in total.
-
- Joomla! Champion
- Posts: 7018
- Joined: Wed Nov 22, 2006 3:35 pm
- Location: Nebraska
- Contact:
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
That makes me -->annerajb wrote: BTW: joomla is a great community
Feedback:
- API - all caps
- Never forget the ! on Joomla! (don't ask, just do it! )
- Get rid of "we"
- remove extra words, too. For example, you can change this:
To:Requirements: You will need some basic knowledge of PHP programming language
Geeks don't like to read.Requirements: Basic knowledge of PHP
- perfom should be perform
- exampe if we are putting -- For example, if we are putting
In general - try to format your code with a Courier New 10 (something fixed).
In the addScript function - consider printing all of the lines together, either before or after each individual line is explained.
++++
This is an example of a plugin I wrote that uses the addScript. That might be a better format since it uses the JURI::base().
It's getting there - and this will be useful - so thanks for your efforts!global $mainframe;
// Load the Mootools library
JHTML::_('behavior.mootools');
// Add Javascript
$document =& JFactory::getDocument();
$document->addScript( JURI::base() . 'plugins/content/mootoolsaccordion.js' );
Amy
PS - White space is very helpful with technical documents.
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
sorry my native language is not English thats why i have so many typos.
you mean change the font of the document? if yes i don't have that font in openofficeIn general - try to format your code with a Courier New 10 (something fixed).
Last edited by annerajb on Tue Dec 04, 2007 1:55 pm, edited 1 time in total.
-
- Joomla! Champion
- Posts: 7018
- Joined: Wed Nov 22, 2006 3:35 pm
- Location: Nebraska
- Contact:
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Don't worry - we all have typo's!
I would use Courier New (size 10) for the code examples - not the entire document. It is a very standard font - I wonder if you looked in the font drop down list box for Open Office, if you would find it? Check it out and see.
Thanks!
Amy
I would use Courier New (size 10) for the code examples - not the entire document. It is a very standard font - I wonder if you looked in the font drop down list box for Open Office, if you would find it? Check it out and see.
Thanks!
Amy
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
i checked only have courier i am using fedora so maybe thats why is not there. also i remember reading somewhere that complete path ie. http://www.joomla.org/hello.js are more resource intensive on the server or the other way around. does JURI:base() returns the complete path as webadress or just the folder that joomla is in?
-
- Joomla! Champion
- Posts: 7018
- Joined: Wed Nov 22, 2006 3:35 pm
- Location: Nebraska
- Contact:
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
JURI:base() returns the folder.
Courier is fine!
Doing good! Thanks!
Amy
Courier is fine!
Doing good! Thanks!
Amy
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
well done for today need to head to school. heres my latest revision. enjoy
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
anybody has any feedback on the latest revision of my doc?
- Chris Davenport
- Joomla! Ace
- Posts: 1370
- Joined: Thu Aug 18, 2005 8:57 am
- Location: Shrewsbury, Shropshire, United Kingdom
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Good work Chalet. I can see that you have listened to the feedback and taken it on board. Here are some suggestions to make it even better:
The code samples are not particularly readable, mostly because of long lines getting wrapped. I would suggest you remove the comment blocks containing the @copyright and @license tags as these are not really adding anything useful to the samples. I think you can also drop the code samples down to 10pt instead of 12pt so they are less likely to wrap.
Code samples in the official documentation get copied and pasted a lot so we try to make sure they show best practice ways of doing things. So with that in mind, all references to external files should be prefixed with JURI::base().
The second piece of example code can, I think, be stripped down to the single line:
leaving the third example to set it in context.
Always have a single line of white space above and below each code fragment.
There are numerous grammatical errors, but as you are not a native English-speaker I won't criticise you for that. Contributions to the official documentation from native and non-native English-speakers are equally welcome as the Doc Team will always apply the final "translation" and polish. However, these are a few things to watch out for:-
Regards,
Chris.
The code samples are not particularly readable, mostly because of long lines getting wrapped. I would suggest you remove the comment blocks containing the @copyright and @license tags as these are not really adding anything useful to the samples. I think you can also drop the code samples down to 10pt instead of 12pt so they are less likely to wrap.
Code samples in the official documentation get copied and pasted a lot so we try to make sure they show best practice ways of doing things. So with that in mind, all references to external files should be prefixed with JURI::base().
The second piece of example code can, I think, be stripped down to the single line:
Code: Select all
$document =& JFactory::getDocument();
Always have a single line of white space above and below each code fragment.
There are numerous grammatical errors, but as you are not a native English-speaker I won't criticise you for that. Contributions to the official documentation from native and non-native English-speakers are equally welcome as the Doc Team will always apply the final "translation" and polish. However, these are a few things to watch out for:-
- Always spell Joomla! with a capital "J" and with a final "!".
- Be careful with the word "Joomla!" in the middle of a sentence as most word processors will automatically capitalise the first letter of the next word.
- "Api" should be capitalised so it becomes "API".
Regards,
Chris.
Chris Davenport
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
yeah i am focusing first on the actual content after that i will ask for somebody to help me find gramatical errors. thanks for your feedback guys
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
woot i took a look and there are some awesome task to do.
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
where here it is latest version of my document as always any feedback will be welcome if it's ok tell me to send it to somebody for grammar checking.
You do not have the required permissions to view the files attached to this post.
- Chris Davenport
- Joomla! Ace
- Posts: 1370
- Joined: Thu Aug 18, 2005 8:57 am
- Location: Shrewsbury, Shropshire, United Kingdom
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Yep, that's a step closer.
In the first code sample: you still have a problem with line wrapping. This is a common issue that we face in the Doc Team all the time and we have developed some simple strategies for getting round such problems. The obvious one is to reduce the font size, which you have done, but you still have a problem. So then we might try shortening the code lines, perhaps by giving some variables shorter names or using shorter pathnames, but there doesn't seem to be much scope for that here. So the next idea is to try re-phrasing the code to achieve the same effect but maybe use more, shorter lines, instead of a single, long line. So try this..... try replacing this:
with this:
Incidentally, are you sure that JURI::base() returns '/' when the Joomla! root is in the web server document root? If it just returns an empty string then your code must supply the '/' itself, so it would become:
Still on the first code sample, I like the way you put the line(s) of interest to the reader into bold on your other code samples. Perhaps you could do the same with this one.
On the third code sample, you seem to have included a call to addScript just before the call to addScriptDeclaration. I think that should be removed (probably a cut-and-paste error).
Nearly there. Keep up the good work.
Regards,
Chris.
In the first code sample: you still have a problem with line wrapping. This is a common issue that we face in the Doc Team all the time and we have developed some simple strategies for getting round such problems. The obvious one is to reduce the font size, which you have done, but you still have a problem. So then we might try shortening the code lines, perhaps by giving some variables shorter names or using shorter pathnames, but there doesn't seem to be much scope for that here. So the next idea is to try re-phrasing the code to achieve the same effect but maybe use more, shorter lines, instead of a single, long line. So try this..... try replacing this:
Code: Select all
$this->addScript(JURI::base()."templates/".$this->template."/hello.js");
Code: Select all
$js = 'templates/' . $this->template . '/hello.js';
$this->addScript( JURI::base() . $js );
Code: Select all
$js = '/templates/' . $this->template . '/hello.js';
$this->addScript( JURI::base() . $js );
On the third code sample, you seem to have included a call to addScript just before the call to addScriptDeclaration. I think that should be removed (probably a cut-and-paste error).
Nearly there. Keep up the good work.
Regards,
Chris.
Chris Davenport
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
fixed a bug in the code
also deleted the xhtml dtd line because theres now way to stop if from wrapping and added a js variable as instructed in case that line of code wraps too i use the highest resolution on my pc's so i am not sure if its my end or yours so just to be sure . comments as always wanna get started coding
also deleted the xhtml dtd line because theres now way to stop if from wrapping and added a js variable as instructed in case that line of code wraps too i use the highest resolution on my pc's so i am not sure if its my end or yours so just to be sure . comments as always wanna get started coding
You do not have the required permissions to view the files attached to this post.
- Chris Davenport
- Joomla! Ace
- Posts: 1370
- Joined: Thu Aug 18, 2005 8:57 am
- Location: Shrewsbury, Shropshire, United Kingdom
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Hi annerajb,
This looks really good now. Well done.
If you want to ask someone to correct grammatical errors that's up to you. It won't affect your chances of winning any prize as we will make allowances for your being a non-native English-speaker.
When you are happy with your entry please call for a Final Review.
Good work!
Chris.
This looks really good now. Well done.
If you want to ask someone to correct grammatical errors that's up to you. It won't affect your chances of winning any prize as we will make allowances for your being a non-native English-speaker.
When you are happy with your entry please call for a Final Review.
Good work!
Chris.
Chris Davenport
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
wuju going to upload to google later today let me send it to somebody for prof reading.
-
- Joomla! Intern
- Posts: 62
- Joined: Tue Sep 04, 2007 8:59 pm
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
i uploaded into Google my final revision http://code.google.com/p/google-highly- ... %20Summary
- Chris Davenport
- Joomla! Ace
- Posts: 1370
- Joined: Thu Aug 18, 2005 8:57 am
- Location: Shrewsbury, Shropshire, United Kingdom
Re: 060 - Write a document describing how to add JavaScript to a Joomla template
Task closed.
Thanks annerjb.
Chris.
Thanks annerjb.
Chris.
Chris Davenport
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/
Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/