Skip to content

Instantly share code, notes, and snippets.

@braidn
Last active December 24, 2015 12:18
Show Gist options
  • Save braidn/6796451 to your computer and use it in GitHub Desktop.
Save braidn/6796451 to your computer and use it in GitHub Desktop.
// do some stuff with the breadcrumbs
$('ol.progress-steps > .current-first')
.after("<a href='#' class='bill_breadcrumb'><li class='completed-first'><span>Billing</span></li></a>")
.wrap("<a href='#' class='ship_breadcrumb'></a>")
$('input.submit_promo').on('click', function(e){
e.preventDefault();
if ($('#order_bill_address_attributes_firstname').val().length == 0) {
address.toggle();
address.toggle_bill_crumb();
address.push();
} else {
$(this).click();
}
});
$('.bill_breadcrumb').on('click', function(e){
e.preventDefault();
address.bill_crumb();
});
$('.ship_breadcrumb').on('click', function(e){
e.preventDefault();
address.ship_crumb();
});
var address = {
toggle: function() {
$('fieldset#shipping').toggle();
$('fieldset#gift-billing').toggle();
},
toggle_bill_crumb: function() {
$('.bill_breadcrumb > li').toggleClass('current-first').toggleClass('completed-first');
},
toggle_ship_crumb: function() {
$('.ship_breadcrumb > li').toggleClass('current-first').toggleClass('completed-first');
},
push: function() {
history.pushState(null, null, window.location + '#billing');
this.pop_listener(true);
},
pop_listener: function(truthy) {
var self = this;
if (truthy) {
window.addEventListener('popstate', function(e) {
self.toggle();
});
} else {
window.removeEventListener('popstate');
}
},
bill_crumb: function() {
if ($('.ship_breadcrumb > li').hasClass('current-first')) {
this.push();
this.toggle();
this.toggle_bill_crumb();
this.toggle_ship_crumb();
}
},
ship_crumb: function() {
if ($('.bill_breadcrumb > li').hasClass('current-first')) {
window.history.back();
this.toggle_bill_crumb();
this.toggle_ship_crumb();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment