1
1
/**
2
- * TinyMCE for phpMyFAQ
2
+ * Jodit Editor for phpMyFAQ
3
3
*
4
4
* This Source Code Form is subject to the terms of the Mozilla Public License,
5
5
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
@@ -38,6 +38,81 @@ import 'jodit/esm/plugins/symbols/symbols.js';
38
38
import 'jodit/esm/modules/uploader/uploader.js' ;
39
39
import 'jodit/esm/plugins/video/video.js' ;
40
40
41
+ // Define the phpMyFAQ plugin
42
+ Jodit . plugins . add ( 'phpMyFAQ' , ( editor ) => {
43
+ // Register the button
44
+ editor . registerButton ( {
45
+ name : 'phpMyFAQ' ,
46
+ } ) ;
47
+
48
+ // Register the command
49
+ editor . registerCommand ( 'phpMyFAQ' , ( ) => {
50
+ const dialog = editor . dlg ( { closeOnClickOverlay : true } ) ;
51
+
52
+ const content = `<form class="row row-cols-lg-auto g-3 align-items-center m-4">
53
+ <div class="col-12">
54
+ <label class="visually-hidden" for="pmf-search-internal-links">Search</label>
55
+ <input type="text" class="form-control" id="pmf-search-internal-links" placeholder="Search">
56
+ </div>
57
+ </form>
58
+ <div class="m-4" id="pmf-search-results"></div>
59
+ <div class="m-4">
60
+ <button type="button" class="btn btn-primary" id="select-faq-button">Select FAQ</button>
61
+ </div>` ;
62
+
63
+ dialog . setMod ( 'theme' , editor . o . theme ) . setHeader ( 'phpMyFAQ Plugin' ) . setContent ( content ) ;
64
+
65
+ dialog . open ( ) ;
66
+
67
+ const searchInput = document . getElementById ( 'pmf-search-internal-links' ) ;
68
+ const resultsContainer = document . getElementById ( 'pmf-search-results' ) ;
69
+ const csrfToken = document . getElementById ( 'pmf-csrf-token' ) . value ;
70
+ const selectLink = document . getElementById ( 'select-faq-button' ) ;
71
+
72
+ searchInput . addEventListener ( 'keyup' , ( ) => {
73
+ const query = searchInput . value ;
74
+ if ( query . length > 0 ) {
75
+ fetch ( 'api/faq/search' , {
76
+ method : 'POST' ,
77
+ headers : {
78
+ 'Content-Type' : 'application/json' ,
79
+ } ,
80
+ body : JSON . stringify ( {
81
+ search : query ,
82
+ csrf : csrfToken ,
83
+ } ) ,
84
+ } )
85
+ . then ( ( response ) => response . json ( ) )
86
+ . then ( ( data ) => {
87
+ resultsContainer . innerHTML = '' ;
88
+ data . success . forEach ( ( result ) => {
89
+ resultsContainer . innerHTML += `<label class="form-check-label">
90
+ <input class="form-check-input" type="radio" name="faqURL" value="${ result . url } ">
91
+ ${ result . question }
92
+ </label><br>` ;
93
+ } ) ;
94
+ } )
95
+ . catch ( ( error ) => console . error ( 'Error:' , error ) ) ;
96
+ } else {
97
+ resultsContainer . innerHTML = '' ;
98
+ }
99
+ } ) ;
100
+
101
+ selectLink . addEventListener ( 'click' , ( ) => {
102
+ const selected = document . querySelector ( 'input[name=faqURL]:checked' ) ;
103
+ if ( selected ) {
104
+ const url = selected . value ;
105
+ const question = selected . parentNode . textContent . trim ( ) ;
106
+ const anchor = `<a href="${ url } ">${ question } </a>` ;
107
+ editor . selection . insertHTML ( anchor ) ;
108
+ dialog . close ( ) ;
109
+ } else {
110
+ alert ( 'Please select an FAQ.' ) ;
111
+ }
112
+ } ) ;
113
+ } ) ;
114
+ } ) ;
115
+
41
116
export const renderEditor = ( ) => {
42
117
const editor = document . getElementById ( 'editor' ) ;
43
118
if ( ! editor ) {
@@ -158,6 +233,7 @@ export const renderEditor = () => {
158
233
imageDefaultWidth : 300 ,
159
234
removeButtons : [ ] ,
160
235
disablePlugins : [ ] ,
236
+ extraPlugins : [ 'phpMyFAQ' ] ,
161
237
extraButtons : [ ] ,
162
238
buttons : [
163
239
'source' ,
@@ -172,7 +248,6 @@ export const renderEditor = () => {
172
248
'superscript' ,
173
249
'subscript' ,
174
250
'|' ,
175
- 'justify' ,
176
251
'outdent' ,
177
252
'indent' ,
178
253
'|' ,
@@ -181,13 +256,16 @@ export const renderEditor = () => {
181
256
'lineHeight' ,
182
257
'brush' ,
183
258
'paragraph' ,
259
+ 'left' ,
260
+ 'center' ,
261
+ 'right' ,
262
+ 'justify' ,
184
263
'|' ,
185
264
'copy' ,
186
265
'cut' ,
187
266
'paste' ,
188
267
'selectall' ,
189
268
'|' ,
190
- 'file' ,
191
269
'image' ,
192
270
'video' ,
193
271
'table' ,
@@ -205,6 +283,8 @@ export const renderEditor = () => {
205
283
'fullsize' ,
206
284
'preview' ,
207
285
'print' ,
286
+ '|' ,
287
+ 'phpMyFAQ' ,
208
288
] ,
209
289
events : { } ,
210
290
textIcons : false ,
0 commit comments