op_cart 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80553909efd0c95f0fed6955e399223f241b2efe
4
- data.tar.gz: 2416d21f1b359f719f0e51e09ac2fb90c191c7e0
3
+ metadata.gz: 4723d50abb5120a0ecff9d043948e177cf0f82a2
4
+ data.tar.gz: 7b80fed1820e1c2e0d94f05f6f6d152aa3136bdd
5
5
  SHA512:
6
- metadata.gz: 7883f2f9685b75e35d8c0942cc8079d2d94f50378dd59571f93ae22293db8292310299e9287236ddd82d60d7e9a05aa73270999ba57de69d110c5eaaaa191678
7
- data.tar.gz: 67246ac06134e68ac64d8c0ad65981694f1e54ee8863ecb8c926475c9ffcbad0092048d6c244d6b38db031b45a102ac27a362c54a590c8432c0571680800e105
6
+ metadata.gz: 3b00c7acf3af7d99ddd5313a217248d96d1ff4306f3e57c731b6855ac1be7d6d39f9ef18bbdacd7065413d40a7d7d35b99e4457851f7c1c9f60bf916a869e6b8
7
+ data.tar.gz: 17a76a975a39f406d94a1a434e174b6e3ae6ddf435df2483efba61f39cf78f084988e38924650442ce40bc8c1f41a79cc167b24c0b102889a8c44ea40342bdba
@@ -0,0 +1,52 @@
1
+ (function( $ ) {
2
+ var requests = {};
3
+ var zipValid = {
4
+ us: /[0-9]{5}(-[0-9]{4})?/
5
+ };
6
+
7
+ $.ziptastic = function(country, zip, callback){
8
+ // If only zip and callback are given default to US
9
+ if (arguments.length == 2 && typeof arguments[1] == 'function') {
10
+ callback = arguments[1];
11
+ zip = arguments[0];
12
+ country = 'US';
13
+ }
14
+
15
+ country = country.toUpperCase();
16
+ // Only make unique requests
17
+ if(!requests[country]) {
18
+ requests[country] = {};
19
+ }
20
+ if(!requests[country][zip]) {
21
+ requests[country][zip] = $.getJSON('http://zip.getziptastic.com/v2/' + country + '/' + zip);
22
+ }
23
+
24
+ // Bind to the finished request
25
+ requests[country][zip].done(function(data) {
26
+ if (typeof callback == 'function') {
27
+ callback(data.country, data.state, data.state_short, data.city, zip);
28
+ }
29
+ });
30
+
31
+ // Allow for binding to the deferred object
32
+ return requests[country][zip];
33
+ };
34
+
35
+ $.fn.ziptastic = function( options ) {
36
+ return this.each(function() {
37
+ var ele = $(this);
38
+
39
+ ele.on('keyup', function() {
40
+ var zip = ele.val();
41
+
42
+ // TODO Non-US zip codes?
43
+ if(zipValid.us.test(zip)) {
44
+ $.ziptastic(zip, function(country, state, state_short, city) {
45
+ // Trigger the updated information
46
+ ele.trigger('zipChange', [country, state, state_short, city, zip]);
47
+ });
48
+ }
49
+ });
50
+ });
51
+ };
52
+ })( jQuery );
@@ -10,4 +10,5 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require 'jquery.ziptastic'
13
14
  //= require_tree .
@@ -3,11 +3,22 @@ OpCart =
3
3
  $number = $ '#order_credit_card_number'
4
4
  $expiry = $ '#order_credit_card_expiry'
5
5
  $cvc = $ '#order_credit_card_cvc'
6
+ $city = $ '#order_shipping_address_city'
7
+ $state = $ '#order_shipping_address_state'
8
+ $zip = $ '#order_shipping_address_zip_code'
6
9
 
7
10
  $number.payment 'formatCardNumber'
8
11
  $expiry.payment 'formatCardExpiry'
9
12
  $cvc.payment 'formatCardCVC'
10
13
 
14
+ $zip.change ->
15
+ if $zip.val().length == 5
16
+ $.ziptastic $zip.val(), (country, state, state_short, city, zip) ->
17
+ $city.val city
18
+ $state.val state
19
+ $city.prop "disabled", false
20
+ $state.prop "disabled", false
21
+
11
22
  @stripeCreateToken()
12
23
 
13
24
  load: -> @ready()
@@ -1,3 +1,3 @@
1
1
  module OpCart
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: op_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
@@ -76,6 +76,7 @@ files:
76
76
  - MIT-LICENSE
77
77
  - README.md
78
78
  - Rakefile
79
+ - app/assets/javascripts/jquery.ziptastic.js
79
80
  - app/assets/javascripts/op_cart/application.js
80
81
  - app/assets/javascripts/op_cart/orders.js.coffee
81
82
  - app/assets/stylesheets/op_cart/application.css