From 3ca28a93746ed0860bf19ede83e3e9bac979bfb5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 13 Aug 2017 16:42:22 -0700 Subject: wip --- ext/fg/js/popup.js | 105 ++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 54 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index cd7e846a..ba3289d4 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -40,51 +40,51 @@ class Popup { return this.injected; } - show(elementRect, options) { - return this.inject().then(() => { - const containerStyle = window.getComputedStyle(this.container); - const containerHeight = parseInt(containerStyle.height); - const containerWidth = parseInt(containerStyle.width); - - const limitX = document.body.clientWidth; - const limitY = window.innerHeight; - - let x = elementRect.left; - let width = Math.max(containerWidth, options.general.popupWidth); - const overflowX = Math.max(x + width - limitX, 0); - if (overflowX > 0) { - if (x >= overflowX) { - x -= overflowX; - } else { - width = limitX; - x = 0; - } - } + async show(elementRect, options) { + await this.inject(); + + const containerStyle = window.getComputedStyle(this.container); + const containerHeight = parseInt(containerStyle.height); + const containerWidth = parseInt(containerStyle.width); + + const limitX = document.body.clientWidth; + const limitY = window.innerHeight; - let y = 0; - let height = Math.max(containerHeight, options.general.popupHeight); - const yBelow = elementRect.bottom + options.general.popupOffset; - const yAbove = elementRect.top - options.general.popupOffset; - const overflowBelow = Math.max(yBelow + height - limitY, 0); - const overflowAbove = Math.max(height - yAbove, 0); - if (overflowBelow > 0 || overflowAbove > 0) { - if (overflowBelow < overflowAbove) { - height = Math.max(height - overflowBelow, 0); - y = yBelow; - } else { - height = Math.max(height - overflowAbove, 0); - y = Math.max(yAbove - height, 0); - } + let x = elementRect.left; + let width = Math.max(containerWidth, options.general.popupWidth); + const overflowX = Math.max(x + width - limitX, 0); + if (overflowX > 0) { + if (x >= overflowX) { + x -= overflowX; } else { + width = limitX; + x = 0; + } + } + + let y = 0; + let height = Math.max(containerHeight, options.general.popupHeight); + const yBelow = elementRect.bottom + options.general.popupOffset; + const yAbove = elementRect.top - options.general.popupOffset; + const overflowBelow = Math.max(yBelow + height - limitY, 0); + const overflowAbove = Math.max(height - yAbove, 0); + if (overflowBelow > 0 || overflowAbove > 0) { + if (overflowBelow < overflowAbove) { + height = Math.max(height - overflowBelow, 0); y = yBelow; + } else { + height = Math.max(height - overflowAbove, 0); + y = Math.max(yAbove - height, 0); } + } else { + y = yBelow; + } - this.container.style.left = `${x}px`; - this.container.style.top = `${y}px`; - this.container.style.width = `${width}px`; - this.container.style.height = `${height}px`; - this.container.style.visibility = 'visible'; - }); + this.container.style.left = `${x}px`; + this.container.style.top = `${y}px`; + this.container.style.width = `${width}px`; + this.container.style.height = `${height}px`; + this.container.style.visibility = 'visible'; } hide() { @@ -95,25 +95,22 @@ class Popup { return this.injected && this.container.style.visibility !== 'hidden'; } - showTermDefs(elementRect, definitions, options, context) { - this.show(elementRect, options).then(() => { - this.invokeApi('showTermDefs', {definitions, options, context}); - }); - } - - showKanjiDefs(elementRect, definitions, options, context) { - this.show(elementRect, options).then(() => { - this.invokeApi('showKanjiDefs', {definitions, options, context}); - }); + async termsShow(elementRect, definitions, options, context) { + await this.show(elementRect, options); + this.invokeApi('termsShow', {definitions, options, context}); } - showOrphaned(elementRect, options) { - this.show(elementRect, options).then(() => { - this.invokeApi('showOrphaned'); - }); + async kanjiShow(elementRect, definitions, options, context) { + await this.show(elementRect, options); + this.invokeApi('termsShow', {definitions, options, context}); } invokeApi(action, params={}) { this.container.contentWindow.postMessage({action, params}, '*'); } + + async onOrphaned(elementRect, options) { + await this.show(elementRect, options); + this.invokeApi('orphaned'); + } } -- cgit v1.2.3 From 82863cd86156d48b9f18dc10a560bedb82641862 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 14 Aug 2017 19:55:04 -0700 Subject: renaming files --- ext/bg/context.html | 43 +++++++++++++ ext/bg/js/context.js | 31 ++++++++++ ext/bg/js/display-window.js | 54 ---------------- ext/bg/js/popup.js | 31 ---------- ext/bg/js/search.js | 56 +++++++++++++++++ ext/bg/popup.html | 43 ------------- ext/bg/search.html | 4 +- ext/fg/css/client.css | 2 +- ext/fg/float.html | 43 +++++++++++++ ext/fg/frame.html | 43 ------------- ext/fg/js/display-frame.js | 86 -------------------------- ext/fg/js/float.js | 88 ++++++++++++++++++++++++++ ext/fg/js/popup.js | 4 +- ext/manifest.json | 5 +- ext/mixed/css/display.css | 146 ++++++++++++++++++++++++++++++++++++++++++++ ext/mixed/css/frame.css | 146 -------------------------------------------- 16 files changed, 414 insertions(+), 411 deletions(-) create mode 100644 ext/bg/context.html create mode 100644 ext/bg/js/context.js delete mode 100644 ext/bg/js/display-window.js delete mode 100644 ext/bg/js/popup.js create mode 100644 ext/bg/js/search.js delete mode 100644 ext/bg/popup.html create mode 100644 ext/fg/float.html delete mode 100644 ext/fg/frame.html delete mode 100644 ext/fg/js/display-frame.js create mode 100644 ext/fg/js/float.js create mode 100644 ext/mixed/css/display.css delete mode 100644 ext/mixed/css/frame.css (limited to 'ext/fg/js/popup.js') diff --git a/ext/bg/context.html b/ext/bg/context.html new file mode 100644 index 00000000..3828c9fe --- /dev/null +++ b/ext/bg/context.html @@ -0,0 +1,43 @@ + + + + + + + + + + +

+ +

+

+

+ + + +
+

+ + + + + + + + + + + + + + diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js new file mode 100644 index 00000000..77cb5166 --- /dev/null +++ b/ext/bg/js/context.js @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2017 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +$(document).ready(() => { + $('#open-search').click(() => apiCommandExec('search')); + $('#open-options').click(() => apiCommandExec('options')); + $('#open-help').click(() => apiCommandExec('help')); + + optionsLoad().then(options => { + const toggle = $('#enable-search'); + toggle.prop('checked', options.general.enable).change(); + toggle.bootstrapToggle(); + toggle.change(() => apiCommandExec('toggle')); + }); +}); diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js deleted file mode 100644 index cbb96681..00000000 --- a/ext/bg/js/display-window.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -window.yomichan_window = new class extends Display { - constructor() { - super($('#spinner'), $('#content')); - - this.search = $('#search').click(this.onSearch.bind(this)); - this.query = $('#query').on('input', this.onSearchInput.bind(this)); - this.intro = $('#intro'); - - window.wanakana.bind(this.query.get(0)); - } - - onError(error) { - window.alert(`Error: ${error}`); - } - - onSearchClear() { - this.query.focus().select(); - } - - onSearchInput() { - this.search.prop('disabled', this.query.val().length === 0); - } - - async onSearch(e) { - e.preventDefault(); - - try { - this.intro.slideUp(); - const {length, definitions} = await apiTermsFind(this.query.val()); - super.termsShow(definitions, await apiOptionsGet()); - } catch (e) { - this.onError(e); - } - } -}; diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js deleted file mode 100644 index 77cb5166..00000000 --- a/ext/bg/js/popup.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2017 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -$(document).ready(() => { - $('#open-search').click(() => apiCommandExec('search')); - $('#open-options').click(() => apiCommandExec('options')); - $('#open-help').click(() => apiCommandExec('help')); - - optionsLoad().then(options => { - const toggle = $('#enable-search'); - toggle.prop('checked', options.general.enable).change(); - toggle.bootstrapToggle(); - toggle.change(() => apiCommandExec('toggle')); - }); -}); diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js new file mode 100644 index 00000000..87f50c32 --- /dev/null +++ b/ext/bg/js/search.js @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class DisplaySearch extends Display { + constructor() { + super($('#spinner'), $('#content')); + + this.search = $('#search').click(this.onSearch.bind(this)); + this.query = $('#query').on('input', this.onSearchInput.bind(this)); + this.intro = $('#intro'); + + window.wanakana.bind(this.query.get(0)); + } + + onError(error) { + window.alert(`Error: ${error}`); + } + + onSearchClear() { + this.query.focus().select(); + } + + onSearchInput() { + this.search.prop('disabled', this.query.val().length === 0); + } + + async onSearch(e) { + e.preventDefault(); + + try { + this.intro.slideUp(); + const {length, definitions} = await apiTermsFind(this.query.val()); + super.termsShow(definitions, await apiOptionsGet()); + } catch (e) { + this.onError(e); + } + } +} + +window.yomichan_search = new DisplaySearch(); diff --git a/ext/bg/popup.html b/ext/bg/popup.html deleted file mode 100644 index 60253d6f..00000000 --- a/ext/bg/popup.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - -

- -

-

-

- - - -
-

- - - - - - - - - - - - - - diff --git a/ext/bg/search.html b/ext/bg/search.html index fe44d74e..d10530f9 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -5,7 +5,7 @@ Yomichan Search - +
@@ -45,6 +45,6 @@ - + diff --git a/ext/fg/css/client.css b/ext/fg/css/client.css index 9f566480..b5b1f6bd 100644 --- a/ext/fg/css/client.css +++ b/ext/fg/css/client.css @@ -17,7 +17,7 @@ */ -iframe#yomichan-popup { +iframe#yomichan-float { all: initial; background-color: #fff; border: 1px solid #999; diff --git a/ext/fg/float.html b/ext/fg/float.html new file mode 100644 index 00000000..a3b66c92 --- /dev/null +++ b/ext/fg/float.html @@ -0,0 +1,43 @@ + + + + + + + + + + + +
+ +
+ +
+ +
+
+

Yomichan Updated!

+

+ The Yomichan extension has been updated to a new version! In order to continue + viewing definitions on this page you must reload this tab or restart your browser. +

+
+
+ + + + + + + + + + + + diff --git a/ext/fg/frame.html b/ext/fg/frame.html deleted file mode 100644 index dda3ef06..00000000 --- a/ext/fg/frame.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - -
- -
- -
- -
-
-

Yomichan Updated!

-

- The Yomichan extension has been updated to a new version! In order to continue - viewing definitions on this page you must reload this tab or restart your browser. -

-
-
- - - - - - - - - - - - diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js deleted file mode 100644 index e3f3e692..00000000 --- a/ext/fg/js/display-frame.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -window.yomichan_frame = new class extends Display { - constructor() { - super($('#spinner'), $('#definitions')); - $(window).on('message', this.onMessage.bind(this)); - } - - onError(error) { - if (window.yomichan_orphaned) { - this.onOrphaned(); - } else { - window.alert(`Error: ${error}`); - } - } - - onOrphaned() { - $('#definitions').hide(); - $('#error-orphaned').show(); - } - - onSearchClear() { - window.parent.postMessage('popupClose', '*'); - } - - onSelectionCopy() { - window.parent.postMessage('selectionCopy', '*'); - } - - onMessage(e) { - const handlers = { - termsShow: ({definitions, options, context}) => { - this.termsShow(definitions, options, context); - }, - - kanjiShow: ({definitions, options, context}) => { - this.kanjiShow(definitions, options, context); - }, - - orphaned: () => { - this.onOrphaned(); - } - }; - - const {action, params} = e.originalEvent.data; - const handler = handlers[action]; - if (handler) { - handler(params); - } - } - - onKeyDown(e) { - const handlers = { - 67: /* c */ () => { - if (e.ctrlKey && !window.getSelection().toString()) { - this.onSelectionCopy(); - return true; - } - } - }; - - const handler = handlers[e.keyCode]; - if (handler && handler()) { - e.preventDefault(); - } else { - super.onKeyDown(e); - } - } -}; diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js new file mode 100644 index 00000000..59293239 --- /dev/null +++ b/ext/fg/js/float.js @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class DisplayFloat extends Display { + constructor() { + super($('#spinner'), $('#definitions')); + $(window).on('message', e => this.onMessage(e)); + } + + onError(error) { + if (window.yomichan_orphaned) { + this.onOrphaned(); + } else { + window.alert(`Error: ${error}`); + } + } + + onOrphaned() { + $('#definitions').hide(); + $('#error-orphaned').show(); + } + + onSearchClear() { + window.parent.postMessage('popupClose', '*'); + } + + onSelectionCopy() { + window.parent.postMessage('selectionCopy', '*'); + } + + onMessage(e) { + const handlers = { + termsShow: ({definitions, options, context}) => { + this.termsShow(definitions, options, context); + }, + + kanjiShow: ({definitions, options, context}) => { + this.kanjiShow(definitions, options, context); + }, + + orphaned: () => { + this.onOrphaned(); + } + }; + + const {action, params} = e.originalEvent.data; + const handler = handlers[action]; + if (handler) { + handler(params); + } + } + + onKeyDown(e) { + const handlers = { + 67: /* c */ () => { + if (e.ctrlKey && !window.getSelection().toString()) { + this.onSelectionCopy(); + return true; + } + } + }; + + const handler = handlers[e.keyCode]; + if (handler && handler()) { + e.preventDefault(); + } else { + super.onKeyDown(e); + } + } +} + +window.yomichan_display = new DisplayFloat(); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index ba3289d4..8e61169a 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -20,10 +20,10 @@ class Popup { constructor() { this.container = document.createElement('iframe'); - this.container.id = 'yomichan-popup'; + this.container.id = 'yomichan-float'; this.container.addEventListener('mousedown', e => e.stopPropagation()); this.container.addEventListener('scroll', e => e.stopPropagation()); - this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html')); + this.container.setAttribute('src', chrome.extension.getURL('/fg/float.html')); this.container.style.width = '0px'; this.container.style.height = '0px'; this.injected = null; diff --git a/ext/manifest.json b/ext/manifest.json index ee3bd2ac..a8b68bfb 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -7,7 +7,7 @@ "icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"}, "browser_action": { "default_icon": {"19": "mixed/img/icon19.png", "38": "mixed/img/icon38.png"}, - "default_popup": "bg/popup.html" + "default_popup": "bg/context.html" }, "author": "Alex Yatskov", @@ -20,7 +20,6 @@ "fg/js/popup.js", "fg/js/source.js", "fg/js/util.js", - "fg/js/frontend.js" ], "css": ["fg/css/client.css"] @@ -48,7 +47,7 @@ "description": "Open search window" } }, - "web_accessible_resources": ["fg/frame.html"], + "web_accessible_resources": ["fg/float.html"], "applications": { "gecko": { "id": "yomichan-live@foosoft.net", diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css new file mode 100644 index 00000000..8b1819bd --- /dev/null +++ b/ext/mixed/css/display.css @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the entrys of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +/* + * Fonts + */ + +@font-face { + font-family: kanji-stroke-orders; + src: url('/mixed/ttf/kanji-stroke-orders.ttf'); +} + +/* + * General + */ + +hr { + padding: 0px; + margin: 0px; +} + +#spinner { + bottom: 5px; + display: none; + position: fixed; + right: 5px; +} + +#error-orphaned { + display: none; +} + + +/* + * Entries + */ + +.entry, .note { + padding-top: 10px; + padding-bottom: 10px; +} + +.tag-default { + background-color: #8a8a91; +} + +.tag-name { + background-color: #5cb85c; +} + +.tag-expression { + background-color: #f0ad4e; +} + +.tag-popular { + background-color: #0275d8; +} + +.tag-frequent { + background-color: #5bc0de; +} + +.tag-archaism { + background-color: #d9534f; +} + +.tag-dictionary { + background-color: #aa66cc; +} + +.actions .disabled { + pointer-events: none; + cursor: default; +} + +.actions .disabled img { + -webkit-filter: grayscale(100%); + opacity: 0.25; +} + +.actions .pending { + visibility: hidden; +} + +.actions { + display: inline-block; + float: right; +} + +.actions:after { + clear: both; + content: ''; + display: block; +} + +.expression { + display: inline-block; + font-size: 24px; +} + +.expression a { + border-bottom: 1px #777 dashed; + color: #333; + text-decoration: none; +} + +.reasons { + color: #777; + display: inline-block; +} + +.glossary ol, .glossary ul { + padding-left: 1.4em; +} + +.glossary li { + color: #777; +} + +.glossary-item { + color: #000; +} + +.glyph { + font-family: kanji-stroke-orders; + font-size: 120px; + line-height: 120px; + padding: 0.01em; + vertical-align: top; +} diff --git a/ext/mixed/css/frame.css b/ext/mixed/css/frame.css deleted file mode 100644 index 8b1819bd..00000000 --- a/ext/mixed/css/frame.css +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the entrys of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -/* - * Fonts - */ - -@font-face { - font-family: kanji-stroke-orders; - src: url('/mixed/ttf/kanji-stroke-orders.ttf'); -} - -/* - * General - */ - -hr { - padding: 0px; - margin: 0px; -} - -#spinner { - bottom: 5px; - display: none; - position: fixed; - right: 5px; -} - -#error-orphaned { - display: none; -} - - -/* - * Entries - */ - -.entry, .note { - padding-top: 10px; - padding-bottom: 10px; -} - -.tag-default { - background-color: #8a8a91; -} - -.tag-name { - background-color: #5cb85c; -} - -.tag-expression { - background-color: #f0ad4e; -} - -.tag-popular { - background-color: #0275d8; -} - -.tag-frequent { - background-color: #5bc0de; -} - -.tag-archaism { - background-color: #d9534f; -} - -.tag-dictionary { - background-color: #aa66cc; -} - -.actions .disabled { - pointer-events: none; - cursor: default; -} - -.actions .disabled img { - -webkit-filter: grayscale(100%); - opacity: 0.25; -} - -.actions .pending { - visibility: hidden; -} - -.actions { - display: inline-block; - float: right; -} - -.actions:after { - clear: both; - content: ''; - display: block; -} - -.expression { - display: inline-block; - font-size: 24px; -} - -.expression a { - border-bottom: 1px #777 dashed; - color: #333; - text-decoration: none; -} - -.reasons { - color: #777; - display: inline-block; -} - -.glossary ol, .glossary ul { - padding-left: 1.4em; -} - -.glossary li { - color: #777; -} - -.glossary-item { - color: #000; -} - -.glyph { - font-family: kanji-stroke-orders; - font-size: 120px; - line-height: 120px; - padding: 0.01em; - vertical-align: top; -} -- cgit v1.2.3 From bdf231082f4b4ca7c4c90d8b0cd40b6c4201723d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 14 Aug 2017 21:43:09 -0700 Subject: lots of fixes to backend --- ext/bg/context.html | 5 +---- ext/bg/js/anki.js | 9 +++++++++ ext/bg/js/api.js | 2 +- ext/bg/js/backend.js | 20 +++++++++++++------ ext/bg/js/context.js | 4 ++-- ext/bg/js/database.js | 2 +- ext/bg/js/deinflector.js | 2 +- ext/bg/js/dictionary.js | 2 +- ext/bg/js/handlebars.js | 2 +- ext/bg/js/search.js | 5 ++--- ext/bg/js/settings.js | 50 ++++++++++++++++++++++++------------------------ ext/bg/js/util.js | 7 ++++++- ext/bg/settings.html | 3 +-- ext/fg/js/api.js | 22 ++++++++++++++------- ext/fg/js/frontend.js | 2 +- ext/fg/js/popup.js | 2 +- ext/mixed/js/display.js | 9 +++++---- 17 files changed, 87 insertions(+), 61 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/bg/context.html b/ext/bg/context.html index 3828c9fe..8a72acc7 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -30,13 +30,10 @@ - - - - + diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index f0ec4571..c327969f 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -17,6 +17,10 @@ */ +/* + * AnkiConnect + */ + class AnkiConnect { constructor(server) { this.server = server; @@ -68,6 +72,11 @@ class AnkiConnect { } } + +/* + * AnkiNull + */ + class AnkiNull { async addNote(note) { return null; diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 024ba75e..b55e306f 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index e8c9452c..97e5602a 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -77,7 +77,11 @@ class Backend { const handlers = { optionsGet: ({callback}) => { - forward(optionsLoad(), callback); + forward(apiOptionsGet(), callback); + }, + + optionsSet: ({options, callback}) => { + forward(apiOptionsSet(options), callback); }, kanjiFind: ({text, callback}) => { @@ -88,10 +92,6 @@ class Backend { forward(apiTermsFind(text), callback); }, - templateRender: ({template, data, callback}) => { - forward(apiTemplateRender(template, data), callback); - }, - definitionAdd: ({definition, mode, callback}) => { forward(apiDefinitionAdd(definition, mode), callback); }, @@ -102,6 +102,14 @@ class Backend { noteView: ({noteId}) => { forward(apiNoteView(noteId), callback); + }, + + templateRender: ({template, data, callback}) => { + forward(apiTemplateRender(template, data), callback); + }, + + commandExec: ({command, callback}) => { + forward(apiCommandExec(command), callback); } }; diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js index 77cb5166..689d6863 100644 --- a/ext/bg/js/context.js +++ b/ext/bg/js/context.js @@ -17,7 +17,7 @@ */ -$(document).ready(() => { +$(document).ready(utilAsync(() => { $('#open-search').click(() => apiCommandExec('search')); $('#open-options').click(() => apiCommandExec('options')); $('#open-help').click(() => apiCommandExec('help')); @@ -28,4 +28,4 @@ $(document).ready(() => { toggle.bootstrapToggle(); toggle.change(() => apiCommandExec('toggle')); }); -}); +})); diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index b38e00db..e00cb7a3 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js index 8b67761b..0abde99d 100644 --- a/ext/bg/js/deinflector.js +++ b/ext/bg/js/deinflector.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 6f9b30e4..c8d431b9 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js index df98bef1..debb0690 100644 --- a/ext/bg/js/handlebars.js +++ b/ext/bg/js/handlebars.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 87f50c32..54cda8ec 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -41,9 +41,8 @@ class DisplaySearch extends Display { } async onSearch(e) { - e.preventDefault(); - try { + e.preventDefault(); this.intro.slideUp(); const {length, definitions} = await apiTermsFind(this.query.val()); super.termsShow(definitions, await apiOptionsGet()); diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index ce9e14a2..89b1581f 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -90,12 +90,12 @@ function formUpdateVisibility(options) { } } -async function onFormOptionsChanged(e) {(async () => { - if (!e.originalEvent && !e.isTrigger) { - return; - } - +async function onFormOptionsChanged(e) { try { + if (!e.originalEvent && !e.isTrigger) { + return; + } + ankiErrorShow(); ankiSpinnerShow(true); @@ -116,9 +116,9 @@ async function onFormOptionsChanged(e) {(async () => { } finally { ankiSpinnerShow(false); } -})();} +} -function onReady() {(async () => { +async function onReady() { const options = await optionsLoad(); $('#show-usage-guide').prop('checked', options.general.showGuide); @@ -139,16 +139,16 @@ function onReady() {(async () => { $('#scan-length').val(options.scanning.length); $('#scan-modifier-key').val(options.scanning.modifier); - $('#dict-purge').click(onDictionaryPurge); - $('#dict-file').change(onDictionaryImport); + $('#dict-purge').click(utilAsync(onDictionaryPurge)); + $('#dict-file').change(utilAsync(onDictionaryImport)); $('#anki-enable').prop('checked', options.anki.enable); $('#card-tags').val(options.anki.tags.join(' ')); $('#generate-html-cards').prop('checked', options.anki.htmlCards); $('#sentence-detection-extent').val(options.anki.sentenceExt); $('#interface-server').val(options.anki.server); - $('input, select').not('.anki-model').change(onFormOptionsChanged); - $('.anki-model').change(onAnkiModelChanged); + $('input, select').not('.anki-model').change(utilAsync(onFormOptionsChanged)); + $('.anki-model').change(utilAsync(onAnkiModelChanged)); try { await dictionaryGroupsPopulate(options); @@ -163,9 +163,9 @@ function onReady() {(async () => { } formUpdateVisibility(options); -})();} +} -$(document).ready(onReady); +$(document).ready(utilAsync(onReady)); /* @@ -237,7 +237,7 @@ async function dictionaryGroupsPopulate(options) { }); } -async function onDictionaryPurge(e) {(async () => { +async function onDictionaryPurge(e) { e.preventDefault(); const dictControls = $('#dict-importer, #dict-groups').hide(); @@ -261,9 +261,9 @@ async function onDictionaryPurge(e) {(async () => { dictControls.show(); dictProgress.hide(); } -})();} +} -function onDictionaryImport(e) {(async () => { +async function onDictionaryImport(e) { const dictFile = $('#dict-file'); const dictControls = $('#dict-importer').hide(); const dictProgress = $('#dict-import-progress').show(); @@ -291,7 +291,7 @@ function onDictionaryImport(e) {(async () => { dictControls.show(); dictProgress.hide(); } -})();} +} /* @@ -398,7 +398,7 @@ async function ankiFieldsPopulate(element, options) { container.append($(html)); } - tab.find('.anki-field-value').change(onFormOptionsChanged); + tab.find('.anki-field-value').change(utilAsync(onFormOptionsChanged)); tab.find('.marker-link').click(onAnkiMarkerClicked); } @@ -408,12 +408,12 @@ function onAnkiMarkerClicked(e) { $(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change'); } -function onAnkiModelChanged(e) {(async () => { - if (!e.originalEvent) { - return; - } - +async function onAnkiModelChanged(e) { try { + if (!e.originalEvent) { + return; + } + ankiErrorShow(); ankiSpinnerShow(true); @@ -431,4 +431,4 @@ function onAnkiModelChanged(e) {(async () => { } finally { ankiSpinnerShow(false); } -})();} +} diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 9dc57950..11ec23eb 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -16,6 +16,11 @@ * along with this program. If not, see . */ +function utilAsync(func) { + return function(...args) { + func.apply(this, args); + }; +} function utilBackend() { return chrome.extension.getBackgroundPage().yomichan_backend; diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 719c67a2..237750b3 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -276,8 +276,7 @@ - - + diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index b4d75c3c..174531ba 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,10 @@ */ +function apiOptionsSet(options) { + return utilInvoke('optionsSet', {options}); +} + function apiOptionsGet() { return utilInvoke('optionsGet'); } @@ -29,18 +33,22 @@ function apiKanjiFind(text) { return utilInvoke('kanjiFind', {text}); } -function apiTemplateRender(template, data) { - return utilInvoke('templateRender', {data, template}); +function apiDefinitionAdd(definition, mode) { + return utilInvoke('definitionAdd', {definition, mode}); } function apiDefinitionsAddable(definitions, modes) { return utilInvoke('definitionsAddable', {definitions, modes}).catch(() => null); } -function apiDefinitionAdd(definition, mode) { - return utilInvoke('definitionAdd', {definition, mode}); -} - function apiNoteView(noteId) { return utilInvoke('noteView', {noteId}); } + +function apiTemplateRender(template, data) { + return utilInvoke('templateRender', {data, template}); +} + +function apiCommandExec(command) { + return utilInvoke('commandExec', {command}); +} diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 005139e6..cc4d99c8 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -230,7 +230,7 @@ class Frontend { const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; - this.popup.showKanji( + this.popup.kanjiShow( textSource.getRect(), definitions, this.options, diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 8e61169a..8cb16b5a 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -102,7 +102,7 @@ class Popup { async kanjiShow(elementRect, definitions, options, context) { await this.show(elementRect, options); - this.invokeApi('termsShow', {definitions, options, context}); + this.invokeApi('kanjiShow', {definitions, options, context}); } invokeApi(action, params={}) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 97dd7d5c..21748f5d 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -42,7 +42,7 @@ class Display { onSourceTermView(e) { e.preventDefault(); - this.sourceBack(); + this.sourceTermView(); } async onKanjiLookup(e) { @@ -154,7 +154,7 @@ class Display { 66: /* b */ () => { if (e.altKey) { - this.sourceBack(); + this.sourceTermView(); return true; } }, @@ -276,6 +276,7 @@ class Display { this.entryScrollIntoView(context && context.index || 0); $('.action-add-note').click(this.onNoteAdd.bind(this)); + $('.action-view-note').click(this.onNoteView.bind(this)); $('.source-term').click(this.onSourceTermView.bind(this)); await this.adderButtonUpdate(['kanji'], sequence); @@ -288,7 +289,7 @@ class Display { try { this.spinner.show(); - const states = apiDefinitionsAddable(this.definitions, modes); + const states = await apiDefinitionsAddable(this.definitions, modes); if (!states || sequence !== this.sequence) { return; } @@ -332,7 +333,7 @@ class Display { this.index = index; } - sourceBack() { + sourceTermView() { if (this.context && this.context.source) { const context = { url: this.context.source.url, -- cgit v1.2.3 From 3362a68e06a16efa87a2ad7cc75f18f8f4b2ea25 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 15 Aug 2017 20:04:15 -0700 Subject: frontend cleanup --- ext/fg/js/frontend.js | 44 +++++++++++++++++++++++--------------------- ext/fg/js/popup.js | 12 ++++++------ ext/fg/js/source.js | 10 +++++++++- ext/fg/js/util.js | 2 +- 4 files changed, 39 insertions(+), 29 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 7d26f946..58a721bf 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -21,10 +21,10 @@ class Frontend { constructor() { this.popup = new Popup(); this.popupTimer = null; - this.lastMousePos = null; + this.mousePosLast = null; this.mouseDownLeft = false; this.mouseDownMiddle = false; - this.lastTextSource = null; + this.textSourceLast = null; this.pendingLookup = false; this.options = null; } @@ -53,7 +53,7 @@ class Frontend { } onMouseMove(e) { - this.lastMousePos = {x: e.clientX, y: e.clientY}; + this.mousePosLast = {x: e.clientX, y: e.clientY}; this.popupTimerClear(); if (!this.options.general.enable) { @@ -75,7 +75,7 @@ class Frontend { return; } - const searchFunc = () => this.searchAt(this.lastMousePos); + const searchFunc = () => this.searchAt(this.mousePosLast); if (this.options.scanning.modifier === 'none') { this.popupTimerSet(searchFunc); } else { @@ -84,7 +84,7 @@ class Frontend { } onMouseDown(e) { - this.lastMousePos = {x: e.clientX, y: e.clientY}; + this.mousePosLast = {x: e.clientX, y: e.clientY}; this.popupTimerClear(); this.searchClear(); @@ -143,13 +143,7 @@ class Frontend { } onError(error) { - if (window.yomichan_orphaned) { - if (this.lastTextSource && this.options.scanning.modifier !== 'none') { - this.popup.showOrphaned(this.lastTextSource.getRect(), this.options); - } - } else { - window.alert(`Error: ${error}`); - } + window.alert(`Error: ${error}`); } popupTimerSet(callback) { @@ -165,18 +159,20 @@ class Frontend { } async searchAt(point) { + let textSource = null; + try { if (this.pendingLookup) { return; } - const textSource = docRangeFromPoint(point); + textSource = docRangeFromPoint(point); if (!textSource || !textSource.containsPoint(point)) { docImposterDestroy(); return; } - if (this.lastTextSource && this.lastTextSource.equals(textSource)) { + if (this.textSourceLast && this.textSourceLast.equals(textSource)) { return; } @@ -186,7 +182,13 @@ class Frontend { await this.searchKanji(textSource); } } catch (e) { - this.onError(e); + if (window.yomichan_orphaned) { + if (textSource && this.options.scanning.modifier !== 'none') { + this.popup.showOrphaned(textSource.getRect(), this.options); + } + } else { + this.onError(e); + } } finally { docImposterDestroy(); this.pendingLookup = false; @@ -212,7 +214,7 @@ class Frontend { {sentence, url} ); - this.lastTextSource = textSource; + this.textSourceLast = textSource; if (this.options.scanning.selectText) { textSource.select(); } @@ -237,7 +239,7 @@ class Frontend { {sentence, url} ); - this.lastTextSource = textSource; + this.textSourceLast = textSource; if (this.options.scanning.selectText) { textSource.select(); } @@ -249,11 +251,11 @@ class Frontend { docImposterDestroy(); this.popup.hide(); - if (this.options.scanning.selectText && this.lastTextSource) { - this.lastTextSource.deselect(); + if (this.options.scanning.selectText && this.textSourceLast) { + this.textSourceLast.deselect(); } - this.lastTextSource = null; + this.textSourceLast = null; } } diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 8cb16b5a..03958832 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -87,6 +87,11 @@ class Popup { this.container.style.visibility = 'visible'; } + async showOrphaned(elementRect, options) { + await this.show(elementRect, options); + this.invokeApi('orphaned'); + } + hide() { this.container.style.visibility = 'hidden'; } @@ -108,9 +113,4 @@ class Popup { invokeApi(action, params={}) { this.container.contentWindow.postMessage({action, params}, '*'); } - - async onOrphaned(elementRect, options) { - await this.show(elementRect, options); - this.invokeApi('orphaned'); - } } diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 210dda12..3b6ecb2a 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,10 @@ */ +/* + * TextSourceRange + */ + class TextSourceRange { constructor(range, content='') { this.range = range; @@ -176,6 +180,10 @@ class TextSourceRange { } +/* + * TextSourceElement + */ + class TextSourceElement { constructor(element, content='') { this.element = element; diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index 3faf3b47..5eff4018 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify -- cgit v1.2.3