forked from intercom/ember-href-to
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm trying to make easier to run ember apps without jquery. I'm preparing my addons to work without it to set an example, and my addons use this addon.
- Loading branch information
Showing
6 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
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.tagName !== 'A') { | ||
el = el.parentElement; | ||
} | ||
return el; | ||
} | ||
} | ||
export default { | ||
name: 'ember-href-to', | ||
initialize: function(applicationInstance) { | ||
let $body = Em.$(document.body); | ||
$body.off('click.href-to', 'a'); | ||
|
||
$body.on('click.href-to', 'a', (e) => { | ||
let hrefTo = new HrefTo(applicationInstance, e); | ||
hrefTo.maybeHandle(); | ||
|
||
return true; | ||
}); | ||
initialize(applicationInstance) { | ||
document.body.removeEventListener('click', hrefToClickHandler); | ||
hrefToClickHandler = function(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); | ||
} | ||
}; |
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
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
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
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