diff options
| author | Darius Jahandarie <djahandarie@gmail.com> | 2023-12-06 03:53:16 +0000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-06 03:53:16 +0000 | 
| commit | bd5bc1a5db29903bc098995cd9262c4576bf76af (patch) | |
| tree | c9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/pages/settings/popup-preview-controller.js | |
| parent | fd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff) | |
| parent | 23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff) | |
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/pages/settings/popup-preview-controller.js')
| -rw-r--r-- | ext/js/pages/settings/popup-preview-controller.js | 32 | 
1 files changed, 26 insertions, 6 deletions
diff --git a/ext/js/pages/settings/popup-preview-controller.js b/ext/js/pages/settings/popup-preview-controller.js index a0cb696e..7239ca17 100644 --- a/ext/js/pages/settings/popup-preview-controller.js +++ b/ext/js/pages/settings/popup-preview-controller.js @@ -17,22 +17,32 @@   */  export class PopupPreviewController { +    /** +     * @param {import('./settings-controller.js').SettingsController} settingsController +     */      constructor(settingsController) { +        /** @type {import('./settings-controller.js').SettingsController} */          this._settingsController = settingsController; +        /** @type {string} */          this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, ''); +        /** @type {?HTMLIFrameElement} */          this._frame = null; +        /** @type {?HTMLTextAreaElement} */          this._customCss = null; +        /** @type {?HTMLTextAreaElement} */          this._customOuterCss = null; +        /** @type {?HTMLElement} */          this._previewFrameContainer = null;      } +    /** */      async prepare() {          if (new URLSearchParams(location.search).get('popup-preview') === 'false') { return; } -        this._frame = document.querySelector('#popup-preview-frame'); -        this._customCss = document.querySelector('#custom-popup-css'); -        this._customOuterCss = document.querySelector('#custom-popup-outer-css'); -        this._previewFrameContainer = document.querySelector('.preview-frame-container'); +        this._frame = /** @type {HTMLIFrameElement} */ (document.querySelector('#popup-preview-frame')); +        this._customCss = /** @type {HTMLTextAreaElement} */ (document.querySelector('#custom-popup-css')); +        this._customOuterCss = /** @type {HTMLTextAreaElement} */ (document.querySelector('#custom-popup-outer-css')); +        this._previewFrameContainer = /** @type {HTMLElement} */ (document.querySelector('.preview-frame-container'));          this._customCss.addEventListener('input', this._onCustomCssChange.bind(this), false);          this._customCss.addEventListener('settingChanged', this._onCustomCssChange.bind(this), false); @@ -46,25 +56,35 @@ export class PopupPreviewController {      // Private +    /** */      _onFrameLoad() {          this._onOptionsContextChange();          this._onCustomCssChange();          this._onCustomOuterCssChange();      } +    /** */      _onCustomCssChange() { -        this._invoke('PopupPreviewFrame.setCustomCss', {css: this._customCss.value}); +        const css = /** @type {HTMLTextAreaElement} */ (this._customCss).value; +        this._invoke('PopupPreviewFrame.setCustomCss', {css});      } +    /** */      _onCustomOuterCssChange() { -        this._invoke('PopupPreviewFrame.setCustomOuterCss', {css: this._customOuterCss.value}); +        const css = /** @type {HTMLTextAreaElement} */ (this._customOuterCss).value; +        this._invoke('PopupPreviewFrame.setCustomOuterCss', {css});      } +    /** */      _onOptionsContextChange() {          const optionsContext = this._settingsController.getOptionsContext();          this._invoke('PopupPreviewFrame.updateOptionsContext', {optionsContext});      } +    /** +     * @param {string} action +     * @param {import('core').SerializableObject} params +     */      _invoke(action, params) {          if (this._frame === null || this._frame.contentWindow === null) { return; }          this._frame.contentWindow.postMessage({action, params}, this._targetOrigin);  |