Test Setup Failed
Push — master ( c73065...3e6d69 )
by Aristeides
02:06
created

controls/js/src/editor.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 31
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3
mnd 1
bc 3
fnc 2
bpm 1.5
cpm 1.5
noi 2
1
/* global tinyMCE */
2
wp.customize.controlConstructor['kirki-editor'] = wp.customize.kirkiDynamicControl.extend({
3
4
	initKirkiControl: function() {
5
6
		var control = this,
7
		    element = control.container.find( 'textarea' ),
8
		    id      = 'kirki-editor-' + control.id.replace( '[', '' ).replace( ']', '' ),
9
		    editor;
10
11
		wp.editor.initialize( id, {
12
			tinymce: {
13
				wpautop: true
14
			},
15
			quicktags: true,
16
			mediaButtons: true
17
		});
18
19
		editor = tinyMCE.get( id );
20
21
		if ( editor ) {
22
			editor.onChange.add( function( ed ) {
23
				var content;
24
25
				ed.save();
26
				content = editor.getContent();
27
				element.val( content ).trigger( 'change' );
28
				wp.customize.instance( control.id ).set( content );
29
			});
30
		}
31
	}
32
});
33