JQuery

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

JQuery

Post by John P »

I'm playing with this develop version but I'm wondering how to use jquery in the site.

In a custom page I show some sliders generated by jquery and they are in the middle of the template, generated in php.
Now the jquery library Is in the footer I get the message $jquery not defined.

A picture may help
JQuery slider
JQuery slider
Naamloos-2.jpg (18.6 KiB) Viewed 8303 times

morgar
Registered User
Posts: 1
Joined: Fri May 25, 2007 7:02 pm

Re: JQuery

Post by morgar »

Sorry about my English. You surely are calling some JQuery code before it have been loaded. You should keep the JQuery library reference in the <HEAD>.

Regards
Spanish-English www.ShertonEnglish.com
Portuguese-English www.ShertonEnglishPT.com

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: JQuery

Post by John P »

Yes I know, then it will work but here at phpbb they decided to put it in the footer.
So how should this ever go to work?

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: JQuery

Post by EXreaction »

Add functions to onload_functions.

Example:
https://github.com/marc1706/phpbb3/comm ... 8607685b80

User avatar
hanakin
Front-End Dev Team Lead
Front-End Dev Team Lead
Posts: 968
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

Re: JQuery

Post by hanakin »

morgar wrote:Sorry about my English. You surely are calling some JQuery code before it have been loaded. You should keep the JQuery library reference in the <HEAD>.

Regards
stupid idea keep it where it is and do as Exreaction has instructed or include all code after the Jquery reference in the footer.

If you use Jquery regularly this should be common practice.
Donations welcome via Paypal Image

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: JQuery

Post by callumacrae »

John P wrote:Yes I know, then it will work but here at phpbb they decided to put it in the footer.
So how should this ever go to work?
Load your script after jQuery.
EXreaction wrote:Add functions to onload_functions.

Example:
https://github.com/marc1706/phpbb3/comm ... 8607685b80
I thought onload_functions was removed? It shouldn't be used anyway.
Made by developers, for developers!
My blog

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: JQuery

Post by DavidIQ »

callumacrae wrote:I thought onload_functions was removed? It shouldn't be used anyway.
Why not?
Image

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: JQuery

Post by John P »

For better understanding, the sliders are in a table generated in a template.
Like the example from Marc I have to output the same information twice. Once for generating the table and once for generating the jquery.
I'm going to move the library in the head, it's more logical.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: JQuery

Post by callumacrae »

DavidIQ wrote:
callumacrae wrote:I thought onload_functions was removed? It shouldn't be used anyway.
Why not?
JavaScript should be loaded after jQuery has been loaded. Then why use onload_functions when $() is available?
Made by developers, for developers!
My blog

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: JQuery

Post by DavidIQ »

I guess people are used to loading js in the header and this would still allow them to do that? *shrug*
I'm not sure why loading the js in the footer that the OP is wanting to use was a problem. Should have been fine to do so without having to edit any files.
Image

Post Reply