PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _acf-tinymce.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 1 week ago pro 1 week ago _acf-compatibility.js 1 year ago _acf-condition-types.js 7 months ago _acf-condition.js 1 year ago _acf-conditions.js 1 year ago _acf-field-accordion.js 6 months ago _acf-field-button-group.js 7 months ago _acf-field-checkbox.js 1 month ago _acf-field-color-picker.js 7 months ago _acf-field-date-picker.js 1 month ago _acf-field-date-time-picker.js 1 month ago _acf-field-file.js 1 month ago _acf-field-google-map.js 6 months ago _acf-field-icon-picker.js 1 month ago _acf-field-image.js 1 month ago _acf-field-link.js 1 year ago _acf-field-oembed.js 1 month ago _acf-field-page-link.js 1 year ago _acf-field-post-object.js 1 year ago _acf-field-radio.js 1 month ago _acf-field-range.js 1 year ago _acf-field-relationship.js 1 month ago _acf-field-select.js 1 month ago _acf-field-tab.js 3 weeks ago _acf-field-taxonomy.js 7 months ago _acf-field-time-picker.js 1 month ago _acf-field-true-false.js 1 month ago _acf-field-url.js 1 year ago _acf-field-user.js 1 year ago _acf-field-wysiwyg.js 1 month ago _acf-field.js 1 year ago _acf-fields.js 1 year ago _acf-helpers.js 1 year ago _acf-hooks.js 1 year ago _acf-internal-post-type.js 7 months ago _acf-media.js 1 week ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 7 months ago _acf-panel.js 1 year ago _acf-popup.js 7 months ago _acf-postbox.js 1 year ago _acf-screen.js 10 months ago _acf-select2.js 1 year ago _acf-tinymce.js 6 months ago _acf-tooltip.js 10 months ago _acf-unload.js 1 year ago _acf-validation.js 1 month ago _acf.js 7 months ago _browse-fields-modal.js 7 months ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 3 months ago _field-group-fields.js 10 months ago _field-group-locations.js 1 year ago _field-group-settings.js 1 year ago _field-group.js 10 months ago acf-escaped-html-notice.js 1 year ago acf-field-group.js 1 year ago acf-input.js 1 year ago acf-internal-post-type.js 1 year ago acf.js 1 year ago
_acf-tinymce.js
421 lines
1 ( function ( $, undefined ) {
2 acf.tinymce = {
3 /*
4 * defaults
5 *
6 * This function will return default mce and qt settings
7 *
8 * @type function
9 * @date 18/8/17
10 * @since ACF 5.6.0
11 *
12 * @param $post_id (int)
13 * @return $post_id (int)
14 */
15
16 defaults: function () {
17 // bail early if no tinyMCEPreInit
18 if ( typeof tinyMCEPreInit === 'undefined' ) return false;
19
20 // vars
21 var defaults = {
22 tinymce: tinyMCEPreInit.mceInit.acf_content,
23 quicktags: tinyMCEPreInit.qtInit.acf_content,
24 };
25
26 // return
27 return defaults;
28 },
29
30 /*
31 * initialize
32 *
33 * This function will initialize the tinymce and quicktags instances
34 *
35 * @type function
36 * @date 18/8/17
37 * @since ACF 5.6.0
38 *
39 * @param $post_id (int)
40 * @return $post_id (int)
41 */
42
43 initialize: function ( id, args ) {
44 // defaults
45 args = acf.parseArgs( args, {
46 tinymce: true,
47 quicktags: true,
48 toolbar: 'full',
49 mode: 'visual', // visual,text
50 field: false,
51 } );
52
53 // tinymce
54 if ( args.tinymce ) {
55 this.initializeTinymce( id, args );
56 }
57
58 // quicktags
59 if ( args.quicktags ) {
60 this.initializeQuicktags( id, args );
61 }
62 },
63
64 /*
65 * initializeTinymce
66 *
67 * This function will initialize the tinymce instance
68 *
69 * @type function
70 * @date 18/8/17
71 * @since ACF 5.6.0
72 *
73 * @param $post_id (int)
74 * @return $post_id (int)
75 */
76
77 initializeTinymce: function ( id, args ) {
78 // vars
79 var $textarea = $( '#' + id );
80 var defaults = this.defaults();
81 var toolbars = acf.get( 'toolbars' );
82 var field = args.field || false;
83 var $field = field.$el || false;
84
85 // bail early
86 if ( typeof tinymce === 'undefined' ) return false;
87 if ( ! defaults ) return false;
88
89 // check if exists
90 if ( tinymce.get( id ) ) {
91 return this.enable( id );
92 }
93
94 // settings
95 var init = $.extend( {}, defaults.tinymce, args.tinymce );
96 init.id = id;
97 init.selector = '#' + id;
98
99 // toolbar
100 var toolbar = args.toolbar;
101 if ( toolbar && toolbars && toolbars[ toolbar ] ) {
102 for ( var i = 1; i <= 4; i++ ) {
103 init[ 'toolbar' + i ] = toolbars[ toolbar ][ i ] || '';
104 }
105 }
106
107 // event
108 init.setup = function ( ed ) {
109 ed.on( 'change', function ( e ) {
110 ed.save(); // save to textarea
111 if ( ! $textarea.closest( '.attachment-info' ).length ) {
112 $textarea.trigger( 'change' );
113 }
114 } );
115
116 ed.on( 'blur', function ( e ) {
117 if ( $textarea.closest( '.attachment-info' ).length ) {
118 ed.save();
119 $textarea.trigger( 'change' );
120 }
121 } );
122
123 // Fix bug where Gutenberg does not hear "mouseup" event and tries to select multiple blocks.
124 ed.on( 'mouseup', function ( e ) {
125 const event = new MouseEvent( 'mouseup' );
126 window.dispatchEvent( event );
127 } );
128
129 // Temporarily comment out. May not be necessary due to wysiwyg field actions.
130 //ed.on('unload', function(e) {
131 // acf.tinymce.remove( id );
132 //});
133 };
134
135 // disable wp_autoresize_on (no solution yet for fixed toolbar)
136 init.wp_autoresize_on = false;
137
138 // Enable wpautop allowing value to save without <p> tags.
139 // Only if the "TinyMCE Advanced" plugin hasn't already set this functionality.
140 if ( ! init.tadv_noautop ) {
141 init.wpautop = true;
142 }
143
144 // hook for 3rd party customization
145 init = acf.applyFilters(
146 'wysiwyg_tinymce_settings',
147 init,
148 id,
149 field
150 );
151
152 // z-index fix (caused too many conflicts)
153 //if( acf.isset(tinymce,'ui','FloatPanel') ) {
154 // tinymce.ui.FloatPanel.zIndex = 900000;
155 //}
156
157 // store settings
158 tinyMCEPreInit.mceInit[ id ] = init;
159
160 // visual tab is active
161 if ( args.mode == 'visual' ) {
162 // init
163 var result = tinymce.init( init );
164
165 // get editor
166 var ed = tinymce.get( id );
167
168 // validate
169 if ( ! ed ) {
170 return false;
171 }
172
173 // add reference
174 ed.acf = args.field;
175
176 // action
177 acf.doAction( 'wysiwyg_tinymce_init', ed, ed.id, init, field );
178 }
179 },
180
181 /*
182 * initializeQuicktags
183 *
184 * This function will initialize the quicktags instance
185 *
186 * @type function
187 * @date 18/8/17
188 * @since ACF 5.6.0
189 *
190 * @param $post_id (int)
191 * @return $post_id (int)
192 */
193
194 initializeQuicktags: function ( id, args ) {
195 // vars
196 var defaults = this.defaults();
197
198 // bail early
199 if ( typeof quicktags === 'undefined' ) return false;
200 if ( ! defaults ) return false;
201
202 // settings
203 var init = $.extend( {}, defaults.quicktags, args.quicktags );
204 init.id = id;
205
206 // filter
207 var field = args.field || false;
208 var $field = field.$el || false;
209 init = acf.applyFilters(
210 'wysiwyg_quicktags_settings',
211 init,
212 init.id,
213 field
214 );
215
216 // store settings
217 tinyMCEPreInit.qtInit[ id ] = init;
218
219 // init
220 var ed = quicktags( init );
221
222 // validate
223 if ( ! ed ) {
224 return false;
225 }
226
227 // generate HTML
228 this.buildQuicktags( ed );
229
230 // action for 3rd party customization
231 acf.doAction( 'wysiwyg_quicktags_init', ed, ed.id, init, field );
232 },
233
234 /*
235 * buildQuicktags
236 *
237 * This function will build the quicktags HTML
238 *
239 * @type function
240 * @date 18/8/17
241 * @since ACF 5.6.0
242 *
243 * @param $post_id (int)
244 * @return $post_id (int)
245 */
246
247 buildQuicktags: function ( ed ) {
248 var canvas,
249 name,
250 settings,
251 theButtons,
252 html,
253 ed,
254 id,
255 i,
256 use,
257 instanceId,
258 defaults =
259 ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
260
261 canvas = ed.canvas;
262 name = ed.name;
263 settings = ed.settings;
264 html = '';
265 theButtons = {};
266 use = '';
267 instanceId = ed.id;
268
269 // set buttons
270 if ( settings.buttons ) {
271 use = ',' + settings.buttons + ',';
272 }
273
274 for ( i in edButtons ) {
275 if ( ! edButtons[ i ] ) {
276 continue;
277 }
278
279 id = edButtons[ i ].id;
280 if (
281 use &&
282 defaults.indexOf( ',' + id + ',' ) !== -1 &&
283 use.indexOf( ',' + id + ',' ) === -1
284 ) {
285 continue;
286 }
287
288 if (
289 ! edButtons[ i ].instance ||
290 edButtons[ i ].instance === instanceId
291 ) {
292 theButtons[ id ] = edButtons[ i ];
293
294 if ( edButtons[ i ].html ) {
295 html += edButtons[ i ].html( name + '_' );
296 }
297 }
298 }
299
300 if ( use && use.indexOf( ',dfw,' ) !== -1 ) {
301 theButtons.dfw = new QTags.DFWButton();
302 html += theButtons.dfw.html( name + '_' );
303 }
304
305 if ( 'rtl' === document.getElementsByTagName( 'html' )[ 0 ].dir ) {
306 theButtons.textdirection = new QTags.TextDirectionButton();
307 html += theButtons.textdirection.html( name + '_' );
308 }
309
310 ed.toolbar.innerHTML = html;
311 ed.theButtons = theButtons;
312
313 if ( typeof jQuery !== 'undefined' ) {
314 jQuery( document ).triggerHandler( 'quicktags-init', [ ed ] );
315 }
316 },
317
318 disable: function ( id ) {
319 this.destroyTinymce( id );
320 },
321
322 remove: function ( id ) {
323 this.destroyTinymce( id );
324 },
325
326 destroy: function ( id ) {
327 this.destroyTinymce( id );
328 },
329
330 destroyTinymce: function ( id ) {
331 // bail early
332 if ( typeof tinymce === 'undefined' ) return false;
333
334 // get editor
335 var ed = tinymce.get( id );
336
337 // bail early if no editor
338 if ( ! ed ) return false;
339
340 // save
341 ed.save();
342
343 // destroy editor
344 ed.destroy();
345
346 // return
347 return true;
348 },
349
350 enable: function ( id ) {
351 this.enableTinymce( id );
352 },
353
354 enableTinymce: function ( id ) {
355 // bail early
356 if ( typeof switchEditors === 'undefined' ) return false;
357
358 // bail early if not initialized
359 if ( typeof tinyMCEPreInit.mceInit[ id ] === 'undefined' )
360 return false;
361
362 // Ensure textarea element is visible
363 // - Fixes bug in block editor when switching between "Block" and "Document" tabs.
364 if ( ! tinymce.get( id ) ) {
365 $( '#' + id ).show();
366 }
367
368 // toggle
369 switchEditors.go( id, 'tmce' );
370
371 // return
372 return true;
373 },
374 };
375
376 var editorManager = new acf.Model( {
377 // hook in before fieldsEventManager, conditions, etc
378 priority: 5,
379
380 actions: {
381 prepare: 'onPrepare',
382 ready: 'onReady',
383 },
384 onPrepare: function () {
385 // find hidden editor which may exist within a field
386 var $div = $( '#acf-hidden-wp-editor' );
387
388 // move to footer
389 if ( $div.exists() ) {
390 $div.appendTo( 'body' );
391 }
392 },
393 onReady: function () {
394 // Restore wp.editor functions used by tinymce removed in WP5.
395 if ( acf.isset( window, 'wp', 'oldEditor' ) ) {
396 wp.editor.autop = wp.oldEditor.autop;
397 wp.editor.removep = wp.oldEditor.removep;
398 }
399
400 // bail early if no tinymce
401 if ( ! acf.isset( window, 'tinymce', 'on' ) ) return;
402
403 // restore default activeEditor
404 tinymce.on( 'AddEditor', function ( data ) {
405 // vars
406 var editor = data.editor;
407
408 // bail early if not 'acf'
409 if ( editor.id.substr( 0, 3 ) !== 'acf' ) return;
410
411 // override if 'content' exists
412 editor = tinymce.editors.content || editor;
413
414 // update vars
415 tinymce.activeEditor = editor;
416 wpActiveEditor = editor.id;
417 } );
418 },
419 } );
420 } )( jQuery );
421