Last active
August 29, 2015 13:57
-
-
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.
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
# For more information see: http://emberjs.com/guides/routing/ | |
Vidz.Router.reopen | |
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 = location.search || '' | |
url += search | |
url | |
setURL: (path) -> | |
get(this, 'location').href = path | |
replaceURL: (path) -> | |
onUpdateURL: (callback) -> | |
location = get(this, 'location') | |
path = location.pathname | |
url = path | |
callback(url) | |
formatURL: (url) -> | |
url | |
willDestroy: -> | |
Ember.Application.initializer | |
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