Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Initial proof of concept for JavaScript libraries plugin #110

Closed
wants to merge 29 commits into
from

Conversation

Projects
None yet
3 participants
Member

jlleblanc commented Mar 3, 2012

This is a working proof of concept, with one major missing feature: Currently no way of designating libraries as CDN copies, nor is there any "CDN mode." We might possibly assume that anything beginning with 'http' is a CDN version, but then we will also need to keep track of the minimum local version and the minimum remote version.

@gnomeontherun gnomeontherun and 1 other commented on an outdated diff Mar 3, 2012

plugins/system/jslibs/jslibs.php
+{
+ /**
+ * A catalog of libraries and paths
+ *
+ * @var array
+ */
+ static public $libraries = array();
+
+ /**
+ * A quick and dirty check to see if jQuery has already been loaded.
+ * Assumes that jQuery is already loaded if a JavaScript file with the
+ * string 'jquery' is present.
+ *
+ * @return boolean
+ */
+ static public function jquery_loaded()
@gnomeontherun

gnomeontherun Mar 3, 2012

Owner

Couldn't we generalize this as a is_loaded() function with an arguement for library?

is_loaded('mootools') or is_loaded('jquery') for example, if we use the filenames as determinants for what the files contain.

@jlleblanc

jlleblanc Mar 3, 2012

Member

@gnomeontherun so here's the intent: the jQuery one is definitely a special case where we're cycling through the header and doing a brute lookup to make a determination. The MooTools one (if we add it) would be there to determine if Joomla has loaded its own copy of MooTools; this would be for replacing it with a CDN copy. In all other cases, we're counting on this plugin to catch on and people just use it rather than try to do a brute search.

As we discussed on the side, it would be a good idea to take the functionality of jquery_loaded() and generalize it as something like loaded('jquery'), which would allow you to specify the brute search term.

@jlleblanc

jlleblanc Mar 8, 2012

Member

I've now added a library_loaded() function that generalizes checking for libraries in the head section (among a few other features).

Member

jlleblanc commented Mar 10, 2012

Added a mechanism for automatically adding jQuery.noConflict() immediately after jQuery is loaded, as seen in www.designvsdevelop.com/jquery-in-joomla-i-was-wrong/

Owner

gnomeontherun commented Mar 10, 2012

Is there any reason you might want to not use noConflict and if another script already calls it is there any reason calling it more than once can hurt?

Adjusting mod_version in admin for Square One display
Makes an instance of mod_version by default (#112)
Makes current version info available, showing both Square One and Joomla versions (#108)
Member

jlleblanc commented Mar 10, 2012

Possibly. If you know for sure that you're not loading another library that uses $ (MooTools, Zepto, etc...), you might prefer to use $ instead of wrapping everything in a closure. You might also have some edge case where you need to debug and don't want to call noConflict.

I don't think calling it twice hurts, but the script is only being added once the manager confirms that jQuery hasn't already been loaded.

Regardless, I'll add a flag allowing someone to opt-out of noConflict().

On Mar 10, 2012, at 10:32 AM, Jeremy Wilken wrote:

Is there any reason you might want to not use noConflict and if another script already calls it is there any reason calling it more than once can hurt?


Reply to this email directly or view it on GitHub:
#110 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment