зеркало из https://github.com/golang/pkgsite.git
content/static: rewrite keyboard.js with typescript
For golang/go#43359 Change-Id: I5d5331c5aa072650bb97d4bf70c6a1df00a3602f Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/299256 Trust: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org>
This commit is contained in:
Родитель
b56d986367
Коммит
d8cbc4f9d7
|
@ -1,23 +1,23 @@
|
|||
/**
|
||||
'use strict';
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019-2020 The Go Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// This file implements the behavior of the keyboard shortcut which allows
|
||||
// for users to press 'y' to to change browser URL to the canonical URL
|
||||
// without triggering a reload.
|
||||
|
||||
const canonicalURLPath = document.querySelector('.js-canonicalURLPath').dataset['canonicalUrlPath'];
|
||||
var _a;
|
||||
const canonicalURLPath =
|
||||
(_a = document.querySelector('.js-canonicalURLPath')) === null || _a === void 0
|
||||
? void 0
|
||||
: _a.dataset['canonicalUrlPath'];
|
||||
if (canonicalURLPath && canonicalURLPath !== '') {
|
||||
document.addEventListener('keydown', e => {
|
||||
// TODO(golang.org/issue/40246): consolidate keyboard shortcut behavior across the site.
|
||||
const t = e.target.tagName;
|
||||
var _a, _b;
|
||||
const t = (_a = e.target) === null || _a === void 0 ? void 0 : _a.tagName;
|
||||
if (t === 'INPUT' || t === 'SELECT' || t === 'TEXTAREA') {
|
||||
return;
|
||||
}
|
||||
if (e.target.isContentEditable) {
|
||||
if ((_b = e.target) === null || _b === void 0 ? void 0 : _b.isContentEditable) {
|
||||
return;
|
||||
}
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
|
@ -30,3 +30,4 @@ if (canonicalURLPath && canonicalURLPath !== '') {
|
|||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=keyboard.js.map
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["keyboard.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAMH,MAAM,gBAAgB,SAAG,QAAQ,CAAC,aAAa,CAAiB,sBAAsB,CAAC,0CAAE,OAAO,CAC9F,kBAAkB,CACnB,CAAC;AACF,IAAI,gBAAgB,IAAI,gBAAgB,KAAK,EAAE,EAAE;IAC/C,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE;;QAEvC,MAAM,CAAC,SAAI,CAAC,CAAC,MAAsB,0CAAE,OAAO,CAAC;QAC7C,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,UAAU,EAAE;YACvD,OAAO;SACR;QACD,UAAK,CAAC,CAAC,MAAsB,0CAAE,iBAAiB,EAAE;YAChD,OAAO;SACR;QACD,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,EAAE;YAC1B,OAAO;SACR;QACD,QAAQ,CAAC,CAAC,GAAG,EAAE;YACb,KAAK,GAAG;gBACN,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC;gBACxD,MAAM;SACT;IACH,CAAC,CAAC,CAAC;CACJ"}
|
|
@ -0,0 +1,34 @@
|
|||
/*!
|
||||
* @license
|
||||
* Copyright 2019-2020 The Go Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// This file implements the behavior of the keyboard shortcut which allows
|
||||
// for users to press 'y' to to change browser URL to the canonical URL
|
||||
// without triggering a reload.
|
||||
|
||||
const canonicalURLPath = document.querySelector<HTMLDivElement>('.js-canonicalURLPath')?.dataset[
|
||||
'canonicalUrlPath'
|
||||
];
|
||||
if (canonicalURLPath && canonicalURLPath !== '') {
|
||||
document.addEventListener('keydown', e => {
|
||||
// TODO(golang.org/issue/40246): consolidate keyboard shortcut behavior across the site.
|
||||
const t = (e.target as HTMLElement)?.tagName;
|
||||
if (t === 'INPUT' || t === 'SELECT' || t === 'TEXTAREA') {
|
||||
return;
|
||||
}
|
||||
if ((e.target as HTMLElement)?.isContentEditable) {
|
||||
return;
|
||||
}
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
switch (e.key) {
|
||||
case 'y':
|
||||
window.history.replaceState(null, '', canonicalURLPath);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
Загрузка…
Ссылка в новой задаче