Last active
December 11, 2015 00:18
-
-
Save pieterjongsma/4515248 to your computer and use it in GitHub Desktop.
This file contains 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
var get = Ember.get, set = Ember.set; | |
Ember.HashExclamationLocation = Ember.Object.extend({ | |
init: function() { | |
set(this, 'location', get(this, 'location') || window.location); | |
}, | |
getURL: function() { | |
return get(this, 'location').hash.substr(2); | |
}, | |
setURL: function(path) { | |
exclam_path = '!'+path; | |
get(this, 'location').hash = exclam_path; | |
set(this, 'lastSetURL', exclam_path); | |
}, | |
onUpdateURL: function(callback) { | |
var self = this; | |
var guid = Ember.guidFor(this); | |
Ember.$(window).bind('hashchange.ember-location-'+guid, function() { | |
var path = location.hash.substr(2); | |
if (get(self, 'lastSetURL') === path) { return; } | |
set(self, 'lastSetURL', null); | |
callback(path); | |
}); | |
}, | |
formatURL: function(url) { | |
return '#!'+url; | |
}, | |
willDestroy: function() { | |
var guid = Ember.guidFor(this); | |
Ember.$(window).unbind('hashchange.ember-location-'+guid); | |
} | |
}); | |
Ember.Location.registerImplementation('hash_exclamation', Ember.HashExclamationLocation); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment