Last active
December 23, 2015 10:49
-
-
Save jonathandavis/6624114 to your computer and use it in GitHub Desktop.
Shipping method selector behaviors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* shipmethods.js - Shopp catalog behaviors library | |
* Copyright © 2008-2013 by Ingenesis Limited | |
* Licensed under the GPLv3 {@see license.txt} | |
*/ | |
$('#shopp form').on('change', '.shipmethod', function () { | |
var prefix = '.shopp-cart.cart-', | |
spans = 'span'+prefix, | |
inputs = 'input'+prefix, | |
fields = ['shipping','tax','total'], | |
selectors = [], | |
values = {}, | |
retry = 0, | |
disableset = '.shopp .shipmethod, .payoption-button input', | |
$this = $(this), | |
send = function () { | |
$(disableset).attr('disabled',true); | |
$.getJSON($co.ajaxurl +"?action=shopp_ship_costs&method=" + $this.val(), function (r) { | |
if ( ! r && retry++ < 2 ) return setTimeout(send, 1000); | |
$(disableset).attr('disabled', false); | |
$.each(fields, function (i, name) { | |
if ( ! r || undefined == r[name] ) { | |
$(spans+name).html(values[name]); | |
return; | |
} | |
$(spans+name).html(asMoney(new Number(r[name]))); | |
$(inputs+name).val(new Number(r[name])); | |
}); | |
}); | |
}; | |
$.each(fields, function (i, name) { | |
selectors.push(spans + name); | |
values[name] = $(spans + name).html(); | |
}); | |
if (!c_upd) c_upd = '?'; | |
$(selectors.join(',')).html(c_upd); | |
send(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment