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
9 changes: 3 additions & 6 deletions app/javascript/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var StoryView = Backbone.NativeView.extend({
if (this.model.get("open")) {
this.el.classList.add("open");
if (storyLead) storyLead.style.display = "none";
window.scrollTo(0, this.el.getBoundingClientRect().top + window.scrollY);
this.el.scrollIntoView({ block: "start" });
} else {
this.el.classList.remove("open");
if (storyLead) storyLead.style.display = "";
Expand All @@ -149,10 +149,7 @@ var StoryView = Backbone.NativeView.extend({

itemSelected: function() {
this.el.classList.toggle("cursor", this.model.get("selected"));
var rect = this.el.getBoundingClientRect();
if (rect.top < 0 || rect.bottom > window.innerHeight) {
window.scrollTo(0, rect.top + window.scrollY);
}
requestAnimationFrame(() => { this.el.scrollIntoView({ block: "nearest" }); });
},

render: function() {
Expand Down Expand Up @@ -184,7 +181,7 @@ var StoryView = Backbone.NativeView.extend({
if (this.model.shouldSave()) this.model.save(null, { headers: requestHeaders() });
} else {
this.model.toggle();
window.scrollTo(0, this.el.getBoundingClientRect().top + window.scrollY);
this.el.scrollIntoView({ block: "start" });
}
},

Expand Down
2 changes: 2 additions & 0 deletions spec/javascript/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const templateHTML = [

document.body.insertAdjacentHTML("beforeend", templateHTML);

window.HTMLElement.prototype.scrollIntoView = function () { /* noop */ };

import { Story, StoryView, StoryList, AppView } from "../../app/javascript/application";

globalThis.Story = Story;
Expand Down
Loading