[RFC|Merged] Inclusion of jQuery

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Inclusion of jQuery

Post by callumacrae »

+1, so many things are so much easier in jQuery - event listeners (blergh DOM2 in 3.0 :( ), AJAX, DOM manipulation :-)
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: [RFC] Inclusion of jQuery

Post by DavidIQ »

I'm wondering what exactly we would replace with jQuery that is currently in use that wouldn't or isn't already handled by some basic JavaScript. In some instances I don't know that there is a whole lot of benefit vs. the added overhead of jQuery (or any other js library). I suppose the biggest one would be the color switcher and possibly the Smiley insertion. Some of the other stuff is so simple I'm not sure replacing EVERYTHING with jQuery would be worth it or would be more efficient. Showing/hiding panels also comes to mind especially in the ACP.
Image

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

Re: [RFC] Inclusion of jQuery

Post by callumacrae »

The code I was working on yesterday was the BBCode buttons on the signature edit page in the ACP. On *every single button*, it had an onmouseover= and onmouseout= (which is bad). The entire thing could have been shortened to:

Code: Select all

var buttons = $('.button2');
buttons.bind('mouseover', function()
{
    helpline(this.accesskey);
});
//helpline should default to tip, too.
buttons.bind('mouseout', helpline);
That code probably doesn't work (Im writing this post from my phone), and I can't remember the names of stuff anyway, but you get the picture.

The reason that jQuery should be used for this is because Internet Explorer sucks, and it also makes attaching events to multiple elements really really easy.

EDIT: Here 'tis: https://github.com/phpbb/phpbb3/blob/09 ... e.html#L50
Made by developers, for developers!
My blog

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

Re: [RFC] Inclusion of jQuery

Post by callumacrae »

A couple more notes from me:

In my opinion, phpBB should be using the google CDN with a local fallback. It's very easy to do (see HTML5BL) - two lines of code. The only time I remember the Google CDN going down was a while ago, and a large chunk of the Internet broke for a few hours. Using the latest jQuery file on the CDN (jquery.js, not jquery-1.x.x.js) would be less secure in the case of vulnerabilities or bugs being found in jQuery, but it would remove the need for patch releases if a buggy version of jQuery was released with phpBB.

I also think that the core phpBB js should be changed to jQuery for 3.1, not 3.2 as suggested above. With the right tools, it is extremely fast to write, it's just a matter of finding it (which only I would find difficult).
Made by developers, for developers!
My blog

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] Inclusion of jQuery

Post by Oleg »

As was mentioned in another topic the jquery include should be moved from head into the footer.
igorw wrote: Ok, judging from the wikipedia release history there is only one development line. So when 1.7 is released, there are likely no more updates to 1.6. For this reason I think we should always ship the latest version available whenever we release a new version of phpBB.
So basically we offer no guarantees of js compatibility in patch releases?

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: [RFC] Inclusion of jQuery

Post by nickvergessen »

Oleg wrote:So basically we offer no guarantees of js compatibility in patch releases?
Well, we had one patch release so far and I hope we dont ever get another one. And I'd say yes, we may ship it with an outdated jQuery in that case.
Member of the Development-TeamNo Support via PM

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

Re: [RFC] Inclusion of jQuery

Post by DavidIQ »

Oleg wrote:As was mentioned in another topic the jquery include should be moved from head into the footer.
This explains what was mentioned in another topic by callum. But what's the purpose/benefit behind this?
Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: [RFC] Inclusion of jQuery

Post by naderman »

To speed up initial rendering of the page. It does not need to wait for jquery to load before rendering the page that way. The javascript is loaded at the end and then attaches event handlers to various elements.

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

Re: [RFC] Inclusion of jQuery

Post by callumacrae »

DavidIQ wrote:
Oleg wrote:As was mentioned in another topic the jquery include should be moved from head into the footer.
This explains what was mentioned in another topic by callum. But what's the purpose/benefit behind this?
To add to what naderman said:

The rendering engine loads the page in the order it reads it (duh). When it gets to something like a reference to a style sheet or external script (but not images), it stops doing everything else and loads the external stuff instead, before resuming page load. Putting it in the page footer won't actually speed up page loading time, but it will appear to, as it will refer the body before downloading and rendering the large jQuery library. Therefore, on sites that do not rely on jQuery / JS on page load, JavaScript should be put in the footer.

Nothing will use or rely on jQuery at page load.

~Callum
Made by developers, for developers!
My blog

igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Inclusion of jQuery

Post by igorw »

I have moved jQuery to the bottom of the page. This however means that we cannot use jQuery in any in-line javascript and that we have to stick all of our JavaScript into one huge file.

That trade-off works for me, it forces us to take a clean approach to our JavaScript and properly rewrite any of the existing code. We might want to consider some kind of compilation/concatenation though, because sticking everything in one file is kind of cumbersome in development.

Thoughts?

Post Reply