diff --git a/themes/common-theme/template/includes/GeoLocation.ftl b/themes/common-theme/template/includes/GeoLocation.ftl index 7803787bb7..c85f722891 100644 --- a/themes/common-theme/template/includes/GeoLocation.ftl +++ b/themes/common-theme/template/includes/GeoLocation.ftl @@ -16,11 +16,6 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -<#-- Define OpenLayers js and css tags to be added to html head tag when multi-block=true. --> - - <#if geoChart?has_content> <#-- ================================= Golbal Init ======================================--> <#if geoChart.id?has_content> @@ -120,62 +115,65 @@ under the License. <#elseif "GEOPT_OSM" == geoChart.dataSourceId>
#if> diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js index 7636760bab..cedceb6fd0 100644 --- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js +++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js @@ -1418,3 +1418,40 @@ function sendJWT(targetUrl) { }); } } + +var importLibrary = function() { + var importLibraryFiles = new Map(); + return function (urls, onSuccessFn, onErrorFn) { + function cachedScript(url, options) { + // Allow user to set any option except for dataType, cache, and url + options = $.extend(options || {}, { + dataType: "script", + cache: true, + url: url + }); + + // Use $.ajax() since it is more flexible than $.getScript + // Return the jqXHR object so we can chain callbacks + return jQuery.ajax(options); + }; + + jQuery.when.apply(jQuery, + jQuery.map(urls, function (url) { + if (!importLibraryFiles.has(url)) { + var deferObj = (url.endsWith(".css") ? + jQuery.get(url, function (css) { + jQuery("").appendTo("head"); + } + ) : + cachedScript(url)); + importLibraryFiles.set(url, deferObj); + return deferObj; + } else { + return importLibraryFiles.get(url); + } + }) + ).then(onSuccessFn).catch(onErrorFn || function () { + alert('Error loading one of the files: \n' + urls.join('\n')) + }); + } +}(); \ No newline at end of file