From dc3254303d3cfa201f18d15140efbea54f581ee9 Mon Sep 17 00:00:00 2001 From: sorawee <sorawee@users.noreply.github.com> Date: Fri, 6 Nov 2020 07:55:50 -0800 Subject: [PATCH 1/6] Use key instead of keyCode In non QWERTY keyboard, pressing S won't focus the search bar. This commit fixes the problem. Note that `keyCode` is not supported in IE8 already, so the fact that `key` is not supported in IE8 too doesn't really matter: the PR doesn't cause browser compatibility for the features to degrade. --- scribble-lib/scribble/scribble-common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribble-lib/scribble/scribble-common.js b/scribble-lib/scribble/scribble-common.js index dd3c23c4..f1b1bf63 100644 --- a/scribble-lib/scribble/scribble-common.js +++ b/scribble-lib/scribble/scribble-common.js @@ -129,7 +129,7 @@ function NormalizePath(path) { function DoSearchKey(event, field, ver, top_path) { var val = field.value; - if (event && event.keyCode == 13) { + if (event && event.key === 'Enter') { var u = GetCookie("PLT_Root."+ver, null); if (u == null) u = top_path; // default: go to the top path u += "search/index.html?q=" + encodeURIComponent(val); @@ -171,8 +171,8 @@ AddOnLoad(function(){ // Pressing "S" or "s" focuses on the "...search manuals..." text field AddOnLoad(function(){ - window.addEventListener("keyup", function(event) { - if (event && (event.keyCode == 83 || event.keyCode == 115) && event.target == document.body) { + window.addEventListener("keyup", function(e) { + if ((e.key === 's' || e.key === 'S') && e.target === document.body) { var field = document.getElementsByClassName("searchbox")[0]; field.focus(); } From c054b62765281ea6b2c992feee8fb8f56993883d Mon Sep 17 00:00:00 2001 From: Sorawee Porncharoenwase <sorawee.pwase@gmail.com> Date: Mon, 28 Sep 2020 18:03:34 -0700 Subject: [PATCH 2/6] Refactor search placeholder HTML supports the placeholder attribute, so we should use it instead of implementing it ourselves. The placeholder attribute is not available prior IE10 (not including IE10). However: 1. In non-supporting browsers (e.g., IE9), the search functionality should still work correctly. 2. Non-supporting browsers don't qualify for the "full support" level detailed in https://github.com/racket/scribble/pull/240/ IE9 for instance is released in 2011, and Microsoft announced its end of support in 2016. --- scribble-lib/scribble/html-render.rkt | 16 +++------------- scribble-lib/scribble/scribble.css | 5 ++++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/scribble-lib/scribble/html-render.rkt b/scribble-lib/scribble/html-render.rkt index 6a9304b5..11cb6759 100644 --- a/scribble-lib/scribble/html-render.rkt +++ b/scribble-lib/scribble/html-render.rkt @@ -221,26 +221,16 @@ (string->symbol (alt-tag-name s))))) (define (make-search-box top-path) ; appears on every page - (let ([sa string-append] - [emptylabel "...search manuals..."] - [dimcolor "#888"]) + (let ([emptylabel "...search manuals..."]) `(form ([class "searchform"]) (input ([class "searchbox"] - [style ,(sa "color: "dimcolor";")] [type "text"] [tabindex "1"] - [value ,emptylabel] + [placeholder ,emptylabel] [title "Enter a search string to search the manuals"] [onkeypress ,(format "return DoSearchKey(event, this, ~s, ~s);" - (version) top-path)] - [onfocus ,(sa "this.style.color=\"black\"; " - "this.style.textAlign=\"left\"; " - "if (this.value == \""emptylabel"\") this.value=\"\";")] - [onblur ,(sa "if (this.value.match(/^ *$/)) {" - " this.style.color=\""dimcolor"\";" - " this.style.textAlign=\"center\";" - " this.value=\""emptylabel"\"; }")]))))) + (version) top-path)]))))) (define search-box (make-search-box "../")) (define top-search-box (make-search-box "")) diff --git a/scribble-lib/scribble/scribble.css b/scribble-lib/scribble/scribble.css index 2d0079d4..ca780a6d 100644 --- a/scribble-lib/scribble/scribble.css +++ b/scribble-lib/scribble/scribble.css @@ -152,10 +152,13 @@ table td { padding: 0px; background-color: #eee; border: 1px solid #ddd; - text-align: center; vertical-align: middle; } +.searchbox::placeholder { + text-align: center; +} + #contextindicator { position: fixed; background-color: #c6f; From 2767dd2c0694ae58da3b852f56424dd41fc3f7a3 Mon Sep 17 00:00:00 2001 From: shhyou <shu-hung.you@eecs.northwestern.edu> Date: Fri, 18 Sep 2020 20:03:53 -0500 Subject: [PATCH 3/6] Block scribble from changing fonts to ptm in LNCS --- scribble-lib/scribble/lncs/lang.rkt | 3 ++- scribble-lib/scribble/lncs/lncs-load.tex | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 scribble-lib/scribble/lncs/lncs-load.tex diff --git a/scribble-lib/scribble/lncs/lang.rkt b/scribble-lib/scribble/lncs/lang.rkt index 59c98b2b..0026e8d9 100644 --- a/scribble-lib/scribble/lncs/lang.rkt +++ b/scribble-lib/scribble/lncs/lang.rkt @@ -50,7 +50,8 @@ unicode-encoding-packages)) (scribble-file "lncs/style.tex") (list cls-file) - #f)) + #f + #:replacements (hash "scribble-load-replace.tex" (scribble-file "lncs/lncs-load.tex")))) (define lncs-extras (let ([abs (lambda (s) diff --git a/scribble-lib/scribble/lncs/lncs-load.tex b/scribble-lib/scribble/lncs/lncs-load.tex new file mode 100644 index 00000000..0c767d0b --- /dev/null +++ b/scribble-lib/scribble/lncs/lncs-load.tex @@ -0,0 +1,14 @@ +% Scribble should not change the default font from CMR +% to ptm for LNCS. See Guidelines for Authors of Papers +% to be Published in Springer Computer Science Proceedings, +% section 2.3, Fonts. +% +% IMPORTANT: the default package newtxmath *still* +% changes the math font. If you want to disable it, +% uncomment the next line +% \renewcommand\packageTxfonts\relax +% However, scribble would still generate LaTeX commands +% that depend on newtxmath upon rendering symbols +% \multimap, \multimapinv, \invamp and \square in +% scribble-lib/scribble/latex-render.rkt. +\renewcommand\renewrmdefault\relax From 8f21a9a26ab6f2799a7c0233c1013e179f5ae5f9 Mon Sep 17 00:00:00 2001 From: Matthew Flatt <mflatt@racket-lang.org> Date: Fri, 6 Nov 2020 11:18:49 -0700 Subject: [PATCH 4/6] doc: `css-addition` et al. propagate to HTML for nested parts --- scribble-doc/scribblings/scribble/core.scrbl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scribble-doc/scribblings/scribble/core.scrbl b/scribble-doc/scribblings/scribble/core.scrbl index b7940d2e..d04896e7 100644 --- a/scribble-doc/scribblings/scribble/core.scrbl +++ b/scribble-doc/scribblings/scribble/core.scrbl @@ -1771,10 +1771,13 @@ HTML that is rendered before and after element content. bytes?)])]{ Used as a @tech{style property} to supply a CSS file (if @racket[path] -is a path, string, or list), URL (if @racket[path] is a @racket[url]) or content (if @racket[path] is a byte -string) to be referenced or included in the generated HTML. This -property can be attached to any style, and all additions are collected -to the top of the generated HTML page. +is a path, string, or list), URL (if @racket[path] is a @racket[url]) +or content (if @racket[path] is a byte string) to be referenced or +included in the generated HTML. This property can be attached to any +style, and all additions are collected and lifted to the enclosing +generated HTML. When the style property is attached to a @tech{part}, +then it is also propagated to any generated HTML for a subpart of the +part. The @racket[path] field can be a result of @racket[path->main-collects-relative].} From 7c7e1213d039bebde7e553b9a74a8329216d2799 Mon Sep 17 00:00:00 2001 From: Matthew Flatt <mflatt@racket-lang.org> Date: Fri, 6 Nov 2020 11:48:11 -0700 Subject: [PATCH 5/6] scribble/html-properties: add `html-addition` --- scribble-doc/scribblings/scribble/core.scrbl | 9 +++++++++ scribble-lib/info.rkt | 2 +- scribble-lib/scribble/html-properties.rkt | 1 + scribble-lib/scribble/html-render.rkt | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scribble-doc/scribblings/scribble/core.scrbl b/scribble-doc/scribblings/scribble/core.scrbl index d04896e7..78b37fe7 100644 --- a/scribble-doc/scribblings/scribble/core.scrbl +++ b/scribble-doc/scribblings/scribble/core.scrbl @@ -1851,6 +1851,15 @@ For a @racket[part] that corresponds to an HTML page, adds content to the @tt{<head>} tag.} +@defstruct[head-addition ([xexpr xexpr/c])]{ + +Like @racket[head-extra] in content, but propagated to enclosing and +nested HTML pages like @racket[css-addition]. Additions to @tt{<head>} +via @racket[head-addition] appear before additions via @racket[head-extra]. + +@history[#:added "1.38"]} + + @defstruct[render-convertible-as ([types (listof (or/c 'png-bytes 'svg-bytes 'gif-bytes))])]{ For a @racket[part] that corresponds to an HTML page, controls how objects that subscribe to the @racketmodname[file/convertible] diff --git a/scribble-lib/info.rkt b/scribble-lib/info.rkt index a80f5a71..f8f64e31 100644 --- a/scribble-lib/info.rkt +++ b/scribble-lib/info.rkt @@ -23,4 +23,4 @@ (define pkg-authors '(mflatt eli)) -(define version "1.37") +(define version "1.38") diff --git a/scribble-lib/scribble/html-properties.rkt b/scribble-lib/scribble/html-properties.rkt index f4df208c..8c6f1475 100644 --- a/scribble-lib/scribble/html-properties.rkt +++ b/scribble-lib/scribble/html-properties.rkt @@ -30,4 +30,5 @@ [link-resource ([path path-string?])] [head-extra ([xexpr xexpr/c])] + [head-addition ([xexpr xexpr/c])] [render-convertible-as ([types (listof (or/c 'png-bytes 'svg-bytes 'gif-bytes))])]) diff --git a/scribble-lib/scribble/html-render.rkt b/scribble-lib/scribble/html-render.rkt index 11cb6759..c7b325eb 100644 --- a/scribble-lib/scribble/html-render.rkt +++ b/scribble-lib/scribble/html-render.rkt @@ -894,6 +894,7 @@ (extract js-style-addition? js-style-addition-path) (reverse extra-script-files))) ,(xml:comment "[if IE 6]><style type=\"text/css\">.SIEHidden { overflow: hidden; }</style><![endif]") + ,@(extract head-addition? head-addition-xexpr) ,@(for/list ([p (style-properties (part-style d))] #:when (head-extra? p)) (head-extra-xexpr p))) From 154ffe21b5c7f13f5b08f424a45b40ff549bacdd Mon Sep 17 00:00:00 2001 From: sorawee <sorawee.pwase@gmail.com> Date: Mon, 16 Nov 2020 07:44:38 -0800 Subject: [PATCH 6/6] Fix JS error when searchbox is not present When the search box is not present (e.g., https://docs.racket-lang.org/demo-m1/index.html), pressing "S" will result in a JS error. This PR fixes the problem. Note that semantically it makes more sense to give an ID to the search box as we know exactly what search box we want. --- scribble-lib/scribble/html-render.rkt | 1 + scribble-lib/scribble/scribble-common.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scribble-lib/scribble/html-render.rkt b/scribble-lib/scribble/html-render.rkt index c7b325eb..e243d8b8 100644 --- a/scribble-lib/scribble/html-render.rkt +++ b/scribble-lib/scribble/html-render.rkt @@ -225,6 +225,7 @@ `(form ([class "searchform"]) (input ([class "searchbox"] + [id "searchbox"] [type "text"] [tabindex "1"] [placeholder ,emptylabel] diff --git a/scribble-lib/scribble/scribble-common.js b/scribble-lib/scribble/scribble-common.js index f1b1bf63..dcd79b48 100644 --- a/scribble-lib/scribble/scribble-common.js +++ b/scribble-lib/scribble/scribble-common.js @@ -173,8 +173,10 @@ AddOnLoad(function(){ AddOnLoad(function(){ window.addEventListener("keyup", function(e) { if ((e.key === 's' || e.key === 'S') && e.target === document.body) { - var field = document.getElementsByClassName("searchbox")[0]; - field.focus(); + var searchBox = document.getElementById('searchbox'); + if (searchBox) { + searchBox.focus(); + } } }, false); });