PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.2
Secure Custom Fields v6.4.2
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
pro 1 year ago _acf-compatibility.js 1 year ago _acf-condition-types.js 1 year ago _acf-condition.js 1 year ago _acf-conditions.js 1 year ago _acf-field-accordion.js 1 year ago _acf-field-button-group.js 1 year ago _acf-field-checkbox.js 1 year ago _acf-field-color-picker.js 1 year ago _acf-field-date-picker.js 1 year ago _acf-field-date-time-picker.js 1 year ago _acf-field-file.js 1 year ago _acf-field-google-map.js 1 year ago _acf-field-icon-picker.js 1 year ago _acf-field-image.js 1 year ago _acf-field-link.js 1 year ago _acf-field-oembed.js 1 year ago _acf-field-page-link.js 1 year ago _acf-field-post-object.js 1 year ago _acf-field-radio.js 1 year ago _acf-field-range.js 1 year ago _acf-field-relationship.js 1 year ago _acf-field-select.js 1 year ago _acf-field-tab.js 1 year ago _acf-field-taxonomy.js 1 year ago _acf-field-time-picker.js 1 year ago _acf-field-true-false.js 1 year ago _acf-field-url.js 1 year ago _acf-field-user.js 1 year ago _acf-field-wysiwyg.js 1 year 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 1 year ago _acf-media.js 1 year ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 1 year ago _acf-panel.js 1 year ago _acf-popup.js 1 year ago _acf-postbox.js 1 year ago _acf-screen.js 1 year ago _acf-select2.js 1 year ago _acf-tinymce.js 1 year ago _acf-tooltip.js 1 year ago _acf-unload.js 1 year ago _acf-validation.js 1 year ago _acf.js 1 year ago _browse-fields-modal.js 1 year ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 1 year ago _field-group-fields.js 1 year ago _field-group-locations.js 1 year ago _field-group-settings.js 1 year ago _field-group.js 1 year 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
410 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 $textarea.trigger( 'change' );
112 } );
113
114 // Fix bug where Gutenberg does not hear "mouseup" event and tries to select multiple blocks.
115 ed.on( 'mouseup', function ( e ) {
116 var event = new MouseEvent( 'mouseup' );
117 window.dispatchEvent( event );
118 } );
119
120 // Temporarily comment out. May not be necessary due to wysiwyg field actions.
121 //ed.on('unload', function(e) {
122 // acf.tinymce.remove( id );
123 //});
124 };
125
126 // disable wp_autoresize_on (no solution yet for fixed toolbar)
127 init.wp_autoresize_on = false;
128
129 // Enable wpautop allowing value to save without <p> tags.
130 // Only if the "TinyMCE Advanced" plugin hasn't already set this functionality.
131 if ( ! init.tadv_noautop ) {
132 init.wpautop = true;
133 }
134
135 // hook for 3rd party customization
136 init = acf.applyFilters(
137 'wysiwyg_tinymce_settings',
138 init,
139 id,
140 field
141 );
142
143 // z-index fix (caused too many conflicts)
144 //if( acf.isset(tinymce,'ui','FloatPanel') ) {
145 // tinymce.ui.FloatPanel.zIndex = 900000;
146 //}
147
148 // store settings
149 tinyMCEPreInit.mceInit[ id ] = init;
150
151 // visual tab is active
152 if ( args.mode == 'visual' ) {
153 // init
154 var result = tinymce.init( init );
155
156 // get editor
157 var ed = tinymce.get( id );
158
159 // validate
160 if ( ! ed ) {
161 return false;
162 }
163
164 // add reference
165 ed.acf = args.field;
166
167 // action
168 acf.doAction( 'wysiwyg_tinymce_init', ed, ed.id, init, field );
169 }
170 },
171
172 /*
173 * initializeQuicktags
174 *
175 * This function will initialize the quicktags instance
176 *
177 * @type function
178 * @date 18/8/17
179 * @since ACF 5.6.0
180 *
181 * @param $post_id (int)
182 * @return $post_id (int)
183 */
184
185 initializeQuicktags: function ( id, args ) {
186 // vars
187 var defaults = this.defaults();
188
189 // bail early
190 if ( typeof quicktags === 'undefined' ) return false;
191 if ( ! defaults ) return false;
192
193 // settings
194 var init = $.extend( {}, defaults.quicktags, args.quicktags );
195 init.id = id;
196
197 // filter
198 var field = args.field || false;
199 var $field = field.$el || false;
200 init = acf.applyFilters(
201 'wysiwyg_quicktags_settings',
202 init,
203 init.id,
204 field
205 );
206
207 // store settings
208 tinyMCEPreInit.qtInit[ id ] = init;
209
210 // init
211 var ed = quicktags( init );
212
213 // validate
214 if ( ! ed ) {
215 return false;
216 }
217
218 // generate HTML
219 this.buildQuicktags( ed );
220
221 // action for 3rd party customization
222 acf.doAction( 'wysiwyg_quicktags_init', ed, ed.id, init, field );
223 },
224
225 /*
226 * buildQuicktags
227 *
228 * This function will build the quicktags HTML
229 *
230 * @type function
231 * @date 18/8/17
232 * @since ACF 5.6.0
233 *
234 * @param $post_id (int)
235 * @return $post_id (int)
236 */
237
238 buildQuicktags: function ( ed ) {
239 var canvas,
240 name,
241 settings,
242 theButtons,
243 html,
244 ed,
245 id,
246 i,
247 use,
248 instanceId,
249 defaults =
250 ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
251
252 canvas = ed.canvas;
253 name = ed.name;
254 settings = ed.settings;
255 html = '';
256 theButtons = {};
257 use = '';
258 instanceId = ed.id;
259
260 // set buttons
261 if ( settings.buttons ) {
262 use = ',' + settings.buttons + ',';
263 }
264
265 for ( i in edButtons ) {
266 if ( ! edButtons[ i ] ) {
267 continue;
268 }
269
270 id = edButtons[ i ].id;
271 if (
272 use &&
273 defaults.indexOf( ',' + id + ',' ) !== -1 &&
274 use.indexOf( ',' + id + ',' ) === -1
275 ) {
276 continue;
277 }
278
279 if (
280 ! edButtons[ i ].instance ||
281 edButtons[ i ].instance === instanceId
282 ) {
283 theButtons[ id ] = edButtons[ i ];
284
285 if ( edButtons[ i ].html ) {
286 html += edButtons[ i ].html( name + '_' );
287 }
288 }
289 }
290
291 if ( use && use.indexOf( ',dfw,' ) !== -1 ) {
292 theButtons.dfw = new QTags.DFWButton();
293 html += theButtons.dfw.html( name + '_' );
294 }
295
296 if ( 'rtl' === document.getElementsByTagName( 'html' )[ 0 ].dir ) {
297 theButtons.textdirection = new QTags.TextDirectionButton();
298 html += theButtons.textdirection.html( name + '_' );
299 }
300
301 ed.toolbar.innerHTML = html;
302 ed.theButtons = theButtons;
303
304 if ( typeof jQuery !== 'undefined' ) {
305 jQuery( document ).triggerHandler( 'quicktags-init', [ ed ] );
306 }
307 },
308
309 disable: function ( id ) {
310 this.destroyTinymce( id );
311 },
312
313 remove: function ( id ) {
314 this.destroyTinymce( id );
315 },
316
317 destroy: function ( id ) {
318 this.destroyTinymce( id );
319 },
320
321 destroyTinymce: function ( id ) {
322 // bail early
323 if ( typeof tinymce === 'undefined' ) return false;
324
325 // get editor
326 var ed = tinymce.get( id );
327
328 // bail early if no editor
329 if ( ! ed ) return false;
330
331 // save
332 ed.save();
333
334 // destroy editor
335 ed.destroy();
336
337 // return
338 return true;
339 },
340
341 enable: function ( id ) {
342 this.enableTinymce( id );
343 },
344
345 enableTinymce: function ( id ) {
346 // bail early
347 if ( typeof switchEditors === 'undefined' ) return false;
348
349 // bail early if not initialized
350 if ( typeof tinyMCEPreInit.mceInit[ id ] === 'undefined' )
351 return false;
352
353 // Ensure textarea element is visible
354 // - Fixes bug in block editor when switching between "Block" and "Document" tabs.
355 $( '#' + id ).show();
356
357 // toggle
358 switchEditors.go( id, 'tmce' );
359
360 // return
361 return true;
362 },
363 };
364
365 var editorManager = new acf.Model( {
366 // hook in before fieldsEventManager, conditions, etc
367 priority: 5,
368
369 actions: {
370 prepare: 'onPrepare',
371 ready: 'onReady',
372 },
373 onPrepare: function () {
374 // find hidden editor which may exist within a field
375 var $div = $( '#acf-hidden-wp-editor' );
376
377 // move to footer
378 if ( $div.exists() ) {
379 $div.appendTo( 'body' );
380 }
381 },
382 onReady: function () {
383 // Restore wp.editor functions used by tinymce removed in WP5.
384 if ( acf.isset( window, 'wp', 'oldEditor' ) ) {
385 wp.editor.autop = wp.oldEditor.autop;
386 wp.editor.removep = wp.oldEditor.removep;
387 }
388
389 // bail early if no tinymce
390 if ( ! acf.isset( window, 'tinymce', 'on' ) ) return;
391
392 // restore default activeEditor
393 tinymce.on( 'AddEditor', function ( data ) {
394 // vars
395 var editor = data.editor;
396
397 // bail early if not 'acf'
398 if ( editor.id.substr( 0, 3 ) !== 'acf' ) return;
399
400 // override if 'content' exists
401 editor = tinymce.editors.content || editor;
402
403 // update vars
404 tinymce.activeEditor = editor;
405 wpActiveEditor = editor.id;
406 } );
407 },
408 } );
409 } )( jQuery );
410