|
1 | 1 | (function () { |
2 | | - var WSC_DISABLE_AUTO_SEARCH_IN = [ |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + function asBoolean(value, fallback) { |
| 5 | + if (value === true || value === 'true') return true; |
| 6 | + if (value === false || value === 'false') return false; |
| 7 | + return fallback; |
| 8 | + } |
| 9 | + |
| 10 | + function asArray(value) { |
| 11 | + return Array.isArray(value) ? value : []; |
| 12 | + } |
| 13 | + |
| 14 | + const serviceConfig = window.WSCServiceConfig || {}; |
| 15 | + const proofreaderConfig = window.WSCProofreaderConfig || {}; |
| 16 | + |
| 17 | + const isBadgeEnabled = asBoolean(proofreaderConfig.enableBadgeButton, true); |
| 18 | + const badgeActions = isBadgeEnabled |
| 19 | + ? ['addWord', 'ignoreAll', 'settings', 'toggle', 'proofreadDialog'] |
| 20 | + : ['addWord', 'ignoreAll', 'settings', 'proofreadDialog']; |
| 21 | + |
| 22 | + const disableAutoSearchIn = [ |
3 | 23 | '.wp-block-table__cell-content', |
4 | 24 | '.ui-autocomplete-input', |
5 | 25 | '#wp-link-url', |
|
16 | 36 | '#mailserver_login', |
17 | 37 | '#ping_sites', |
18 | 38 | '#permalink_structure', |
19 | | - '.inline-edit-password-input' |
| 39 | + '.inline-edit-password-input', |
20 | 40 | ]; |
21 | 41 |
|
22 | 42 | window.WEBSPELLCHECKER_CONFIG = { |
23 | 43 | autoSearch: true, |
24 | 44 | appType: 'wp_plugin', |
25 | | - serviceProtocol: 'https', |
26 | | - serviceHost: 'svc.webspellchecker.net', |
27 | | - servicePath: 'spellcheck31/api', |
28 | | - servicePort: '443', |
29 | | - enableGrammar: (WSCProofreaderConfig.enableGrammar === 'true'), |
30 | | - settingsSections: WSCProofreaderConfig.settingsSections, |
31 | | - serviceId: WSCProofreaderConfig.key_for_proofreader, |
32 | | - lang: WSCProofreaderConfig.slang, |
33 | | - enableBadgeButton: (WSCProofreaderConfig.enableBadgeButton !== 'true'), |
34 | | - actionItems: (WSCProofreaderConfig.disableBadgeButton === 'true') ? ['addWord', 'ignoreAll', 'settings', 'toggle', 'proofreadDialog'] : ['addWord', 'ignoreAll', 'settings', 'proofreadDialog'], |
35 | | - disableAutoSearchIn: WSC_DISABLE_AUTO_SEARCH_IN, |
36 | | - disableOptionsStorage: [], |
37 | | - globalBadge: (WSCProofreaderConfig.globalBadge === 'true'), |
38 | | - compactBadge: false, |
| 45 | + serviceProtocol: serviceConfig.serviceProtocol || 'https', |
| 46 | + serviceHost: serviceConfig.serviceHost || 'svc.webspellchecker.net', |
| 47 | + servicePath: serviceConfig.servicePath || 'api', |
| 48 | + servicePort: serviceConfig.servicePort || '443', |
| 49 | + enableGrammar: asBoolean(proofreaderConfig.enableGrammar, false), |
| 50 | + aiWritingAssistant: asBoolean(proofreaderConfig.aiWritingAssistant, false), |
| 51 | + settingsSections: asArray(proofreaderConfig.settingsSections), |
| 52 | + serviceId: proofreaderConfig.key_for_proofreader, |
| 53 | + lang: proofreaderConfig.slang, |
| 54 | + enableBadgeButton: isBadgeEnabled, |
| 55 | + actionItems: badgeActions, |
| 56 | + disableAutoSearchIn: disableAutoSearchIn, |
| 57 | + disableOptionsStorage: asArray(proofreaderConfig.disableOptionsStorage), |
| 58 | + disableDictionariesPreferences: asBoolean(proofreaderConfig.disableDictionariesPreferences, false), |
| 59 | + autocomplete: asBoolean(proofreaderConfig.autocomplete, false), |
| 60 | + globalBadge: asBoolean(proofreaderConfig.globalBadge, true), |
| 61 | + compactBadge: asBoolean(proofreaderConfig.compactBadge, false), |
39 | 62 | allSuggestionsMode: true, |
40 | 63 | onLoad: function () { |
41 | | - var self = this; |
| 64 | + const instance = this; |
42 | 65 |
|
43 | 66 | this.subscribe('replaceProblem', function () { |
44 | 67 | try { |
45 | | - var element = self.getContainerNode(), |
46 | | - event = document.createEvent('Event'); |
47 | | - |
48 | | - event.initEvent('input', true, false); |
49 | | - element.dispatchEvent(event); |
| 68 | + const element = instance.getContainerNode(); |
| 69 | + element.dispatchEvent(new Event('input', { bubbles: true })); |
50 | 70 | } catch (e) { |
| 71 | + // Container may have been detached by the host editor — safe to ignore. |
51 | 72 | } |
52 | 73 | }); |
53 | | - |
54 | 74 | }, |
55 | | - onBeforeAutoSearchInstanceCreate: function (activeElement, options) { |
56 | | - var id = activeElement.element.id; |
| 75 | + onBeforeAutoSearchInstanceCreate: function (activeElement) { |
| 76 | + const id = activeElement.element.id; |
57 | 77 | return !(id && id.indexOf('url-input-control') === 0); |
58 | | - } |
| 78 | + }, |
| 79 | + }; |
| 80 | + |
| 81 | + if (Array.isArray(proofreaderConfig.generalOptions) && proofreaderConfig.generalOptions.length) { |
| 82 | + window.WEBSPELLCHECKER_CONFIG.generalOptions = proofreaderConfig.generalOptions; |
59 | 83 | } |
60 | 84 | })(); |
61 | | - |
|
0 commit comments