diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-08-09 13:27:21 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-09 13:27:21 -0400 | 
| commit | 6da02c6eee803756d9a9075bfde333eeb31ce64b (patch) | |
| tree | 158d81b89ca99095c06db31c1ebc7bb46a57c33a /ext/mixed/js | |
| parent | 480e0e15e3109165d077c18985893d7cca79959e (diff) | |
document.js refactor (#719)
* Refactor document.js into a class
* Move public functions first
* Rename private functions
* Rename
* Rename argument
* Use instance of DocumentUtil
* Update tests
* Refactor
* Rename (test-)document.js to (test-)document-util.js
Diffstat (limited to 'ext/mixed/js')
| -rw-r--r-- | ext/mixed/js/display.js | 11 | ||||
| -rw-r--r-- | ext/mixed/js/text-scanner.js | 6 | 
2 files changed, 9 insertions, 8 deletions
| diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 927c2c2c..170b9d23 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -20,14 +20,13 @@   * DOM   * DisplayGenerator   * DisplayHistory + * DocumentUtil   * Frontend   * MediaLoader   * PopupFactory   * QueryParser   * WindowScroll   * api - * docRangeFromPoint - * docSentenceExtract   * dynamicLoader   */ @@ -74,12 +73,14 @@ class Display extends EventDispatcher {          this._defaultTitle = 'Yomichan Search';          this._defaultTitleMaxLength = 1000;          this._fullQuery = ''; +        this._documentUtil = new DocumentUtil();          this._queryParserVisible = false;          this._queryParserVisibleOverride = null;          this._queryParserContainer = document.querySelector('#query-parser-container');          this._queryParser = new QueryParser({              getOptionsContext: this.getOptionsContext.bind(this), -            setSpinnerVisible: this.setSpinnerVisible.bind(this) +            setSpinnerVisible: this.setSpinnerVisible.bind(this), +            documentUtil: this._documentUtil          });          this._mode = null; @@ -588,7 +589,7 @@ class Display extends EventDispatcher {          const scannedElement = e.target;          const sentenceExtent = this._options.anki.sentenceExt;          const layoutAwareScan = this._options.scanning.layoutAwareScan; -        const sentence = docSentenceExtract(textSource, sentenceExtent, layoutAwareScan); +        const sentence = this._documentUtil.extractSentence(textSource, sentenceExtent, layoutAwareScan);          state.focusEntry = this._entryIndexFind(scannedElement);          state.scrollX = this._windowScroll.x; @@ -616,7 +617,7 @@ class Display extends EventDispatcher {          e.preventDefault();          const {length: scanLength, deepDomScan: deepScan, layoutAwareScan} = this._options.scanning; -        const textSource = docRangeFromPoint(e.clientX, e.clientY, deepScan); +        const textSource = this._documentUtil.getRangeFromPoint(e.clientX, e.clientY, deepScan);          if (textSource === null) {              return false;          } diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index 61e9256d..923784b3 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -17,16 +17,16 @@  /* global   * DOM - * docRangeFromPoint   */  class TextScanner extends EventDispatcher { -    constructor({node, ignoreElements, ignorePoint, search}) { +    constructor({node, ignoreElements, ignorePoint, search, documentUtil}) {          super();          this._node = node;          this._ignoreElements = ignoreElements;          this._ignorePoint = ignorePoint;          this._search = search; +        this._documentUtil = documentUtil;          this._isPrepared = false;          this._ignoreNodes = null; @@ -124,7 +124,7 @@ class TextScanner extends EventDispatcher {                  return;              } -            const textSource = docRangeFromPoint(x, y, this._deepContentScan); +            const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);              try {                  if (this._textSourceCurrent !== null && this._textSourceCurrent.equals(textSource)) {                      return; |