Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] JS function "getScript" conflict

JS function "getScript" conflict 12 Aug 2013 10:06 #10750

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
It's not a real bug, because if you install the jcook-generated component in a fresh standard joomla website, everything works perfectly.
But in the real world, this will not happen so often, usually you'll never use the default joomla templates or ONLY the default core components.
So I found out the following function, located in the ROOT\administrator\components\com_yourcomponent\dom\assets\ajax\js\ajax.js
(function($) {
	'use strict';
	 
	/**
	* Multiple parallel getScript
	* https://gist.github.com/vseventer/1378913
	* 
	* @access public
	* @param Array|String url (one or more URLs)
	* @param callback fn (oncomplete, optional)
	* @returns void
	*/
	var getScript = $.getScript;
	$.getScript = function(url, fn)
	{
		if(!$.isArray(url)) {//juggle type
			url = [url];
		}
		 
		$.when.apply(null, $.map(url, getScript)).done(function() {
			fn && fn();
		});
	};
 
}(jQuery));

sometimes has conflicts with other functions with the same name, last time this happened to me was with a yootheme template. I suggest to change the name of the function to something more uncommon, but this is my opinion, I let the admin think about it. by the way changing the function name solved me JS conflicts with that template, here what I replaced:
(function($) {
	'use strict';
	 
	/**
	* Multiple parallel getScript
	* https://gist.github.com/vseventer/1378913
	* 
	* @access public
	* @param Array|String url (one or more URLs)
	* @param callback fn (oncomplete, optional)
	* @returns void
	*/
	var JCookGetScript = $.JCookGetScript;
	$.JCookGetScript = function(url, fn)
	{
		if(!$.isArray(url)) {//juggle type
			url = [url];
		}
		 
		$.when.apply(null, $.map(url, JCookGetScript)).done(function() {
			fn && fn();
		});
	};
 
}(jQuery));

p.s.
obviously it's needed to change the function name on each place that function is called.
Last Edit: 12 Aug 2013 10:07 by Tomaselli.
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:12 #10757

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I cannot do what you suggest.

getScript() is the proper name because it is an override of a native jQuery function.

When JDom try to load a special control though ajax, jQuery.getScript() is called to load properly the scripts.
The problem is when multiple js files are required (never for the moment, but opened for it). so this function allows to getScript() to recieve array in parameter.

This function is only an override to be allowed to load multiple scripts at once, without waiting for cascading.

Well, you can rename this function, but modify also in JDom :
ajaxCallbackOnLoad() function is calling getScript()



I would like to see what error you have.

I think it is the yootheme template that cause the error.
Or, maybe getScript() native has changed but I cannot see anything on the web.
Coding is now a piece of cake
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:13 #10758

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
EDIT : Ok, I can call it :
$.getScripts() eventually
Coding is now a piece of cake
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:23 #10759

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
thanks for the reply, I didn't investigate too much about the getScript function, I just saw it had some conflict and I know yootheme developers doesn't follow often the joomla standards (I know for sure they are on the wrong side) but in the other hand I found easier to change the function name, and everythings seem to work, tomorrow I'll investigate a bit more.
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:26 #10760

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
....and yes, I renamed it anywhere in the jcook-generated component.
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:43 #10762

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed.

Enjoy ;-)
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

JS function "getScript" conflict 12 Aug 2013 13:44 #10763

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
great!
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:48 #10764

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
By the way, do not increminate YooTheme.
It is really painfull to follow all the standards when so many libraries are in use. For cook the same.

In this case it is not Joomla standard, but jQuery's standard.

And I want to say thanks again for the community because thank to you our products can evolve. I say 'our' because I imagine other developpers are facing the same issues and together we make it possible.

For this function, I only added 's' at the end of the function. Maybe one day jQuery will name a function such name, but for the moment it is what I retain because of naming conventions.
I do not like to write 'cook' or 'ck' in your creations variables or functions names (or Css,... you understand).
Coding is now a piece of cake
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:51 #10765

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
YooTheme is doing great job.

Almost never had problems or bugs with their huge creations. Worth every cent.
I highly recommend them by the way.
Coding is now a piece of cake
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:55 #10766

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
I like what they do, but I don't like how they code :-), I hate the template override system they use, even if I understand why they do in that way.
But I agree with you.
The administrator has disabled public write access.

JS function "getScript" conflict 12 Aug 2013 13:59 #10767

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Do you like Cook graphisms (XHTML, CSS...) ? lol...

Coder or developper... 2 schools.
Coding is now a piece of cake
The administrator has disabled public write access.

JS function "getScript" conflict 14 Aug 2013 08:50 #10774

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
Yes I do :-).....at the end, it doesn't really matter how the things are written.
The administrator has disabled public write access.
The following user(s) said Thank You: admin
Time to create page: 0.142 seconds

Get Started