esri-loader
Version:
A tiny library to help load ArcGIS API for JavaScript modules in non-Dojo applications
43 lines (42 loc) • 1.39 kB
JavaScript
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
var DEFAULT_VERSION = '4.13';
var NEXT = 'next';
export function parseVersion(version) {
if (version.toLowerCase() === NEXT) {
return NEXT;
}
var match = version && version.match(/^(\d)\.(\d+)/);
return match && {
major: parseInt(match[1], 10),
minor: parseInt(match[2], 10)
};
}
/**
* Get the CDN url for a given version
*
* @param version Ex: '4.13' or '3.30'. Defaults to the latest 4.x version.
*/
export function getCdnUrl(version) {
if (version === void 0) { version = DEFAULT_VERSION; }
return "https://js.arcgis.com/" + version + "/";
}
/**
* Get the CDN url for a the CSS for a given version and/or theme
*
* @param version Ex: '4.13', '3.30', or 'next'. Defaults to the latest 4.x version.
*/
export function getCdnCssUrl(version) {
if (version === void 0) { version = DEFAULT_VERSION; }
var baseUrl = getCdnUrl(version);
var parsedVersion = parseVersion(version);
if (parsedVersion !== NEXT && parsedVersion.major === 3) {
// NOTE: at 3.11 the CSS moved from the /js folder to the root
var path = parsedVersion.minor <= 10 ? 'js/' : '';
return "" + baseUrl + path + "esri/css/esri.css";
}
else {
// assume 4.x
return baseUrl + "esri/themes/light/main.css";
}
}