Skip to content

Commit

Permalink
_content/doc/codewalk: fix more js problems
Browse files Browse the repository at this point in the history
The scrolling logic really needs the full page to fit in a browser window.
Do that by hiding the huge footer entirely.
Also fix a bug that was keeping the selected file name from displaying.

Change-Id: I641e7b1de9fc7a512f79e020ecdaa727e67d9810
Reviewed-on: https://go-review.googlesource.com/c/website/+/535275
Reviewed-by: Eli Bendersky <eliben@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
rsc committed Nov 9, 2023
1 parent a7a2638 commit b8642e1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions _content/doc/codewalk/codewalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ CodewalkViewer.prototype.changeCodeSide = function(codeSide) {
CodewalkViewer.prototype.changeSelectedComment = function(target) {
var currentFile = target.find('.comment-link').attr('href');
if (!currentFile) return;
currentFile = currentFile.replaceAll('%2f', '/').replaceAll('/go.dev/', '/');

if (!(this.lastSelected && this.lastSelected.get(0) === target.get(0))) {
if (this.lastSelected) this.lastSelected.removeClass('selected');
Expand All @@ -261,7 +262,7 @@ CodewalkViewer.prototype.changeSelectedComment = function(target) {
}
var fname = currentFile.match(/(?:select=|fileprint=)\/[^&]+/)[0];
fname = fname.slice(fname.indexOf('=')+2, fname.length);
this.context.find('#code-selector').val(fname);
this.context.find('#code-selector').val('/doc/codewalk/?fileprint=/'+fname);
this.context.find('#prev-comment').toggleClass(
'disabled', !target.prev().length);
this.context.find('#next-comment').toggleClass(
Expand All @@ -279,12 +280,15 @@ CodewalkViewer.prototype.changeSelectedComment = function(target) {
* after the user changes the window size.
*/
CodewalkViewer.prototype.updateHeight = function() {
var windowHeight = jQuery(window).height() - 5 // GOK
/* The new go.dev footer is too big; hide it since we are trying to keep the whole page on the screen. */
jQuery('.Footer').hide();

/* The -30 here work around some margin that seems to be introduced by the browsers. */
var windowHeight = jQuery(window).height() - 30
var areaHeight = windowHeight - this.codeArea.offset().top
/* The new go.dev footer is too big to keep on the page, so zero out footerHeight */
var footerHeight = 0 /* jQuery('.Site-footer').outerHeight(true) */
var footerHeight = jQuery('.Site-footer').outerHeight(true)
this.commentArea.height(areaHeight - footerHeight - this.context.find('#comment-options').outerHeight(true))
var codeHeight = areaHeight - footerHeight - 15 // GOK
var codeHeight = areaHeight - footerHeight - 30
this.codeArea.height(codeHeight)
this.codeDisplay.height(codeHeight - this.codeDisplay.offset().top + this.codeArea.offset().top);
this.sizer.height(codeHeight);
Expand Down

0 comments on commit b8642e1

Please sign in to comment.