PluginProbe ʕ •ᴥ•ʔ
Advanced Editor Tools / 5.5.0
Advanced Editor Tools v5.5.0
trunk 1.0 1.0.1 2.0 2.2 3.0 3.0.1 3.1 3.2 3.2.4 3.2.7 3.3.9 3.3.9.1 3.3.9.2 3.4.2 3.4.2.1 3.4.5 3.4.5.1 3.4.9 3.5.8 3.5.9 3.5.9.1 4.0 4.0.1 4.0.2 4.1 4.1.1 4.1.7 4.1.9 4.2.3 4.2.3.1 4.2.5 4.2.8 4.3.10 4.3.10.1 4.3.8 4.4.1 4.4.3 4.5.6 4.6.3 4.6.7 4.7.11 4.8.0 4.8.1 4.8.2 5.0.0 5.0.1 5.1.0 5.2 5.2.1 5.3 5.4.0 5.5.0 5.5.1 5.6.0 5.9.0 5.9.1 5.9.2
tinymce-advanced / plugin-assets / tadv.js
tinymce-advanced / plugin-assets Last commit date
images 7 years ago tadv.css 6 years ago tadv.js 6 years ago
tadv.js
252 lines
1 /**
2 * This file is part of the TinyMCE Advanced WordPress plugin and is released under the same license.
3 * For more information please see tinymce-advanced.php.
4 *
5 * Copyright (c) 2007-2019 Andrew Ozz. All rights reserved.
6 */
7
8 jQuery( document ).ready( function( $ ) {
9 var $importElement = $('#tadv-import');
10 var $importError = $('#tadv-import-error');
11
12 function sortClassic() {
13 var container = $('.container');
14
15 if ( container.sortable( 'instance' ) ) {
16 container.sortable( 'destroy' );
17 }
18
19 container.sortable({
20 connectWith: '.container',
21 items: '> li',
22 cursor: 'move',
23 stop: function( event, ui ) {
24 var toolbar_id;
25
26 if ( ui && ( toolbar_id = ui.item.parent().attr('id') ) ) {
27 ui.item.find('input.tadv-button').attr('name', toolbar_id + '[]');
28 }
29 },
30 activate: function( event, ui ) {
31 $(this).parent().addClass( 'highlighted' );
32 },
33 deactivate: function( event, ui ) {
34 $(this).parent().removeClass( 'highlighted' );
35 },
36 revert: 300,
37 opacity: 0.7,
38 placeholder: 'tadv-placeholder',
39 forcePlaceholderSize: true
40 });
41 }
42
43 function sortBlock() {
44 var classicBlock = $( '.container-classic-block' );
45 var block = $( '.container-block' );
46 var blockToolbar = $( '#toolbar_block' );
47
48 if ( classicBlock.sortable( 'instance' ) ) {
49 classicBlock.sortable( 'destroy' );
50 }
51
52 if ( block.sortable( 'instance' ) ) {
53 block.sortable( 'destroy' );
54 }
55
56 if ( blockToolbar.sortable( 'instance' ) ) {
57 blockToolbar.sortable( 'destroy' );
58 }
59
60 classicBlock.sortable({
61 connectWith: '.container-classic-block',
62 items: '> li',
63 cursor: 'move',
64 stop: function( event, ui ) {
65 var toolbar_id = ui.item.parent().attr( 'id' );
66 resetItemName( toolbar_id, ui.item );
67 },
68 activate: function( event, ui ) {
69 $(this).parent().addClass( 'highlighted' );
70 },
71 deactivate: function( event, ui ) {
72 $(this).parent().removeClass( 'highlighted' );
73 },
74 revert: 300,
75 opacity: 0.7,
76 placeholder: 'tadv-placeholder',
77 forcePlaceholderSize: true
78 });
79
80 blockToolbar.sortable({
81 connectWith: '.container-block',
82 items: '> li',
83 cursor: 'move',
84 stop: function( event, ui ) {
85 var toolbar_id = ui.item.parent().attr( 'id' );
86
87 resetItemName( toolbar_id, ui.item );
88 sortBlockToolbar();
89 },
90 activate: function( event, ui ) {
91 $(this).parent().addClass( 'highlighted' );
92 },
93 deactivate: function( event, ui ) {
94 $(this).parent().removeClass( 'highlighted' );
95 },
96 revert: 300,
97 opacity: 0.7,
98 placeholder: 'tadv-placeholder',
99 forcePlaceholderSize: true
100 });
101
102 block.sortable({
103 connectWith: '.container-block, #toolbar_block',
104 items: '> li',
105 cursor: 'move',
106 stop: function( event, ui ) {
107 var toolbar_id = ui.item.parent().attr( 'id' );
108
109 resetItemName( toolbar_id, ui.item );
110 sortBlockToolbar();
111 },
112 activate: function( event, ui ) {
113 $(this).parent().addClass( 'highlighted' );
114 },
115 deactivate: function( event, ui ) {
116 $(this).parent().removeClass( 'highlighted' );
117 },
118 receive: function( event, ui ) {
119 if (
120 $( event.target ).is( '#toolbar_block_side' ) &&
121 ( ui.item.is( 'li.core-image' ) || ui.item.is( 'li.core-text-color' ) )
122 ) {
123 block.sortable( 'cancel' );
124 }
125 },
126 revert: 300,
127 opacity: 0.7,
128 placeholder: 'tadv-block-placeholder',
129 forcePlaceholderSize: true
130 });
131 }
132
133 function resetItemName( name, item ) {
134 if ( name ) {
135 item.find( 'input[type="hidden"]' ).attr( 'name', name + '[]' );
136 }
137 }
138
139 function sortBlockToolbar() {
140 var container = $( '#toolbar_block' );
141 var items = container.find( 'li' );
142
143 items.sort( function ( a, b ) {
144 var aa = $( a ).find( 'div' ).attr( 'title' );
145 var bb = $( b ).find( 'div' ).attr( 'title' );
146
147 return ( aa > bb ) ? 1 : -1;
148 });
149
150 container.append( items );
151 }
152
153 // Make block editor tab sortable on load
154 sortBlock();
155
156 $( '.settings-toggle.block' ).on( 'focus', function( event ) {
157 $( '.wrap' ).removeClass( 'classic-active' ).addClass( 'block-active' );
158 sortBlock();
159 });
160
161 $( '.settings-toggle.classic' ).on( 'focus', function( event ) {
162 $( '.wrap' ).removeClass( 'block-active' ).addClass( 'classic-active' );
163 sortClassic();
164 });
165
166 $( '#menubar' ).on( 'change', function() {
167 $( '.tadv-mce-menu.tadv-classic-editor' ).toggleClass( 'enabled', $(this).prop('checked') );
168 });
169
170 $( '#menubar_block' ).on( 'change', function() {
171 $( '.tadv-mce-menu.tadv-block-editor' ).toggleClass( 'enabled', $(this).prop('checked') );
172 });
173
174 $( '#tadvadmins' ).on( 'submit', function() {
175 $( 'ul.container' ).each( function( i, node ) {
176 $( node ).find( '.tadv-button' ).attr( 'name', node.id ? node.id + '[]' : '' );
177 });
178 });
179
180 $( 'input[name="selected_text_color"]' ).on( 'change', function() {
181 if ( this.id === 'selected_text_color_yes' ) {
182 $( '.panel-block-text-color' ).removeClass( 'disabled' );
183 } else {
184 $( '.panel-block-text-color' ).addClass( 'disabled' );
185 }
186 } );
187
188 $( 'input[name="selected_text_background_color"]' ).on( 'change', function() {
189 if ( this.id === 'selected_text_background_color_yes' ) {
190 $( '.panel-block-background-color' ).removeClass( 'disabled' );
191 } else {
192 $( '.panel-block-background-color' ).addClass( 'disabled' );
193 }
194 } );
195
196 $( '.tadv-popout-help-toggle, .tadv-popout-help-close' ).on( 'click', function( event ) {
197 $( '.tadv-popout-help' ).toggleClass( 'hidden' );
198 } );
199
200 $('#tadv-export-select').click( function() {
201 $('#tadv-export').focus().select();
202 });
203
204 $importElement.change( function() {
205 $importError.empty();
206 });
207
208 $('#tadv-import-verify').click( function() {
209 var string;
210
211 string = ( $importElement.val() || '' ).replace( /^[^{]*/, '' ).replace( /[^}]*$/, '' );
212 $importElement.val( string );
213
214 try {
215 JSON.parse( string );
216 $importError.text( 'No errors.' );
217 } catch( error ) {
218 $importError.text( error );
219 }
220 });
221
222 function translate( str ) {
223 if ( window.tadvTranslation.hasOwnProperty( str ) ) {
224 return window.tadvTranslation[str];
225 }
226 return str;
227 }
228
229 if ( typeof window.tadvTranslation === 'object' ) {
230 $( '.tadvitem' ).each( function( i, element ) {
231 var $element = $( element ),
232 $descr = $element.find( '.descr' ),
233 text = $descr.text();
234
235 if ( text ) {
236 text = translate( text );
237 $descr.text( text );
238 $element.find( '.mce-ico' ).attr( 'title', text );
239 }
240 });
241
242 $( '.tadv-mce-menu .tadv-translate' ).each( function( i, element ) {
243 var $element = $( element ),
244 text = $element.text();
245
246 if ( text ) {
247 $element.text( translate( text ) );
248 }
249 });
250 }
251 });
252