spree_backend 4.2.7 → 4.3.0.rc1
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_backend_manifest.js +129 -0
- data/app/assets/images/backend-arrows-fullscreen.svg +3 -0
- data/app/assets/images/backend-box.svg +3 -0
- data/app/assets/images/backend-circle-fill.svg +3 -0
- data/app/assets/images/backend-circle.svg +3 -0
- data/app/assets/images/backend-default-layout.svg +6 -0
- data/app/assets/images/backend-eye-slash-fill.svg +4 -0
- data/app/assets/images/backend-file-richtext.svg +4 -0
- data/app/assets/images/backend-fullscreen-exit.svg +3 -0
- data/app/assets/images/backend-fullscreen.svg +3 -0
- data/app/assets/images/backend-mobile.svg +5 -0
- data/app/assets/images/backend-pages.svg +10 -0
- data/app/assets/images/backend-phone.svg +4 -0
- data/app/assets/images/backend-reversed-layout.svg +6 -0
- data/app/assets/images/backend-spree-icon.svg +1 -0
- data/app/assets/images/backend-spree-logo.svg +6 -0
- data/app/assets/images/backend-store.svg +2 -13
- data/app/assets/images/backend-translate.svg +4 -0
- data/app/assets/images/backend-users.svg +2 -5
- data/app/assets/images/backend-window-sidebar.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/product.png +0 -0
- data/app/assets/images/noimage/small.png +0 -0
- data/app/assets/javascripts/spree/backend/address_states.es6 +44 -0
- data/app/assets/javascripts/spree/backend/admin.js +45 -307
- data/app/assets/javascripts/spree/backend/checkouts/edit.js +22 -13
- data/app/assets/javascripts/spree/backend/cms/_index.es6 +4 -0
- data/app/assets/javascripts/spree/backend/cms/links.es6 +25 -0
- data/app/assets/javascripts/spree/backend/cms/live_preview.es6 +34 -0
- data/app/assets/javascripts/spree/backend/cms/page.es6 +133 -0
- data/app/assets/javascripts/spree/backend/cms/section.es6 +43 -0
- data/app/assets/javascripts/spree/backend/global/_index.js +11 -0
- data/app/assets/javascripts/spree/backend/global/alerts.es6 +66 -0
- data/app/assets/javascripts/spree/backend/global/api_functions.es6 +5 -0
- data/app/assets/javascripts/spree/backend/global/bootstrap.es6 +15 -0
- data/app/assets/javascripts/spree/backend/global/flatpickr.es6 +22 -0
- data/app/assets/javascripts/spree/backend/global/info_alert.es6 +38 -0
- data/app/assets/javascripts/spree/backend/global/radio_panel_toggle.es6 +18 -0
- data/app/assets/javascripts/spree/backend/global/ransack.es6 +108 -0
- data/app/assets/javascripts/spree/backend/global/responsive_menus.es6 +56 -0
- data/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +143 -0
- data/app/assets/javascripts/spree/backend/global/select2_populate.es6 +61 -0
- data/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 +137 -0
- data/app/assets/javascripts/spree/backend/global/sortable.es6 +35 -0
- data/app/assets/javascripts/spree/backend/global/tinymce.es6 +11 -0
- data/app/assets/javascripts/spree/backend/menus/_index.es6 +2 -0
- data/app/assets/javascripts/spree/backend/menus/menu.es6 +58 -0
- data/app/assets/javascripts/spree/backend/menus/menu_item.es6 +26 -0
- data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +7 -17
- data/app/assets/javascripts/spree/backend/option_value_picker.js +10 -22
- data/app/assets/javascripts/spree/backend/payments/edit.js +1 -1
- data/app/assets/javascripts/spree/backend/payments/new.js +18 -5
- data/app/assets/javascripts/spree/backend/spree-select2.js +19 -1
- data/app/assets/javascripts/spree/backend/stock_location.js +1 -2
- data/app/assets/javascripts/spree/backend/taxons.js +74 -73
- data/app/assets/javascripts/spree/backend/user_picker.js +7 -10
- data/app/assets/javascripts/spree/backend.js +28 -1
- data/app/assets/javascripts/spree.js +78 -0
- data/app/assets/stylesheets/spree/backend/components/_filters.scss +1 -3
- data/app/assets/stylesheets/spree/backend/components/_main.scss +0 -1
- data/app/assets/stylesheets/spree/backend/components/_navbar.scss +35 -0
- data/app/assets/stylesheets/spree/backend/components/_navigation.scss +13 -0
- data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +0 -1
- data/app/assets/stylesheets/spree/backend/components/_tables.scss +4 -5
- data/app/assets/stylesheets/spree/backend/global/_mixins.scss +59 -0
- data/app/assets/stylesheets/spree/backend/plugins/_nav_x.scss +95 -0
- data/app/assets/stylesheets/spree/backend/plugins/_sweetalert2_custom.scss +100 -0
- data/app/assets/stylesheets/spree/backend/plugins/_tinymce_custom.scss +4 -0
- data/app/assets/stylesheets/spree/backend/shared/_base.scss +28 -26
- data/app/assets/stylesheets/spree/backend/shared/_forms.scss +8 -0
- data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +5 -0
- data/app/assets/stylesheets/spree/backend/views/_cms_pages.scss +148 -0
- data/app/assets/stylesheets/spree/backend/views/_menus.scss +61 -0
- data/app/controllers/concerns/spree/admin/order_concern.rb +24 -0
- data/app/controllers/concerns/spree/admin/product_concern.rb +11 -0
- data/app/controllers/spree/admin/base_controller.rb +63 -3
- data/app/controllers/spree/admin/cms_pages_controller.rb +29 -0
- data/app/controllers/spree/admin/cms_sections_controller.rb +15 -0
- data/app/controllers/spree/admin/customer_returns_controller.rb +4 -5
- data/app/controllers/spree/admin/errors_controller.rb +11 -0
- data/app/controllers/spree/admin/general_settings_controller.rb +1 -1
- data/app/controllers/spree/admin/images_controller.rb +8 -22
- data/app/controllers/spree/admin/log_entries_controller.rb +4 -3
- data/app/controllers/spree/admin/menu_items_controller.rb +33 -0
- data/app/controllers/spree/admin/menus_controller.rb +32 -0
- data/app/controllers/spree/admin/option_types_controller.rb +1 -1
- data/app/controllers/spree/admin/orders/customer_details_controller.rb +6 -11
- data/app/controllers/spree/admin/orders_controller.rb +22 -30
- data/app/controllers/spree/admin/payment_methods_controller.rb +17 -4
- data/app/controllers/spree/admin/payments_controller.rb +5 -10
- data/app/controllers/spree/admin/prices_controller.rb +2 -2
- data/app/controllers/spree/admin/products_controller.rb +21 -10
- data/app/controllers/spree/admin/promotion_actions_controller.rb +1 -1
- data/app/controllers/spree/admin/promotion_rules_controller.rb +1 -1
- data/app/controllers/spree/admin/promotions_controller.rb +3 -3
- data/app/controllers/spree/admin/prototypes_controller.rb +1 -1
- data/app/controllers/spree/admin/reimbursements_controller.rb +1 -1
- data/app/controllers/spree/admin/reports_controller.rb +5 -1
- data/app/controllers/spree/admin/resource_controller.rb +35 -5
- data/app/controllers/spree/admin/return_index_controller.rb +1 -1
- data/app/controllers/spree/admin/state_changes_controller.rb +2 -7
- data/app/controllers/spree/admin/stock_items_controller.rb +2 -2
- data/app/controllers/spree/admin/stock_locations_controller.rb +2 -2
- data/app/controllers/spree/admin/stock_movements_controller.rb +1 -1
- data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
- data/app/controllers/spree/admin/store_credits_controller.rb +13 -8
- data/app/controllers/spree/admin/stores_controller.rb +14 -17
- data/app/controllers/spree/admin/taxons_controller.rb +9 -5
- data/app/controllers/spree/admin/users_controller.rb +9 -7
- data/app/controllers/spree/admin/variants_controller.rb +16 -15
- data/app/helpers/spree/admin/base_helper.rb +52 -14
- data/app/helpers/spree/admin/cms_helper.rb +15 -0
- data/app/helpers/spree/admin/menu_helper.rb +30 -0
- data/app/helpers/spree/admin/stores_helper.rb +21 -0
- data/app/models/spree/backend_configuration.rb +2 -0
- data/app/views/spree/admin/adjustments/_adjustment.html.erb +7 -5
- data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
- data/app/views/spree/admin/cms_pages/_form.html.erb +135 -0
- data/app/views/spree/admin/cms_pages/_live_preview_area.html.erb +61 -0
- data/app/views/spree/admin/cms_pages/_section_template.html.erb +16 -0
- data/app/views/spree/admin/cms_pages/edit.html.erb +21 -0
- data/app/views/spree/admin/cms_pages/index.html.erb +84 -0
- data/app/views/spree/admin/cms_pages/new.html.erb +8 -0
- data/app/views/spree/admin/cms_sections/_form.html.erb +69 -0
- data/app/views/spree/admin/cms_sections/edit.html.erb +19 -0
- data/app/views/spree/admin/cms_sections/new.html.erb +11 -0
- data/app/views/spree/admin/cms_sections/types/_featured_article.html.erb +50 -0
- data/app/views/spree/admin/cms_sections/types/_hero_image.html.erb +62 -0
- data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +177 -0
- data/app/views/spree/admin/cms_sections/types/_product_carousel.html.erb +5 -0
- data/app/views/spree/admin/cms_sections/types/_rich_text_content.html.erb +4 -0
- data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +121 -0
- data/app/views/spree/admin/countries/index.html.erb +5 -3
- data/app/views/spree/admin/customer_returns/_reimbursements_table.html.erb +6 -4
- data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +9 -7
- data/app/views/spree/admin/customer_returns/index.html.erb +4 -2
- data/app/views/spree/admin/errors/forbidden.html.erb +0 -0
- data/app/views/spree/admin/images/index.html.erb +5 -3
- data/app/views/spree/admin/menu_items/_form.html.erb +115 -0
- data/app/views/spree/admin/menu_items/edit.html.erb +11 -0
- data/app/views/spree/admin/menu_items/new.html.erb +11 -0
- data/app/views/spree/admin/menus/_form.html.erb +19 -0
- data/app/views/spree/admin/menus/edit.html.erb +57 -0
- data/app/views/spree/admin/menus/index.html.erb +90 -0
- data/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb +30 -0
- data/app/views/spree/admin/menus/new.html.erb +22 -0
- data/app/views/spree/admin/option_types/_form.html.erb +3 -0
- data/app/views/spree/admin/option_types/_option_value_fields.html.erb +5 -1
- data/app/views/spree/admin/option_types/index.html.erb +5 -3
- data/app/views/spree/admin/orders/_channel_form.html.erb +2 -2
- data/app/views/spree/admin/orders/_line_items.html.erb +9 -7
- data/app/views/spree/admin/orders/_shipment.html.erb +26 -18
- data/app/views/spree/admin/orders/_shipment_manifest.html.erb +10 -8
- data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +2 -2
- data/app/views/spree/admin/orders/index.html.erb +100 -101
- data/app/views/spree/admin/payment_methods/_form.html.erb +6 -4
- data/app/views/spree/admin/payment_methods/edit.html.erb +1 -1
- data/app/views/spree/admin/payment_methods/index.html.erb +22 -3
- data/app/views/spree/admin/payment_methods/new.html.erb +1 -1
- data/app/views/spree/admin/payments/_list.html.erb +9 -7
- data/app/views/spree/admin/prices/_variant_prices.html.erb +7 -14
- data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +9 -7
- data/app/views/spree/admin/products/_autocomplete.js.erb +5 -5
- data/app/views/spree/admin/products/_form.html.erb +24 -5
- data/app/views/spree/admin/products/index.html.erb +14 -13
- data/app/views/spree/admin/products/new.html.erb +6 -1
- data/app/views/spree/admin/products/stock.html.erb +71 -68
- data/app/views/spree/admin/promotion_categories/index.html.erb +5 -3
- data/app/views/spree/admin/promotions/_form.html.erb +7 -0
- data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +1 -0
- data/app/views/spree/admin/promotions/calculators/_default_fields.html.erb +2 -1
- data/app/views/spree/admin/promotions/index.html.erb +33 -34
- data/app/views/spree/admin/properties/_form.html.erb +6 -0
- data/app/views/spree/admin/properties/index.html.erb +9 -3
- data/app/views/spree/admin/prototypes/_form.html.erb +1 -1
- data/app/views/spree/admin/prototypes/_prototypes.html.erb +8 -6
- data/app/views/spree/admin/prototypes/index.html.erb +5 -3
- data/app/views/spree/admin/reimbursement_types/index.html.erb +5 -3
- data/app/views/spree/admin/reports/index.html.erb +1 -1
- data/app/views/spree/admin/reports/sales_total.html.erb +1 -1
- data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
- data/app/views/spree/admin/return_authorizations/index.html.erb +7 -5
- data/app/views/spree/admin/return_index/customer_returns.html.erb +4 -2
- data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -3
- data/app/views/spree/admin/roles/index.html.erb +5 -3
- data/app/views/spree/admin/shared/_account_nav.html.erb +5 -5
- data/app/views/spree/admin/shared/_address_form.html.erb +5 -4
- data/app/views/spree/admin/shared/_content_header.html.erb +20 -6
- data/app/views/spree/admin/shared/_head.html.erb +2 -1
- data/app/views/spree/admin/shared/_header.html.erb +7 -10
- data/app/views/spree/admin/shared/_link_fields.html.erb +22 -0
- data/app/views/spree/admin/shared/_main_menu.html.erb +19 -4
- data/app/views/spree/admin/shared/_order_tabs.html.erb +1 -10
- data/app/views/spree/admin/shared/_paths.html.erb +8 -0
- data/app/views/spree/admin/shared/_refunds.html.erb +4 -2
- data/app/views/spree/admin/shared/_sidebar.html.erb +1 -1
- data/app/views/spree/admin/shared/_store_switcher.html.erb +23 -0
- data/app/views/spree/admin/shared/_table_filter.html.erb +6 -6
- data/app/views/spree/admin/shared/_translations.html.erb +2 -0
- data/app/views/spree/admin/shared/cms/_spree_product.html.erb +14 -0
- data/app/views/spree/admin/shared/cms/_spree_taxon.html.erb +14 -0
- data/app/views/spree/admin/shared/linkables/_home_page.html.erb +3 -0
- data/app/views/spree/admin/shared/linkables/_spree_cms_page.erb +28 -0
- data/app/views/spree/admin/shared/linkables/_spree_product.html.erb +20 -0
- data/app/views/spree/admin/shared/linkables/_spree_taxon.html.erb +22 -0
- data/app/views/spree/admin/shared/linkables/_url.html.erb +16 -0
- data/app/views/spree/admin/shared/named_types/_index.html.erb +7 -5
- data/app/views/spree/admin/shared/sub_menu/_configuration.html.erb +1 -3
- data/app/views/spree/admin/shared/sub_menu/_content.html.erb +4 -0
- data/app/views/spree/admin/shared/sub_menu/_stock.html.erb +4 -0
- data/app/views/spree/admin/shipping_categories/index.html.erb +5 -3
- data/app/views/spree/admin/shipping_methods/index.html.erb +5 -3
- data/app/views/spree/admin/states/_state_list.html.erb +5 -3
- data/app/views/spree/admin/stock_locations/index.html.erb +5 -3
- data/app/views/spree/admin/stock_transfers/index.html.erb +5 -4
- data/app/views/spree/admin/stock_transfers/new.html.erb +9 -7
- data/app/views/spree/admin/store_credit_categories/index.html.erb +5 -3
- data/app/views/spree/admin/store_credits/index.html.erb +7 -5
- data/app/views/spree/admin/stores/_form.html.erb +12 -2
- data/app/views/spree/admin/stores/index.html.erb +12 -10
- data/app/views/spree/admin/tax_categories/index.html.erb +5 -3
- data/app/views/spree/admin/tax_rates/index.html.erb +5 -3
- data/app/views/spree/admin/taxonomies/_list.html.erb +5 -3
- data/app/views/spree/admin/taxons/_form.html.erb +1 -1
- data/app/views/spree/admin/users/_addresses_form.html.erb +2 -4
- data/app/views/spree/admin/users/index.html.erb +5 -3
- data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +18 -12
- data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +12 -8
- data/app/views/spree/admin/variants/_split.js.erb +9 -7
- data/app/views/spree/admin/variants/index.html.erb +8 -5
- data/app/views/spree/admin/zones/index.html.erb +5 -3
- data/app/views/spree/layouts/admin.html.erb +16 -16
- data/config/initializers/assets.rb +5 -1
- data/config/routes.rb +16 -4
- data/lib/generators/spree/backend/install/install_generator.rb +22 -0
- data/lib/generators/spree/backend/install/templates/vendor/assets/javascripts/spree/backend/all.js +8 -0
- data/lib/generators/spree/backend/install/templates/vendor/assets/stylesheets/spree/backend/all.css +9 -0
- data/lib/spree/backend/engine.rb +4 -11
- data/lib/spree/backend.rb +7 -4
- data/lib/spree_backend.rb +0 -2
- data/spec/fixtures/files/favicon.ico +0 -0
- data/spec/fixtures/files/icon_512x512.png +0 -0
- data/spree_backend.gemspec +9 -4
- data/vendor/assets/javascripts/cleave.js +8 -0
- data/vendor/assets/javascripts/jsonapi-serializer.min.js +8 -0
- data/vendor/assets/javascripts/jsuri.js +458 -0
- data/vendor/assets/javascripts/sortable.js +2 -3709
- data/vendor/assets/javascripts/sweetalert2.js +2 -0
- metadata +193 -22
- data/app/assets/javascripts/spree/backend/address_states.js +0 -44
- data/app/assets/javascripts/spree/frontend/backend.js +0 -1
- data/app/assets/stylesheets/spree/frontend/backend.css +0 -1
- data/app/views/spree/admin/orders/_store_form.html.erb +0 -18
- /data/app/assets/stylesheets/spree/backend/plugins/{select2_bootstrap4.scss → _select2_bootstrap4.scss} +0 -0
@@ -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));
|