Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
loading jquery and general js practices
I’ve scanned around the forums and textbook and haven’t really found the answer. If I’ve missed it, please point me to a link.
Do I need to do anything special to get jquery to load? I know I can easily just <script type="text/javascript" src="<txp:site_url />/textpattern/jquery.js"></script>
but is there a preferred, special textpattern, method to call it up? If I don’t manually, call it up, I get “$ is not defined”
oh, and this is a clean install of txp 4.0.5 and I’ve updated to the latest release of jquery.js
Finally, I’d like to hear how people like to pop in their custom javascript. I’ve created a form and stick it all there, calling it on the pages I need it. I think that is in the spirit of textpattern, no? Anyone actually make js library files?
thanks
Offline
Re: loading jquery and general js practices
The stm_javascript plugin is very useful if you are working with JS. The way you load JQuery is fine. There really isn’t a better way that I know of.
Offline
Re: loading jquery and general js practices
Your current code should be <txp:site_url />textpattern/jquery.js
because site_url
already outputs a forward slash.
For me, I externalize all of my JavaScript and call it with <txp:site_url />lib/js/file_name.js
. I then load the js for whatever page with:
// site.load is a prefixed addLoadEvent
site.load(function() {
switch(document.body.getAttribute('id')) {
case 'articles':
site.doStuff();
site.doMoreStuff();
break;
default:
site.search('q', 'Enter search terms');
};
});
I find it easier to keep all JS, even minimal templating logic, in the js file.
Last edited by jm (2008-01-20 18:57:54)
Offline
Re: loading jquery and general js practices
great. Thanks fellas
Offline
#5 2008-02-19 07:21:38
- candyman
- Member
- From: Italy
- Registered: 2006-08-08
- Posts: 684
Re: loading jquery and general js practices
So, is better to load the default TXP jquery with the stm_javascript plugin? Or is the same?
Offline
Re: loading jquery and general js practices
no its not better. its slower. although theres nothing wrong with the stm_javascript method, personally i think all js files should be external files. same with css (thanks to rvm_css)
Last edited by iblastoff (2008-02-19 07:45:16)
Offline