Skip to content

Instantly share code, notes, and snippets.

@potatosalad
Created December 30, 2011 21:45
Show Gist options
  • Select an option

  • Save potatosalad/1541612 to your computer and use it in GitHub Desktop.

Select an option

Save potatosalad/1541612 to your computer and use it in GitHub Desktop.
window.History.Adapter.bind window, 'statechange', ->
State = window.History.getState()
window.History.log State.data, State.title, State.url
if State.data.content?
$('.product-page').html(State.data.content)
dimensions = ":input[name='size_id'], :input[name='color_id'], :input[name='config_id']"
window.History.replaceState { content: $('.product-page').html() }, null, window.location
$(document).on 'change', dimensions, (event) ->
input = $(this)
form = input.closest('form')
values = {}
$(dimensions).each (index) ->
values[$(this).attr('id')] = $(this).val()
$.fancybox.showLoading()
xhr = $.post form.data('uri'), $(dimensions).serialize()
xhr.done (data) ->
newLocation = xhr.getResponseHeader 'Location'
if newLocation?
window.History.pushState { content: data }, null, newLocation
xhr.always ->
$.fancybox.hideLoading()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment