зеркало из https://github.com/golang/pkgsite.git
content/static: rewrite toggle-tip.js with typescript
For golang/go#43359 Change-Id: Ifca0779ae6a949c06c765b20d7a3e0f1c591f60a Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/299258 Trust: Jamal Carvalho <jamal@golang.org> Run-TryBot: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Родитель
bc3f77d9ae
Коммит
9826220f9b
|
@ -1,39 +1,38 @@
|
|||
/**
|
||||
'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.
|
||||
*/
|
||||
|
||||
const toggles = document.querySelectorAll('[data-toggletip-content]');
|
||||
|
||||
/**
|
||||
* Adds event listeners to toggletip elements to display their
|
||||
* content when the toggle button is pressed. Used in the right
|
||||
* sidebar details section.
|
||||
*/
|
||||
toggles.forEach(toggle => {
|
||||
const message = toggle.getAttribute('data-toggletip-content');
|
||||
const tip = toggle.nextElementSibling;
|
||||
toggle.addEventListener('click', () => {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
tip.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
tip.innerHTML = '<span class="UnitMetaDetails-toggletipBubble">' + message + '</span>';
|
||||
}, 100);
|
||||
});
|
||||
|
||||
// Close on outside click
|
||||
document.addEventListener('click', e => {
|
||||
if (toggle !== e.target) {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
tip.innerHTML = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Remove toggletip on ESC
|
||||
toggle.addEventListener('keydown', e => {
|
||||
const ESC_KEY = 27;
|
||||
if ((e.keyCode || e.which) === ESC_KEY) {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
tip.innerHTML = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=toggle-tip.js.map
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"toggle-tip.js","sourceRoot":"","sources":["toggle-tip.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,0BAA0B,CAAC,CAAC;AAOtE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;IACvB,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,wBAAwB,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC;IACtC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;QACpC,IAAI,CAAC,GAAG,EAAE;YACR,OAAO;SACR;QACD,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;QACnB,UAAU,CAAC,GAAG,EAAE;YACd,GAAG,CAAC,SAAS,GAAG,gDAAgD,GAAG,OAAO,GAAG,SAAS,CAAC;QACzF,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IAGH,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;QACrC,IAAI,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;YACvB,IAAI,CAAC,GAAG,EAAE;gBACR,OAAO;aACR;YACD,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;SACpB;IACH,CAAC,CAAC,CAAC;IAGH,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE;QACrC,IAAI,CAAC,GAAG,EAAE;YACR,OAAO;SACR;QACD,IAAK,CAAmB,CAAC,GAAG,KAAK,QAAQ,EAAE;YACzC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC;SACpB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@ -0,0 +1,47 @@
|
|||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
const toggles = document.querySelectorAll('[data-toggletip-content]');
|
||||
|
||||
/**
|
||||
* Adds event listeners to toggletip elements to display their
|
||||
* content when the toggle button is pressed. Used in the right
|
||||
* sidebar details section.
|
||||
*/
|
||||
toggles.forEach(toggle => {
|
||||
const message = toggle.getAttribute('data-toggletip-content');
|
||||
const tip = toggle.nextElementSibling;
|
||||
toggle.addEventListener('click', () => {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
tip.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
tip.innerHTML = '<span class="UnitMetaDetails-toggletipBubble">' + message + '</span>';
|
||||
}, 100);
|
||||
});
|
||||
|
||||
// Close on outside click
|
||||
document.addEventListener('click', e => {
|
||||
if (toggle !== e.target) {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
tip.innerHTML = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Remove toggletip on ESC
|
||||
toggle.addEventListener('keydown', e => {
|
||||
if (!tip) {
|
||||
return;
|
||||
}
|
||||
if ((e as KeyboardEvent).key === 'Escape') {
|
||||
tip.innerHTML = '';
|
||||
}
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче