Support caret browsing mode

This commit is contained in:
sienori 2018-06-03 13:47:07 +09:00
parent 15f29b1a72
commit f8f2cd3e53

View file

@ -177,6 +177,13 @@ function sendToPopup() {
//コンテキストメニュークリックでパネルを表示
function showPanelFromMenu() {
button.style.display = "none";
//キャレットブラウズモードに対応
const isTextField = (document.activeElement.tagName == "INPUT") || (document.activeElement.tagName == "TEXTAREA");
if (isTextField) selectionWord = document.activeElement.value.substring(document.activeElement.selectionStart, document.activeElement.selectionEnd);
else selectionWord = String(window.getSelection());
if (typeof (clickPosition) == 'undefined') clickPosition = { 'clientX': 0, 'clientY': 0 }
translate(selectionWord, 'auto', S.get().targetLang);
showPanel(clickPosition);
}