spree_frontend 4.2.7 → 4.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) 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/locale.es6 +13 -0
  17. data/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js +3 -3
  18. data/app/assets/javascripts/spree/frontend/views/spree/products/index.js +0 -9
  19. data/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6 +46 -0
  20. data/app/assets/javascripts/spree/frontend.js +3 -0
  21. data/app/assets/javascripts/spree.js +78 -0
  22. data/app/assets/stylesheets/spree/frontend/application.scss +1 -0
  23. data/app/assets/stylesheets/spree/frontend/components-bootstrap/button.scss +8 -0
  24. data/app/assets/stylesheets/spree/frontend/helpers/spree/frontend_helper.scss +41 -0
  25. data/app/assets/stylesheets/spree/frontend/variables/variables.scss +2 -2
  26. data/app/assets/stylesheets/spree/frontend/views/spree/checkout/edit.scss +17 -5
  27. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/_index.scss +1 -0
  28. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/product_buy_bar.scss +20 -0
  29. data/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss +54 -67
  30. data/app/assets/stylesheets/spree/frontend/views/spree/shared/category_nav_bar.scss +3 -3
  31. data/app/assets/stylesheets/spree/frontend/views/spree/shared/footer.scss +4 -0
  32. data/app/assets/stylesheets/spree/frontend/views/spree/shared/main_nav_bar.scss +12 -1
  33. data/app/controllers/spree/addresses_controller.rb +14 -19
  34. data/app/controllers/spree/checkout_controller.rb +5 -3
  35. data/app/controllers/spree/cms_pages_controller.rb +29 -0
  36. data/app/controllers/spree/content_controller.rb +0 -2
  37. data/app/controllers/spree/errors_controller.rb +11 -0
  38. data/app/controllers/spree/home_controller.rb +34 -1
  39. data/app/controllers/spree/locale_controller.rb +7 -1
  40. data/app/controllers/spree/orders_controller.rb +9 -7
  41. data/app/controllers/spree/products_controller.rb +14 -13
  42. data/app/controllers/spree/store_controller.rb +25 -1
  43. data/app/controllers/spree/taxons_controller.rb +12 -5
  44. data/app/helpers/spree/addresses_helper.rb +9 -4
  45. data/app/helpers/spree/cms_pages_helper.rb +23 -0
  46. data/app/helpers/spree/frontend_helper.rb +109 -10
  47. data/app/helpers/spree/navigation_helper.rb +73 -4
  48. data/app/helpers/spree/products_filters_helper.rb +168 -0
  49. data/app/helpers/spree/store_helper.rb +3 -1
  50. data/app/views/spree/checkout/_address.html.erb +1 -1
  51. data/app/views/spree/checkout/_credit_card.html.erb +1 -0
  52. data/app/views/spree/cms_pages/show.html.erb +16 -0
  53. data/app/views/spree/errors/forbidden.html.erb +0 -0
  54. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  55. data/app/views/spree/home/index.html.erb +19 -118
  56. data/app/views/spree/layouts/spree_application.html.erb +1 -1
  57. data/app/views/spree/products/_description.html.erb +16 -19
  58. data/app/views/spree/products/_filters_desktop.html.erb +50 -15
  59. data/app/views/spree/products/_filters_mobile.html.erb +38 -10
  60. data/app/views/spree/products/_sort_desktop.html.erb +17 -11
  61. data/app/views/spree/products/_sort_mobile.html.erb +16 -0
  62. data/app/views/spree/products/index.html.erb +1 -1
  63. data/app/views/spree/shared/_carousel_4_products.html.erb +2 -2
  64. data/app/views/spree/shared/_checkout_header.html.erb +22 -21
  65. data/app/views/spree/shared/_copyright.html.erb +1 -1
  66. data/app/views/spree/shared/_footer.html.erb +15 -9
  67. data/app/views/spree/shared/_head.html.erb +1 -1
  68. data/app/views/spree/shared/_header.html.erb +3 -3
  69. data/app/views/spree/shared/_main_nav_bar.html.erb +61 -43
  70. data/app/views/spree/shared/_mobile_navigation.html.erb +30 -19
  71. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  72. data/app/views/spree/shared/_option_values.html.erb +2 -21
  73. data/app/views/spree/shared/_order_details.html.erb +1 -1
  74. data/app/views/spree/shared/_paths.html.erb +8 -0
  75. data/app/views/spree/shared/_properties.html.erb +4 -0
  76. data/app/views/spree/shared/_translations.html.erb +2 -1
  77. data/app/views/spree/shared/carousel/_single.html.erb +1 -1
  78. data/app/views/spree/shared/carousel/_thumbnails.html.erb +1 -1
  79. data/app/views/spree/shared/cms/pages/_edit_mode.html.erb +13 -0
  80. data/app/views/spree/shared/cms/sections/_featured_article.html.erb +27 -0
  81. data/app/views/spree/shared/cms/sections/_hero_image.html.erb +60 -0
  82. data/app/views/spree/shared/cms/sections/_image_gallery.html.erb +171 -0
  83. data/app/views/spree/shared/cms/sections/_product_carousel.html.erb +5 -0
  84. data/app/views/spree/shared/cms/sections/_rich_text_content.html.erb +3 -0
  85. data/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb +118 -0
  86. data/app/views/spree/taxons/_header.html.erb +6 -1
  87. data/app/views/spree/users/show.html.erb +1 -1
  88. data/config/initializers/assets.rb +4 -13
  89. data/config/routes.rb +9 -3
  90. data/lib/generators/spree/frontend/install/install_generator.rb +5 -5
  91. data/lib/generators/spree/frontend/install/templates/app/assets/config/manifest.js +2 -0
  92. data/lib/generators/spree/frontend/install/templates/vendor/assets/javascripts/spree/frontend/all.js +8 -0
  93. data/lib/generators/spree/frontend/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +9 -0
  94. data/lib/spree/frontend/engine.rb +6 -0
  95. data/lib/spree/frontend.rb +6 -3
  96. data/spec/fixtures/files/store_favicon.ico +0 -0
  97. data/spree_frontend.gemspec +7 -3
  98. data/vendor/assets/javascripts/cleave.js +8 -0
  99. data/vendor/assets/javascripts/fetch.umd.js +531 -0
  100. data/vendor/assets/javascripts/jquery.payment.js +652 -0
  101. data/vendor/assets/javascripts/jsuri.js +458 -0
  102. data/vendor/assets/javascripts/polyfill.min.js +1 -0
  103. metadata +116 -70
  104. data/app/assets/images/homepage/big_category_banner.jpg +0 -0
  105. data/app/assets/images/homepage/big_category_banner_mobile.jpg +0 -0
  106. data/app/assets/images/homepage/big_category_banner_tablet_landscape.jpg +0 -0
  107. data/app/assets/images/homepage/big_category_banner_tablet_portrait.jpg +0 -0
  108. data/app/assets/images/homepage/category_banner_lower.jpg +0 -0
  109. data/app/assets/images/homepage/category_banner_lower_mobile.jpg +0 -0
  110. data/app/assets/images/homepage/category_banner_lower_tablet_landscape.jpg +0 -0
  111. data/app/assets/images/homepage/category_banner_lower_tablet_portrait.jpg +0 -0
  112. data/app/assets/images/homepage/category_banner_upper.jpg +0 -0
  113. data/app/assets/images/homepage/category_banner_upper_mobile.jpg +0 -0
  114. data/app/assets/images/homepage/category_banner_upper_tablet_landscape.jpg +0 -0
  115. data/app/assets/images/homepage/category_banner_upper_tablet_portrait.jpg +0 -0
  116. data/app/assets/images/homepage/main_banner.jpg +0 -0
  117. data/app/assets/images/homepage/main_banner_mobile.jpg +0 -0
  118. data/app/assets/images/homepage/main_banner_tablet_landscape.jpg +0 -0
  119. data/app/assets/images/homepage/main_banner_tablet_portrait.jpg +0 -0
  120. data/app/assets/images/homepage/promo_banner_left.jpg +0 -0
  121. data/app/assets/images/homepage/promo_banner_left_mobile.jpg +0 -0
  122. data/app/assets/images/homepage/promo_banner_left_tablet_landscape.jpg +0 -0
  123. data/app/assets/images/homepage/promo_banner_left_tablet_portrait.jpg +0 -0
  124. data/app/assets/images/homepage/promo_banner_right.jpg +0 -0
  125. data/app/assets/images/homepage/promo_banner_right_mobile.jpg +0 -0
  126. data/app/assets/images/homepage/promo_banner_right_tablet_landscape.jpg +0 -0
  127. data/app/assets/images/homepage/promo_banner_right_tablet_portrait.jpg +0 -0
  128. data/app/assets/images/meganav/promo_banner_left-first-category.jpg +0 -0
  129. data/app/assets/images/meganav/promo_banner_left-second-category.jpg +0 -0
  130. data/app/assets/images/meganav/promo_banner_left-third-category.jpg +0 -0
  131. data/app/assets/images/meganav/promo_banner_right-first-category.jpg +0 -0
  132. data/app/assets/images/meganav/promo_banner_right-second-category.jpg +0 -0
  133. data/app/assets/images/meganav/promo_banner_right-third-category.jpg +0 -0
  134. data/app/assets/images/noimage/big_category_banner.jpg +0 -0
  135. data/app/assets/images/noimage/big_category_banner_mobile.jpg +0 -0
  136. data/app/assets/images/noimage/big_category_banner_tablet_landscape.jpg +0 -0
  137. data/app/assets/images/noimage/big_category_banner_tablet_portrait.jpg +0 -0
  138. data/app/assets/images/noimage/category_banner.jpg +0 -0
  139. data/app/assets/images/noimage/category_banner_mobile.jpg +0 -0
  140. data/app/assets/images/noimage/category_banner_plp.jpg +0 -0
  141. data/app/assets/images/noimage/category_banner_tablet_landscape.jpg +0 -0
  142. data/app/assets/images/noimage/category_banner_tablet_portrait.jpg +0 -0
  143. data/app/assets/images/noimage/main_banner.jpg +0 -0
  144. data/app/assets/images/noimage/main_banner_mobile.jpg +0 -0
  145. data/app/assets/images/noimage/main_banner_tablet_landscape.jpg +0 -0
  146. data/app/assets/images/noimage/main_banner_tablet_portrait.jpg +0 -0
  147. data/app/assets/images/noimage/product_photo.jpg +0 -0
  148. data/app/assets/images/noimage/promo_banner.jpg +0 -0
  149. data/app/assets/images/noimage/promo_banner_megamenu.jpg +0 -0
  150. data/app/assets/images/noimage/promo_banner_mobile.jpg +0 -0
  151. data/app/assets/images/noimage/promo_banner_tablet_landscape.jpg +0 -0
  152. data/app/assets/images/noimage/promo_banner_tablet_portrait.jpg +0 -0
  153. data/app/assets/javascripts/spree/frontend/locale.js +0 -13
  154. data/app/assets/javascripts/spree/frontend/multi_currency.js +0 -13
  155. data/lib/generators/spree/frontend/install/templates/config/initializers/spree_storefront.rb +0 -1
  156. data/lib/generators/spree/frontend/install/templates/config/spree_storefront.yml +0 -99
@@ -0,0 +1,652 @@
1
+ // Generated by CoffeeScript 1.7.1
2
+ (function() {
3
+ var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlashAndSpace, hasTextSelected, luhnCheck, reFormatCVC, reFormatCardNumber, reFormatExpiry, reFormatNumeric, replaceFullWidthChars, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, safeVal, setCardType,
4
+ __slice = [].slice,
5
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
6
+
7
+ $ = window.jQuery || window.Zepto || window.$;
8
+
9
+ $.payment = {};
10
+
11
+ $.payment.fn = {};
12
+
13
+ $.fn.payment = function() {
14
+ var args, method;
15
+ method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
16
+ return $.payment.fn[method].apply(this, args);
17
+ };
18
+
19
+ defaultFormat = /(\d{1,4})/g;
20
+
21
+ $.payment.cards = cards = [
22
+ {
23
+ type: 'maestro',
24
+ patterns: [5018, 502, 503, 506, 56, 58, 639, 6220, 67],
25
+ format: defaultFormat,
26
+ length: [12, 13, 14, 15, 16, 17, 18, 19],
27
+ cvcLength: [3],
28
+ luhn: true
29
+ }, {
30
+ type: 'forbrugsforeningen',
31
+ patterns: [600],
32
+ format: defaultFormat,
33
+ length: [16],
34
+ cvcLength: [3],
35
+ luhn: true
36
+ }, {
37
+ type: 'dankort',
38
+ patterns: [5019],
39
+ format: defaultFormat,
40
+ length: [16],
41
+ cvcLength: [3],
42
+ luhn: true
43
+ }, {
44
+ type: 'visa',
45
+ patterns: [4],
46
+ format: defaultFormat,
47
+ length: [13, 16],
48
+ cvcLength: [3],
49
+ luhn: true
50
+ }, {
51
+ type: 'mastercard',
52
+ patterns: [51, 52, 53, 54, 55, 22, 23, 24, 25, 26, 27],
53
+ format: defaultFormat,
54
+ length: [16],
55
+ cvcLength: [3],
56
+ luhn: true
57
+ }, {
58
+ type: 'amex',
59
+ patterns: [34, 37],
60
+ format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/,
61
+ length: [15],
62
+ cvcLength: [3, 4],
63
+ luhn: true
64
+ }, {
65
+ type: 'dinersclub',
66
+ patterns: [30, 36, 38, 39],
67
+ format: /(\d{1,4})(\d{1,6})?(\d{1,4})?/,
68
+ length: [14],
69
+ cvcLength: [3],
70
+ luhn: true
71
+ }, {
72
+ type: 'discover',
73
+ patterns: [60, 64, 65, 622],
74
+ format: defaultFormat,
75
+ length: [16],
76
+ cvcLength: [3],
77
+ luhn: true
78
+ }, {
79
+ type: 'unionpay',
80
+ patterns: [62, 88],
81
+ format: defaultFormat,
82
+ length: [16, 17, 18, 19],
83
+ cvcLength: [3],
84
+ luhn: false
85
+ }, {
86
+ type: 'jcb',
87
+ patterns: [35],
88
+ format: defaultFormat,
89
+ length: [16],
90
+ cvcLength: [3],
91
+ luhn: true
92
+ }
93
+ ];
94
+
95
+ cardFromNumber = function(num) {
96
+ var card, p, pattern, _i, _j, _len, _len1, _ref;
97
+ num = (num + '').replace(/\D/g, '');
98
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
99
+ card = cards[_i];
100
+ _ref = card.patterns;
101
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
102
+ pattern = _ref[_j];
103
+ p = pattern + '';
104
+ if (num.substr(0, p.length) === p) {
105
+ return card;
106
+ }
107
+ }
108
+ }
109
+ };
110
+
111
+ cardFromType = function(type) {
112
+ var card, _i, _len;
113
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
114
+ card = cards[_i];
115
+ if (card.type === type) {
116
+ return card;
117
+ }
118
+ }
119
+ };
120
+
121
+ luhnCheck = function(num) {
122
+ var digit, digits, odd, sum, _i, _len;
123
+ odd = true;
124
+ sum = 0;
125
+ digits = (num + '').split('').reverse();
126
+ for (_i = 0, _len = digits.length; _i < _len; _i++) {
127
+ digit = digits[_i];
128
+ digit = parseInt(digit, 10);
129
+ if ((odd = !odd)) {
130
+ digit *= 2;
131
+ }
132
+ if (digit > 9) {
133
+ digit -= 9;
134
+ }
135
+ sum += digit;
136
+ }
137
+ return sum % 10 === 0;
138
+ };
139
+
140
+ hasTextSelected = function($target) {
141
+ var _ref;
142
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
143
+ return true;
144
+ }
145
+ if ((typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? _ref.createRange : void 0 : void 0) != null) {
146
+ if (document.selection.createRange().text) {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
151
+ };
152
+
153
+ safeVal = function(value, $target) {
154
+ var currPair, cursor, digit, error, last, prevPair;
155
+ try {
156
+ cursor = $target.prop('selectionStart');
157
+ } catch (_error) {
158
+ error = _error;
159
+ cursor = null;
160
+ }
161
+ last = $target.val();
162
+ $target.val(value);
163
+ if (cursor !== null && $target.is(":focus")) {
164
+ if (cursor === last.length) {
165
+ cursor = value.length;
166
+ }
167
+ if (last !== value) {
168
+ prevPair = last.slice(cursor - 1, +cursor + 1 || 9e9);
169
+ currPair = value.slice(cursor - 1, +cursor + 1 || 9e9);
170
+ digit = value[cursor];
171
+ if (/\d/.test(digit) && prevPair === ("" + digit + " ") && currPair === (" " + digit)) {
172
+ cursor = cursor + 1;
173
+ }
174
+ }
175
+ $target.prop('selectionStart', cursor);
176
+ return $target.prop('selectionEnd', cursor);
177
+ }
178
+ };
179
+
180
+ replaceFullWidthChars = function(str) {
181
+ var chars, chr, fullWidth, halfWidth, idx, value, _i, _len;
182
+ if (str == null) {
183
+ str = '';
184
+ }
185
+ fullWidth = '\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19';
186
+ halfWidth = '0123456789';
187
+ value = '';
188
+ chars = str.split('');
189
+ for (_i = 0, _len = chars.length; _i < _len; _i++) {
190
+ chr = chars[_i];
191
+ idx = fullWidth.indexOf(chr);
192
+ if (idx > -1) {
193
+ chr = halfWidth[idx];
194
+ }
195
+ value += chr;
196
+ }
197
+ return value;
198
+ };
199
+
200
+ reFormatNumeric = function(e) {
201
+ var $target;
202
+ $target = $(e.currentTarget);
203
+ return setTimeout(function() {
204
+ var value;
205
+ value = $target.val();
206
+ value = replaceFullWidthChars(value);
207
+ value = value.replace(/\D/g, '');
208
+ return safeVal(value, $target);
209
+ });
210
+ };
211
+
212
+ reFormatCardNumber = function(e) {
213
+ var $target;
214
+ $target = $(e.currentTarget);
215
+ return setTimeout(function() {
216
+ var value;
217
+ value = $target.val();
218
+ value = replaceFullWidthChars(value);
219
+ value = $.payment.formatCardNumber(value);
220
+ return safeVal(value, $target);
221
+ });
222
+ };
223
+
224
+ formatCardNumber = function(e) {
225
+ var $target, card, digit, length, re, upperLength, value;
226
+ digit = String.fromCharCode(e.which);
227
+ if (!/^\d+$/.test(digit)) {
228
+ return;
229
+ }
230
+ $target = $(e.currentTarget);
231
+ value = $target.val();
232
+ card = cardFromNumber(value + digit);
233
+ length = (value.replace(/\D/g, '') + digit).length;
234
+ upperLength = 16;
235
+ if (card) {
236
+ upperLength = card.length[card.length.length - 1];
237
+ }
238
+ if (length >= upperLength) {
239
+ return;
240
+ }
241
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
242
+ return;
243
+ }
244
+ if (card && card.type === 'amex') {
245
+ re = /^(\d{4}|\d{4}\s\d{6})$/;
246
+ } else {
247
+ re = /(?:^|\s)(\d{4})$/;
248
+ }
249
+ if (re.test(value)) {
250
+ e.preventDefault();
251
+ return setTimeout(function() {
252
+ return $target.val(value + ' ' + digit);
253
+ });
254
+ } else if (re.test(value + digit)) {
255
+ e.preventDefault();
256
+ return setTimeout(function() {
257
+ return $target.val(value + digit + ' ');
258
+ });
259
+ }
260
+ };
261
+
262
+ formatBackCardNumber = function(e) {
263
+ var $target, value;
264
+ $target = $(e.currentTarget);
265
+ value = $target.val();
266
+ if (e.which !== 8) {
267
+ return;
268
+ }
269
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
270
+ return;
271
+ }
272
+ if (/\d\s$/.test(value)) {
273
+ e.preventDefault();
274
+ return setTimeout(function() {
275
+ return $target.val(value.replace(/\d\s$/, ''));
276
+ });
277
+ } else if (/\s\d?$/.test(value)) {
278
+ e.preventDefault();
279
+ return setTimeout(function() {
280
+ return $target.val(value.replace(/\d$/, ''));
281
+ });
282
+ }
283
+ };
284
+
285
+ reFormatExpiry = function(e) {
286
+ var $target;
287
+ $target = $(e.currentTarget);
288
+ return setTimeout(function() {
289
+ var value;
290
+ value = $target.val();
291
+ value = replaceFullWidthChars(value);
292
+ value = $.payment.formatExpiry(value);
293
+ return safeVal(value, $target);
294
+ });
295
+ };
296
+
297
+ formatExpiry = function(e) {
298
+ var $target, digit, val;
299
+ digit = String.fromCharCode(e.which);
300
+ if (!/^\d+$/.test(digit)) {
301
+ return;
302
+ }
303
+ $target = $(e.currentTarget);
304
+ val = $target.val() + digit;
305
+ if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
306
+ e.preventDefault();
307
+ return setTimeout(function() {
308
+ return $target.val("0" + val + " / ");
309
+ });
310
+ } else if (/^\d\d$/.test(val)) {
311
+ e.preventDefault();
312
+ return setTimeout(function() {
313
+ var m1, m2;
314
+ m1 = parseInt(val[0], 10);
315
+ m2 = parseInt(val[1], 10);
316
+ if (m2 > 2 && m1 !== 0) {
317
+ return $target.val("0" + m1 + " / " + m2);
318
+ } else {
319
+ return $target.val("" + val + " / ");
320
+ }
321
+ });
322
+ }
323
+ };
324
+
325
+ formatForwardExpiry = function(e) {
326
+ var $target, digit, val;
327
+ digit = String.fromCharCode(e.which);
328
+ if (!/^\d+$/.test(digit)) {
329
+ return;
330
+ }
331
+ $target = $(e.currentTarget);
332
+ val = $target.val();
333
+ if (/^\d\d$/.test(val)) {
334
+ return $target.val("" + val + " / ");
335
+ }
336
+ };
337
+
338
+ formatForwardSlashAndSpace = function(e) {
339
+ var $target, val, which;
340
+ which = String.fromCharCode(e.which);
341
+ if (!(which === '/' || which === ' ')) {
342
+ return;
343
+ }
344
+ $target = $(e.currentTarget);
345
+ val = $target.val();
346
+ if (/^\d$/.test(val) && val !== '0') {
347
+ return $target.val("0" + val + " / ");
348
+ }
349
+ };
350
+
351
+ formatBackExpiry = function(e) {
352
+ var $target, value;
353
+ $target = $(e.currentTarget);
354
+ value = $target.val();
355
+ if (e.which !== 8) {
356
+ return;
357
+ }
358
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
359
+ return;
360
+ }
361
+ if (/\d\s\/\s$/.test(value)) {
362
+ e.preventDefault();
363
+ return setTimeout(function() {
364
+ return $target.val(value.replace(/\d\s\/\s$/, ''));
365
+ });
366
+ }
367
+ };
368
+
369
+ reFormatCVC = function(e) {
370
+ var $target;
371
+ $target = $(e.currentTarget);
372
+ return setTimeout(function() {
373
+ var value;
374
+ value = $target.val();
375
+ value = replaceFullWidthChars(value);
376
+ value = value.replace(/\D/g, '').slice(0, 4);
377
+ return safeVal(value, $target);
378
+ });
379
+ };
380
+
381
+ restrictNumeric = function(e) {
382
+ var input;
383
+ if (e.metaKey || e.ctrlKey) {
384
+ return true;
385
+ }
386
+ if (e.which === 32) {
387
+ return false;
388
+ }
389
+ if (e.which === 0) {
390
+ return true;
391
+ }
392
+ if (e.which < 33) {
393
+ return true;
394
+ }
395
+ input = String.fromCharCode(e.which);
396
+ return !!/[\d\s]/.test(input);
397
+ };
398
+
399
+ restrictCardNumber = function(e) {
400
+ var $target, card, digit, value;
401
+ $target = $(e.currentTarget);
402
+ digit = String.fromCharCode(e.which);
403
+ if (!/^\d+$/.test(digit)) {
404
+ return;
405
+ }
406
+ if (hasTextSelected($target)) {
407
+ return;
408
+ }
409
+ value = ($target.val() + digit).replace(/\D/g, '');
410
+ card = cardFromNumber(value);
411
+ if (card) {
412
+ return value.length <= card.length[card.length.length - 1];
413
+ } else {
414
+ return value.length <= 16;
415
+ }
416
+ };
417
+
418
+ restrictExpiry = function(e) {
419
+ var $target, digit, value;
420
+ $target = $(e.currentTarget);
421
+ digit = String.fromCharCode(e.which);
422
+ if (!/^\d+$/.test(digit)) {
423
+ return;
424
+ }
425
+ if (hasTextSelected($target)) {
426
+ return;
427
+ }
428
+ value = $target.val() + digit;
429
+ value = value.replace(/\D/g, '');
430
+ if (value.length > 6) {
431
+ return false;
432
+ }
433
+ };
434
+
435
+ restrictCVC = function(e) {
436
+ var $target, digit, val;
437
+ $target = $(e.currentTarget);
438
+ digit = String.fromCharCode(e.which);
439
+ if (!/^\d+$/.test(digit)) {
440
+ return;
441
+ }
442
+ if (hasTextSelected($target)) {
443
+ return;
444
+ }
445
+ val = $target.val() + digit;
446
+ return val.length <= 4;
447
+ };
448
+
449
+ setCardType = function(e) {
450
+ var $target, allTypes, card, cardType, val;
451
+ $target = $(e.currentTarget);
452
+ val = $target.val();
453
+ cardType = $.payment.cardType(val) || 'unknown';
454
+ if (!$target.hasClass(cardType)) {
455
+ allTypes = (function() {
456
+ var _i, _len, _results;
457
+ _results = [];
458
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
459
+ card = cards[_i];
460
+ _results.push(card.type);
461
+ }
462
+ return _results;
463
+ })();
464
+ $target.removeClass('unknown');
465
+ $target.removeClass(allTypes.join(' '));
466
+ $target.addClass(cardType);
467
+ $target.toggleClass('identified', cardType !== 'unknown');
468
+ return $target.trigger('payment.cardType', cardType);
469
+ }
470
+ };
471
+
472
+ $.payment.fn.formatCardCVC = function() {
473
+ this.on('keypress', restrictNumeric);
474
+ this.on('keypress', restrictCVC);
475
+ this.on('paste', reFormatCVC);
476
+ this.on('change', reFormatCVC);
477
+ this.on('input', reFormatCVC);
478
+ return this;
479
+ };
480
+
481
+ $.payment.fn.formatCardExpiry = function() {
482
+ this.on('keypress', restrictNumeric);
483
+ this.on('keypress', restrictExpiry);
484
+ this.on('keypress', formatExpiry);
485
+ this.on('keypress', formatForwardSlashAndSpace);
486
+ this.on('keypress', formatForwardExpiry);
487
+ this.on('keydown', formatBackExpiry);
488
+ this.on('change', reFormatExpiry);
489
+ this.on('input', reFormatExpiry);
490
+ return this;
491
+ };
492
+
493
+ $.payment.fn.formatCardNumber = function() {
494
+ this.on('keypress', restrictNumeric);
495
+ this.on('keypress', restrictCardNumber);
496
+ this.on('keypress', formatCardNumber);
497
+ this.on('keydown', formatBackCardNumber);
498
+ this.on('keyup', setCardType);
499
+ this.on('paste', reFormatCardNumber);
500
+ this.on('change', reFormatCardNumber);
501
+ this.on('input', reFormatCardNumber);
502
+ this.on('input', setCardType);
503
+ return this;
504
+ };
505
+
506
+ $.payment.fn.restrictNumeric = function() {
507
+ this.on('keypress', restrictNumeric);
508
+ this.on('paste', reFormatNumeric);
509
+ this.on('change', reFormatNumeric);
510
+ this.on('input', reFormatNumeric);
511
+ return this;
512
+ };
513
+
514
+ $.payment.fn.cardExpiryVal = function() {
515
+ return $.payment.cardExpiryVal($(this).val());
516
+ };
517
+
518
+ $.payment.cardExpiryVal = function(value) {
519
+ var month, prefix, year, _ref;
520
+ _ref = value.split(/[\s\/]+/, 2), month = _ref[0], year = _ref[1];
521
+ if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) {
522
+ prefix = (new Date).getFullYear();
523
+ prefix = prefix.toString().slice(0, 2);
524
+ year = prefix + year;
525
+ }
526
+ month = parseInt(month, 10);
527
+ year = parseInt(year, 10);
528
+ return {
529
+ month: month,
530
+ year: year
531
+ };
532
+ };
533
+
534
+ $.payment.validateCardNumber = function(num) {
535
+ var card, _ref;
536
+ num = (num + '').replace(/\s+|-/g, '');
537
+ if (!/^\d+$/.test(num)) {
538
+ return false;
539
+ }
540
+ card = cardFromNumber(num);
541
+ if (!card) {
542
+ return false;
543
+ }
544
+ return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
545
+ };
546
+
547
+ $.payment.validateCardExpiry = function(month, year) {
548
+ var currentTime, expiry, _ref;
549
+ if (typeof month === 'object' && 'month' in month) {
550
+ _ref = month, month = _ref.month, year = _ref.year;
551
+ }
552
+ if (!(month && year)) {
553
+ return false;
554
+ }
555
+ month = $.trim(month);
556
+ year = $.trim(year);
557
+ if (!/^\d+$/.test(month)) {
558
+ return false;
559
+ }
560
+ if (!/^\d+$/.test(year)) {
561
+ return false;
562
+ }
563
+ if (!((1 <= month && month <= 12))) {
564
+ return false;
565
+ }
566
+ if (year.length === 2) {
567
+ if (year < 70) {
568
+ year = "20" + year;
569
+ } else {
570
+ year = "19" + year;
571
+ }
572
+ }
573
+ if (year.length !== 4) {
574
+ return false;
575
+ }
576
+ expiry = new Date(year, month);
577
+ currentTime = new Date;
578
+ expiry.setMonth(expiry.getMonth() - 1);
579
+ expiry.setMonth(expiry.getMonth() + 1, 1);
580
+ return expiry > currentTime;
581
+ };
582
+
583
+ $.payment.validateCardCVC = function(cvc, type) {
584
+ var card, _ref;
585
+ cvc = $.trim(cvc);
586
+ if (!/^\d+$/.test(cvc)) {
587
+ return false;
588
+ }
589
+ card = cardFromType(type);
590
+ if (card != null) {
591
+ return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0;
592
+ } else {
593
+ return cvc.length >= 3 && cvc.length <= 4;
594
+ }
595
+ };
596
+
597
+ $.payment.cardType = function(num) {
598
+ var _ref;
599
+ if (!num) {
600
+ return null;
601
+ }
602
+ return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null;
603
+ };
604
+
605
+ $.payment.formatCardNumber = function(num) {
606
+ var card, groups, upperLength, _ref;
607
+ num = num.replace(/\D/g, '');
608
+ card = cardFromNumber(num);
609
+ if (!card) {
610
+ return num;
611
+ }
612
+ upperLength = card.length[card.length.length - 1];
613
+ num = num.slice(0, upperLength);
614
+ if (card.format.global) {
615
+ return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
616
+ } else {
617
+ groups = card.format.exec(num);
618
+ if (groups == null) {
619
+ return;
620
+ }
621
+ groups.shift();
622
+ groups = $.grep(groups, function(n) {
623
+ return n;
624
+ });
625
+ return groups.join(' ');
626
+ }
627
+ };
628
+
629
+ $.payment.formatExpiry = function(expiry) {
630
+ var mon, parts, sep, year;
631
+ parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);
632
+ if (!parts) {
633
+ return '';
634
+ }
635
+ mon = parts[1] || '';
636
+ sep = parts[2] || '';
637
+ year = parts[3] || '';
638
+ if (year.length > 0) {
639
+ sep = ' / ';
640
+ } else if (sep === ' /') {
641
+ mon = mon.substring(0, 1);
642
+ sep = '';
643
+ } else if (mon.length === 2 || sep.length > 0) {
644
+ sep = ' / ';
645
+ } else if (mon.length === 1 && (mon !== '0' && mon !== '1')) {
646
+ mon = "0" + mon;
647
+ sep = ' / ';
648
+ }
649
+ return mon + sep + year;
650
+ };
651
+
652
+ }).call(this);