{"id":1149,"date":"2013-07-09T20:07:00","date_gmt":"2013-07-09T18:07:00","guid":{"rendered":"http:\/\/www.kavdesign.net\/blog\/?p=1149"},"modified":"2013-07-10T14:37:58","modified_gmt":"2013-07-10T12:37:58","slug":"joomla-3-0-and-loading-jquery","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/coding\/joomla-3-0-and-loading-jquery\/","title":{"rendered":"Joomla! 3.0 and loading jQuery \/ Migrate Joomla template from 2.5 to 3.1"},"content":{"rendered":"<p><strong>If you need to migrate yout Joomla template from Joomla 2.5 to Joomla 3.0 or 3.1 maybe you will need this info as I did.<\/strong><\/p>\n<p>The Joomla! 3.0 core ships with jQuery, and previous Joomla! versions did not. Extension developers like us therefor included a custom call to load jQuery in the past, whenever it was needed. However this standard needs updating. Here&#8217;s our proposal.<\/p>\n<h3>Loading jQuery only once<\/h3>\n<p>Because jQuery could be loaded in the past more than 1 time (and loading jQuery twice leads to unwanted errors, plus it makes no sense to load it twice), extension developers more or less agreed to use a flag in the Joomla! application-class:<\/p>\n<pre>$loaded = JFactory::getApplication()-&gt;get('jquery');<\/pre>\n<p>If the flag was not yet loaded, it could simply be loaded by your own extension, after which the flag needed to be set for other extensions to pick up on:<\/p>\n<pre>JFactory::getApplication()-&gt;set('jquery', true);<\/pre>\n<h3>Joomla! 3.0 changes this<\/h3>\n<p>The Joomla! 3.0 core changes the JApplication-class in such a way that the get() and set() methods can no longer be used &#8211; the class no longer extends the JObject class which provided these methods. Simply put: Using the code above under Joomla! 3.0 throws a PHP Fatal Error.<\/p>\n<p>But Joomla! 3.0 has also introduced jQuery as a core feature. Third party extensions no longer require to load jQuery, because it is already shipped with Joomla!. The only thing that extensions require is a simple call to the JHtml-class:<\/p>\n<pre>JHtml::_('jquery.framework');<\/pre>\n<h3>Code proposal<\/h3>\n<p>So what is our proposal? Simple: Use the old method for Joomla! 2.5 and older, and use the new method for Joomla! 3.0. The version of Joomla! can be checked using framework-calls as well, so the code would look a bit like this:<\/p>\n<pre>JLoader::import( 'joomla.version' );\r\n$version = new JVersion();\r\nif (version_compare( $version-&gt;RELEASE, '2.5', '&lt;=')) {\r\n    if(JFactory::getApplication()-&gt;get('jquery') !== true) {\r\n        \/\/ load jQuery here\r\n        JFactory::getApplication()-&gt;set('jquery', true);\r\n    }\r\n} else {\r\n    JHtml::_('jquery.framework');\r\n}<\/pre>\n<p>Original article &#8211; http:\/\/www.yireo.com\/blog\/1556-joomla-30-and-loading-jquery<\/p>\n<p>Full list of possible conflicts between Joomla 2.5 and Joomla 3.x here &#8211; <a href=\"http:\/\/docs.joomla.org\/Potential_backward_compatibility_issues_in_Joomla_3_and_Joomla_Platform_12.2\" target=\"_blank\">http:\/\/docs.joomla.org\/Potential_backward_compatibility_issues_in_Joomla_3_and_Joomla_Platform_12.2<\/a><\/p>\n<p>Probably there are more things to know when migrating Joomla Templates from 2.5 to 3.x and if somebody get something please post a comment to this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to migrate yout Joomla template from Joomla 2.5 to Joomla 3.0 or 3.1 maybe you will need this info as I did.&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.kavdesign.net\/blog\/coding\/joomla-3-0-and-loading-jquery\/\">Continue reading<span class=\"screen-reader-text\">Joomla! 3.0 and loading jQuery \/ Migrate Joomla template from 2.5 to 3.1<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9,29],"tags":[250,319,318,417,320,35],"class_list":["post-1149","post","type-post","status-publish","format-standard","hentry","category-coding","category-joomla","tag-2-5","tag-3-0","tag-3-1","tag-joomla","tag-migrate","tag-template","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=1149"}],"version-history":[{"count":8,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1149\/revisions"}],"predecessor-version":[{"id":1157,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1149\/revisions\/1157"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}