Skip to content

Commit

Permalink
honor fastboot 1.0.0 format over browser intitializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mazondo committed May 28, 2017
1 parent e089f88 commit d847304
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
31 changes: 0 additions & 31 deletions app/instance-initializers/browser/ember-href-to.js

This file was deleted.

34 changes: 34 additions & 0 deletions app/instance-initializers/ember-href-to.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Em from 'ember';
import HrefTo from 'ember-href-to/href-to';

let hrefToClickHandler;
function closestLink(el) {
if (el.closest) {
return el.closest('a');
} else {
el = el.parentElement;
while (el && el.tagName !== 'A') {
el = el.parentElement;
}
return el;
}
}
export default {
name: 'ember-href-to',
initialize(applicationInstance) {
// we only want this to run in the browser, not in fastboot
if (typeof(FastBoot) === "undefined") {
if (hrefToClickHandler !== undefined) {
document.body.removeEventListener('click', hrefToClickHandler);
}
hrefToClickHandler = function _hrefToClickHandler(e) {
let link = e.target.tagName === 'A' ? e.target : closestLink(e.target);
if (link) {
let hrefTo = new HrefTo(applicationInstance, e, link);
hrefTo.maybeHandle();
}
}
document.body.addEventListener('click', hrefToClickHandler);
}
}
};

0 comments on commit d847304

Please sign in to comment.