camaleon_ecommerce 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/plugins/ecommerce/admin.js +33 -0
  6. data/app/assets/javascripts/plugins/ecommerce/cart.js +207 -0
  7. data/app/assets/javascripts/plugins/ecommerce/fix_form.js +10 -0
  8. data/app/assets/javascripts/plugins/ecommerce/jquery.creditCardValidator.js +208 -0
  9. data/app/assets/stylesheets/plugins/ecommerce/admin.scss +122 -0
  10. data/app/assets/stylesheets/plugins/ecommerce/front.scss +36 -0
  11. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +61 -0
  12. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +96 -0
  13. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +90 -0
  14. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +70 -0
  15. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +22 -0
  16. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +62 -0
  17. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +61 -0
  18. data/app/controllers/plugins/ecommerce/admin_controller.rb +20 -0
  19. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +166 -0
  20. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +255 -0
  21. data/app/controllers/plugins/ecommerce/front_controller.rb +18 -0
  22. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +46 -0
  23. data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +49 -0
  24. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +240 -0
  25. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +67 -0
  26. data/app/models/plugins/ecommerce/cart.rb +40 -0
  27. data/app/models/plugins/ecommerce/coupon.rb +25 -0
  28. data/app/models/plugins/ecommerce/coupon_decorator.rb +60 -0
  29. data/app/models/plugins/ecommerce/order.rb +65 -0
  30. data/app/models/plugins/ecommerce/order_decorator.rb +54 -0
  31. data/app/models/plugins/ecommerce/order_detail.rb +13 -0
  32. data/app/models/plugins/ecommerce/payment_method.rb +29 -0
  33. data/app/models/plugins/ecommerce/product.rb +14 -0
  34. data/app/models/plugins/ecommerce/shipping_method.rb +26 -0
  35. data/app/models/plugins/ecommerce/tax_rate.rb +18 -0
  36. data/app/views/camaleon_cms/html_mailer/order_received.html.erb +3 -0
  37. data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +3 -0
  38. data/app/views/camaleon_cms/html_mailer/recovery_cart.html.erb +4 -0
  39. data/app/views/layouts/plugins/ecommerce/mailer.html.erb +22 -0
  40. data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +73 -0
  41. data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +50 -0
  42. data/app/views/plugins/ecommerce/admin/index.html.erb +2 -0
  43. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +64 -0
  44. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +90 -0
  45. data/app/views/plugins/ecommerce/admin/orders/show.html.erb +173 -0
  46. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +115 -0
  47. data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +43 -0
  48. data/app/views/plugins/ecommerce/admin/payment_methods/show.html.erb +70 -0
  49. data/app/views/plugins/ecommerce/admin/prices/form.html.erb +49 -0
  50. data/app/views/plugins/ecommerce/admin/prices/index.html.erb +39 -0
  51. data/app/views/plugins/ecommerce/admin/prices/show.html.erb +19 -0
  52. data/app/views/plugins/ecommerce/admin/products/index.html.erb +114 -0
  53. data/app/views/plugins/ecommerce/admin/settings/index.html.erb +25 -0
  54. data/app/views/plugins/ecommerce/admin/shipping_methods/form.html.erb +39 -0
  55. data/app/views/plugins/ecommerce/admin/shipping_methods/index.html.erb +41 -0
  56. data/app/views/plugins/ecommerce/admin/shipping_methods/show.html.erb +22 -0
  57. data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +36 -0
  58. data/app/views/plugins/ecommerce/admin/tax_rates/index.html.erb +41 -0
  59. data/app/views/plugins/ecommerce/front/_post_list_item.html.erb +18 -0
  60. data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +59 -0
  61. data/app/views/plugins/ecommerce/front/checkout/index.html.erb +166 -0
  62. data/app/views/plugins/ecommerce/front/index.html.erb +2 -0
  63. data/app/views/plugins/ecommerce/front/list_products.html.erb +34 -0
  64. data/app/views/plugins/ecommerce/front/orders/index.html.erb +46 -0
  65. data/app/views/plugins/ecommerce/front/orders/pay_by_bank_transfer.html.erb +67 -0
  66. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card.html.erb +131 -0
  67. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card_authorize_net.erb +150 -0
  68. data/app/views/plugins/ecommerce/front/orders/select_payment.html.erb +70 -0
  69. data/app/views/plugins/ecommerce/front/orders/show.html.erb +76 -0
  70. data/app/views/plugins/ecommerce/front/product.html.erb +105 -0
  71. data/app/views/plugins/ecommerce/layouts/_ecommerce.html.erb +41 -0
  72. data/app/views/plugins/ecommerce/partials/_form_address.html.erb +84 -0
  73. data/app/views/plugins/ecommerce/partials/_table_order_products.html.erb +85 -0
  74. data/config/camaleon_plugin.json +48 -0
  75. data/config/currency.json +154 -0
  76. data/config/currency_en.json +154 -0
  77. data/config/currency_es.json +154 -0
  78. data/config/custom_models.rb +64 -0
  79. data/config/locales/readme.txt +1 -0
  80. data/config/locales/translation.yml +371 -0
  81. data/config/routes.rb +57 -0
  82. data/lib/camaleon_ecommerce.rb +4 -0
  83. data/lib/ecommerce.rb +4 -0
  84. data/lib/ecommerce/engine.rb +6 -0
  85. data/lib/ecommerce/version.rb +3 -0
  86. data/lib/tasks/ecommerce_tasks.rake +4 -0
  87. metadata +185 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c14d3d8eaab3ba498a24093c9335126ecd5c77e3
4
+ data.tar.gz: 09308d694b0989d78edab11a4a731c0af1f2901c
5
+ SHA512:
6
+ metadata.gz: 094b55b0b27af000cf5c8e73dfee3423d78bedba057570a4b26e1261496ac3b7e393d6838afab20e70eb1794c89a2756820fba12a4e96886816d2dace187ac11
7
+ data.tar.gz: e5acc4616ff7beb1ec8dfd59b1eb5510aa040d197a6583bd2fb8927db01151d7892e732cf1da1d5bebae38e0c2832c536139b2246f432afce546faa6820c4b5c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Owen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Ecommerce
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ecommerce'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,33 @@
1
+ jQuery(function(){
2
+ if($.fn.datepicker)$('#options_expirate_date').datepicker({
3
+ format: 'yyyy-mm-dd'
4
+ })
5
+
6
+
7
+ if($('#tab-select-payment-method > ul a').size() > 0)
8
+ {
9
+ $('#tab-select-payment-method > ul a').click(function (e) {
10
+ e.preventDefault()
11
+ disabled_inputs(this)
12
+ //$(this).tab('show')
13
+ })
14
+
15
+ function disabled_inputs(dom_a){
16
+ var attr_id = $(dom_a).attr('href')
17
+ $('#tab-select-payment-method .tab-content .tab-pane').find('input, select, textarea').attr('disabled', 'disabled');
18
+ $(attr_id).find('input, select, textarea').removeAttr('disabled');
19
+ }
20
+ disabled_inputs($('#tab-select-payment-method > ul li.active a')[0])
21
+ }
22
+
23
+ $('.box-adv-search').each(function(){
24
+ var cont = $(this);
25
+ var rnd = "input_"+Math.floor((Math.random() * 1000000) + 1);
26
+ cont.find('#adv-search > input').change(function(){
27
+ cont.find('form .' + rnd).val($(this).val());
28
+ }).clone().attr('type','hidden').addClass(rnd).appendTo(cont.find('form'));
29
+ cont.find('#adv-search .btn-group > button').click(function(){
30
+ cont.find('form').submit();
31
+ });
32
+ })
33
+ })
@@ -0,0 +1,207 @@
1
+ jQuery(function(){
2
+ if($('#table-shopping-cart td .text-qty').size() > 0)
3
+ {
4
+ $('#table-shopping-cart td .text-qty').change(function(){
5
+ if ($(this).val() < 1) return false;
6
+ var total = $('#table-shopping-cart tbody tr').map(function(){
7
+ var $tr = $(this);
8
+ var price = parseFloat($tr.find('td[data-price]').attr('data-price'));
9
+ var tax = parseFloat($tr.find('td[data-tax]').attr('data-tax'));
10
+ var qty = parseFloat($tr.find('td[data-qty] input.text-qty').val());
11
+ if(qty < 0) qty = 0;
12
+ var subtotal = (price + tax) * qty;
13
+ $tr.find('td[data-subtotal]').html('$'+subtotal.toFixed(2))
14
+ return subtotal;
15
+ }).get().reduce(function(a, b) { return a + b; }, 0);
16
+
17
+ $('#table-shopping-cart #total').html('$'+total.toFixed(2))
18
+ })
19
+ }
20
+ $('#checkout #ec_copy').click(function(){
21
+ $('#checkout #shipping_address').find('input, select, textarea').each(function(){
22
+ var id_from = $(this).attr('id').replace('shipping', 'billing');
23
+ $(this).val($('#billing_address #'+id_from).val())
24
+ })
25
+ return false;
26
+ });
27
+
28
+ if($('#e-payments-types > ul a').size() > 0)
29
+ {
30
+ $('#e-payments-types > ul a').click(function (e) {
31
+ e.preventDefault()
32
+ disabled_inputs(this)
33
+ //$(this).tab('show')
34
+ })
35
+
36
+ function disabled_inputs(dom_a){
37
+ var attr_id = $(dom_a).attr('href')
38
+ $('#e-payments-types .tab-content .tab-pane').find('input, select, textarea').attr('disabled', 'disabled');
39
+ $(attr_id).find('input, select, textarea').removeAttr('disabled');
40
+ }
41
+ disabled_inputs($('#e-payments-types > ul a')[0])
42
+ }
43
+
44
+ function set_total_amount(){
45
+ var value = parseFloat($('#checkout #shipping_methods option:checked').attr('data-price'));
46
+ var pre_total = parseFloat($('#checkout #order_total').attr('data-total'));
47
+ var dis = $('#checkout #coupon_application_total').attr('data-amount');
48
+ $('#checkout #shipping_total span').html(value.toFixed(2));
49
+ if(dis == 'free')
50
+ {
51
+ $('#checkout #order_total span').html(0);
52
+ $('#shipping_total').parent().hide()
53
+ }else{
54
+ $('#shipping_total').parent().show()
55
+ var total_final = (value + pre_total - parseFloat(dis)).toFixed(2);
56
+ $('#checkout #order_total span').html(total_final);
57
+ }
58
+ }
59
+
60
+ $('#checkout #shipping_methods').change(function(){
61
+ set_total_amount()
62
+ });
63
+
64
+ $('#checkout #e_coupon_apply_box button').click(function(){
65
+ var href = $('#e_coupon_apply_box').attr('data-href');
66
+ var token = $('#e_coupon_apply_box').attr('data-token');
67
+ var code = $('#e_coupon_apply_box .coupon-text').val();
68
+ $.post(href, {code: code, authenticity_token: token}, function(res){
69
+ if(res.error){
70
+ alert(res.error)
71
+ }else{
72
+
73
+ var text = res.data.text;
74
+ var discount_type = res.data.options.discount_type;
75
+ var amount = 0;
76
+ var pre_total = parseFloat($('#checkout #order_total').attr('data-total'));
77
+ if(discount_type == 'free_ship'){
78
+ amount = 'free';
79
+ }else if(discount_type == 'percent'){
80
+ amount = (parseFloat(res.data.options.amount) * pre_total / 100).toFixed(2);
81
+ text += ' ('+ res.data.current_unit +' '+ amount +')';
82
+ }else if(discount_type == 'money'){
83
+ amount = res.data.options.amount;
84
+ }
85
+ $('#checkout #coupon_application_total').attr('data-amount', amount);
86
+ $('#checkout #coupon_application_row').show().find('#coupon_application_total span').html(text)
87
+ $('#checkout #coupon_code').val(res.data.code)
88
+ $('#checkout #coupon_options').val(JSON.stringify(res.data.options))
89
+ set_total_amount()
90
+ }
91
+ }, 'json')
92
+ });
93
+
94
+
95
+ // pay by credit card
96
+ var card_valid = false;
97
+ var $form = $('#payment-form');
98
+ if($form.size() > 0){
99
+ /* If you're using Stripe for payments */
100
+ function payWithStripe(e) {
101
+ // e.preventDefault();
102
+
103
+ /* Visual feedback */
104
+ $form.find('[type=submit]').html('Validating <i class="fa fa-spinner fa-pulse"></i>');
105
+
106
+ if(!card_valid)
107
+ {
108
+ /* Visual feedback */
109
+ $form.find('[type=submit]').html('Try again');
110
+ /* Show Stripe errors on the form */
111
+ $form.find('.payment-errors').text("Credit Card Invalid");
112
+ $form.find('.payment-errors').closest('.row').show();
113
+ return false
114
+ }else{
115
+ if($form.valid()){
116
+ /* Visual feedback */
117
+ $form.find('[type=submit]').html('Processing <i class="fa fa-spinner fa-pulse"></i>');
118
+ /* Hide Stripe errors on the form */
119
+ $form.find('.payment-errors').closest('.row').hide();
120
+ $form.find('.payment-errors').text("");
121
+ }else{
122
+ return false;
123
+ }
124
+ }
125
+ }
126
+
127
+ $form.on('submit', payWithStripe);
128
+ $form.find('input[name="cardNumber"]').validateCreditCard(function(result) {
129
+ card_valid = result.valid;
130
+ // $('#credit_card_log').html('Card type: ' + (result.card_type == null ? '-' : result.card_type.name) + (result.valid ? '<span class="label label-success">Valid</span>' : '<span class="label label-danger">Not Valid</span>'))
131
+ });
132
+
133
+ /* Form validation */
134
+ jQuery.validator.addMethod("month", function(value, element) {
135
+ return this.optional(element) || /^(01|02|03|04|05|06|07|08|09|10|11|12)$/.test(value);
136
+ }, "Please specify a valid 2-digit month.");
137
+
138
+ jQuery.validator.addMethod("year", function(value, element) {
139
+ return this.optional(element) || /^[0-9]{2}$/.test(value);
140
+ }, "Please specify a valid 2-digit year.");
141
+
142
+ validator = $form.validate({
143
+ rules: {
144
+ cardNumber: {
145
+ required: true,
146
+ creditcard: true,
147
+ digits: true
148
+ },
149
+ expMonth: {
150
+ required: true,
151
+ month: true
152
+ },
153
+ expYear: {
154
+ required: true,
155
+ year: true
156
+ },
157
+ cvCode: {
158
+ required: true,
159
+ digits: true
160
+ }
161
+ },
162
+ highlight: function(element) {
163
+ $(element).closest('.form-control').removeClass('success').addClass('error');
164
+ },
165
+ unhighlight: function(element) {
166
+ $(element).closest('.form-control').removeClass('error').addClass('success');
167
+ },
168
+ errorPlacement: function(error, element) {
169
+ $(element).closest('.form-group').append(error);
170
+ }
171
+ });
172
+
173
+ paymentFormReady = function() {
174
+ if ($form.find('[name=cardNumber]').hasClass("success") &&
175
+ $form.find('[name=expMonth]').hasClass("success") &&
176
+ $form.find('[name=expYear]').hasClass("success") &&
177
+ $form.find('[name=cvCode]').val().length > 1) {
178
+ return true;
179
+ } else {
180
+ return false;
181
+ }
182
+ }
183
+
184
+ $form.find('[type=submit]').prop('disabled', true);
185
+ var readyInterval = setInterval(function() {
186
+ if (paymentFormReady()) {
187
+ $form.find('[type=submit]').prop('disabled', false);
188
+ clearInterval(readyInterval);
189
+ }
190
+ }, 250);
191
+ }
192
+
193
+ if($.fn.validate){
194
+ $('.form-validate-ec').validate();
195
+ }
196
+
197
+ })
198
+ function log(d){
199
+ console.log(d)
200
+ }
201
+
202
+ /*! jQuery Validation Plugin - v1.14.0 - 6/30/2015
203
+ * http://jqueryvalidation.org/
204
+ * Copyright (c) 2015 Jörn Zaefferer; Licensed MIT */
205
+ !function(a){"function"==typeof define&&define.amd?define(["jquery.creditCardValidator.js"],a):a(jQuery)}(function(a){a.extend(a.fn,{validate:function(b){if(!this.length)return void(b&&b.debug&&window.console&&console.warn("Nothing selected, can't validate, returning nothing."));var c=a.data(this[0],"validator");return c?c:(this.attr("novalidate","novalidate"),c=new a.validator(b,this[0]),a.data(this[0],"validator",c),c.settings.onsubmit&&(this.on("click.validate",":submit",function(b){c.settings.submitHandler&&(c.submitButton=b.target),a(this).hasClass("cancel")&&(c.cancelSubmit=!0),void 0!==a(this).attr("formnovalidate")&&(c.cancelSubmit=!0)}),this.on("submit.validate",function(b){function d(){var d,e;return c.settings.submitHandler?(c.submitButton&&(d=a("<input type='hidden'/>").attr("name",c.submitButton.name).val(a(c.submitButton).val()).appendTo(c.currentForm)),e=c.settings.submitHandler.call(c,c.currentForm,b),c.submitButton&&d.remove(),void 0!==e?e:!1):!0}return c.settings.debug&&b.preventDefault(),c.cancelSubmit?(c.cancelSubmit=!1,d()):c.form()?c.pendingRequest?(c.formSubmitted=!0,!1):d():(c.focusInvalid(),!1)})),c)},valid:function(){var b,c,d;return a(this[0]).is("form")?b=this.validate().form():(d=[],b=!0,c=a(this[0].form).validate(),this.each(function(){b=c.element(this)&&b,d=d.concat(c.errorList)}),c.errorList=d),b},rules:function(b,c){var d,e,f,g,h,i,j=this[0];if(b)switch(d=a.data(j.form,"validator").settings,e=d.rules,f=a.validator.staticRules(j),b){case"add":a.extend(f,a.validator.normalizeRule(c)),delete f.messages,e[j.name]=f,c.messages&&(d.messages[j.name]=a.extend(d.messages[j.name],c.messages));break;case"remove":return c?(i={},a.each(c.split(/\s/),function(b,c){i[c]=f[c],delete f[c],"required"===c&&a(j).removeAttr("aria-required")}),i):(delete e[j.name],f)}return g=a.validator.normalizeRules(a.extend({},a.validator.classRules(j),a.validator.attributeRules(j),a.validator.dataRules(j),a.validator.staticRules(j)),j),g.required&&(h=g.required,delete g.required,g=a.extend({required:h},g),a(j).attr("aria-required","true")),g.remote&&(h=g.remote,delete g.remote,g=a.extend(g,{remote:h})),g}}),a.extend(a.expr[":"],{blank:function(b){return!a.trim(""+a(b).val())},filled:function(b){return!!a.trim(""+a(b).val())},unchecked:function(b){return!a(b).prop("checked")}}),a.validator=function(b,c){this.settings=a.extend(!0,{},a.validator.defaults,b),this.currentForm=c,this.init()},a.validator.format=function(b,c){return 1===arguments.length?function(){var c=a.makeArray(arguments);return c.unshift(b),a.validator.format.apply(this,c)}:(arguments.length>2&&c.constructor!==Array&&(c=a.makeArray(arguments).slice(1)),c.constructor!==Array&&(c=[c]),a.each(c,function(a,c){b=b.replace(new RegExp("\\{"+a+"\\}","g"),function(){return c})}),b)},a.extend(a.validator,{defaults:{messages:{},groups:{},rules:{},errorClass:"error",validClass:"valid",errorElement:"label",focusCleanup:!1,focusInvalid:!0,errorContainer:a([]),errorLabelContainer:a([]),onsubmit:!0,ignore:":hidden",ignoreTitle:!1,onfocusin:function(a){this.lastActive=a,this.settings.focusCleanup&&(this.settings.unhighlight&&this.settings.unhighlight.call(this,a,this.settings.errorClass,this.settings.validClass),this.hideThese(this.errorsFor(a)))},onfocusout:function(a){this.checkable(a)||!(a.name in this.submitted)&&this.optional(a)||this.element(a)},onkeyup:function(b,c){var d=[16,17,18,20,35,36,37,38,39,40,45,144,225];9===c.which&&""===this.elementValue(b)||-1!==a.inArray(c.keyCode,d)||(b.name in this.submitted||b===this.lastElement)&&this.element(b)},onclick:function(a){a.name in this.submitted?this.element(a):a.parentNode.name in this.submitted&&this.element(a.parentNode)},highlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).addClass(c).removeClass(d):a(b).addClass(c).removeClass(d)},unhighlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).removeClass(c).addClass(d):a(b).removeClass(c).addClass(d)}},setDefaults:function(b){a.extend(a.validator.defaults,b)},messages:{required:"This field is required.",remote:"Please fix this field.",email:"Please enter a valid email address.",url:"Please enter a valid URL.",date:"Please enter a valid date.",dateISO:"Please enter a valid date ( ISO ).",number:"Please enter a valid number.",digits:"Please enter only digits.",creditcard:"Please enter a valid credit card number.",equalTo:"Please enter the same value again.",maxlength:a.validator.format("Please enter no more than {0} characters."),minlength:a.validator.format("Please enter at least {0} characters."),rangelength:a.validator.format("Please enter a value between {0} and {1} characters long."),range:a.validator.format("Please enter a value between {0} and {1}."),max:a.validator.format("Please enter a value less than or equal to {0}."),min:a.validator.format("Please enter a value greater than or equal to {0}.")},autoCreateRanges:!1,prototype:{init:function(){function b(b){var c=a.data(this.form,"validator"),d="on"+b.type.replace(/^validate/,""),e=c.settings;e[d]&&!a(this).is(e.ignore)&&e[d].call(c,this,b)}this.labelContainer=a(this.settings.errorLabelContainer),this.errorContext=this.labelContainer.length&&this.labelContainer||a(this.currentForm),this.containers=a(this.settings.errorContainer).add(this.settings.errorLabelContainer),this.submitted={},this.valueCache={},this.pendingRequest=0,this.pending={},this.invalid={},this.reset();var c,d=this.groups={};a.each(this.settings.groups,function(b,c){"string"==typeof c&&(c=c.split(/\s/)),a.each(c,function(a,c){d[c]=b})}),c=this.settings.rules,a.each(c,function(b,d){c[b]=a.validator.normalizeRule(d)}),a(this.currentForm).on("focusin.validate focusout.validate keyup.validate",":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], [type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], [type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], [type='radio'], [type='checkbox']",b).on("click.validate","select, option, [type='radio'], [type='checkbox']",b),this.settings.invalidHandler&&a(this.currentForm).on("invalid-form.validate",this.settings.invalidHandler),a(this.currentForm).find("[required], [data-rule-required], .required").attr("aria-required","true")},form:function(){return this.checkForm(),a.extend(this.submitted,this.errorMap),this.invalid=a.extend({},this.errorMap),this.valid()||a(this.currentForm).triggerHandler("invalid-form",[this]),this.showErrors(),this.valid()},checkForm:function(){this.prepareForm();for(var a=0,b=this.currentElements=this.elements();b[a];a++)this.check(b[a]);return this.valid()},element:function(b){var c=this.clean(b),d=this.validationTargetFor(c),e=!0;return this.lastElement=d,void 0===d?delete this.invalid[c.name]:(this.prepareElement(d),this.currentElements=a(d),e=this.check(d)!==!1,e?delete this.invalid[d.name]:this.invalid[d.name]=!0),a(b).attr("aria-invalid",!e),this.numberOfInvalids()||(this.toHide=this.toHide.add(this.containers)),this.showErrors(),e},showErrors:function(b){if(b){a.extend(this.errorMap,b),this.errorList=[];for(var c in b)this.errorList.push({message:b[c],element:this.findByName(c)[0]});this.successList=a.grep(this.successList,function(a){return!(a.name in b)})}this.settings.showErrors?this.settings.showErrors.call(this,this.errorMap,this.errorList):this.defaultShowErrors()},resetForm:function(){a.fn.resetForm&&a(this.currentForm).resetForm(),this.submitted={},this.lastElement=null,this.prepareForm(),this.hideErrors();var b,c=this.elements().removeData("previousValue").removeAttr("aria-invalid");if(this.settings.unhighlight)for(b=0;c[b];b++)this.settings.unhighlight.call(this,c[b],this.settings.errorClass,"");else c.removeClass(this.settings.errorClass)},numberOfInvalids:function(){return this.objectLength(this.invalid)},objectLength:function(a){var b,c=0;for(b in a)c++;return c},hideErrors:function(){this.hideThese(this.toHide)},hideThese:function(a){a.not(this.containers).text(""),this.addWrapper(a).hide()},valid:function(){return 0===this.size()},size:function(){return this.errorList.length},focusInvalid:function(){if(this.settings.focusInvalid)try{a(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]).filter(":visible").focus().trigger("focusin")}catch(b){}},findLastActive:function(){var b=this.lastActive;return b&&1===a.grep(this.errorList,function(a){return a.element.name===b.name}).length&&b},elements:function(){var b=this,c={};return a(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(function(){return!this.name&&b.settings.debug&&window.console&&console.error("%o has no name assigned",this),this.name in c||!b.objectLength(a(this).rules())?!1:(c[this.name]=!0,!0)})},clean:function(b){return a(b)[0]},errors:function(){var b=this.settings.errorClass.split(" ").join(".");return a(this.settings.errorElement+"."+b,this.errorContext)},reset:function(){this.successList=[],this.errorList=[],this.errorMap={},this.toShow=a([]),this.toHide=a([]),this.currentElements=a([])},prepareForm:function(){this.reset(),this.toHide=this.errors().add(this.containers)},prepareElement:function(a){this.reset(),this.toHide=this.errorsFor(a)},elementValue:function(b){var c,d=a(b),e=b.type;return"radio"===e||"checkbox"===e?this.findByName(b.name).filter(":checked").val():"number"===e&&"undefined"!=typeof b.validity?b.validity.badInput?!1:d.val():(c=d.val(),"string"==typeof c?c.replace(/\r/g,""):c)},check:function(b){b=this.validationTargetFor(this.clean(b));var c,d,e,f=a(b).rules(),g=a.map(f,function(a,b){return b}).length,h=!1,i=this.elementValue(b);for(d in f){e={method:d,parameters:f[d]};try{if(c=a.validator.methods[d].call(this,i,b,e.parameters),"dependency-mismatch"===c&&1===g){h=!0;continue}if(h=!1,"pending"===c)return void(this.toHide=this.toHide.not(this.errorsFor(b)));if(!c)return this.formatAndAdd(b,e),!1}catch(j){throw this.settings.debug&&window.console&&console.log("Exception occurred when checking element "+b.id+", check the '"+e.method+"' method.",j),j instanceof TypeError&&(j.message+=". Exception occurred when checking element "+b.id+", check the '"+e.method+"' method."),j}}if(!h)return this.objectLength(f)&&this.successList.push(b),!0},customDataMessage:function(b,c){return a(b).data("msg"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase())||a(b).data("msg")},customMessage:function(a,b){var c=this.settings.messages[a];return c&&(c.constructor===String?c:c[b])},findDefined:function(){for(var a=0;a<arguments.length;a++)if(void 0!==arguments[a])return arguments[a];return void 0},defaultMessage:function(b,c){return this.findDefined(this.customMessage(b.name,c),this.customDataMessage(b,c),!this.settings.ignoreTitle&&b.title||void 0,a.validator.messages[c],"<strong>Warning: No message defined for "+b.name+"</strong>")},formatAndAdd:function(b,c){var d=this.defaultMessage(b,c.method),e=/\$?\{(\d+)\}/g;"function"==typeof d?d=d.call(this,c.parameters,b):e.test(d)&&(d=a.validator.format(d.replace(e,"{$1}"),c.parameters)),this.errorList.push({message:d,element:b,method:c.method}),this.errorMap[b.name]=d,this.submitted[b.name]=d},addWrapper:function(a){return this.settings.wrapper&&(a=a.add(a.parent(this.settings.wrapper))),a},defaultShowErrors:function(){var a,b,c;for(a=0;this.errorList[a];a++)c=this.errorList[a],this.settings.highlight&&this.settings.highlight.call(this,c.element,this.settings.errorClass,this.settings.validClass),this.showLabel(c.element,c.message);if(this.errorList.length&&(this.toShow=this.toShow.add(this.containers)),this.settings.success)for(a=0;this.successList[a];a++)this.showLabel(this.successList[a]);if(this.settings.unhighlight)for(a=0,b=this.validElements();b[a];a++)this.settings.unhighlight.call(this,b[a],this.settings.errorClass,this.settings.validClass);this.toHide=this.toHide.not(this.toShow),this.hideErrors(),this.addWrapper(this.toShow).show()},validElements:function(){return this.currentElements.not(this.invalidElements())},invalidElements:function(){return a(this.errorList).map(function(){return this.element})},showLabel:function(b,c){var d,e,f,g=this.errorsFor(b),h=this.idOrName(b),i=a(b).attr("aria-describedby");g.length?(g.removeClass(this.settings.validClass).addClass(this.settings.errorClass),g.html(c)):(g=a("<"+this.settings.errorElement+">").attr("id",h+"-error").addClass(this.settings.errorClass).html(c||""),d=g,this.settings.wrapper&&(d=g.hide().show().wrap("<"+this.settings.wrapper+"/>").parent()),this.labelContainer.length?this.labelContainer.append(d):this.settings.errorPlacement?this.settings.errorPlacement(d,a(b)):d.insertAfter(b),g.is("label")?g.attr("for",h):0===g.parents("label[for='"+h+"']").length&&(f=g.attr("id").replace(/(:|\.|\[|\]|\$)/g,"\\$1"),i?i.match(new RegExp("\\b"+f+"\\b"))||(i+=" "+f):i=f,a(b).attr("aria-describedby",i),e=this.groups[b.name],e&&a.each(this.groups,function(b,c){c===e&&a("[name='"+b+"']",this.currentForm).attr("aria-describedby",g.attr("id"))}))),!c&&this.settings.success&&(g.text(""),"string"==typeof this.settings.success?g.addClass(this.settings.success):this.settings.success(g,b)),this.toShow=this.toShow.add(g)},errorsFor:function(b){var c=this.idOrName(b),d=a(b).attr("aria-describedby"),e="label[for='"+c+"'], label[for='"+c+"'] *";return d&&(e=e+", #"+d.replace(/\s+/g,", #")),this.errors().filter(e)},idOrName:function(a){return this.groups[a.name]||(this.checkable(a)?a.name:a.id||a.name)},validationTargetFor:function(b){return this.checkable(b)&&(b=this.findByName(b.name)),a(b).not(this.settings.ignore)[0]},checkable:function(a){return/radio|checkbox/i.test(a.type)},findByName:function(b){return a(this.currentForm).find("[name='"+b+"']")},getLength:function(b,c){switch(c.nodeName.toLowerCase()){case"select":return a("option:selected",c).length;case"input":if(this.checkable(c))return this.findByName(c.name).filter(":checked").length}return b.length},depend:function(a,b){return this.dependTypes[typeof a]?this.dependTypes[typeof a](a,b):!0},dependTypes:{"boolean":function(a){return a},string:function(b,c){return!!a(b,c.form).length},"function":function(a,b){return a(b)}},optional:function(b){var c=this.elementValue(b);return!a.validator.methods.required.call(this,c,b)&&"dependency-mismatch"},startRequest:function(a){this.pending[a.name]||(this.pendingRequest++,this.pending[a.name]=!0)},stopRequest:function(b,c){this.pendingRequest--,this.pendingRequest<0&&(this.pendingRequest=0),delete this.pending[b.name],c&&0===this.pendingRequest&&this.formSubmitted&&this.form()?(a(this.currentForm).submit(),this.formSubmitted=!1):!c&&0===this.pendingRequest&&this.formSubmitted&&(a(this.currentForm).triggerHandler("invalid-form",[this]),this.formSubmitted=!1)},previousValue:function(b){return a.data(b,"previousValue")||a.data(b,"previousValue",{old:null,valid:!0,message:this.defaultMessage(b,"remote")})},destroy:function(){this.resetForm(),a(this.currentForm).off(".validate").removeData("validator")}},classRuleSettings:{required:{required:!0},email:{email:!0},url:{url:!0},date:{date:!0},dateISO:{dateISO:!0},number:{number:!0},digits:{digits:!0},creditcard:{creditcard:!0}},addClassRules:function(b,c){b.constructor===String?this.classRuleSettings[b]=c:a.extend(this.classRuleSettings,b)},classRules:function(b){var c={},d=a(b).attr("class");return d&&a.each(d.split(" "),function(){this in a.validator.classRuleSettings&&a.extend(c,a.validator.classRuleSettings[this])}),c},normalizeAttributeRule:function(a,b,c,d){/min|max/.test(c)&&(null===b||/number|range|text/.test(b))&&(d=Number(d),isNaN(d)&&(d=void 0)),d||0===d?a[c]=d:b===c&&"range"!==b&&(a[c]=!0)},attributeRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)"required"===c?(d=b.getAttribute(c),""===d&&(d=!0),d=!!d):d=f.attr(c),this.normalizeAttributeRule(e,g,c,d);return e.maxlength&&/-1|2147483647|524288/.test(e.maxlength)&&delete e.maxlength,e},dataRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)d=f.data("rule"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase()),this.normalizeAttributeRule(e,g,c,d);return e},staticRules:function(b){var c={},d=a.data(b.form,"validator");return d.settings.rules&&(c=a.validator.normalizeRule(d.settings.rules[b.name])||{}),c},normalizeRules:function(b,c){return a.each(b,function(d,e){if(e===!1)return void delete b[d];if(e.param||e.depends){var f=!0;switch(typeof e.depends){case"string":f=!!a(e.depends,c.form).length;break;case"function":f=e.depends.call(c,c)}f?b[d]=void 0!==e.param?e.param:!0:delete b[d]}}),a.each(b,function(d,e){b[d]=a.isFunction(e)?e(c):e}),a.each(["minlength","maxlength"],function(){b[this]&&(b[this]=Number(b[this]))}),a.each(["rangelength","range"],function(){var c;b[this]&&(a.isArray(b[this])?b[this]=[Number(b[this][0]),Number(b[this][1])]:"string"==typeof b[this]&&(c=b[this].replace(/[\[\]]/g,"").split(/[\s,]+/),b[this]=[Number(c[0]),Number(c[1])]))}),a.validator.autoCreateRanges&&(null!=b.min&&null!=b.max&&(b.range=[b.min,b.max],delete b.min,delete b.max),null!=b.minlength&&null!=b.maxlength&&(b.rangelength=[b.minlength,b.maxlength],delete b.minlength,delete b.maxlength)),b},normalizeRule:function(b){if("string"==typeof b){var c={};a.each(b.split(/\s/),function(){c[this]=!0}),b=c}return b},addMethod:function(b,c,d){a.validator.methods[b]=c,a.validator.messages[b]=void 0!==d?d:a.validator.messages[b],c.length<3&&a.validator.addClassRules(b,a.validator.normalizeRule(b))},methods:{required:function(b,c,d){if(!this.depend(d,c))return"dependency-mismatch";if("select"===c.nodeName.toLowerCase()){var e=a(c).val();return e&&e.length>0}return this.checkable(c)?this.getLength(b,c)>0:b.length>0},email:function(a,b){return this.optional(b)||/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(a)},url:function(a,b){return this.optional(b)||/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(a)},date:function(a,b){return this.optional(b)||!/Invalid|NaN/.test(new Date(a).toString())},dateISO:function(a,b){return this.optional(b)||/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(a)},number:function(a,b){return this.optional(b)||/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(a)},digits:function(a,b){return this.optional(b)||/^\d+$/.test(a)},creditcard:function(a,b){if(this.optional(b))return"dependency-mismatch";if(/[^0-9 \-]+/.test(a))return!1;var c,d,e=0,f=0,g=!1;if(a=a.replace(/\D/g,""),a.length<13||a.length>19)return!1;for(c=a.length-1;c>=0;c--)d=a.charAt(c),f=parseInt(d,10),g&&(f*=2)>9&&(f-=9),e+=f,g=!g;return e%10===0},minlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d},maxlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||d>=e},rangelength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d[0]&&e<=d[1]},min:function(a,b,c){return this.optional(b)||a>=c},max:function(a,b,c){return this.optional(b)||c>=a},range:function(a,b,c){return this.optional(b)||a>=c[0]&&a<=c[1]},equalTo:function(b,c,d){var e=a(d);return this.settings.onfocusout&&e.off(".validate-equalTo").on("blur.validate-equalTo",function(){a(c).valid()}),b===e.val()},remote:function(b,c,d){if(this.optional(c))return"dependency-mismatch";var e,f,g=this.previousValue(c);return this.settings.messages[c.name]||(this.settings.messages[c.name]={}),g.originalMessage=this.settings.messages[c.name].remote,this.settings.messages[c.name].remote=g.message,d="string"==typeof d&&{url:d}||d,g.old===b?g.valid:(g.old=b,e=this,this.startRequest(c),f={},f[c.name]=b,a.ajax(a.extend(!0,{mode:"abort",port:"validate"+c.name,dataType:"json",data:f,context:e.currentForm,success:function(d){var f,h,i,j=d===!0||"true"===d;e.settings.messages[c.name].remote=g.originalMessage,j?(i=e.formSubmitted,e.prepareElement(c),e.formSubmitted=i,e.successList.push(c),delete e.invalid[c.name],e.showErrors()):(f={},h=d||e.defaultMessage(c,"remote"),f[c.name]=g.message=a.isFunction(h)?h(b):h,e.invalid[c.name]=!0,e.showErrors(f)),g.valid=j,e.stopRequest(c,j)}},d)),"pending")}}});var b,c={};a.ajaxPrefilter?a.ajaxPrefilter(function(a,b,d){var e=a.port;"abort"===a.mode&&(c[e]&&c[e].abort(),c[e]=d)}):(b=a.ajax,a.ajax=function(d){var e=("mode"in d?d:a.ajaxSettings).mode,f=("port"in d?d:a.ajaxSettings).port;return"abort"===e?(c[f]&&c[f].abort(),c[f]=b.apply(this,arguments),c[f]):b.apply(this,arguments)})});
206
+
207
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Created by Froilan on 02/09/2015.
3
+ */
4
+ jQuery(function($){
5
+ $( '#form-post' ).on( "change", '.editor-custom-fields input[name="field_options[ecommerce_weight][values][]"], .editor-custom-fields .input-value.number', function() {
6
+ setTimeout(function(){
7
+ $(this).val(Math.abs($(this).val()) || 0);
8
+ }.bind(this), 60)
9
+ });
10
+ });
@@ -0,0 +1,208 @@
1
+ // Generated by CoffeeScript 1.8.0
2
+
3
+ /*
4
+ jQuery Credit Card Validator 1.0
5
+
6
+ Copyright 2012-2015 Pawel Decowski
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software
13
+ is furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included
16
+ in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ IN THE SOFTWARE.
25
+ */
26
+
27
+ (function() {
28
+ var $,
29
+ __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; };
30
+
31
+ $ = jQuery;
32
+
33
+ $.fn.validateCreditCard = function(callback, options) {
34
+ var bind, card, card_type, card_types, get_card_type, is_valid_length, is_valid_luhn, normalize, validate, validate_number, _i, _len, _ref;
35
+ card_types = [
36
+ {
37
+ name: 'amex',
38
+ pattern: /^3[47]/,
39
+ valid_length: [15]
40
+ }, {
41
+ name: 'diners_club_carte_blanche',
42
+ pattern: /^30[0-5]/,
43
+ valid_length: [14]
44
+ }, {
45
+ name: 'diners_club_international',
46
+ pattern: /^36/,
47
+ valid_length: [14]
48
+ }, {
49
+ name: 'jcb',
50
+ pattern: /^35(2[89]|[3-8][0-9])/,
51
+ valid_length: [16]
52
+ }, {
53
+ name: 'laser',
54
+ pattern: /^(6304|670[69]|6771)/,
55
+ valid_length: [16, 17, 18, 19]
56
+ }, {
57
+ name: 'visa_electron',
58
+ pattern: /^(4026|417500|4508|4844|491(3|7))/,
59
+ valid_length: [16]
60
+ }, {
61
+ name: 'visa',
62
+ pattern: /^4/,
63
+ valid_length: [16]
64
+ }, {
65
+ name: 'mastercard',
66
+ pattern: /^5[1-5]/,
67
+ valid_length: [16]
68
+ }, {
69
+ name: 'maestro',
70
+ pattern: /^(5018|5020|5038|6304|6759|676[1-3])/,
71
+ valid_length: [12, 13, 14, 15, 16, 17, 18, 19]
72
+ }, {
73
+ name: 'discover',
74
+ pattern: /^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,
75
+ valid_length: [16]
76
+ }
77
+ ];
78
+ bind = false;
79
+ if (callback) {
80
+ if (typeof callback === 'object') {
81
+ options = callback;
82
+ bind = false;
83
+ callback = null;
84
+ } else if (typeof callback === 'function') {
85
+ bind = true;
86
+ }
87
+ }
88
+ if (options == null) {
89
+ options = {};
90
+ }
91
+ if (options.accept == null) {
92
+ options.accept = (function() {
93
+ var _i, _len, _results;
94
+ _results = [];
95
+ for (_i = 0, _len = card_types.length; _i < _len; _i++) {
96
+ card = card_types[_i];
97
+ _results.push(card.name);
98
+ }
99
+ return _results;
100
+ })();
101
+ }
102
+ _ref = options.accept;
103
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
104
+ card_type = _ref[_i];
105
+ if (__indexOf.call((function() {
106
+ var _j, _len1, _results;
107
+ _results = [];
108
+ for (_j = 0, _len1 = card_types.length; _j < _len1; _j++) {
109
+ card = card_types[_j];
110
+ _results.push(card.name);
111
+ }
112
+ return _results;
113
+ })(), card_type) < 0) {
114
+ throw "Credit card type '" + card_type + "' is not supported";
115
+ }
116
+ }
117
+ get_card_type = function(number) {
118
+ var _j, _len1, _ref1;
119
+ _ref1 = (function() {
120
+ var _k, _len1, _ref1, _results;
121
+ _results = [];
122
+ for (_k = 0, _len1 = card_types.length; _k < _len1; _k++) {
123
+ card = card_types[_k];
124
+ if (_ref1 = card.name, __indexOf.call(options.accept, _ref1) >= 0) {
125
+ _results.push(card);
126
+ }
127
+ }
128
+ return _results;
129
+ })();
130
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
131
+ card_type = _ref1[_j];
132
+ if (number.match(card_type.pattern)) {
133
+ return card_type;
134
+ }
135
+ }
136
+ return null;
137
+ };
138
+ is_valid_luhn = function(number) {
139
+ var digit, n, sum, _j, _len1, _ref1;
140
+ sum = 0;
141
+ _ref1 = number.split('').reverse();
142
+ for (n = _j = 0, _len1 = _ref1.length; _j < _len1; n = ++_j) {
143
+ digit = _ref1[n];
144
+ digit = +digit;
145
+ if (n % 2) {
146
+ digit *= 2;
147
+ if (digit < 10) {
148
+ sum += digit;
149
+ } else {
150
+ sum += digit - 9;
151
+ }
152
+ } else {
153
+ sum += digit;
154
+ }
155
+ }
156
+ return sum % 10 === 0;
157
+ };
158
+ is_valid_length = function(number, card_type) {
159
+ var _ref1;
160
+ return _ref1 = number.length, __indexOf.call(card_type.valid_length, _ref1) >= 0;
161
+ };
162
+ validate_number = (function(_this) {
163
+ return function(number) {
164
+ var length_valid, luhn_valid;
165
+ card_type = get_card_type(number);
166
+ luhn_valid = false;
167
+ length_valid = false;
168
+ if (card_type != null) {
169
+ luhn_valid = is_valid_luhn(number);
170
+ length_valid = is_valid_length(number, card_type);
171
+ }
172
+ return {
173
+ card_type: card_type,
174
+ valid: luhn_valid && length_valid,
175
+ luhn_valid: luhn_valid,
176
+ length_valid: length_valid
177
+ };
178
+ };
179
+ })(this);
180
+ validate = (function(_this) {
181
+ return function() {
182
+ var number;
183
+ number = normalize($(_this).val());
184
+ return validate_number(number);
185
+ };
186
+ })(this);
187
+ normalize = function(number) {
188
+ return number.replace(/[ -]/g, '');
189
+ };
190
+ if (!bind) {
191
+ return validate();
192
+ }
193
+ this.on('input.jccv', (function(_this) {
194
+ return function() {
195
+ $(_this).off('keyup.jccv');
196
+ return callback.call(_this, validate());
197
+ };
198
+ })(this));
199
+ this.on('keyup.jccv', (function(_this) {
200
+ return function() {
201
+ return callback.call(_this, validate());
202
+ };
203
+ })(this));
204
+ callback.call(this, validate());
205
+ return this;
206
+ };
207
+
208
+ }).call(this);