Created
December 30, 2011 21:45
-
-
Save potatosalad/1541612 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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