Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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);
});
}),
});
12 changes: 8 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,17 @@ function hashchange() {
}

export function initialize() {
$(window).on('hashchange', hashchange);
if (typeof window.addEventListener === 'undefined') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will also need a typeof window !== 'undefined' guard here to work well in FastBoot. AFAICT you basically never need to run this initializer in SSR modes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Will do.

return; // Fastboot
}
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