Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\Utils\url.js

  1. /* global define */
  2.  
  3. /**
  4. * Utility module containint useful static classes.
  5. *
  6. * @module Utils
  7. * @uses dojo/_base/declare
  8. * @uses dojo/io-query
  9. */
  10.  
  11. define(["dojo/_base/declare", "dojo/io-query"],
  12. function (declare, dojoQuery) {
  13. "use strict";
  14. return declare(null, {
  15. /**
  16. * A simple class that replaces the `dojo._Url` functionality that became deprecated
  17. * Construct a Url object from a url string, then the uri and query
  18. * part of the url string can be accessed from the Url's uri and query
  19. * field respectively.
  20. *
  21. * #####Example
  22. *
  23. * require(["scripts/Url"], function(Url) {
  24. * var urlObj = new Url("http://somewebsite.com");
  25. *
  26. * // Access the uri and query using the urlObj's fields
  27. * var uri = urlObj.uri;
  28. * var query = urlObj.query;
  29. * });
  30. *
  31. * @class Url
  32. * @constructor
  33. * @param {String} fullUrl a string denoting the full url of a webpage
  34. * @uses dojo/_base/declare
  35. * @uses dojo/io-query
  36. */
  37. constructor: function (fullUrl) {
  38. var index = fullUrl.indexOf('?');
  39.  
  40. if (index === -1) {
  41. this.uri = fullUrl;
  42. this.query = "";
  43. } else {
  44. this.uri = fullUrl.substring(0, index);
  45. this.query = fullUrl.substring(index + 1);
  46. }
  47. this.queryObject = dojoQuery.queryToObject(this.query);
  48. }
  49. });
  50. });