Skip to content

Commit

Permalink
Merge pull request #13824 from colemanw/loadScriptCode
Browse files Browse the repository at this point in the history
Make cacheCode optional in CRM.loadScript
  • Loading branch information
eileenmcnaughton authored Mar 15, 2019
2 parents 60defb3 + 2bdce12 commit c948e0f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions js/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ if (!CRM.vars) CRM.vars = {};
};

var scriptsLoaded = {};
CRM.loadScript = function(url) {
CRM.loadScript = function(url, appendCacheCode) {
if (!scriptsLoaded[url]) {
var script = document.createElement('script');
var script = document.createElement('script'),
src = url;
if (appendCacheCode !== false) {
src += (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode;
}
scriptsLoaded[url] = $.Deferred();
script.onload = function () {
// Give the script time to execute
Expand All @@ -256,7 +260,7 @@ if (!CRM.vars) CRM.vars = {};
CRM.CMSjQuery = window.jQuery;
window.jQuery = CRM.$;
}
script.src = url + (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode;
script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
}
return scriptsLoaded[url];
Expand Down

0 comments on commit c948e0f

Please sign in to comment.