spree_frontend 4.2.3.1 → 4.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/config/spree_frontend_manifest.js +4 -0
  4. data/app/assets/images/card-image.svg +4 -0
  5. data/app/assets/images/file-image.svg +4 -0
  6. data/app/assets/images/image.svg +4 -0
  7. data/app/assets/images/noimage/large.png +0 -0
  8. data/app/assets/images/noimage/mini.png +0 -0
  9. data/app/assets/images/noimage/plp.svg +23 -0
  10. data/app/assets/images/noimage/product.png +0 -0
  11. data/app/assets/images/noimage/small.png +0 -0
  12. data/app/assets/javascripts/spree/api/main.js +36 -0
  13. data/app/assets/javascripts/spree/api/storefront/cart.js +49 -0
  14. data/app/assets/javascripts/spree/frontend/checkout/payment.js +18 -5
  15. data/app/assets/javascripts/spree/frontend/checkout.js +16 -0
  16. data/app/assets/javascripts/spree/frontend/currency.js +11 -9
  17. data/app/assets/javascripts/spree/frontend/locale.es6 +13 -0
  18. data/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js +3 -3
  19. data/app/assets/javascripts/spree/frontend/views/spree/products/index.js +0 -9
  20. data/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6 +46 -0
  21. data/app/assets/javascripts/spree/frontend.js +3 -0
  22. data/app/assets/javascripts/spree.js +78 -0
  23. data/app/assets/stylesheets/spree/frontend/application.scss +1 -0
  24. data/app/assets/stylesheets/spree/frontend/components-bootstrap/button.scss +8 -0
  25. data/app/assets/stylesheets/spree/frontend/helpers/spree/frontend_helper.scss +41 -0
  26. data/app/assets/stylesheets/spree/frontend/variables/variables.scss +2 -2
  27. data/app/assets/stylesheets/spree/frontend/views/spree/checkout/edit.scss +17 -5
  28. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/_index.scss +1 -0
  29. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/product_buy_bar.scss +20 -0
  30. data/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss +54 -67
  31. data/app/assets/stylesheets/spree/frontend/views/spree/shared/category_nav_bar.scss +3 -3
  32. data/app/assets/stylesheets/spree/frontend/views/spree/shared/footer.scss +4 -0
  33. data/app/assets/stylesheets/spree/frontend/views/spree/shared/main_nav_bar.scss +12 -1
  34. data/app/controllers/spree/addresses_controller.rb +14 -19
  35. data/app/controllers/spree/checkout_controller.rb +5 -3
  36. data/app/controllers/spree/cms_pages_controller.rb +29 -0
  37. data/app/controllers/spree/content_controller.rb +0 -2
  38. data/app/controllers/spree/errors_controller.rb +11 -0
  39. data/app/controllers/spree/home_controller.rb +34 -1
  40. data/app/controllers/spree/locale_controller.rb +7 -1
  41. data/app/controllers/spree/orders_controller.rb +9 -7
  42. data/app/controllers/spree/products_controller.rb +14 -13
  43. data/app/controllers/spree/store_controller.rb +25 -1
  44. data/app/controllers/spree/taxons_controller.rb +12 -5
  45. data/app/helpers/spree/addresses_helper.rb +9 -4
  46. data/app/helpers/spree/cms_pages_helper.rb +23 -0
  47. data/app/helpers/spree/frontend_helper.rb +109 -10
  48. data/app/helpers/spree/navigation_helper.rb +73 -4
  49. data/app/helpers/spree/products_filters_helper.rb +168 -0
  50. data/app/helpers/spree/store_helper.rb +3 -1
  51. data/app/views/spree/checkout/_address.html.erb +1 -1
  52. data/app/views/spree/checkout/_credit_card.html.erb +1 -0
  53. data/app/views/spree/cms_pages/show.html.erb +16 -0
  54. data/app/views/spree/errors/forbidden.html.erb +0 -0
  55. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  56. data/app/views/spree/home/index.html.erb +19 -118
  57. data/app/views/spree/layouts/spree_application.html.erb +2 -2
  58. data/app/views/spree/products/_description.html.erb +16 -19
  59. data/app/views/spree/products/_filters_desktop.html.erb +50 -15
  60. data/app/views/spree/products/_filters_mobile.html.erb +38 -10
  61. data/app/views/spree/products/_sort_desktop.html.erb +17 -11
  62. data/app/views/spree/products/_sort_mobile.html.erb +16 -0
  63. data/app/views/spree/products/index.html.erb +1 -1
  64. data/app/views/spree/shared/_carousel_4_products.html.erb +8 -8
  65. data/app/views/spree/shared/_checkout_header.html.erb +22 -21
  66. data/app/views/spree/shared/_copyright.html.erb +1 -1
  67. data/app/views/spree/shared/_footer.html.erb +18 -12
  68. data/app/views/spree/shared/_head.html.erb +1 -1
  69. data/app/views/spree/shared/_header.html.erb +3 -3
  70. data/app/views/spree/shared/_main_nav_bar.html.erb +61 -43
  71. data/app/views/spree/shared/_mobile_navigation.html.erb +30 -19
  72. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  73. data/app/views/spree/shared/_option_values.html.erb +2 -21
  74. data/app/views/spree/shared/_order_details.html.erb +1 -1
  75. data/app/views/spree/shared/_paths.html.erb +8 -0
  76. data/app/views/spree/shared/_properties.html.erb +4 -0
  77. data/app/views/spree/shared/_translations.html.erb +2 -1
  78. data/app/views/spree/shared/carousel/_single.html.erb +1 -1
  79. data/app/views/spree/shared/carousel/_thumbnails.html.erb +1 -1
  80. data/app/views/spree/shared/cms/pages/_edit_mode.html.erb +13 -0
  81. data/app/views/spree/shared/cms/sections/_featured_article.html.erb +27 -0
  82. data/app/views/spree/shared/cms/sections/_hero_image.html.erb +60 -0
  83. data/app/views/spree/shared/cms/sections/_image_gallery.html.erb +171 -0
  84. data/app/views/spree/shared/cms/sections/_product_carousel.html.erb +5 -0
  85. data/app/views/spree/shared/cms/sections/_rich_text_content.html.erb +3 -0
  86. data/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb +118 -0
  87. data/app/views/spree/taxons/_header.html.erb +6 -1
  88. data/app/views/spree/users/show.html.erb +4 -1
  89. data/config/initializers/assets.rb +4 -13
  90. data/config/routes.rb +9 -3
  91. data/lib/generators/spree/frontend/install/install_generator.rb +5 -5
  92. data/lib/generators/spree/frontend/install/templates/app/assets/config/manifest.js +2 -0
  93. data/lib/generators/spree/frontend/install/templates/vendor/assets/javascripts/spree/frontend/all.js +8 -0
  94. data/lib/generators/spree/frontend/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +9 -0
  95. data/lib/spree/frontend/engine.rb +6 -0
  96. data/lib/spree/frontend.rb +6 -3
  97. data/spec/fixtures/files/store_favicon.ico +0 -0
  98. data/spree_frontend.gemspec +13 -9
  99. data/vendor/assets/javascripts/cleave.js +8 -0
  100. data/vendor/assets/javascripts/fetch.umd.js +531 -0
  101. data/vendor/assets/javascripts/jquery.payment.js +652 -0
  102. data/vendor/assets/javascripts/jsuri.js +458 -0
  103. data/vendor/assets/javascripts/polyfill.min.js +1 -0
  104. metadata +132 -86
  105. data/app/assets/images/homepage/big_category_banner.jpg +0 -0
  106. data/app/assets/images/homepage/big_category_banner_mobile.jpg +0 -0
  107. data/app/assets/images/homepage/big_category_banner_tablet_landscape.jpg +0 -0
  108. data/app/assets/images/homepage/big_category_banner_tablet_portrait.jpg +0 -0
  109. data/app/assets/images/homepage/category_banner_lower.jpg +0 -0
  110. data/app/assets/images/homepage/category_banner_lower_mobile.jpg +0 -0
  111. data/app/assets/images/homepage/category_banner_lower_tablet_landscape.jpg +0 -0
  112. data/app/assets/images/homepage/category_banner_lower_tablet_portrait.jpg +0 -0
  113. data/app/assets/images/homepage/category_banner_upper.jpg +0 -0
  114. data/app/assets/images/homepage/category_banner_upper_mobile.jpg +0 -0
  115. data/app/assets/images/homepage/category_banner_upper_tablet_landscape.jpg +0 -0
  116. data/app/assets/images/homepage/category_banner_upper_tablet_portrait.jpg +0 -0
  117. data/app/assets/images/homepage/main_banner.jpg +0 -0
  118. data/app/assets/images/homepage/main_banner_mobile.jpg +0 -0
  119. data/app/assets/images/homepage/main_banner_tablet_landscape.jpg +0 -0
  120. data/app/assets/images/homepage/main_banner_tablet_portrait.jpg +0 -0
  121. data/app/assets/images/homepage/promo_banner_left.jpg +0 -0
  122. data/app/assets/images/homepage/promo_banner_left_mobile.jpg +0 -0
  123. data/app/assets/images/homepage/promo_banner_left_tablet_landscape.jpg +0 -0
  124. data/app/assets/images/homepage/promo_banner_left_tablet_portrait.jpg +0 -0
  125. data/app/assets/images/homepage/promo_banner_right.jpg +0 -0
  126. data/app/assets/images/homepage/promo_banner_right_mobile.jpg +0 -0
  127. data/app/assets/images/homepage/promo_banner_right_tablet_landscape.jpg +0 -0
  128. data/app/assets/images/homepage/promo_banner_right_tablet_portrait.jpg +0 -0
  129. data/app/assets/images/meganav/promo_banner_left-first-category.jpg +0 -0
  130. data/app/assets/images/meganav/promo_banner_left-second-category.jpg +0 -0
  131. data/app/assets/images/meganav/promo_banner_left-third-category.jpg +0 -0
  132. data/app/assets/images/meganav/promo_banner_right-first-category.jpg +0 -0
  133. data/app/assets/images/meganav/promo_banner_right-second-category.jpg +0 -0
  134. data/app/assets/images/meganav/promo_banner_right-third-category.jpg +0 -0
  135. data/app/assets/images/noimage/big_category_banner.jpg +0 -0
  136. data/app/assets/images/noimage/big_category_banner_mobile.jpg +0 -0
  137. data/app/assets/images/noimage/big_category_banner_tablet_landscape.jpg +0 -0
  138. data/app/assets/images/noimage/big_category_banner_tablet_portrait.jpg +0 -0
  139. data/app/assets/images/noimage/category_banner.jpg +0 -0
  140. data/app/assets/images/noimage/category_banner_mobile.jpg +0 -0
  141. data/app/assets/images/noimage/category_banner_plp.jpg +0 -0
  142. data/app/assets/images/noimage/category_banner_tablet_landscape.jpg +0 -0
  143. data/app/assets/images/noimage/category_banner_tablet_portrait.jpg +0 -0
  144. data/app/assets/images/noimage/main_banner.jpg +0 -0
  145. data/app/assets/images/noimage/main_banner_mobile.jpg +0 -0
  146. data/app/assets/images/noimage/main_banner_tablet_landscape.jpg +0 -0
  147. data/app/assets/images/noimage/main_banner_tablet_portrait.jpg +0 -0
  148. data/app/assets/images/noimage/product_photo.jpg +0 -0
  149. data/app/assets/images/noimage/promo_banner.jpg +0 -0
  150. data/app/assets/images/noimage/promo_banner_megamenu.jpg +0 -0
  151. data/app/assets/images/noimage/promo_banner_mobile.jpg +0 -0
  152. data/app/assets/images/noimage/promo_banner_tablet_landscape.jpg +0 -0
  153. data/app/assets/images/noimage/promo_banner_tablet_portrait.jpg +0 -0
  154. data/app/assets/javascripts/spree/frontend/locale.js +0 -13
  155. data/app/assets/javascripts/spree/frontend/multi_currency.js +0 -13
  156. data/lib/generators/spree/frontend/install/templates/config/initializers/spree_storefront.rb +0 -1
  157. data/lib/generators/spree/frontend/install/templates/config/spree_storefront.yml +0 -99
@@ -0,0 +1,458 @@
1
+ /*!
2
+ * jsUri
3
+ * https://github.com/derek-watson/jsUri
4
+ *
5
+ * Copyright 2013, Derek Watson
6
+ * Released under the MIT license.
7
+ *
8
+ * Includes parseUri regular expressions
9
+ * http://blog.stevenlevithan.com/archives/parseuri
10
+ * Copyright 2007, Steven Levithan
11
+ * Released under the MIT license.
12
+ */
13
+
14
+ /*globals define, module */
15
+
16
+ (function(global) {
17
+
18
+ var re = {
19
+ starts_with_slashes: /^\/+/,
20
+ ends_with_slashes: /\/+$/,
21
+ pluses: /\+/g,
22
+ query_separator: /[&;]/,
23
+ uri_parser: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*)(?::([^:@]*))?)?@)?(\[[0-9a-fA-F:.]+\]|[^:\/?#]*)(?::(\d+|(?=:)))?(:)?)((((?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
24
+ };
25
+
26
+ /**
27
+ * Define forEach for older js environments
28
+ * @see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach#Compatibility
29
+ */
30
+ if (!Array.prototype.forEach) {
31
+ Array.prototype.forEach = function(callback, thisArg) {
32
+ var T, k;
33
+
34
+ if (this == null) {
35
+ throw new TypeError(' this is null or not defined');
36
+ }
37
+
38
+ var O = Object(this);
39
+ var len = O.length >>> 0;
40
+
41
+ if (typeof callback !== "function") {
42
+ throw new TypeError(callback + ' is not a function');
43
+ }
44
+
45
+ if (arguments.length > 1) {
46
+ T = thisArg;
47
+ }
48
+
49
+ k = 0;
50
+
51
+ while (k < len) {
52
+ var kValue;
53
+ if (k in O) {
54
+ kValue = O[k];
55
+ callback.call(T, kValue, k, O);
56
+ }
57
+ k++;
58
+ }
59
+ };
60
+ }
61
+
62
+ /**
63
+ * unescape a query param value
64
+ * @param {string} s encoded value
65
+ * @return {string} decoded value
66
+ */
67
+ function decode(s) {
68
+ if (s) {
69
+ s = s.toString().replace(re.pluses, '%20');
70
+ s = decodeURIComponent(s);
71
+ }
72
+ return s;
73
+ }
74
+
75
+ /**
76
+ * Breaks a uri string down into its individual parts
77
+ * @param {string} str uri
78
+ * @return {object} parts
79
+ */
80
+ function parseUri(str) {
81
+ var parser = re.uri_parser;
82
+ var parserKeys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "isColonUri", "relative", "path", "directory", "file", "query", "anchor"];
83
+ var m = parser.exec(str || '');
84
+ var parts = {};
85
+
86
+ parserKeys.forEach(function(key, i) {
87
+ parts[key] = m[i] || '';
88
+ });
89
+
90
+ return parts;
91
+ }
92
+
93
+ /**
94
+ * Breaks a query string down into an array of key/value pairs
95
+ * @param {string} str query
96
+ * @return {array} array of arrays (key/value pairs)
97
+ */
98
+ function parseQuery(str) {
99
+ var i, ps, p, n, k, v, l;
100
+ var pairs = [];
101
+
102
+ if (typeof(str) === 'undefined' || str === null || str === '') {
103
+ return pairs;
104
+ }
105
+
106
+ if (str.indexOf('?') === 0) {
107
+ str = str.substring(1);
108
+ }
109
+
110
+ ps = str.toString().split(re.query_separator);
111
+
112
+ for (i = 0, l = ps.length; i < l; i++) {
113
+ p = ps[i];
114
+ n = p.indexOf('=');
115
+
116
+ if (n !== 0) {
117
+ k = decode(p.substring(0, n));
118
+ v = decode(p.substring(n + 1));
119
+ pairs.push(n === -1 ? [p, null] : [k, v]);
120
+ }
121
+
122
+ }
123
+ return pairs;
124
+ }
125
+
126
+ /**
127
+ * Creates a new Uri object
128
+ * @constructor
129
+ * @param {string} str
130
+ */
131
+ function Uri(str) {
132
+ this.uriParts = parseUri(str);
133
+ this.queryPairs = parseQuery(this.uriParts.query);
134
+ this.hasAuthorityPrefixUserPref = null;
135
+ }
136
+
137
+ /**
138
+ * Define getter/setter methods
139
+ */
140
+ ['protocol', 'userInfo', 'host', 'port', 'path', 'anchor'].forEach(function(key) {
141
+ Uri.prototype[key] = function(val) {
142
+ if (typeof val !== 'undefined') {
143
+ this.uriParts[key] = val;
144
+ }
145
+ return this.uriParts[key];
146
+ };
147
+ });
148
+
149
+ /**
150
+ * if there is no protocol, the leading // can be enabled or disabled
151
+ * @param {Boolean} val
152
+ * @return {Boolean}
153
+ */
154
+ Uri.prototype.hasAuthorityPrefix = function(val) {
155
+ if (typeof val !== 'undefined') {
156
+ this.hasAuthorityPrefixUserPref = val;
157
+ }
158
+
159
+ if (this.hasAuthorityPrefixUserPref === null) {
160
+ return (this.uriParts.source.indexOf('//') !== -1);
161
+ } else {
162
+ return this.hasAuthorityPrefixUserPref;
163
+ }
164
+ };
165
+
166
+ Uri.prototype.isColonUri = function (val) {
167
+ if (typeof val !== 'undefined') {
168
+ this.uriParts.isColonUri = !!val;
169
+ } else {
170
+ return !!this.uriParts.isColonUri;
171
+ }
172
+ };
173
+
174
+ /**
175
+ * Serializes the internal state of the query pairs
176
+ * @param {string} [val] set a new query string
177
+ * @return {string} query string
178
+ */
179
+ Uri.prototype.query = function(val) {
180
+ var s = '', i, param, l;
181
+
182
+ if (typeof val !== 'undefined') {
183
+ this.queryPairs = parseQuery(val);
184
+ }
185
+
186
+ for (i = 0, l = this.queryPairs.length; i < l; i++) {
187
+ param = this.queryPairs[i];
188
+ if (s.length > 0) {
189
+ s += '&';
190
+ }
191
+ if (param[1] === null) {
192
+ s += param[0];
193
+ } else {
194
+ s += param[0];
195
+ s += '=';
196
+ if (typeof param[1] !== 'undefined') {
197
+ s += encodeURIComponent(param[1]);
198
+ }
199
+ }
200
+ }
201
+ return s.length > 0 ? '?' + s : s;
202
+ };
203
+
204
+ /**
205
+ * returns the first query param value found for the key
206
+ * @param {string} key query key
207
+ * @return {string} first value found for key
208
+ */
209
+ Uri.prototype.getQueryParamValue = function (key) {
210
+ var param, i, l;
211
+ for (i = 0, l = this.queryPairs.length; i < l; i++) {
212
+ param = this.queryPairs[i];
213
+ if (key === param[0]) {
214
+ return param[1];
215
+ }
216
+ }
217
+ };
218
+
219
+ /**
220
+ * returns an array of query param values for the key
221
+ * @param {string} key query key
222
+ * @return {array} array of values
223
+ */
224
+ Uri.prototype.getQueryParamValues = function (key) {
225
+ var arr = [], i, param, l;
226
+ for (i = 0, l = this.queryPairs.length; i < l; i++) {
227
+ param = this.queryPairs[i];
228
+ if (key === param[0]) {
229
+ arr.push(param[1]);
230
+ }
231
+ }
232
+ return arr;
233
+ };
234
+
235
+ /**
236
+ * removes query parameters
237
+ * @param {string} key remove values for key
238
+ * @param {val} [val] remove a specific value, otherwise removes all
239
+ * @return {Uri} returns self for fluent chaining
240
+ */
241
+ Uri.prototype.deleteQueryParam = function (key, val) {
242
+ var arr = [], i, param, keyMatchesFilter, valMatchesFilter, l;
243
+
244
+ for (i = 0, l = this.queryPairs.length; i < l; i++) {
245
+
246
+ param = this.queryPairs[i];
247
+ keyMatchesFilter = decode(param[0]) === decode(key);
248
+ valMatchesFilter = param[1] === val;
249
+
250
+ if ((arguments.length === 1 && !keyMatchesFilter) || (arguments.length === 2 && (!keyMatchesFilter || !valMatchesFilter))) {
251
+ arr.push(param);
252
+ }
253
+ }
254
+
255
+ this.queryPairs = arr;
256
+
257
+ return this;
258
+ };
259
+
260
+ /**
261
+ * adds a query parameter
262
+ * @param {string} key add values for key
263
+ * @param {string} val value to add
264
+ * @param {integer} [index] specific index to add the value at
265
+ * @return {Uri} returns self for fluent chaining
266
+ */
267
+ Uri.prototype.addQueryParam = function (key, val, index) {
268
+ if (arguments.length === 3 && index !== -1) {
269
+ index = Math.min(index, this.queryPairs.length);
270
+ this.queryPairs.splice(index, 0, [key, val]);
271
+ } else if (arguments.length > 0) {
272
+ this.queryPairs.push([key, val]);
273
+ }
274
+ return this;
275
+ };
276
+
277
+ /**
278
+ * test for the existence of a query parameter
279
+ * @param {string} key check values for key
280
+ * @return {Boolean} true if key exists, otherwise false
281
+ */
282
+ Uri.prototype.hasQueryParam = function (key) {
283
+ var i, len = this.queryPairs.length;
284
+ for (i = 0; i < len; i++) {
285
+ if (this.queryPairs[i][0] == key)
286
+ return true;
287
+ }
288
+ return false;
289
+ };
290
+
291
+ /**
292
+ * replaces query param values
293
+ * @param {string} key key to replace value for
294
+ * @param {string} newVal new value
295
+ * @param {string} [oldVal] replace only one specific value (otherwise replaces all)
296
+ * @return {Uri} returns self for fluent chaining
297
+ */
298
+ Uri.prototype.replaceQueryParam = function (key, newVal, oldVal) {
299
+ var index = -1, len = this.queryPairs.length, i, param;
300
+
301
+ if (arguments.length === 3) {
302
+ for (i = 0; i < len; i++) {
303
+ param = this.queryPairs[i];
304
+ if (decode(param[0]) === decode(key) && decodeURIComponent(param[1]) === decode(oldVal)) {
305
+ index = i;
306
+ break;
307
+ }
308
+ }
309
+ if (index >= 0) {
310
+ this.deleteQueryParam(key, decode(oldVal)).addQueryParam(key, newVal, index);
311
+ }
312
+ } else {
313
+ for (i = 0; i < len; i++) {
314
+ param = this.queryPairs[i];
315
+ if (decode(param[0]) === decode(key)) {
316
+ index = i;
317
+ break;
318
+ }
319
+ }
320
+ this.deleteQueryParam(key);
321
+ this.addQueryParam(key, newVal, index);
322
+ }
323
+ return this;
324
+ };
325
+
326
+ /**
327
+ * Define fluent setter methods (setProtocol, setHasAuthorityPrefix, etc)
328
+ */
329
+ ['protocol', 'hasAuthorityPrefix', 'isColonUri', 'userInfo', 'host', 'port', 'path', 'query', 'anchor'].forEach(function(key) {
330
+ var method = 'set' + key.charAt(0).toUpperCase() + key.slice(1);
331
+ Uri.prototype[method] = function(val) {
332
+ this[key](val);
333
+ return this;
334
+ };
335
+ });
336
+
337
+ /**
338
+ * Scheme name, colon and doubleslash, as required
339
+ * @return {string} http:// or possibly just //
340
+ */
341
+ Uri.prototype.scheme = function() {
342
+ var s = '';
343
+
344
+ if (this.protocol()) {
345
+ s += this.protocol();
346
+ if (this.protocol().indexOf(':') !== this.protocol().length - 1) {
347
+ s += ':';
348
+ }
349
+ s += '//';
350
+ } else {
351
+ if (this.hasAuthorityPrefix() && this.host()) {
352
+ s += '//';
353
+ }
354
+ }
355
+
356
+ return s;
357
+ };
358
+
359
+ /**
360
+ * Same as Mozilla nsIURI.prePath
361
+ * @return {string} scheme://user:password@host:port
362
+ * @see https://developer.mozilla.org/en/nsIURI
363
+ */
364
+ Uri.prototype.origin = function() {
365
+ var s = this.scheme();
366
+
367
+ if (this.userInfo() && this.host()) {
368
+ s += this.userInfo();
369
+ if (this.userInfo().indexOf('@') !== this.userInfo().length - 1) {
370
+ s += '@';
371
+ }
372
+ }
373
+
374
+ if (this.host()) {
375
+ s += this.host();
376
+ if (this.port() || (this.path() && this.path().substr(0, 1).match(/[0-9]/))) {
377
+ s += ':' + this.port();
378
+ }
379
+ }
380
+
381
+ return s;
382
+ };
383
+
384
+ /**
385
+ * Adds a trailing slash to the path
386
+ */
387
+ Uri.prototype.addTrailingSlash = function() {
388
+ var path = this.path() || '';
389
+
390
+ if (path.substr(-1) !== '/') {
391
+ this.path(path + '/');
392
+ }
393
+
394
+ return this;
395
+ };
396
+
397
+ /**
398
+ * Serializes the internal state of the Uri object
399
+ * @return {string}
400
+ */
401
+ Uri.prototype.toString = function() {
402
+ var path, s = this.origin();
403
+
404
+ if (this.isColonUri()) {
405
+ if (this.path()) {
406
+ s += ':'+this.path();
407
+ }
408
+ } else if (this.path()) {
409
+ path = this.path();
410
+ if (!(re.ends_with_slashes.test(s) || re.starts_with_slashes.test(path))) {
411
+ s += '/';
412
+ } else {
413
+ if (s) {
414
+ s.replace(re.ends_with_slashes, '/');
415
+ }
416
+ path = path.replace(re.starts_with_slashes, '/');
417
+ }
418
+ s += path;
419
+ } else {
420
+ if (this.host() && (this.query().toString() || this.anchor())) {
421
+ s += '/';
422
+ }
423
+ }
424
+ if (this.query().toString()) {
425
+ s += this.query().toString();
426
+ }
427
+
428
+ if (this.anchor()) {
429
+ if (this.anchor().indexOf('#') !== 0) {
430
+ s += '#';
431
+ }
432
+ s += this.anchor();
433
+ }
434
+
435
+ return s;
436
+ };
437
+
438
+ /**
439
+ * Clone a Uri object
440
+ * @return {Uri} duplicate copy of the Uri
441
+ */
442
+ Uri.prototype.clone = function() {
443
+ return new Uri(this.toString());
444
+ };
445
+
446
+ /**
447
+ * export via AMD or CommonJS, otherwise leak a global
448
+ */
449
+ if (typeof define === 'function' && define.amd) {
450
+ define(function() {
451
+ return Uri;
452
+ });
453
+ } else if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
454
+ module.exports = Uri;
455
+ } else {
456
+ global.Uri = Uri;
457
+ }
458
+ }(this));