author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
/* global getUserSetting, setUserSetting */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
( function( tinymce ) { |
16 | 3 |
// Set the minimum value for the modals z-index higher than #wpadminbar (100000). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
if ( ! tinymce.ui.FloatPanel.zIndex || tinymce.ui.FloatPanel.zIndex < 100100 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
tinymce.ui.FloatPanel.zIndex = 100100; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
} |
5 | 7 |
|
8 |
tinymce.PluginManager.add( 'wordpress', function( editor ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
var wpAdvButton, style, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
DOM = tinymce.DOM, |
5 | 11 |
each = tinymce.each, |
12 |
__ = editor.editorManager.i18n.translate, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
$ = window.jQuery, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
wp = window.wp, |
9 | 15 |
hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ), |
16 |
wpTooltips = false; |
|
5 | 17 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
if ( $ ) { |
18 | 19 |
// Runs as soon as TinyMCE has started initializing, while plugins are loading. |
20 |
// Handlers attached after the `tinymce.init()` call may not get triggered for this instance. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
$( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); |
5 | 22 |
} |
23 |
||
24 |
function toggleToolbars( state ) { |
|
9 | 25 |
var initial, toolbars, iframeHeight, |
26 |
pixels = 0, |
|
27 |
classicBlockToolbar = tinymce.$( '.block-library-classic__toolbar' ); |
|
5 | 28 |
|
9 | 29 |
if ( state === 'hide' ) { |
30 |
initial = true; |
|
31 |
} else if ( classicBlockToolbar.length && ! classicBlockToolbar.hasClass( 'has-advanced-toolbar' ) ) { |
|
32 |
// Show the second, third, etc. toolbar rows in the Classic block instance. |
|
33 |
classicBlockToolbar.addClass( 'has-advanced-toolbar' ); |
|
34 |
state = 'show'; |
|
35 |
} |
|
5 | 36 |
|
37 |
if ( editor.theme.panel ) { |
|
38 |
toolbars = editor.theme.panel.find('.toolbar:not(.menubar)'); |
|
39 |
} |
|
40 |
||
9 | 41 |
if ( toolbars && toolbars.length > 1 ) { |
42 |
if ( ! state && toolbars[1].visible() ) { |
|
43 |
state = 'hide'; |
|
44 |
} |
|
5 | 45 |
|
9 | 46 |
each( toolbars, function( toolbar, i ) { |
47 |
if ( i > 0 ) { |
|
48 |
if ( state === 'hide' ) { |
|
49 |
toolbar.hide(); |
|
50 |
pixels += 34; |
|
51 |
} else { |
|
52 |
toolbar.show(); |
|
53 |
pixels -= 34; |
|
54 |
} |
|
55 |
} |
|
56 |
}); |
|
5 | 57 |
} |
58 |
||
9 | 59 |
// Resize editor iframe, not needed for iOS and inline instances. |
60 |
// Don't resize if the editor is in a hidden container. |
|
61 |
if ( pixels && ! tinymce.Env.iOS && editor.iframeElement && editor.iframeElement.clientHeight ) { |
|
62 |
iframeHeight = editor.iframeElement.clientHeight + pixels; |
|
63 |
||
64 |
// Keep min-height. |
|
65 |
if ( iframeHeight > 50 ) { |
|
66 |
DOM.setStyle( editor.iframeElement, 'height', iframeHeight ); |
|
5 | 67 |
} |
9 | 68 |
} |
5 | 69 |
|
9 | 70 |
if ( ! initial ) { |
5 | 71 |
if ( state === 'hide' ) { |
9 | 72 |
setUserSetting( 'hidetb', '0' ); |
5 | 73 |
wpAdvButton && wpAdvButton.active( false ); |
74 |
} else { |
|
9 | 75 |
setUserSetting( 'hidetb', '1' ); |
5 | 76 |
wpAdvButton && wpAdvButton.active( true ); |
77 |
} |
|
78 |
} |
|
79 |
||
80 |
editor.fire( 'wp-toolbar-toggle' ); |
|
81 |
} |
|
82 |
||
83 |
// Add the kitchen sink button :) |
|
84 |
editor.addButton( 'wp_adv', { |
|
85 |
tooltip: 'Toolbar Toggle', |
|
86 |
cmd: 'WP_Adv', |
|
87 |
onPostRender: function() { |
|
88 |
wpAdvButton = this; |
|
9 | 89 |
wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' ); |
5 | 90 |
} |
91 |
}); |
|
92 |
||
16 | 93 |
// Hide the toolbars after loading. |
5 | 94 |
editor.on( 'PostRender', function() { |
95 |
if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) { |
|
96 |
toggleToolbars( 'hide' ); |
|
9 | 97 |
} else { |
98 |
tinymce.$( '.block-library-classic__toolbar' ).addClass( 'has-advanced-toolbar' ); |
|
5 | 99 |
} |
100 |
}); |
|
101 |
||
102 |
editor.addCommand( 'WP_Adv', function() { |
|
103 |
toggleToolbars(); |
|
104 |
}); |
|
105 |
||
106 |
editor.on( 'focus', function() { |
|
107 |
window.wpActiveEditor = editor.id; |
|
108 |
}); |
|
109 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
editor.on( 'BeforeSetContent', function( event ) { |
5 | 111 |
var title; |
112 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
if ( event.content ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
if ( event.content.indexOf( '<!--more' ) !== -1 ) { |
5 | 115 |
title = __( 'Read more...' ); |
116 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
event.content = event.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) { |
5 | 118 |
return '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="more" data-wp-more-text="' + moretext + '" ' + |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
'class="wp-more-tag mce-wp-more" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />'; |
5 | 120 |
}); |
121 |
} |
|
122 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
if ( event.content.indexOf( '<!--nextpage-->' ) !== -1 ) { |
5 | 124 |
title = __( 'Page break' ); |
125 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
event.content = event.content.replace( /<!--nextpage-->/g, |
5 | 127 |
'<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="nextpage" class="wp-more-tag mce-wp-nextpage" ' + |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
'alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
if ( event.load && event.format !== 'raw' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
if ( hasWpautop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
event.content = wp.editor.autop( event.content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
// Prevent creation of paragraphs out of multiple HTML comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
event.content = event.content.replace( /-->\s+<!--/g, '--><!--' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
if ( event.content.indexOf( '<script' ) !== -1 || event.content.indexOf( '<style' ) !== -1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
event.content = event.content.replace( /<(script|style)[^>]*>[\s\S]*?<\/\1>/g, function( match, tag ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
return '<img ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
'src="' + tinymce.Env.transparentSrc + '" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
'data-wp-preserve="' + encodeURIComponent( match ) + '" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
'data-mce-resize="false" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
'data-mce-placeholder="1" '+ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
'class="mce-object" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
'width="20" height="20" '+ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
'alt="<' + tag + '>" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
'title="<' + tag + '>" ' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
'/>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
} ); |
5 | 153 |
} |
154 |
} |
|
155 |
}); |
|
156 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
editor.on( 'setcontent', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
// Remove spaces from empty paragraphs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
editor.$( 'p' ).each( function( i, node ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
if ( node.innerHTML && node.innerHTML.length < 10 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
var html = tinymce.trim( node.innerHTML ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
if ( ! html || html === ' ' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
node.innerHTML = ( tinymce.Env.ie && tinymce.Env.ie < 11 ) ? '' : '<br data-mce-bogus="1">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
editor.on( 'PostProcess', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
if ( event.get ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
event.content = event.content.replace(/<img[^>]+>/g, function( image ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
var match, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
string, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
moretext = ''; |
5 | 176 |
|
177 |
if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) { |
|
178 |
if ( match = image.match( /data-wp-more-text="([^"]+)"/ ) ) { |
|
179 |
moretext = match[1]; |
|
180 |
} |
|
181 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
string = '<!--more' + moretext + '-->'; |
5 | 183 |
} else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
string = '<!--nextpage-->'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} else if ( image.indexOf( 'data-wp-preserve' ) !== -1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
if ( match = image.match( / data-wp-preserve="([^"]+)"/ ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
string = decodeURIComponent( match[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
5 | 189 |
} |
190 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
return string || image; |
5 | 192 |
}); |
193 |
} |
|
194 |
}); |
|
195 |
||
16 | 196 |
// Display the tag name instead of img in element path. |
5 | 197 |
editor.on( 'ResolveName', function( event ) { |
198 |
var attr; |
|
199 |
||
200 |
if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) { |
|
201 |
event.name = attr; |
|
202 |
} |
|
203 |
}); |
|
204 |
||
16 | 205 |
// Register commands. |
5 | 206 |
editor.addCommand( 'WP_More', function( tag ) { |
207 |
var parent, html, title, |
|
208 |
classname = 'wp-more-tag', |
|
209 |
dom = editor.dom, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
node = editor.selection.getNode(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
rootNode = editor.getBody(); |
5 | 212 |
|
213 |
tag = tag || 'more'; |
|
214 |
classname += ' mce-wp-' + tag; |
|
215 |
title = tag === 'more' ? 'Read more...' : 'Next page'; |
|
216 |
title = __( title ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
html = '<img src="' + tinymce.Env.transparentSrc + '" alt="" title="' + title + '" class="' + classname + '" ' + |
5 | 218 |
'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />'; |
219 |
||
16 | 220 |
// Most common case. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
if ( node === rootNode || ( node.nodeName === 'P' && node.parentNode === rootNode ) ) { |
5 | 222 |
editor.insertContent( html ); |
223 |
return; |
|
224 |
} |
|
225 |
||
16 | 226 |
// Get the top level parent node. |
5 | 227 |
parent = dom.getParent( node, function( found ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
if ( found.parentNode && found.parentNode === rootNode ) { |
5 | 229 |
return true; |
230 |
} |
|
231 |
||
232 |
return false; |
|
233 |
}, editor.getBody() ); |
|
234 |
||
235 |
if ( parent ) { |
|
236 |
if ( parent.nodeName === 'P' ) { |
|
237 |
parent.appendChild( dom.create( 'p', null, html ).firstChild ); |
|
238 |
} else { |
|
239 |
dom.insertAfter( dom.create( 'p', null, html ), parent ); |
|
240 |
} |
|
241 |
||
242 |
editor.nodeChanged(); |
|
243 |
} |
|
244 |
}); |
|
245 |
||
246 |
editor.addCommand( 'WP_Code', function() { |
|
247 |
editor.formatter.toggle('code'); |
|
248 |
}); |
|
249 |
||
250 |
editor.addCommand( 'WP_Page', function() { |
|
251 |
editor.execCommand( 'WP_More', 'nextpage' ); |
|
252 |
}); |
|
253 |
||
254 |
editor.addCommand( 'WP_Help', function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
var access = tinymce.Env.mac ? __( 'Ctrl + Alt + letter:' ) : __( 'Shift + Alt + letter:' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
meta = tinymce.Env.mac ? __( 'Cmd + letter:' ) : __( 'Ctrl + letter:' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
table1 = [], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
table2 = [], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
row1 = {}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
row2 = {}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
i1 = 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
i2 = 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
labels = editor.settings.wp_shortcut_labels, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
header, html, dialog, $wrap; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
if ( ! labels ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
function tr( row, columns ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
var out = '<tr>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
var i = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
columns = columns || 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
each( row, function( text, key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
out += '<td><kbd>' + key + '</kbd></td><td>' + __( text ) + '</td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
i++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
while ( i < columns ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
out += '<td></td><td></td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
i++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
return out + '</tr>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
each ( labels, function( label, name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
var letter; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
if ( label.indexOf( 'meta' ) !== -1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
i1++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
letter = label.replace( 'meta', '' ).toLowerCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
if ( letter ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
row1[ letter ] = name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
if ( i1 % 2 === 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
table1.push( tr( row1, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
row1 = {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
} else if ( label.indexOf( 'access' ) !== -1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
i2++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
letter = label.replace( 'access', '' ).toLowerCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
if ( letter ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
row2[ letter ] = name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
if ( i2 % 2 === 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
table2.push( tr( row2, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
row2 = {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
// Add remaining single entries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
if ( i1 % 2 > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
table1.push( tr( row1, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
if ( i2 % 2 > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
table2.push( tr( row2, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
html = '<div class="wp-editor-help">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
|
16 | 333 |
// Main section, default and additional shortcuts. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
html = html + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
'<h2>' + __( 'Default shortcuts,' ) + ' ' + meta + '</h2>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
'<table class="wp-help-th-center fixed">' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
header + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
table1.join('') + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
'</table>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
'<h2>' + __( 'Additional shortcuts,' ) + ' ' + access + '</h2>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
'<table class="wp-help-th-center fixed">' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
header + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
table2.join('') + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
'</table>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) { |
16 | 347 |
// Text pattern section. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
html = html + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
'<h2>' + __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ) + '</h2>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
'<table class="wp-help-th-center fixed">' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
tr({ '*': 'Bullet list', '1.': 'Numbered list' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
tr({ '-': 'Bullet list', '1)': 'Numbered list' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
'</table>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
html = html + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
'<h2>' + __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ) + '</h2>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
'<table class="wp-help-single">' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
tr({ '>': 'Blockquote' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
tr({ '##': 'Heading 2' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
tr({ '###': 'Heading 3' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
tr({ '####': 'Heading 4' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
tr({ '#####': 'Heading 5' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
tr({ '######': 'Heading 6' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
tr({ '---': 'Horizontal line' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
'</table>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
|
16 | 368 |
// Focus management section. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
html = html + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
'<h2>' + __( 'Focus shortcuts:' ) + '</h2>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
'<table class="wp-help-single">' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
tr({ 'Alt + F8': 'Inline toolbar (when an image, link or preview is selected)' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
tr({ 'Alt + F9': 'Editor menu (when enabled)' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
tr({ 'Alt + F10': 'Editor toolbar' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
tr({ 'Alt + F11': 'Elements path' }) + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
'</table>' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
'<p>' + __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ) + '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
html += '</div>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
dialog = editor.windowManager.open( { |
9 | 382 |
title: editor.settings.classic_block_editor ? 'Classic Block Keyboard Shortcuts' : 'Keyboard Shortcuts', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
items: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
type: 'container', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
classes: 'wp-help', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
html: html |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
buttons: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
text: 'Close', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
onclick: 'close' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
if ( dialog.$el ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
dialog.$el.find( 'div[role="application"]' ).attr( 'role', 'document' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
$wrap = dialog.$el.find( '.mce-wp-help' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
if ( $wrap[0] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
$wrap.attr( 'tabindex', '0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
$wrap[0].focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
$wrap.on( 'keydown', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
// Prevent use of: page up, page down, end, home, left arrow, up arrow, right arrow, down arrow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
// in the dialog keydown handler. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
if ( event.keyCode >= 33 && event.keyCode <= 40 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
event.stopPropagation(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
} ); |
5 | 411 |
|
412 |
editor.addCommand( 'WP_Medialib', function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
if ( wp && wp.media && wp.media.editor ) { |
5 | 414 |
wp.media.editor.open( editor.id ); |
415 |
} |
|
416 |
}); |
|
417 |
||
16 | 418 |
// Register buttons. |
5 | 419 |
editor.addButton( 'wp_more', { |
420 |
tooltip: 'Insert Read More tag', |
|
421 |
onclick: function() { |
|
422 |
editor.execCommand( 'WP_More', 'more' ); |
|
423 |
} |
|
424 |
}); |
|
425 |
||
426 |
editor.addButton( 'wp_page', { |
|
427 |
tooltip: 'Page break', |
|
428 |
onclick: function() { |
|
429 |
editor.execCommand( 'WP_More', 'nextpage' ); |
|
430 |
} |
|
431 |
}); |
|
432 |
||
433 |
editor.addButton( 'wp_help', { |
|
434 |
tooltip: 'Keyboard Shortcuts', |
|
435 |
cmd: 'WP_Help' |
|
436 |
}); |
|
437 |
||
438 |
editor.addButton( 'wp_code', { |
|
439 |
tooltip: 'Code', |
|
440 |
cmd: 'WP_Code', |
|
441 |
stateSelector: 'code' |
|
442 |
}); |
|
443 |
||
16 | 444 |
// Insert->Add Media. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
if ( wp && wp.media && wp.media.editor ) { |
9 | 446 |
editor.addButton( 'wp_add_media', { |
447 |
tooltip: 'Add Media', |
|
448 |
icon: 'dashicon dashicons-admin-media', |
|
449 |
cmd: 'WP_Medialib' |
|
450 |
} ); |
|
451 |
||
5 | 452 |
editor.addMenuItem( 'add_media', { |
453 |
text: 'Add Media', |
|
454 |
icon: 'wp-media-library', |
|
455 |
context: 'insert', |
|
456 |
cmd: 'WP_Medialib' |
|
457 |
}); |
|
458 |
} |
|
459 |
||
16 | 460 |
// Insert "Read More...". |
5 | 461 |
editor.addMenuItem( 'wp_more', { |
462 |
text: 'Insert Read More tag', |
|
463 |
icon: 'wp_more', |
|
464 |
context: 'insert', |
|
465 |
onclick: function() { |
|
466 |
editor.execCommand( 'WP_More', 'more' ); |
|
467 |
} |
|
468 |
}); |
|
469 |
||
16 | 470 |
// Insert "Next Page". |
5 | 471 |
editor.addMenuItem( 'wp_page', { |
472 |
text: 'Page break', |
|
473 |
icon: 'wp_page', |
|
474 |
context: 'insert', |
|
475 |
onclick: function() { |
|
476 |
editor.execCommand( 'WP_More', 'nextpage' ); |
|
477 |
} |
|
478 |
}); |
|
479 |
||
480 |
editor.on( 'BeforeExecCommand', function(e) { |
|
481 |
if ( tinymce.Env.webkit && ( e.command === 'InsertUnorderedList' || e.command === 'InsertOrderedList' ) ) { |
|
482 |
if ( ! style ) { |
|
483 |
style = editor.dom.create( 'style', {'type': 'text/css'}, |
|
484 |
'#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}'); |
|
485 |
} |
|
486 |
||
487 |
editor.getDoc().head.appendChild( style ); |
|
488 |
} |
|
489 |
}); |
|
490 |
||
491 |
editor.on( 'ExecCommand', function( e ) { |
|
492 |
if ( tinymce.Env.webkit && style && |
|
493 |
( 'InsertUnorderedList' === e.command || 'InsertOrderedList' === e.command ) ) { |
|
494 |
||
495 |
editor.dom.remove( style ); |
|
496 |
} |
|
497 |
}); |
|
498 |
||
499 |
editor.on( 'init', function() { |
|
500 |
var env = tinymce.Env, |
|
16 | 501 |
bodyClass = ['mceContentBody'], // Back-compat for themes that use this in editor-style.css... |
5 | 502 |
doc = editor.getDoc(), |
503 |
dom = editor.dom; |
|
504 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
if ( env.iOS ) { |
5 | 506 |
dom.addClass( doc.documentElement, 'ios' ); |
507 |
} |
|
508 |
||
509 |
if ( editor.getParam( 'directionality' ) === 'rtl' ) { |
|
510 |
bodyClass.push('rtl'); |
|
511 |
dom.setAttrib( doc.documentElement, 'dir', 'rtl' ); |
|
512 |
} |
|
513 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
dom.setAttrib( doc.documentElement, 'lang', editor.getParam( 'wp_lang_attr' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
|
5 | 516 |
if ( env.ie ) { |
517 |
if ( parseInt( env.ie, 10 ) === 9 ) { |
|
518 |
bodyClass.push('ie9'); |
|
519 |
} else if ( parseInt( env.ie, 10 ) === 8 ) { |
|
520 |
bodyClass.push('ie8'); |
|
521 |
} else if ( env.ie < 8 ) { |
|
522 |
bodyClass.push('ie7'); |
|
523 |
} |
|
524 |
} else if ( env.webkit ) { |
|
525 |
bodyClass.push('webkit'); |
|
526 |
} |
|
527 |
||
528 |
bodyClass.push('wp-editor'); |
|
529 |
||
530 |
each( bodyClass, function( cls ) { |
|
531 |
if ( cls ) { |
|
532 |
dom.addClass( doc.body, cls ); |
|
533 |
} |
|
534 |
}); |
|
535 |
||
16 | 536 |
// Remove invalid parent paragraphs when inserting HTML. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
editor.on( 'BeforeSetContent', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
if ( event.content ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
event.content = event.content.replace( /<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
.replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '</$1>' ); |
5 | 541 |
} |
542 |
}); |
|
543 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
if ( $ ) { |
18 | 545 |
// Run on DOM ready. Otherwise TinyMCE may initialize earlier and handlers attached |
546 |
// on DOM ready of after the `tinymce.init()` call may not get triggered. |
|
547 |
$( function() { |
|
548 |
$( document ).triggerHandler( 'tinymce-editor-init', [editor] ); |
|
549 |
}); |
|
5 | 550 |
} |
551 |
||
552 |
if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) { |
|
553 |
dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
if ( $ ) { |
5 | 555 |
// Trigger the jQuery handlers. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
$( document ).trigger( new $.Event( event ) ); |
5 | 557 |
} |
558 |
}); |
|
559 |
} |
|
560 |
||
561 |
if ( editor.getParam( 'wp_paste_filters', true ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
editor.on( 'PastePreProcess', function( event ) { |
16 | 563 |
// Remove trailing <br> added by WebKit browsers to the clipboard. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
event.content = event.content.replace( /<br class="?Apple-interchange-newline"?>/gi, '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
|
16 | 566 |
// In WebKit this is handled by removeWebKitStyles(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
if ( ! tinymce.Env.webkit ) { |
16 | 568 |
// Remove all inline styles. |
5 | 569 |
event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' ); |
570 |
||
16 | 571 |
// Put back the internal styles. |
5 | 572 |
event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
}); |
5 | 575 |
|
576 |
editor.on( 'PastePostProcess', function( event ) { |
|
16 | 577 |
// Remove empty paragraphs. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
editor.$( 'p', event.node ).each( function( i, node ) { |
5 | 579 |
if ( dom.isEmpty( node ) ) { |
580 |
dom.remove( node ); |
|
581 |
} |
|
582 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
if ( tinymce.isIE ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
editor.$( 'a', event.node ).find( 'font, u' ).each( function( i, node ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
dom.remove( node, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
} |
5 | 589 |
}); |
590 |
} |
|
591 |
}); |
|
592 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
editor.on( 'SaveContent', function( event ) { |
16 | 594 |
// If editor is hidden, we just want the textarea's value to be saved. |
5 | 595 |
if ( ! editor.inline && editor.isHidden() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
event.content = event.element.value; |
5 | 597 |
return; |
598 |
} |
|
599 |
||
600 |
// Keep empty paragraphs :( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
event.content = event.content.replace( /<p>(?:<br ?\/?>|\u00a0|\uFEFF| )*<\/p>/g, '<p> </p>' ); |
5 | 602 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
if ( hasWpautop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
event.content = wp.editor.removep( event.content ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
// Restore formatting of block boundaries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
event.content = event.content.replace( /-->\s*<!-- wp:/g, '-->\n\n<!-- wp:' ); |
5 | 608 |
} |
609 |
}); |
|
610 |
||
611 |
editor.on( 'preInit', function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
'i,' + // Don't replace <i> with <em> and <b> with <strong> and don't remove them when empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
'b,' + |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
'script[src|async|defer|type|charset|crossorigin|integrity]'; // Add support for <script>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
editor.schema.addValidElements( validElementsSetting ); |
5 | 619 |
|
620 |
if ( tinymce.Env.iOS ) { |
|
621 |
editor.settings.height = 300; |
|
622 |
} |
|
623 |
||
624 |
each( { |
|
625 |
c: 'JustifyCenter', |
|
626 |
r: 'JustifyRight', |
|
627 |
l: 'JustifyLeft', |
|
628 |
j: 'JustifyFull', |
|
629 |
q: 'mceBlockQuote', |
|
630 |
u: 'InsertUnorderedList', |
|
631 |
o: 'InsertOrderedList', |
|
632 |
m: 'WP_Medialib', |
|
633 |
t: 'WP_More', |
|
634 |
d: 'Strikethrough', |
|
635 |
p: 'WP_Page', |
|
636 |
x: 'WP_Code' |
|
637 |
}, function( command, key ) { |
|
638 |
editor.shortcuts.add( 'access+' + key, '', command ); |
|
639 |
} ); |
|
640 |
||
641 |
editor.addShortcut( 'meta+s', '', function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
if ( wp && wp.autosave ) { |
5 | 643 |
wp.autosave.server.triggerSave(); |
644 |
} |
|
645 |
} ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
|
16 | 647 |
// Alt+Shift+Z removes a block in the block editor, don't add it to the Classic block. |
9 | 648 |
if ( ! editor.settings.classic_block_editor ) { |
649 |
editor.addShortcut( 'access+z', '', 'WP_Adv' ); |
|
650 |
} |
|
651 |
||
16 | 652 |
// Workaround for not triggering the global help modal in the block editor by the Classic block shortcut. |
9 | 653 |
editor.on( 'keydown', function( event ) { |
654 |
var match; |
|
655 |
||
656 |
if ( tinymce.Env.mac ) { |
|
657 |
match = event.ctrlKey && event.altKey && event.code === 'KeyH'; |
|
658 |
} else { |
|
659 |
match = event.shiftKey && event.altKey && event.code === 'KeyH'; |
|
660 |
} |
|
661 |
||
662 |
if ( match ) { |
|
663 |
editor.execCommand( 'WP_Help' ); |
|
664 |
event.stopPropagation(); |
|
665 |
event.stopImmediatePropagation(); |
|
666 |
return false; |
|
667 |
} |
|
668 |
||
669 |
return true; |
|
670 |
}); |
|
671 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
if ( window.getUserSetting( 'editor_plain_text_paste_warning' ) > 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
editor.settings.paste_plaintext_inform = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
// Change the editor iframe title on MacOS, add the correct help shortcut. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
if ( tinymce.Env.mac ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
tinymce.$( editor.iframeElement ).attr( 'title', __( 'Rich Text Area. Press Control-Option-H for help.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
} |
5 | 680 |
} ); |
681 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
editor.on( 'PastePlainTextToggle', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
// Warn twice, then stop. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
if ( event.state === true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
var times = parseInt( window.getUserSetting( 'editor_plain_text_paste_warning' ), 10 ) || 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
if ( times < 2 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
window.setUserSetting( 'editor_plain_text_paste_warning', ++times ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
|
9 | 693 |
editor.on( 'beforerenderui', function() { |
694 |
if ( editor.theme.panel ) { |
|
695 |
each( [ 'button', 'colorbutton', 'splitbutton' ], function( buttonType ) { |
|
696 |
replaceButtonsTooltips( editor.theme.panel.find( buttonType ) ); |
|
697 |
} ); |
|
698 |
||
699 |
addShortcutsToListbox(); |
|
700 |
} |
|
701 |
} ); |
|
702 |
||
703 |
function prepareTooltips() { |
|
704 |
var access = 'Shift+Alt+'; |
|
705 |
var meta = 'Ctrl+'; |
|
706 |
||
707 |
wpTooltips = {}; |
|
708 |
||
16 | 709 |
// For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325. |
9 | 710 |
if ( tinymce.Env.mac ) { |
711 |
access = '\u2303\u2325'; |
|
712 |
meta = '\u2318'; |
|
713 |
} |
|
714 |
||
715 |
// Some tooltips are translated, others are not... |
|
716 |
if ( editor.settings.wp_shortcut_labels ) { |
|
717 |
each( editor.settings.wp_shortcut_labels, function( value, tooltip ) { |
|
718 |
var translated = editor.translate( tooltip ); |
|
719 |
||
720 |
value = value.replace( 'access', access ).replace( 'meta', meta ); |
|
721 |
wpTooltips[ tooltip ] = value; |
|
722 |
||
723 |
// Add the translated so we can match all of them. |
|
724 |
if ( tooltip !== translated ) { |
|
725 |
wpTooltips[ translated ] = value; |
|
726 |
} |
|
727 |
} ); |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
function getTooltip( tooltip ) { |
|
732 |
var translated = editor.translate( tooltip ); |
|
733 |
var label; |
|
734 |
||
735 |
if ( ! wpTooltips ) { |
|
736 |
prepareTooltips(); |
|
737 |
} |
|
738 |
||
739 |
if ( wpTooltips.hasOwnProperty( translated ) ) { |
|
740 |
label = wpTooltips[ translated ]; |
|
741 |
} else if ( wpTooltips.hasOwnProperty( tooltip ) ) { |
|
742 |
label = wpTooltips[ tooltip ]; |
|
743 |
} |
|
744 |
||
745 |
return label ? translated + ' (' + label + ')' : translated; |
|
746 |
} |
|
747 |
||
748 |
function replaceButtonsTooltips( buttons ) { |
|
749 |
||
750 |
if ( ! buttons ) { |
|
751 |
return; |
|
752 |
} |
|
753 |
||
754 |
each( buttons, function( button ) { |
|
755 |
var tooltip; |
|
756 |
||
757 |
if ( button && button.settings.tooltip ) { |
|
758 |
tooltip = getTooltip( button.settings.tooltip ); |
|
759 |
button.settings.tooltip = tooltip; |
|
760 |
||
761 |
// Override the aria label wiht the translated tooltip + shortcut. |
|
762 |
if ( button._aria && button._aria.label ) { |
|
763 |
button._aria.label = tooltip; |
|
764 |
} |
|
765 |
} |
|
766 |
} ); |
|
767 |
} |
|
768 |
||
769 |
function addShortcutsToListbox() { |
|
16 | 770 |
// listbox for the "blocks" drop-down. |
9 | 771 |
each( editor.theme.panel.find( 'listbox' ), function( listbox ) { |
772 |
if ( listbox && listbox.settings.text === 'Paragraph' ) { |
|
773 |
each( listbox.settings.values, function( item ) { |
|
774 |
if ( item.text && wpTooltips.hasOwnProperty( item.text ) ) { |
|
775 |
item.shortcut = '(' + wpTooltips[ item.text ] + ')'; |
|
776 |
} |
|
777 |
} ); |
|
778 |
} |
|
779 |
} ); |
|
780 |
} |
|
781 |
||
5 | 782 |
/** |
783 |
* Experimental: create a floating toolbar. |
|
784 |
* This functionality will change in the next releases. Not recommended for use by plugins. |
|
785 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
editor.on( 'preinit', function() { |
5 | 787 |
var Factory = tinymce.ui.Factory, |
788 |
settings = editor.settings, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
activeToolbar, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
currentSelection, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
timeout, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
container = editor.getContainer(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
wpAdminbar = document.getElementById( 'wpadminbar' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
mceIframe = document.getElementById( editor.id + '_ifr' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
mceToolbar, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
mceStatusbar, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
wpStatusbar, |
16 | 798 |
cachedWinSize; |
5 | 799 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
if ( container ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
mceToolbar = tinymce.$( '.mce-toolbar-grp', container )[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
mceStatusbar = tinymce.$( '.mce-statusbar', container )[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
if ( editor.id === 'content' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
wpStatusbar = document.getElementById( 'post-status-info' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
function create( buttons, bottom ) { |
5 | 810 |
var toolbar, |
811 |
toolbarItems = [], |
|
812 |
buttonGroup; |
|
813 |
||
814 |
each( buttons, function( item ) { |
|
815 |
var itemName; |
|
9 | 816 |
var tooltip; |
5 | 817 |
|
818 |
function bindSelectorChanged() { |
|
819 |
var selection = editor.selection; |
|
820 |
||
821 |
if ( itemName === 'bullist' ) { |
|
822 |
selection.selectorChanged( 'ul > li', function( state, args ) { |
|
823 |
var i = args.parents.length, |
|
824 |
nodeName; |
|
825 |
||
826 |
while ( i-- ) { |
|
827 |
nodeName = args.parents[ i ].nodeName; |
|
828 |
||
829 |
if ( nodeName === 'OL' || nodeName == 'UL' ) { |
|
830 |
break; |
|
831 |
} |
|
832 |
} |
|
833 |
||
834 |
item.active( state && nodeName === 'UL' ); |
|
835 |
} ); |
|
836 |
} |
|
837 |
||
838 |
if ( itemName === 'numlist' ) { |
|
839 |
selection.selectorChanged( 'ol > li', function( state, args ) { |
|
840 |
var i = args.parents.length, |
|
841 |
nodeName; |
|
842 |
||
843 |
while ( i-- ) { |
|
844 |
nodeName = args.parents[ i ].nodeName; |
|
845 |
||
846 |
if ( nodeName === 'OL' || nodeName === 'UL' ) { |
|
847 |
break; |
|
848 |
} |
|
849 |
} |
|
850 |
||
851 |
item.active( state && nodeName === 'OL' ); |
|
852 |
} ); |
|
853 |
} |
|
854 |
||
855 |
if ( item.settings.stateSelector ) { |
|
856 |
selection.selectorChanged( item.settings.stateSelector, function( state ) { |
|
857 |
item.active( state ); |
|
858 |
}, true ); |
|
859 |
} |
|
860 |
||
861 |
if ( item.settings.disabledStateSelector ) { |
|
862 |
selection.selectorChanged( item.settings.disabledStateSelector, function( state ) { |
|
863 |
item.disabled( state ); |
|
864 |
} ); |
|
865 |
} |
|
866 |
} |
|
867 |
||
868 |
if ( item === '|' ) { |
|
869 |
buttonGroup = null; |
|
870 |
} else { |
|
871 |
if ( Factory.has( item ) ) { |
|
872 |
item = { |
|
873 |
type: item |
|
874 |
}; |
|
875 |
||
876 |
if ( settings.toolbar_items_size ) { |
|
877 |
item.size = settings.toolbar_items_size; |
|
878 |
} |
|
879 |
||
880 |
toolbarItems.push( item ); |
|
881 |
||
882 |
buttonGroup = null; |
|
883 |
} else { |
|
884 |
if ( ! buttonGroup ) { |
|
885 |
buttonGroup = { |
|
886 |
type: 'buttongroup', |
|
887 |
items: [] |
|
888 |
}; |
|
889 |
||
890 |
toolbarItems.push( buttonGroup ); |
|
891 |
} |
|
892 |
||
893 |
if ( editor.buttons[ item ] ) { |
|
894 |
itemName = item; |
|
895 |
item = editor.buttons[ itemName ]; |
|
896 |
||
897 |
if ( typeof item === 'function' ) { |
|
898 |
item = item(); |
|
899 |
} |
|
900 |
||
901 |
item.type = item.type || 'button'; |
|
902 |
||
903 |
if ( settings.toolbar_items_size ) { |
|
904 |
item.size = settings.toolbar_items_size; |
|
905 |
} |
|
906 |
||
9 | 907 |
tooltip = item.tooltip || item.title; |
908 |
||
909 |
if ( tooltip ) { |
|
910 |
item.tooltip = getTooltip( tooltip ); |
|
911 |
} |
|
912 |
||
5 | 913 |
item = Factory.create( item ); |
914 |
||
915 |
buttonGroup.items.push( item ); |
|
916 |
||
917 |
if ( editor.initialized ) { |
|
918 |
bindSelectorChanged(); |
|
919 |
} else { |
|
920 |
editor.on( 'init', bindSelectorChanged ); |
|
921 |
} |
|
922 |
} |
|
923 |
} |
|
924 |
} |
|
925 |
} ); |
|
926 |
||
927 |
toolbar = Factory.create( { |
|
928 |
type: 'panel', |
|
929 |
layout: 'stack', |
|
930 |
classes: 'toolbar-grp inline-toolbar-grp', |
|
931 |
ariaRoot: true, |
|
932 |
ariaRemember: true, |
|
933 |
items: [ { |
|
934 |
type: 'toolbar', |
|
935 |
layout: 'flow', |
|
936 |
items: toolbarItems |
|
937 |
} ] |
|
938 |
} ); |
|
939 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
toolbar.bottom = bottom; |
5 | 941 |
|
942 |
function reposition() { |
|
943 |
if ( ! currentSelection ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
return this; |
5 | 945 |
} |
946 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
var scrollX = window.pageXOffset || document.documentElement.scrollLeft, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
scrollY = window.pageYOffset || document.documentElement.scrollTop, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
windowWidth = window.innerWidth, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
windowHeight = window.innerHeight, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
iframeRect = mceIframe ? mceIframe.getBoundingClientRect() : { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
top: 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
right: windowWidth, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
bottom: windowHeight, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
left: 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
width: windowWidth, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
height: windowHeight |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
toolbar = this.getEl(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
toolbarWidth = toolbar.offsetWidth, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
toolbarHeight = toolbar.clientHeight, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
selection = currentSelection.getBoundingClientRect(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
selectionMiddle = ( selection.left + selection.right ) / 2, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
buffer = 5, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
spaceNeeded = toolbarHeight + buffer, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
wpAdminbarBottom = wpAdminbar ? wpAdminbar.getBoundingClientRect().bottom : 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
mceToolbarBottom = mceToolbar ? mceToolbar.getBoundingClientRect().bottom : 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
mceStatusbarTop = mceStatusbar ? windowHeight - mceStatusbar.getBoundingClientRect().top : 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
wpStatusbarTop = wpStatusbar ? windowHeight - wpStatusbar.getBoundingClientRect().top : 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
blockedTop = Math.max( 0, wpAdminbarBottom, mceToolbarBottom, iframeRect.top ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
blockedBottom = Math.max( 0, mceStatusbarTop, wpStatusbarTop, windowHeight - iframeRect.bottom ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
spaceTop = selection.top + iframeRect.top - blockedTop, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
spaceBottom = windowHeight - iframeRect.top - selection.bottom - blockedBottom, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
editorHeight = windowHeight - blockedTop - blockedBottom, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
className = '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
iosOffsetTop = 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
iosOffsetBottom = 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
top, left; |
5 | 979 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
if ( spaceTop >= editorHeight || spaceBottom >= editorHeight ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
this.scrolling = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
this.hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
this.scrolling = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
return this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
// Add offset in iOS to move the menu over the image, out of the way of the default iOS menu. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
iosOffsetTop = 54; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
iosOffsetBottom = 46; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
if ( this.bottom ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
if ( spaceBottom >= spaceNeeded ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
className = ' mce-arrow-up'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
} else if ( spaceTop >= spaceNeeded ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
className = ' mce-arrow-down'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
top = selection.top + iframeRect.top + scrollY - toolbarHeight + iosOffsetTop; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
} |
5 | 1001 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
if ( spaceTop >= spaceNeeded ) { |
5 | 1003 |
className = ' mce-arrow-down'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
top = selection.top + iframeRect.top + scrollY - toolbarHeight + iosOffsetTop; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
} else if ( spaceBottom >= spaceNeeded && editorHeight / 2 > selection.bottom + iframeRect.top - blockedTop ) { |
5 | 1006 |
className = ' mce-arrow-up'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom; |
5 | 1008 |
} |
1009 |
} |
|
1010 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
if ( typeof top === 'undefined' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
top = scrollY + blockedTop + buffer + iosOffsetBottom; |
5 | 1013 |
} |
1014 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
left = selectionMiddle - toolbarWidth / 2 + iframeRect.left + scrollX; |
5 | 1016 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
if ( selection.left < 0 || selection.right > iframeRect.width ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
left = iframeRect.left + scrollX + ( iframeRect.width - toolbarWidth ) / 2; |
5 | 1019 |
} else if ( toolbarWidth >= windowWidth ) { |
1020 |
className += ' mce-arrow-full'; |
|
1021 |
left = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
} else if ( ( left < 0 && selection.left + toolbarWidth > windowWidth ) || ( left + toolbarWidth > windowWidth && selection.right - toolbarWidth < 0 ) ) { |
5 | 1023 |
left = ( windowWidth - toolbarWidth ) / 2; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
} else if ( left < iframeRect.left + scrollX ) { |
5 | 1025 |
className += ' mce-arrow-left'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
left = selection.left + iframeRect.left + scrollX; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
} else if ( left + toolbarWidth > iframeRect.width + iframeRect.left + scrollX ) { |
5 | 1028 |
className += ' mce-arrow-right'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
left = selection.right - toolbarWidth + iframeRect.left + scrollX; |
5 | 1030 |
} |
1031 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
// No up/down arrows on the menu over images in iOS. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
className = className.replace( / ?mce-arrow-(up|down)/g, '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
} |
5 | 1036 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
toolbar.className = toolbar.className.replace( / ?mce-arrow-[\w]+/g, '' ) + className; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
DOM.setStyles( toolbar, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
'left': left, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
'top': top |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
} ); |
5 | 1043 |
|
1044 |
return this; |
|
1045 |
} |
|
1046 |
||
1047 |
toolbar.on( 'show', function() { |
|
1048 |
this.reposition(); |
|
1049 |
} ); |
|
1050 |
||
1051 |
toolbar.on( 'keydown', function( event ) { |
|
1052 |
if ( event.keyCode === 27 ) { |
|
1053 |
this.hide(); |
|
1054 |
editor.focus(); |
|
1055 |
} |
|
1056 |
} ); |
|
1057 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
editor.on( 'remove', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
toolbar.remove(); |
5 | 1060 |
} ); |
1061 |
||
1062 |
toolbar.reposition = reposition; |
|
1063 |
toolbar.hide().renderTo( document.body ); |
|
1064 |
||
1065 |
return toolbar; |
|
1066 |
} |
|
1067 |
||
1068 |
editor.shortcuts.add( 'alt+119', '', function() { |
|
1069 |
var node; |
|
1070 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
if ( activeToolbar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
node = activeToolbar.find( 'toolbar' )[0]; |
5 | 1073 |
node && node.focus( true ); |
1074 |
} |
|
1075 |
} ); |
|
1076 |
||
1077 |
editor.on( 'nodechange', function( event ) { |
|
1078 |
var collapsed = editor.selection.isCollapsed(); |
|
1079 |
||
1080 |
var args = { |
|
1081 |
element: event.element, |
|
1082 |
parents: event.parents, |
|
1083 |
collapsed: collapsed |
|
1084 |
}; |
|
1085 |
||
1086 |
editor.fire( 'wptoolbar', args ); |
|
1087 |
||
1088 |
currentSelection = args.selection || args.element; |
|
1089 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
if ( activeToolbar && activeToolbar !== args.toolbar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
activeToolbar.hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
if ( args.toolbar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
activeToolbar = args.toolbar; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
if ( activeToolbar.visible() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
activeToolbar.reposition(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
activeToolbar.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
activeToolbar = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
editor.on( 'focus', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
if ( activeToolbar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
activeToolbar.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
} |
5 | 1111 |
} ); |
1112 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
function hide( event ) { |
16 | 1114 |
var win; |
1115 |
var size; |
|
1116 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
if ( activeToolbar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
if ( activeToolbar.tempHide || event.type === 'hide' || event.type === 'blur' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
activeToolbar.hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
activeToolbar = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
} else if ( ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
event.type === 'resizewindow' || |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
event.type === 'scrollwindow' || |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
event.type === 'resize' || |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
event.type === 'scroll' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
) && ! activeToolbar.blockHide ) { |
16 | 1127 |
/* |
1128 |
* Showing a tooltip may trigger a `resize` event in Chromium browsers. |
|
1129 |
* That results in a flicketing inline menu; tooltips are shown on hovering over a button, |
|
1130 |
* which then hides the toolbar on `resize`, then it repeats as soon as the toolbar is shown again. |
|
1131 |
*/ |
|
1132 |
if ( event.type === 'resize' || event.type === 'resizewindow' ) { |
|
1133 |
win = editor.getWin(); |
|
1134 |
size = win.innerHeight + win.innerWidth; |
|
1135 |
||
1136 |
// Reset old cached size. |
|
1137 |
if ( cachedWinSize && ( new Date() ).getTime() - cachedWinSize.timestamp > 2000 ) { |
|
1138 |
cachedWinSize = null; |
|
1139 |
} |
|
1140 |
||
1141 |
if ( cachedWinSize ) { |
|
1142 |
if ( size && Math.abs( size - cachedWinSize.size ) < 2 ) { |
|
1143 |
// `resize` fired but the window hasn't been resized. Bail. |
|
1144 |
return; |
|
1145 |
} |
|
1146 |
} else { |
|
1147 |
// First of a new series of `resize` events. Store the cached size and bail. |
|
1148 |
cachedWinSize = { |
|
1149 |
timestamp: ( new Date() ).getTime(), |
|
1150 |
size: size, |
|
1151 |
}; |
|
1152 |
||
1153 |
return; |
|
1154 |
} |
|
1155 |
} |
|
1156 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
clearTimeout( timeout ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
timeout = setTimeout( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
if ( activeToolbar && typeof activeToolbar.show === 'function' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
activeToolbar.scrolling = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
activeToolbar.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
}, 250 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
activeToolbar.scrolling = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
activeToolbar.hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
|
16 | 1172 |
if ( editor.inline ) { |
1173 |
editor.on( 'resizewindow', hide ); |
|
9 | 1174 |
|
1175 |
// Enable `capture` for the event. |
|
1176 |
// This will hide/reposition the toolbar on any scrolling in the document. |
|
1177 |
document.addEventListener( 'scroll', hide, true ); |
|
1178 |
} else { |
|
16 | 1179 |
// Bind to the editor iframe and to the parent window. |
1180 |
editor.dom.bind( editor.getWin(), 'resize scroll', hide ); |
|
9 | 1181 |
editor.on( 'resizewindow scrollwindow', hide ); |
1182 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
editor.on( 'remove', function() { |
9 | 1185 |
document.removeEventListener( 'scroll', hide, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
editor.off( 'resizewindow scrollwindow', hide ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
editor.dom.unbind( editor.getWin(), 'resize scroll', hide ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
editor.on( 'blur hide', hide ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
|
5 | 1192 |
editor.wp = editor.wp || {}; |
1193 |
editor.wp._createToolbar = create; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
}, true ); |
5 | 1195 |
|
1196 |
function noop() {} |
|
1197 |
||
16 | 1198 |
// Expose some functions (back-compat). |
5 | 1199 |
return { |
1200 |
_showButtons: noop, |
|
1201 |
_hideButtons: noop, |
|
1202 |
_setEmbed: noop, |
|
1203 |
_getEmbed: noop |
|
1204 |
}; |
|
1205 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
}( window.tinymce )); |