Skip to content

Instantly share code, notes, and snippets.

@KamiKillertO
Last active November 14, 2018 15:14
Show Gist options
  • Save KamiKillertO/9d32046a1ba2b4e7530dfdfcb631dd43 to your computer and use it in GitHub Desktop.
Save KamiKillertO/9d32046a1ba2b4e7530dfdfcb631dd43 to your computer and use it in GitHub Desktop.
Redirection service v1
import Service from '@ember/service';
import { set } from '@ember/object';
export default Service.extend({
__route: null,
displayModal: false,
__setUpRedirection(url) {
set(this, '__route', url);
set(this, 'displayModal', true);
},
actions: {
redirect(event) {
event.preventDefault();
let target = event.target;
while (target.tagName !== 'A') {
target = target.parentNode;
}
this.__setUpRedirection(target.href);
},
proceedRedirection() {
window.location = this.__route;
},
cancelRedirection() {
this.__cancelRedirection();
}
},
__cancelRedirection() {
set(this, '__route', null);
set(this, 'displayModal', false);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment