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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/assets/config/spree_frontend_manifest.js +4 -0
- data/app/assets/images/card-image.svg +4 -0
- data/app/assets/images/file-image.svg +4 -0
- data/app/assets/images/image.svg +4 -0
- data/app/assets/images/noimage/large.png +0 -0
- data/app/assets/images/noimage/mini.png +0 -0
- data/app/assets/images/noimage/plp.svg +23 -0
- data/app/assets/images/noimage/product.png +0 -0
- data/app/assets/images/noimage/small.png +0 -0
- data/app/assets/javascripts/spree/api/main.js +36 -0
- data/app/assets/javascripts/spree/api/storefront/cart.js +49 -0
- data/app/assets/javascripts/spree/frontend/checkout/payment.js +18 -5
- data/app/assets/javascripts/spree/frontend/checkout.js +16 -0
- data/app/assets/javascripts/spree/frontend/currency.js +11 -9
- data/app/assets/javascripts/spree/frontend/locale.es6 +13 -0
- data/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js +3 -3
- data/app/assets/javascripts/spree/frontend/views/spree/products/index.js +0 -9
- data/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6 +46 -0
- data/app/assets/javascripts/spree/frontend.js +3 -0
- data/app/assets/javascripts/spree.js +78 -0
- data/app/assets/stylesheets/spree/frontend/application.scss +1 -0
- data/app/assets/stylesheets/spree/frontend/components-bootstrap/button.scss +8 -0
- data/app/assets/stylesheets/spree/frontend/helpers/spree/frontend_helper.scss +41 -0
- data/app/assets/stylesheets/spree/frontend/variables/variables.scss +2 -2
- data/app/assets/stylesheets/spree/frontend/views/spree/checkout/edit.scss +17 -5
- data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/_index.scss +1 -0
- data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/product_buy_bar.scss +20 -0
- data/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss +54 -67
- data/app/assets/stylesheets/spree/frontend/views/spree/shared/category_nav_bar.scss +3 -3
- data/app/assets/stylesheets/spree/frontend/views/spree/shared/footer.scss +4 -0
- data/app/assets/stylesheets/spree/frontend/views/spree/shared/main_nav_bar.scss +12 -1
- data/app/controllers/spree/addresses_controller.rb +14 -19
- data/app/controllers/spree/checkout_controller.rb +5 -3
- data/app/controllers/spree/cms_pages_controller.rb +29 -0
- data/app/controllers/spree/content_controller.rb +0 -2
- data/app/controllers/spree/errors_controller.rb +11 -0
- data/app/controllers/spree/home_controller.rb +34 -1
- data/app/controllers/spree/locale_controller.rb +7 -1
- data/app/controllers/spree/orders_controller.rb +9 -7
- data/app/controllers/spree/products_controller.rb +14 -13
- data/app/controllers/spree/store_controller.rb +25 -1
- data/app/controllers/spree/taxons_controller.rb +12 -5
- data/app/helpers/spree/addresses_helper.rb +9 -4
- data/app/helpers/spree/cms_pages_helper.rb +23 -0
- data/app/helpers/spree/frontend_helper.rb +109 -10
- data/app/helpers/spree/navigation_helper.rb +73 -4
- data/app/helpers/spree/products_filters_helper.rb +168 -0
- data/app/helpers/spree/store_helper.rb +3 -1
- data/app/views/spree/checkout/_address.html.erb +1 -1
- data/app/views/spree/checkout/_credit_card.html.erb +1 -0
- data/app/views/spree/cms_pages/show.html.erb +16 -0
- data/app/views/spree/errors/forbidden.html.erb +0 -0
- data/app/views/spree/errors/unauthorized.html.erb +0 -0
- data/app/views/spree/home/index.html.erb +19 -118
- data/app/views/spree/layouts/spree_application.html.erb +2 -2
- data/app/views/spree/products/_description.html.erb +16 -19
- data/app/views/spree/products/_filters_desktop.html.erb +50 -15
- data/app/views/spree/products/_filters_mobile.html.erb +38 -10
- data/app/views/spree/products/_sort_desktop.html.erb +17 -11
- data/app/views/spree/products/_sort_mobile.html.erb +16 -0
- data/app/views/spree/products/index.html.erb +1 -1
- data/app/views/spree/shared/_carousel_4_products.html.erb +8 -8
- data/app/views/spree/shared/_checkout_header.html.erb +22 -21
- data/app/views/spree/shared/_copyright.html.erb +1 -1
- data/app/views/spree/shared/_footer.html.erb +18 -12
- data/app/views/spree/shared/_head.html.erb +1 -1
- data/app/views/spree/shared/_header.html.erb +3 -3
- data/app/views/spree/shared/_main_nav_bar.html.erb +61 -43
- data/app/views/spree/shared/_mobile_navigation.html.erb +30 -19
- data/app/views/spree/shared/_nav_bar.html.erb +1 -1
- data/app/views/spree/shared/_option_values.html.erb +2 -21
- data/app/views/spree/shared/_order_details.html.erb +1 -1
- data/app/views/spree/shared/_paths.html.erb +8 -0
- data/app/views/spree/shared/_properties.html.erb +4 -0
- data/app/views/spree/shared/_translations.html.erb +2 -1
- data/app/views/spree/shared/carousel/_single.html.erb +1 -1
- data/app/views/spree/shared/carousel/_thumbnails.html.erb +1 -1
- data/app/views/spree/shared/cms/pages/_edit_mode.html.erb +13 -0
- data/app/views/spree/shared/cms/sections/_featured_article.html.erb +27 -0
- data/app/views/spree/shared/cms/sections/_hero_image.html.erb +60 -0
- data/app/views/spree/shared/cms/sections/_image_gallery.html.erb +171 -0
- data/app/views/spree/shared/cms/sections/_product_carousel.html.erb +5 -0
- data/app/views/spree/shared/cms/sections/_rich_text_content.html.erb +3 -0
- data/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb +118 -0
- data/app/views/spree/taxons/_header.html.erb +6 -1
- data/app/views/spree/users/show.html.erb +4 -1
- data/config/initializers/assets.rb +4 -13
- data/config/routes.rb +9 -3
- data/lib/generators/spree/frontend/install/install_generator.rb +5 -5
- data/lib/generators/spree/frontend/install/templates/app/assets/config/manifest.js +2 -0
- data/lib/generators/spree/frontend/install/templates/vendor/assets/javascripts/spree/frontend/all.js +8 -0
- data/lib/generators/spree/frontend/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +9 -0
- data/lib/spree/frontend/engine.rb +6 -0
- data/lib/spree/frontend.rb +6 -3
- data/spec/fixtures/files/store_favicon.ico +0 -0
- data/spree_frontend.gemspec +13 -9
- data/vendor/assets/javascripts/cleave.js +8 -0
- data/vendor/assets/javascripts/fetch.umd.js +531 -0
- data/vendor/assets/javascripts/jquery.payment.js +652 -0
- data/vendor/assets/javascripts/jsuri.js +458 -0
- data/vendor/assets/javascripts/polyfill.min.js +1 -0
- metadata +132 -86
- data/app/assets/images/homepage/big_category_banner.jpg +0 -0
- data/app/assets/images/homepage/big_category_banner_mobile.jpg +0 -0
- data/app/assets/images/homepage/big_category_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/big_category_banner_tablet_portrait.jpg +0 -0
- data/app/assets/images/homepage/category_banner_lower.jpg +0 -0
- data/app/assets/images/homepage/category_banner_lower_mobile.jpg +0 -0
- data/app/assets/images/homepage/category_banner_lower_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/category_banner_lower_tablet_portrait.jpg +0 -0
- data/app/assets/images/homepage/category_banner_upper.jpg +0 -0
- data/app/assets/images/homepage/category_banner_upper_mobile.jpg +0 -0
- data/app/assets/images/homepage/category_banner_upper_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/category_banner_upper_tablet_portrait.jpg +0 -0
- data/app/assets/images/homepage/main_banner.jpg +0 -0
- data/app/assets/images/homepage/main_banner_mobile.jpg +0 -0
- data/app/assets/images/homepage/main_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/main_banner_tablet_portrait.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_left.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_left_mobile.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_left_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_left_tablet_portrait.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_right.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_right_mobile.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_right_tablet_landscape.jpg +0 -0
- data/app/assets/images/homepage/promo_banner_right_tablet_portrait.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_left-first-category.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_left-second-category.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_left-third-category.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_right-first-category.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_right-second-category.jpg +0 -0
- data/app/assets/images/meganav/promo_banner_right-third-category.jpg +0 -0
- data/app/assets/images/noimage/big_category_banner.jpg +0 -0
- data/app/assets/images/noimage/big_category_banner_mobile.jpg +0 -0
- data/app/assets/images/noimage/big_category_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/noimage/big_category_banner_tablet_portrait.jpg +0 -0
- data/app/assets/images/noimage/category_banner.jpg +0 -0
- data/app/assets/images/noimage/category_banner_mobile.jpg +0 -0
- data/app/assets/images/noimage/category_banner_plp.jpg +0 -0
- data/app/assets/images/noimage/category_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/noimage/category_banner_tablet_portrait.jpg +0 -0
- data/app/assets/images/noimage/main_banner.jpg +0 -0
- data/app/assets/images/noimage/main_banner_mobile.jpg +0 -0
- data/app/assets/images/noimage/main_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/noimage/main_banner_tablet_portrait.jpg +0 -0
- data/app/assets/images/noimage/product_photo.jpg +0 -0
- data/app/assets/images/noimage/promo_banner.jpg +0 -0
- data/app/assets/images/noimage/promo_banner_megamenu.jpg +0 -0
- data/app/assets/images/noimage/promo_banner_mobile.jpg +0 -0
- data/app/assets/images/noimage/promo_banner_tablet_landscape.jpg +0 -0
- data/app/assets/images/noimage/promo_banner_tablet_portrait.jpg +0 -0
- data/app/assets/javascripts/spree/frontend/locale.js +0 -13
- data/app/assets/javascripts/spree/frontend/multi_currency.js +0 -13
- data/lib/generators/spree/frontend/install/templates/config/initializers/spree_storefront.rb +0 -1
- 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));
|