ds/UrlSettings.js

  1. /**
  2. * @fileoverview Exposed data type for use outside of DsClient.
  3. * All properties should be exposed to allow use from uncompiled
  4. * code.
  5. *
  6. * @author anders.rejdebrant@spark-vision.com (Anders Rejdebrant)
  7. */
  8. goog.provide('spv.ds.UrlSettings');
  9. /**
  10. * Base URLs needed for most GET operations for images etc.
  11. *
  12. * @struct
  13. * @constructor
  14. * @param {string} gui_url
  15. * @param {string} icon_url
  16. * @param {string} composed_url
  17. * @param {string} readmore_content_url
  18. * @param {string} summary_content_url
  19. */
  20. spv.ds.UrlSettings = function(
  21. gui_url,
  22. icon_url,
  23. composed_url,
  24. readmore_content_url,
  25. summary_content_url)
  26. {
  27. /**
  28. * @nocollapse
  29. * @type {string}
  30. */
  31. this.gui_url = spv.ds.UrlSettings.urlFix( gui_url );
  32. /**
  33. * @nocollapse
  34. * @type {string}
  35. */
  36. this.icon_url = spv.ds.UrlSettings.urlFix( icon_url );
  37. /**
  38. * @nocollapse
  39. * @type {string}
  40. */
  41. this.composed_url = spv.ds.UrlSettings.urlFix( composed_url );
  42. /**
  43. * @nocollapse
  44. * @type {string}
  45. */
  46. this.readmore_content_url = spv.ds.UrlSettings.urlFix( readmore_content_url );
  47. /**
  48. * @nocollapse
  49. * @type {string}
  50. */
  51. this.summary_content_url = spv.ds.UrlSettings.urlFix( summary_content_url );
  52. };
  53. /**
  54. * @param {string} url
  55. * @return {string}
  56. */
  57. spv.ds.UrlSettings.urlFix = function( url )
  58. {
  59. // A bit of a hack. The backend can't always return https due to the proxy.
  60. if( location.protocol == "https:" )
  61. {
  62. var protocol_i = url.indexOf(":");
  63. if( protocol_i != -1 )
  64. url = "https:" + url.substring( protocol_i+1 );
  65. }
  66. return spv.ds.UrlSettings.enforceEndSlash( url );
  67. }
  68. /**
  69. * @param {string} url
  70. * @return {string}
  71. */
  72. spv.ds.UrlSettings.enforceEndSlash = function( url )
  73. {
  74. var ends_with_slash = url.length > 0 && url[ url.length - 1 ] === '/';
  75. if( ends_with_slash )
  76. {
  77. return url;
  78. }
  79. else
  80. {
  81. return url + '/';
  82. }
  83. };