PluginProbe
WProofreader spell & grammar check plugin for WordPress / trunk
WProofreader spell & grammar check plugin for WordPress vtrunk
3.2.1 3.2.2 3.2.0 trunk 1.0 1.1 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.6.1 2.6.10 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 All 28 releases
webspellchecker / assets / proofreaderConfig.js

proofreaderConfig.js in WProofreader spell & grammar check plugin for WordPress trunk, at assets/proofreaderConfig.js

114 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
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 // TinyMCE does not treat a bare DOM input event as an edit; without this the
18 // classic editor may consider the document unchanged and skip saving a correction.
19 function markTinyMceDirty(element) {
20 try {
21 const win = element.ownerDocument.defaultView;
22 const tinymce = win.tinymce || (win.parent && win.parent.tinymce);
23 if (!tinymce || !tinymce.editors) {
24 return;
25 }
26
27 Array.prototype.forEach.call(tinymce.editors, function (editor) {
28 const body = editor.getBody && editor.getBody();
29 if (body && (body === element || body.contains(element))) {
30 editor.setDirty(true);
31 }
32 });
33 } catch (e) {
34 // Cross-frame access or missing TinyMCE — nothing to mark.
35 }
36 }
37
38 const isBadgeEnabled = asBoolean(proofreaderConfig.enableBadgeButton, true);
39 // Order matters: the bundle keeps the leading items in the visible action row of
40 // the suggestion popup and collapses the rest under the "more" button. Report sits
41 // right after addWord so it stays visible on spelling problems.
42 const badgeActions = isBadgeEnabled
43 ? ['addWord', 'report', 'ignoreAll', 'settings', 'toggle', 'proofreadDialog']
44 : ['addWord', 'report', 'ignoreAll', 'settings', 'proofreadDialog'];
45
46 const disableAutoSearchIn = [
47 '.wp-block-table__cell-content',
48 '.ui-autocomplete-input',
49 '#wp-link-url',
50 '#url',
51 '#billing_phone',
52 '#shipping_phone',
53 '#siteurl',
54 '#new_admin_email',
55 '#home',
56 '#billing_postcode',
57 '#billing_email',
58 '#shipping_postcode',
59 '#mailserver_url',
60 '#mailserver_login',
61 '#ping_sites',
62 '#permalink_structure',
63 '.inline-edit-password-input',
64 '#_sale_price',
65 '#_regular_price',
66 '#_weight',
67 ];
68
69 window.WEBSPELLCHECKER_CONFIG = {
70 autoSearch: true,
71 appType: 'wp_plugin',
72 serviceProtocol: serviceConfig.serviceProtocol || 'https',
73 serviceHost: serviceConfig.serviceHost || 'svc.webspellchecker.net',
74 servicePath: serviceConfig.servicePath || 'api',
75 servicePort: serviceConfig.servicePort || '443',
76 enableGrammar: asBoolean(proofreaderConfig.enableGrammar, false),
77 aiWritingAssistant: asBoolean(proofreaderConfig.aiWritingAssistant, false),
78 settingsSections: asArray(proofreaderConfig.settingsSections),
79 serviceId: proofreaderConfig.key_for_proofreader,
80 lang: proofreaderConfig.slang,
81 enableBadgeButton: isBadgeEnabled,
82 actionItems: badgeActions,
83 disableAutoSearchIn: disableAutoSearchIn,
84 disableOptionsStorage: asArray(proofreaderConfig.disableOptionsStorage),
85 disableDictionariesPreferences: asBoolean(proofreaderConfig.disableDictionariesPreferences, false),
86 autocomplete: asBoolean(proofreaderConfig.autocomplete, false),
87 globalBadge: asBoolean(proofreaderConfig.globalBadge, true),
88 compactBadge: asBoolean(proofreaderConfig.compactBadge, false),
89 allSuggestionsMode: true,
90 onLoad: function () {
91 const instance = this;
92
93 this.subscribe('replaceProblem', function () {
94 try {
95 const element = instance.getContainerNode();
96 // Gutenberg's RichText syncs block state from the DOM on input.
97 element.dispatchEvent(new Event('input', { bubbles: true }));
98 markTinyMceDirty(element);
99 } catch (e) {
100 // Container may have been detached by the host editor — safe to ignore.
101 }
102 });
103 },
104 onBeforeAutoSearchInstanceCreate: function (activeElement) {
105 const id = activeElement && activeElement.element ? activeElement.element.id : '';
106 return !(id && id.indexOf('url-input-control') === 0);
107 },
108 };
109
110 if (Array.isArray(proofreaderConfig.generalOptions) && proofreaderConfig.generalOptions.length) {
111 window.WEBSPELLCHECKER_CONFIG.generalOptions = proofreaderConfig.generalOptions;
112 }
113 })();
114