Coding convention for jQuery4CMSimple

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Gert
Posts: 3078
Joined: Fri May 30, 2008 4:53 pm
Location: Berlin
Contact:

Re: Coding convention for jQuery4CMSimple

Post by Gert » Thu Jun 30, 2011 11:11 am

cmb wrote: :!:, so wouldn't it be a good idea to state, that the only JS framework officially sanctioned by CMSimple is jQuery?
That's what I mean, but as I wrote before:
myself wrote:That less than 10 developers of core and plugins should find agreements, making conflicts improbably.
If we will be much more plugin developers anytime in the future, we should write something about in the developers manual, on a special page "JS libraries".

At the moment it's enough, that jQuery is the one and only mentioned JS library there:

http://www.cmsimple-xh.com/wiki/doku.ph ... d_cmsimple
Gert Ebersbach | CMSimple | Templates - Plugins - Services

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Coding convention for jQuery4CMSimple

Post by cmb » Thu Jun 30, 2011 11:40 am

Hello Gert,
Gert wrote: At the moment it's enough, that jQuery is the one and only mentioned JS library there:
Didn't notice this entry in the manual as yet :oops: . So I better should had RTFM ;)

This solution is fine. :)

OT: In the section on & in urls I found, that amp() is not mentioned.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Gert
Posts: 3078
Joined: Fri May 30, 2008 4:53 pm
Location: Berlin
Contact:

Re: Coding convention for jQuery4CMSimple

Post by Gert » Thu Jun 30, 2011 11:44 am

cmb wrote:OT: In the section on & in urls I found, that amp() is not mentioned.
RTFM - again :lol:

The functions of CMSimple (_XH) are listed here:

http://www.cmsimple-xh.com/wiki/doku.ph ... :functions

But we should remove some old functions of CMSimple there - I know ...

The "&" in url's should be "&" in every case, in html AND Xhtml. So you should write "&" and not use amp() in url's.
Gert Ebersbach | CMSimple | Templates - Plugins - Services

jerry
Posts: 177
Joined: Fri Jul 25, 2008 8:54 pm
Location: Denmark
Contact:

Re: Coding convention for jQuery4CMSimple

Post by jerry » Thu Jun 30, 2011 12:25 pm

Hi Christoph
I don't really know which lightbox features you're using, but if you only use the standard feature (giving a rel="...") the solution might be as simple as including another jQuery based lightbox-clone, e.g. slimbox (that may not be the best choice, but it is the one I know, that works).
It's not that easy. I tried but failed, so I have to spend some time reading documentation and find out how to do it. And plugins that use lightbox (Carousel and Flip for Gallery) will be not rewrited right now. I rewrited documentation for this two plugins so lightbox is loaded after jQuery. This should solve conflicts for a while
jerry
Last edited by jerry on Thu Jun 30, 2011 2:38 pm, edited 1 time in total.
jerry/simplesolutions

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Coding convention for jQuery4CMSimple

Post by cmb » Thu Jun 30, 2011 2:13 pm

Hi Jerry,
jerry wrote: It's not that easy.
I hadn't considered your carousel and flip plugins, which bring an additional layer into play. :oops:
jerry wrote: I rewrited documentation for this two plugins so lightbox is loaded after jQuery.
That's not very nice for the user, but should work with jQuery4CMSimple plugins, if the developers only use jQuery instead of $, as is proposed.

BTW: it might be better not to use $'s in the code, so you could spend them elsewhere :lol:

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: Coding convention for jQuery4CMSimple

Post by Holger » Thu Jun 30, 2011 5:06 pm

Ok, I think we must not discuss any longer the no.Conflict() - request ;) .

If I'm right, we can all accept this little convention:
don't use '$' - use jQuery() or (function($) { /* your code in here might use $() */ })(jQuery))
So I'll close that topic to come to the next...

What about compatibility with other frameworks?
IMO just one small change in jQuery4CMSimple should do the trick:

in function include_jQuery, the line

Code: Select all

$hjs .= "\n".'<script type="text/javascript" src="'.$path.'"></script>'; 
should be changed to

Code: Select all

$hjs = '<script type="text/javascript" src="'.$path.'"></script>'.$hjs; 
to be sure that jQuery is always the first loaded library.

This should work as long as all developers
  • don't use $ for jQuery
  • use the " .= " operator to append their non-jQuery-libraries on right side of $hjs - as usual.
And, at least, if you have to include a framework in the template, just put the script after

Code: Select all

<?php echo head();?>
<script type="text/javascript" src="js/prototype.js"></script>
Please do some testing with your prototype etc. plugins together with the proposed little code-change above.
IMO everything should work. And there's no influence to the stuff added to $hjs from the core.

If you confirm and agree, I'll put the changed code to the plugin and extend the documentation with the "coding conventions" ASAP.

Holger

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Coding convention for jQuery4CMSimple

Post by cmb » Thu Jun 30, 2011 7:02 pm

Hello Gert,

sorry, I did overlook your reply.
Gert wrote: RTFM - again
I did, but found the section the same! It talks about replacing the ”&” via php-function str_replace() :?:
Gert wrote: The "&" in url's should be "&" in every case, in html AND Xhtml. So you should write "&" and not use amp() in url's.
Then why does amp() exist the way it works now? Was is an oversight of Peter Harteg. If so, shouldn't the definition be changed? (Perhaps it will take several man years, but I'm willing to help for free ;)) I guess many plugins and templates use it.

And you might have to take a look at Fotogalerie_XH admin.php ;)

One caveat (I've stumbled lately across it): don't use & in e.g. header() ;)

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

jerry
Posts: 177
Joined: Fri Jul 25, 2008 8:54 pm
Location: Denmark
Contact:

Re: Coding convention for jQuery4CMSimple

Post by jerry » Thu Jun 30, 2011 7:32 pm

Hi Holger
As soon jQuery is loaded before other plugins and $ is not used as variabel in jQuery there are no conflicts with lightbox. Your little trick will do it possible to load other frameworks through $hjs, So yes do it :D
jerry
jerry/simplesolutions

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Coding convention for jQuery4CMSimple

Post by cmb » Thu Jun 30, 2011 7:45 pm

Hello Holger,

I'm fine with the proposed solution to not use noConflict().

But I'm not satiesfied with the solution to load jQuery4CMSimple's jquery lib early as possible, because I'm expecting problems with old extensions including their old jquery lib later. That would at least partly overwrite the newer libs definitions, and so it might clash. We've already talked about the order of plugin inclusion in the jQuery4CMSimple thread.

If the newer jquery version will be loaded last, everything should be fine, even for the old extensions (AFAIK jquery is upward compatible).

Jerry's solution is IMHO not very nice for his users, but he'd documented already the <script...></script> to be included in template.htm after <?php echo head(); ?> If I've understand him correctly, he is willing to change from prototype to jquery ASAP. So changing template.htm would be only a temporary necessary solution. And it seems he is willing to accept this inconvinience for not to clash with the jQuery4CMSimple coding conventions. (Thanks Jerry)

So I'd like to suggest to even make a small change in pluginloader, to guarantee that jQuery4CMSimple is loaded last (if installed). So we could avoid any clashes with older jquery libs, except that an old jquery version gets loaded after echo head(), in which case nothing can be done. :(

Sorry if I'm insistent in this case, but I'm hoping to release at least one other jQuery4CMSimple plugin in the future, so I want to avoid as many problems as possible.

If you think: we should not care about older jquery plugins, we could as well use another solution, to avoid conflicts with prototype.js ;)

Christoph

PS: Just seen I'm a little late with my post. But IMHO my arguments could count nevertheless.
Christoph M. Becker – Plugins for CMSimple_XH

jerry
Posts: 177
Joined: Fri Jul 25, 2008 8:54 pm
Location: Denmark
Contact:

Re: Coding convention for jQuery4CMSimple

Post by jerry » Thu Jun 30, 2011 10:53 pm

Hi Christoph
The older jQuery plugins will usually have a hardcoded call to jquery.js in template. For the same reason I have a hardcoded call to lightbox to avoid several call trough $hjs. Holger had the same solution in Gallery with Lightbox. So it was possible to have several plugins using the same framework.
Lightbox was a common way to show pictures and as the conflicts between frameworks is first discussed now then I don't think that jQuery was in use in CMSimple earlier except some tocs.

As jQuery4CMSimple takes account of other framework it is the best solution to load it at the very beginning of $hjs string as sugested by Holger. Then we know where we have it and it wil it possible to load other frameworks after jQuery.through $hjs or hardcoded in template.
jerry
jerry/simplesolutions

Post Reply