spree_backend 4.1.15 → 4.2.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/backend-add.svg +5 -0
  3. data/app/assets/images/backend-adjust.svg +5 -0
  4. data/app/assets/images/backend-approve.svg +3 -0
  5. data/app/assets/images/backend-arrow-down.svg +1 -0
  6. data/app/assets/images/backend-arrow-left.svg +1 -0
  7. data/app/assets/images/backend-arrow-right.svg +1 -0
  8. data/app/assets/images/backend-arrow-up.svg +1 -0
  9. data/app/assets/images/backend-calendar.svg +9 -0
  10. data/app/assets/images/backend-cancel.svg +7 -0
  11. data/app/assets/images/backend-capture.svg +3 -0
  12. data/app/assets/images/backend-cart.svg +1 -0
  13. data/app/assets/images/backend-chevron-down.svg +1 -0
  14. data/app/assets/images/backend-chevron-left.svg +1 -0
  15. data/app/assets/images/backend-chevron-right.svg +1 -0
  16. data/app/assets/images/backend-chevron-up.svg +1 -0
  17. data/app/assets/images/backend-clone.svg +7 -0
  18. data/app/assets/images/backend-close.svg +7 -0
  19. data/app/assets/images/backend-delete.svg +6 -0
  20. data/app/assets/images/backend-double-chevron-left.svg +15 -0
  21. data/app/assets/images/backend-double-chevron-right.svg +17 -0
  22. data/app/assets/images/backend-edit.svg +14 -0
  23. data/app/assets/images/backend-enter.svg +6 -0
  24. data/app/assets/images/backend-envelope.svg +3 -0
  25. data/app/assets/images/backend-exit.svg +13 -0
  26. data/app/assets/images/backend-extensions.svg +4 -0
  27. data/app/assets/images/backend-eye-open.svg +8 -0
  28. data/app/assets/images/backend-file.svg +6 -0
  29. data/app/assets/images/backend-filter.svg +3 -0
  30. data/app/assets/images/backend-folder.svg +4 -0
  31. data/app/assets/images/backend-images.svg +7 -0
  32. data/app/assets/images/backend-info.svg +7 -0
  33. data/app/assets/images/backend-items.svg +5 -0
  34. data/app/assets/images/backend-leaf.svg +7 -0
  35. data/app/assets/images/backend-list.svg +5 -0
  36. data/app/assets/images/backend-location.svg +4 -0
  37. data/app/assets/images/backend-menu.svg +5 -0
  38. data/app/assets/images/backend-money.svg +1 -0
  39. data/app/assets/images/backend-move.svg +5 -0
  40. data/app/assets/images/backend-ok.svg +3 -0
  41. data/app/assets/images/backend-pagination-double-arrow-right.svg +8 -0
  42. data/app/assets/images/backend-payments.svg +8 -0
  43. data/app/assets/images/backend-pencil.svg +1 -0
  44. data/app/assets/images/backend-products.svg +5 -0
  45. data/app/assets/images/backend-promotion.svg +8 -0
  46. data/app/assets/images/backend-recycle.svg +5 -0
  47. data/app/assets/images/backend-remove.svg +6 -0
  48. data/app/assets/images/backend-report.svg +6 -0
  49. data/app/assets/images/backend-resume.svg +5 -0
  50. data/app/assets/images/backend-returns.svg +3 -0
  51. data/app/assets/images/backend-save.svg +3 -0
  52. data/app/assets/images/backend-search.svg +1 -0
  53. data/app/assets/images/backend-settings.svg +6 -0
  54. data/app/assets/images/backend-shipping.svg +3 -0
  55. data/app/assets/images/backend-slack.svg +3 -0
  56. data/app/assets/images/backend-sort.svg +5 -0
  57. data/app/assets/images/backend-split.svg +3 -0
  58. data/app/assets/images/backend-store.svg +14 -0
  59. data/app/assets/images/backend-tick.svg +3 -0
  60. data/app/assets/images/backend-update.svg +3 -0
  61. data/app/assets/images/backend-user.svg +3 -0
  62. data/app/assets/images/backend-users.svg +6 -0
  63. data/app/assets/images/backend-view.svg +8 -0
  64. data/app/assets/images/backend-void.svg +7 -0
  65. data/app/assets/javascripts/spree/backend/admin.js +156 -147
  66. data/app/assets/javascripts/spree/backend/checkouts/edit.js +1 -0
  67. data/app/assets/javascripts/spree/backend/flatpickr_locals.js +37 -0
  68. data/app/assets/javascripts/spree/backend/multi_currency.js +38 -0
  69. data/app/assets/javascripts/spree/backend/payments/edit.js +4 -3
  70. data/app/assets/javascripts/spree/backend/payments/new.js +18 -18
  71. data/app/assets/javascripts/spree/backend/promotions.js +1 -1
  72. data/app/assets/javascripts/spree/backend/spree-select2.js +18 -4
  73. data/app/assets/javascripts/spree/backend/stock_management.js +2 -1
  74. data/app/assets/javascripts/spree/backend/taxon_tree_menu.js +4 -4
  75. data/app/assets/javascripts/spree/backend/taxonomy.js +8 -1
  76. data/app/assets/javascripts/spree/backend/taxons.js +25 -16
  77. data/app/assets/javascripts/spree/backend/user_picker.js +1 -1
  78. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +1 -1
  79. data/app/assets/javascripts/spree/backend/variant_management.js +2 -1
  80. data/app/assets/javascripts/spree/backend.js +5 -2
  81. data/app/assets/stylesheets/spree/backend/components/_buttons.scss +27 -11
  82. data/app/assets/stylesheets/spree/backend/components/_filters.scss +35 -5
  83. data/app/assets/stylesheets/spree/backend/components/_icons.scss +39 -4
  84. data/app/assets/stylesheets/spree/backend/components/_main.scss +32 -6
  85. data/app/assets/stylesheets/spree/backend/components/_navbar.scss +16 -8
  86. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +119 -55
  87. data/app/assets/stylesheets/spree/backend/components/_tables.scss +62 -19
  88. data/app/assets/stylesheets/spree/backend/components/_taxon_products_view.scss +26 -63
  89. data/app/assets/stylesheets/spree/backend/global/_variables.scss +5 -1
  90. data/app/assets/stylesheets/spree/backend/plugins/_flatpickr.scss +95 -0
  91. data/app/assets/stylesheets/spree/backend/plugins/_jquery_ui.scss +0 -117
  92. data/app/assets/stylesheets/spree/backend/plugins/_select2.scss +73 -24
  93. data/app/assets/stylesheets/spree/backend/shared/_base.scss +40 -0
  94. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +38 -0
  95. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +5 -0
  96. data/app/assets/stylesheets/spree/backend/views/_order_payments.scss +12 -0
  97. data/app/assets/stylesheets/spree/backend/views/_product_properties.scss +11 -0
  98. data/app/assets/stylesheets/spree/backend/views/prototypes.scss +42 -0
  99. data/app/assets/stylesheets/spree/backend.css +1 -1
  100. data/app/controllers/spree/admin/general_settings_controller.rb +27 -0
  101. data/app/controllers/spree/admin/prices_controller.rb +39 -0
  102. data/app/controllers/spree/admin/stock_transfers_controller.rb +8 -1
  103. data/app/controllers/spree/admin/stores_controller.rb +61 -1
  104. data/app/controllers/spree/admin/taxons_controller.rb +5 -1
  105. data/app/helpers/spree/admin/base_helper.rb +25 -8
  106. data/app/helpers/spree/admin/navigation_helper.rb +50 -19
  107. data/app/helpers/spree/admin/orders_helper.rb +3 -3
  108. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_first_page.html.erb +1 -1
  109. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_gap.html.erb +1 -1
  110. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_last_page.html.erb +1 -1
  111. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_next_page.html.erb +1 -1
  112. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_page.html.erb +0 -0
  113. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_paginator.html.erb +1 -1
  114. data/app/views/kaminari/{twitter-bootstrap-4 → admin-twitter-bootstrap-4}/_prev_page.html.erb +1 -1
  115. data/app/views/spree/admin/adjustments/_adjustment.html.erb +2 -2
  116. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +16 -16
  117. data/app/views/spree/admin/adjustments/edit.html.erb +2 -2
  118. data/app/views/spree/admin/adjustments/index.html.erb +3 -3
  119. data/app/views/spree/admin/adjustments/new.html.erb +1 -1
  120. data/app/views/spree/admin/countries/_form.html.erb +9 -4
  121. data/app/views/spree/admin/countries/index.html.erb +27 -24
  122. data/app/views/spree/admin/customer_returns/_reimbursements_table.html.erb +37 -35
  123. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +2 -0
  124. data/app/views/spree/admin/customer_returns/_return_item_selection.html.erb +45 -43
  125. data/app/views/spree/admin/customer_returns/index.html.erb +3 -1
  126. data/app/views/spree/admin/customer_returns/new.html.erb +1 -1
  127. data/app/views/spree/admin/general_settings/_form.html.erb +27 -0
  128. data/app/views/spree/admin/general_settings/edit.html.erb +4 -3
  129. data/app/views/spree/admin/images/edit.html.erb +2 -2
  130. data/app/views/spree/admin/images/index.html.erb +7 -7
  131. data/app/views/spree/admin/images/new.html.erb +2 -2
  132. data/app/views/spree/admin/log_entries/index.html.erb +4 -3
  133. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +1 -1
  134. data/app/views/spree/admin/option_types/edit.html.erb +22 -20
  135. data/app/views/spree/admin/option_types/index.html.erb +27 -25
  136. data/app/views/spree/admin/orders/_adjustments.html.erb +26 -26
  137. data/app/views/spree/admin/orders/_line_items.html.erb +7 -7
  138. data/app/views/spree/admin/orders/_order_actions.html.erb +1 -1
  139. data/app/views/spree/admin/orders/_risk_analysis.html.erb +44 -42
  140. data/app/views/spree/admin/orders/_shipment.html.erb +6 -6
  141. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +5 -5
  142. data/app/views/spree/admin/orders/_store_form.html.erb +3 -3
  143. data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
  144. data/app/views/spree/admin/orders/index.html.erb +135 -127
  145. data/app/views/spree/admin/payment_methods/index.html.erb +6 -4
  146. data/app/views/spree/admin/payments/_capture_events.html.erb +18 -16
  147. data/app/views/spree/admin/payments/_form.html.erb +1 -1
  148. data/app/views/spree/admin/payments/_list.html.erb +39 -37
  149. data/app/views/spree/admin/payments/index.html.erb +2 -3
  150. data/app/views/spree/admin/payments/new.html.erb +1 -1
  151. data/app/views/spree/admin/payments/show.html.erb +1 -1
  152. data/app/views/spree/admin/payments/source_forms/_gateway.html.erb +30 -30
  153. data/app/views/spree/admin/payments/source_views/_gateway.html.erb +20 -18
  154. data/app/views/spree/admin/payments/source_views/_storecredit.html.erb +28 -26
  155. data/app/views/spree/admin/prices/_variant_prices.html.erb +43 -0
  156. data/app/views/spree/admin/prices/index.html.erb +21 -0
  157. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +16 -4
  158. data/app/views/spree/admin/product_properties/index.html.erb +24 -19
  159. data/app/views/spree/admin/products/_add_stock_form.html.erb +1 -1
  160. data/app/views/spree/admin/products/_autocomplete.js.erb +27 -21
  161. data/app/views/spree/admin/products/_form.html.erb +40 -9
  162. data/app/views/spree/admin/products/edit.html.erb +1 -1
  163. data/app/views/spree/admin/products/index.html.erb +24 -19
  164. data/app/views/spree/admin/products/new.html.erb +11 -2
  165. data/app/views/spree/admin/products/stock.html.erb +3 -3
  166. data/app/views/spree/admin/promotion_categories/index.html.erb +4 -1
  167. data/app/views/spree/admin/promotions/_actions.html.erb +2 -2
  168. data/app/views/spree/admin/promotions/_form.html.erb +44 -17
  169. data/app/views/spree/admin/promotions/_promotion_action.html.erb +1 -1
  170. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -1
  171. data/app/views/spree/admin/promotions/_rules.html.erb +4 -4
  172. data/app/views/spree/admin/promotions/edit.html.erb +2 -2
  173. data/app/views/spree/admin/promotions/index.html.erb +5 -3
  174. data/app/views/spree/admin/promotions/new.html.erb +7 -6
  175. data/app/views/spree/admin/promotions/rules/_country.html.erb +1 -1
  176. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +5 -5
  177. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +6 -13
  178. data/app/views/spree/admin/promotions/rules/_product.html.erb +1 -1
  179. data/app/views/spree/admin/promotions/rules/_taxon.html.erb +1 -1
  180. data/app/views/spree/admin/properties/index.html.erb +5 -3
  181. data/app/views/spree/admin/prototypes/_prototypes.html.erb +30 -28
  182. data/app/views/spree/admin/prototypes/index.html.erb +21 -19
  183. data/app/views/spree/admin/prototypes/show.html.erb +21 -8
  184. data/app/views/spree/admin/refunds/edit.html.erb +2 -2
  185. data/app/views/spree/admin/refunds/new.html.erb +2 -2
  186. data/app/views/spree/admin/reimbursement_types/_form.html.erb +4 -4
  187. data/app/views/spree/admin/reimbursement_types/index.html.erb +4 -2
  188. data/app/views/spree/admin/reimbursements/edit.html.erb +66 -63
  189. data/app/views/spree/admin/reimbursements/index.html.erb +21 -20
  190. data/app/views/spree/admin/reimbursements/show.html.erb +66 -60
  191. data/app/views/spree/admin/reports/index.html.erb +18 -17
  192. data/app/views/spree/admin/reports/sales_total.html.erb +20 -19
  193. data/app/views/spree/admin/return_authorizations/_form.html.erb +3 -2
  194. data/app/views/spree/admin/return_authorizations/edit.html.erb +3 -3
  195. data/app/views/spree/admin/return_authorizations/index.html.erb +3 -1
  196. data/app/views/spree/admin/return_authorizations/new.html.erb +2 -2
  197. data/app/views/spree/admin/return_index/customer_returns.html.erb +4 -4
  198. data/app/views/spree/admin/return_index/return_authorizations.html.erb +4 -4
  199. data/app/views/spree/admin/roles/index.html.erb +21 -19
  200. data/app/views/spree/admin/shared/_account_nav.html.erb +51 -65
  201. data/app/views/spree/admin/shared/_address_form.html.erb +31 -73
  202. data/app/views/spree/admin/shared/_cal_close.html.erb +10 -0
  203. data/app/views/spree/admin/shared/_content_header.html.erb +40 -21
  204. data/app/views/spree/admin/shared/_edit_resource_links.html.erb +2 -2
  205. data/app/views/spree/admin/shared/_header.html.erb +14 -11
  206. data/app/views/spree/admin/shared/_index_table_options.html.erb +5 -7
  207. data/app/views/spree/admin/shared/_main_menu.html.erb +25 -14
  208. data/app/views/spree/admin/shared/_new_resource_links.html.erb +2 -2
  209. data/app/views/spree/admin/shared/_order_summary.html.erb +2 -0
  210. data/app/views/spree/admin/shared/_order_tabs.html.erb +9 -9
  211. data/app/views/spree/admin/shared/_product_tabs.html.erb +13 -5
  212. data/app/views/spree/admin/shared/_refunds.html.erb +31 -29
  213. data/app/views/spree/admin/shared/_report_order_criteria.html.erb +27 -6
  214. data/app/views/spree/admin/shared/_sidebar.html.erb +19 -1
  215. data/app/views/spree/admin/shared/_table_filter.html.erb +3 -3
  216. data/app/views/spree/admin/shared/_translations.html.erb +33 -1
  217. data/app/views/spree/admin/shared/_version.html.erb +1 -1
  218. data/app/views/spree/admin/shared/named_types/_index.html.erb +3 -1
  219. data/app/views/spree/admin/shipping_categories/index.html.erb +3 -1
  220. data/app/views/spree/admin/shipping_methods/index.html.erb +3 -1
  221. data/app/views/spree/admin/state_changes/index.html.erb +5 -2
  222. data/app/views/spree/admin/states/_state_list.html.erb +25 -24
  223. data/app/views/spree/admin/states/index.html.erb +1 -1
  224. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +2 -2
  225. data/app/views/spree/admin/stock_locations/index.html.erb +3 -1
  226. data/app/views/spree/admin/stock_movements/index.html.erb +28 -26
  227. data/app/views/spree/admin/stock_transfers/_stock_movements.html.erb +20 -18
  228. data/app/views/spree/admin/stock_transfers/index.html.erb +6 -4
  229. data/app/views/spree/admin/stock_transfers/new.html.erb +3 -3
  230. data/app/views/spree/admin/stock_transfers/show.html.erb +3 -3
  231. data/app/views/spree/admin/store_credit_categories/index.html.erb +3 -1
  232. data/app/views/spree/admin/store_credits/index.html.erb +3 -1
  233. data/app/views/spree/admin/stores/_form.html.erb +128 -68
  234. data/app/views/spree/admin/stores/edit.html.erb +1 -1
  235. data/app/views/spree/admin/stores/index.html.erb +4 -2
  236. data/app/views/spree/admin/tax_categories/index.html.erb +29 -27
  237. data/app/views/spree/admin/tax_rates/index.html.erb +3 -1
  238. data/app/views/spree/admin/taxonomies/_list.html.erb +24 -22
  239. data/app/views/spree/admin/taxonomies/edit.html.erb +2 -2
  240. data/app/views/spree/admin/taxonomies/index.html.erb +1 -1
  241. data/app/views/spree/admin/taxons/_form.html.erb +3 -3
  242. data/app/views/spree/admin/taxons/_taxon_table.html.erb +24 -22
  243. data/app/views/spree/admin/taxons/edit.html.erb +6 -2
  244. data/app/views/spree/admin/taxons/index.html.erb +1 -1
  245. data/app/views/spree/admin/users/_lifetime_stats.html.erb +24 -23
  246. data/app/views/spree/admin/users/_sidebar.html.erb +5 -5
  247. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -1
  248. data/app/views/spree/admin/users/edit.html.erb +2 -2
  249. data/app/views/spree/admin/users/index.html.erb +25 -23
  250. data/app/views/spree/admin/users/items.html.erb +3 -2
  251. data/app/views/spree/admin/users/orders.html.erb +30 -29
  252. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +3 -3
  253. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +2 -2
  254. data/app/views/spree/admin/variants/_form.html.erb +14 -2
  255. data/app/views/spree/admin/variants/_split.js.erb +2 -2
  256. data/app/views/spree/admin/variants/index.html.erb +7 -5
  257. data/app/views/spree/admin/zones/index.html.erb +4 -4
  258. data/app/views/spree/layouts/admin.html.erb +33 -27
  259. data/config/initializers/ransack.rb +31 -0
  260. data/config/routes.rb +1 -0
  261. data/lib/spree/backend.rb +2 -0
  262. data/lib/spree_backend.rb +0 -1
  263. data/spec/fixtures/thinking-cat.jpg +0 -0
  264. data/spree_backend.gemspec +6 -4
  265. data/vendor/assets/javascripts/js.cookie.js +154 -156
  266. data/vendor/assets/javascripts/purify.js +1217 -0
  267. data/vendor/assets/javascripts/sortable.js +3709 -0
  268. data/vendor/assets/stylesheets/animate.css +7 -3156
  269. data/vendor/assets/stylesheets/jquery.jstree/themes/spree/style.scss +23 -9
  270. metadata +138 -25
@@ -5,11 +5,11 @@ Gem::Specification.new do |s|
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.name = 'spree_backend'
7
7
  s.version = Spree.version
8
- s.author = 'Sean Schofield'
9
- s.email = 'sean@spreecommerce.com'
8
+ s.authors = ['Sean Schofield', 'Spark Solutions']
9
+ s.email = 'hello@spreecommerce.org'
10
10
  s.summary = 'backend e-commerce functionality for the Spree project.'
11
11
  s.description = 'Required dependency for Spree'
12
- s.homepage = 'http://spreecommerce.org'
12
+ s.homepage = 'https://spreecommerce.org'
13
13
  s.license = 'BSD-3-Clause'
14
14
 
15
15
  s.metadata = {
@@ -28,8 +28,10 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency 'spree_api', s.version
29
29
  s.add_dependency 'spree_core', s.version
30
30
 
31
- s.add_dependency 'bootstrap', '~> 4.3.1'
31
+ s.add_dependency 'bootstrap', '>= 4.3.1', '< 4.6.0'
32
32
  s.add_dependency 'glyphicons', '~> 1.0.2'
33
+ s.add_dependency 'flatpickr', '~> 4.6.0'
34
+ s.add_dependency 'inline_svg', '~> 1.5'
33
35
  s.add_dependency 'jquery-rails', '~> 4.3'
34
36
  s.add_dependency 'jquery-ui-rails', '~> 6.0.1'
35
37
  s.add_dependency 'select2-rails', '~> 3.5.0'
@@ -1,165 +1,163 @@
1
1
  /*!
2
- * JavaScript Cookie v2.2.0
2
+ * JavaScript Cookie v2.2.1
3
3
  * https://github.com/js-cookie/js-cookie
4
4
  *
5
5
  * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
6
6
  * Released under the MIT license
7
7
  */
8
8
  ;(function (factory) {
9
- var registeredInModuleLoader = false;
10
- if (typeof define === 'function' && define.amd) {
11
- define(factory);
12
- registeredInModuleLoader = true;
13
- }
14
- if (typeof exports === 'object') {
15
- module.exports = factory();
16
- registeredInModuleLoader = true;
17
- }
18
- if (!registeredInModuleLoader) {
19
- var OldCookies = window.Cookies;
20
- var api = window.Cookies = factory();
21
- api.noConflict = function () {
22
- window.Cookies = OldCookies;
23
- return api;
24
- };
25
- }
9
+ var registeredInModuleLoader;
10
+ if (typeof define === 'function' && define.amd) {
11
+ define(factory);
12
+ registeredInModuleLoader = true;
13
+ }
14
+ if (typeof exports === 'object') {
15
+ module.exports = factory();
16
+ registeredInModuleLoader = true;
17
+ }
18
+ if (!registeredInModuleLoader) {
19
+ var OldCookies = window.Cookies;
20
+ var api = window.Cookies = factory();
21
+ api.noConflict = function () {
22
+ window.Cookies = OldCookies;
23
+ return api;
24
+ };
25
+ }
26
26
  }(function () {
27
- function extend () {
28
- var i = 0;
29
- var result = {};
30
- for (; i < arguments.length; i++) {
31
- var attributes = arguments[ i ];
32
- for (var key in attributes) {
33
- result[key] = attributes[key];
34
- }
35
- }
36
- return result;
37
- }
38
-
39
- function init (converter) {
40
- function api (key, value, attributes) {
41
- var result;
42
- if (typeof document === 'undefined') {
43
- return;
44
- }
45
-
46
- // Write
47
-
48
- if (arguments.length > 1) {
49
- attributes = extend({
50
- path: '/'
51
- }, api.defaults, attributes);
52
-
53
- if (typeof attributes.expires === 'number') {
54
- var expires = new Date();
55
- expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
56
- attributes.expires = expires;
57
- }
58
-
59
- // We're using "expires" because "max-age" is not supported by IE
60
- attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
61
-
62
- try {
63
- result = JSON.stringify(value);
64
- if (/^[\{\[]/.test(result)) {
65
- value = result;
66
- }
67
- } catch (e) {}
68
-
69
- if (!converter.write) {
70
- value = encodeURIComponent(String(value))
71
- .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
72
- } else {
73
- value = converter.write(value, key);
74
- }
75
-
76
- key = encodeURIComponent(String(key));
77
- key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
78
- key = key.replace(/[\(\)]/g, escape);
79
-
80
- var stringifiedAttributes = '';
81
-
82
- for (var attributeName in attributes) {
83
- if (!attributes[attributeName]) {
84
- continue;
85
- }
86
- stringifiedAttributes += '; ' + attributeName;
87
- if (attributes[attributeName] === true) {
88
- continue;
89
- }
90
- stringifiedAttributes += '=' + attributes[attributeName];
91
- }
92
- return (document.cookie = key + '=' + value + stringifiedAttributes);
93
- }
94
-
95
- // Read
96
-
97
- if (!key) {
98
- result = {};
99
- }
100
-
101
- // To prevent the for loop in the first place assign an empty array
102
- // in case there are no cookies at all. Also prevents odd result when
103
- // calling "get()"
104
- var cookies = document.cookie ? document.cookie.split('; ') : [];
105
- var rdecode = /(%[0-9A-Z]{2})+/g;
106
- var i = 0;
107
-
108
- for (; i < cookies.length; i++) {
109
- var parts = cookies[i].split('=');
110
- var cookie = parts.slice(1).join('=');
111
-
112
- if (!this.json && cookie.charAt(0) === '"') {
113
- cookie = cookie.slice(1, -1);
114
- }
115
-
116
- try {
117
- var name = parts[0].replace(rdecode, decodeURIComponent);
118
- cookie = converter.read ?
119
- converter.read(cookie, name) : converter(cookie, name) ||
120
- cookie.replace(rdecode, decodeURIComponent);
121
-
122
- if (this.json) {
123
- try {
124
- cookie = JSON.parse(cookie);
125
- } catch (e) {}
126
- }
127
-
128
- if (key === name) {
129
- result = cookie;
130
- break;
131
- }
132
-
133
- if (!key) {
134
- result[name] = cookie;
135
- }
136
- } catch (e) {}
137
- }
138
-
139
- return result;
140
- }
141
-
142
- api.set = api;
143
- api.get = function (key) {
144
- return api.call(api, key);
145
- };
146
- api.getJSON = function () {
147
- return api.apply({
148
- json: true
149
- }, [].slice.call(arguments));
150
- };
151
- api.defaults = {};
152
-
153
- api.remove = function (key, attributes) {
154
- api(key, '', extend(attributes, {
155
- expires: -1
156
- }));
157
- };
158
-
159
- api.withConverter = init;
160
-
161
- return api;
162
- }
163
-
164
- return init(function () {});
27
+ function extend () {
28
+ var i = 0;
29
+ var result = {};
30
+ for (; i < arguments.length; i++) {
31
+ var attributes = arguments[ i ];
32
+ for (var key in attributes) {
33
+ result[key] = attributes[key];
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+
39
+ function decode (s) {
40
+ return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
41
+ }
42
+
43
+ function init (converter) {
44
+ function api() {}
45
+
46
+ function set (key, value, attributes) {
47
+ if (typeof document === 'undefined') {
48
+ return;
49
+ }
50
+
51
+ attributes = extend({
52
+ path: '/'
53
+ }, api.defaults, attributes);
54
+
55
+ if (typeof attributes.expires === 'number') {
56
+ attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
57
+ }
58
+
59
+ // We're using "expires" because "max-age" is not supported by IE
60
+ attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
61
+
62
+ try {
63
+ var result = JSON.stringify(value);
64
+ if (/^[\{\[]/.test(result)) {
65
+ value = result;
66
+ }
67
+ } catch (e) {}
68
+
69
+ value = converter.write ?
70
+ converter.write(value, key) :
71
+ encodeURIComponent(String(value))
72
+ .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
73
+
74
+ key = encodeURIComponent(String(key))
75
+ .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
76
+ .replace(/[\(\)]/g, escape);
77
+
78
+ var stringifiedAttributes = '';
79
+ for (var attributeName in attributes) {
80
+ if (!attributes[attributeName]) {
81
+ continue;
82
+ }
83
+ stringifiedAttributes += '; ' + attributeName;
84
+ if (attributes[attributeName] === true) {
85
+ continue;
86
+ }
87
+
88
+ // Considers RFC 6265 section 5.2:
89
+ // ...
90
+ // 3. If the remaining unparsed-attributes contains a %x3B (";")
91
+ // character:
92
+ // Consume the characters of the unparsed-attributes up to,
93
+ // not including, the first %x3B (";") character.
94
+ // ...
95
+ stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
96
+ }
97
+
98
+ return (document.cookie = key + '=' + value + stringifiedAttributes);
99
+ }
100
+
101
+ function get (key, json) {
102
+ if (typeof document === 'undefined') {
103
+ return;
104
+ }
105
+
106
+ var jar = {};
107
+ // To prevent the for loop in the first place assign an empty array
108
+ // in case there are no cookies at all.
109
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
110
+ var i = 0;
111
+
112
+ for (; i < cookies.length; i++) {
113
+ var parts = cookies[i].split('=');
114
+ var cookie = parts.slice(1).join('=');
115
+
116
+ if (!json && cookie.charAt(0) === '"') {
117
+ cookie = cookie.slice(1, -1);
118
+ }
119
+
120
+ try {
121
+ var name = decode(parts[0]);
122
+ cookie = (converter.read || converter)(cookie, name) ||
123
+ decode(cookie);
124
+
125
+ if (json) {
126
+ try {
127
+ cookie = JSON.parse(cookie);
128
+ } catch (e) {}
129
+ }
130
+
131
+ jar[name] = cookie;
132
+
133
+ if (key === name) {
134
+ break;
135
+ }
136
+ } catch (e) {}
137
+ }
138
+
139
+ return key ? jar[key] : jar;
140
+ }
141
+
142
+ api.set = set;
143
+ api.get = function (key) {
144
+ return get(key, false /* read as raw */);
145
+ };
146
+ api.getJSON = function (key) {
147
+ return get(key, true /* read as json */);
148
+ };
149
+ api.remove = function (key, attributes) {
150
+ set(key, '', extend(attributes, {
151
+ expires: -1
152
+ }));
153
+ };
154
+
155
+ api.defaults = {};
156
+
157
+ api.withConverter = init;
158
+
159
+ return api;
160
+ }
161
+
162
+ return init(function () {});
165
163
  }));