op_cart 0.0.3 → 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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4723d50abb5120a0ecff9d043948e177cf0f82a2
|
4
|
+
data.tar.gz: 7b80fed1820e1c2e0d94f05f6f6d152aa3136bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 );
|
@@ -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()
|
data/lib/op_cart/version.rb
CHANGED
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.
|
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
|