Skip to content

Instantly share code, notes, and snippets.

@pieterjongsma
Last active December 11, 2015 00:18
Show Gist options
  • Save pieterjongsma/4515248 to your computer and use it in GitHub Desktop.
Save pieterjongsma/4515248 to your computer and use it in GitHub Desktop.
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