url.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
  2. * Apache-2.0 */
  3. var DEFAULT_VERSION = '4.23';
  4. var NEXT = 'next';
  5. export function parseVersion(version) {
  6. if (version.toLowerCase() === NEXT) {
  7. return NEXT;
  8. }
  9. var match = version && version.match(/^(\d)\.(\d+)/);
  10. return match && {
  11. major: parseInt(match[1], 10),
  12. minor: parseInt(match[2], 10)
  13. };
  14. }
  15. /**
  16. * Get the CDN url for a given version
  17. *
  18. * @param version Ex: '4.23' or '3.40'. Defaults to the latest 4.x version.
  19. */
  20. export function getCdnUrl(version) {
  21. if (version === void 0) { version = DEFAULT_VERSION; }
  22. return "https://js.arcgis.com/" + version + "/";
  23. }
  24. /**
  25. * Get the CDN url for a the CSS for a given version and/or theme
  26. *
  27. * @param version Ex: '4.23', '3.40', or 'next'. Defaults to the latest 4.x version.
  28. */
  29. export function getCdnCssUrl(version) {
  30. if (version === void 0) { version = DEFAULT_VERSION; }
  31. var baseUrl = getCdnUrl(version);
  32. var parsedVersion = parseVersion(version);
  33. if (parsedVersion !== NEXT && parsedVersion.major === 3) {
  34. // NOTE: at 3.11 the CSS moved from the /js folder to the root
  35. var path = parsedVersion.minor <= 10 ? 'js/' : '';
  36. return "" + baseUrl + path + "esri/css/esri.css";
  37. }
  38. else {
  39. // assume 4.x
  40. return baseUrl + "esri/themes/light/main.css";
  41. }
  42. }