Skip to content

Commit

Permalink
Merge pull request rust-lang#1780 from kzys/remove-jquery
Browse files Browse the repository at this point in the history
Remove jQuery from hashchange.js and controllers
  • Loading branch information
locks authored Jul 10, 2019
2 parents e5c7abd + 0de72c5 commit 73c709e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/controllers/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
import ArrayProxy from '@ember/array/proxy';
import { computed, observer } from '@ember/object';
import { later } from '@ember/runloop';
import $ from 'jquery';
import moment from 'moment';

const NUM_VERSIONS = 5;
Expand Down Expand Up @@ -185,6 +184,13 @@ export default Controller.extend({
},

report: observer('crate.readme', function() {
setTimeout(() => $(window).trigger('hashchange'));
if (typeof document === 'undefined') {
return;
}
setTimeout(() => {
let e = document.createEvent('CustomEvent');
e.initCustomEvent('hashchange', true, true);
window.dispatchEvent(e);
});
}),
});
13 changes: 9 additions & 4 deletions app/initializers/hashchange.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import $ from 'jquery';

function decodeFragmentValue(hash) {
try {
return decodeURIComponent(hash.slice(1));
Expand Down Expand Up @@ -29,11 +27,18 @@ function hashchange() {
}

export function initialize() {
$(window).on('hashchange', hashchange);
if (typeof window === 'undefined' || typeof window.addEventListener === 'undefined') {
// Don't run this initializer under FastBoot
return;
}
window.addEventListener('hashchange', hashchange);

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

0 comments on commit 73c709e

Please sign in to comment.