the problems with jQuery integration in CMSimple extensions is well know to the authors of extensions: version and namespace collisions with other extensions using jQuery or another js framework.
A really helpful invention is the jQuery4CMSimple plugin, which will help to avoid problems with different versions of jQuery used by different extensions, because they all could rely on a single jQuery version brought by jQuery4CMSimple. But this only works, if all existing CMSimple extensions using jQuery will be rewritten accordingly and distributed ASAP.
in the following I'll try to summarize yesterdays discussion about using the jQuery Framework from CMSimple extensions. The discussions were spread over the following threads:
jQuery integration
[New Plugin] jQuery4CMSimple
New plugin: Pagemanager_XH
Pagemanager_XH 0.3
I will quote without refering to the appropriate thread.
But one problem remains: namespace collisions. So I want to propose that we all agree on a coding convention for jQuery4CMSimple with regard to $. This could be added to jQuery4CMSimple's documentation.
If you use jQuery, you usually use the shorthand $ instead of the full name of the function jQuery. But the $ collides with other js framework as e.g. prototype.js. To avoid this there exists jQuery.noConflict(). Calling this function will remove jQuerys definition of $ from the global namespace, so that you have to call jQuery instead. It even has a return value that you can assign to a variable of your choice, e.g.
Code: Select all
var jq = jQuery.noConflict();
Now the IMO important question is: shall we avoid the use of $ altogether, to allow inclusion of other js frameworks, or shall we postulate, that only jQuery shall be used with CMSimple?
Holger wrote: But from my point of view the whole no.Conflict() thing is not needed, because I'll not prefer more than one JS-Framework on the same installation.
Even if I fully agree that one js framework should be enough for a website, I think it's in the open spirit of CMSimple to allow users to do what they want, even if they want to include 100 different frameworks (the resulting performance problems will be their's).Martin wrote: Although I am really convinced that there is absolutely no need to use more than one js-framework in one CMSimple installation, you can't rely on other plugin authors or users with a faible for all kind of plugins
So I recommend to not use $ at all; that is the most compatible way. If we agree on this solution, the call to jQuery.noConflict() could easily be added to jQuery4CMSimple.
Some of you may think: oh no, I have to rewrite all my code that uses $, or even worse: my code uses another jQuery plugin that depends on $. I can't use my plugin any more.
But thanks to js closures (and Martin, who came up with this idea) it is possible to avoid this problem, if you use:
Code: Select all
(function ($) {
// your old code using $ goes here
})(jQuery)
I want to add: and how much time they consume.Martin wrote: But I have to admit, I have no idea what is the content of a, b and c and how much memory they consume
Until it's definitely clear, that the overhead of using noConflict() multiple time is absolutely negletable (it may seem so, because the code uses only 1-2 reference assignments, but I'm not sure if heavy cloning may happen behind the scenes, when other jQuery functions are called; BTW: I'm very knew to js), I suggest, the best is to avoid the usage of jQuery shorthands and use jQuery instead. The overhead of Martins renaming closure suggestion should be the same, and so should better be avoided unless necessary.
Perhaps an advanced Javascript programmer could clear up this point to me and others, please.
I'm really looking forward to read your thoughts on this, so at least a convention concerning the use of $ could be found. The use of additional renaming of jQuery finally is the authors decission.
Regards,
Christoph