Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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