Skip to content

Commit 73c709e

Browse files
authored
Merge pull request #1780 from kzys/remove-jquery
Remove jQuery from hashchange.js and controllers
2 parents e5c7abd + 0de72c5 commit 73c709e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

app/controllers/crate/version.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
55
import ArrayProxy from '@ember/array/proxy';
66
import { computed, observer } from '@ember/object';
77
import { later } from '@ember/runloop';
8-
import $ from 'jquery';
98
import moment from 'moment';
109

1110
const NUM_VERSIONS = 5;
@@ -185,6 +184,13 @@ export default Controller.extend({
185184
},
186185

187186
report: observer('crate.readme', function() {
188-
setTimeout(() => $(window).trigger('hashchange'));
187+
if (typeof document === 'undefined') {
188+
return;
189+
}
190+
setTimeout(() => {
191+
let e = document.createEvent('CustomEvent');
192+
e.initCustomEvent('hashchange', true, true);
193+
window.dispatchEvent(e);
194+
});
189195
}),
190196
});

app/initializers/hashchange.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import $ from 'jquery';
2-
31
function decodeFragmentValue(hash) {
42
try {
53
return decodeURIComponent(hash.slice(1));
@@ -29,11 +27,18 @@ function hashchange() {
2927
}
3028

3129
export function initialize() {
32-
$(window).on('hashchange', hashchange);
30+
if (typeof window === 'undefined' || typeof window.addEventListener === 'undefined') {
31+
// Don't run this initializer under FastBoot
32+
return;
33+
}
34+
window.addEventListener('hashchange', hashchange);
3335

3436
// If clicking on a link to the same fragment as currently in the address bar,
3537
// hashchange won't be fired, so we need to manually trigger rescroll.
36-
$(document).on('a[href]', 'click', function(event) {
38+
document.addEventListener('click', function(event) {
39+
if (event.target.tagName !== 'A') {
40+
return;
41+
}
3742
if (this.href === location.href && location.hash.length > 1) {
3843
setTimeout(function() {
3944
if (!event.defaultPrevented) {

0 commit comments

Comments
 (0)