Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:57
Show Gist options
  • Save rogeruiz/9424906 to your computer and use it in GitHub Desktop.
Save rogeruiz/9424906 to your computer and use it in GitHub Desktop.
Oldie Location. Some old fashion HREF wrangling. Seriously, just a simple page refresh.
# For more information see:
location: if Modernizr.history then 'history' else 'oldie'
# IE Ember.Location
# This new location type handles browser support for browsers without support
# for the History API. The Rails app can properly serve a page so when the History
# API isn't supported the Ember application doesn't bother setting a hash or pushing
# a history state. It simply navigates to that location by modifying the location.href
# directly. This means that Ember just handles everything but routing.
do ->
get = Ember.get
set = Ember.set
OldieLocation = Ember.Object.extend
init: ->
set(this, 'location', get(this, 'location') || window.location)
getURL: ->
# rootURL = get(this, 'rootURL')
location = get(this, 'location')
path = location.pathname
# rootURL = rootURL.replace(/\/$/, '')
url = path
if Ember.FEATURES.isEnabled('query-params')
search = || ''
url += search
setURL: (path) ->
get(this, 'location').href = path
replaceURL: (path) ->
onUpdateURL: (callback) ->
location = get(this, 'location')
path = location.pathname
url = path
formatURL: (url) ->
willDestroy: ->
name: 'oldie-location'
initialize: (container, application) ->
application.register 'location:oldie', OldieLocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment