1 /* global getUserSetting, setUserSetting */
2 ( function( tinymce ) {
3 // Set the minimum value for the modals z-index higher than #wpadminbar (100000)
4 tinymce.ui.FloatPanel.zIndex = 100100;
6 tinymce.PluginManager.add( 'wordpress', function( editor ) {
7 var wpAdvButton, style,
10 __ = editor.editorManager.i18n.translate,
13 hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) );
16 $( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] );
19 function toggleToolbars( state ) {
20 var iframe, initial, toolbars,
23 initial = ( state === 'hide' );
25 if ( editor.theme.panel ) {
26 toolbars = editor.theme.panel.find('.toolbar:not(.menubar)');
29 if ( ! toolbars || toolbars.length < 2 || ( state === 'hide' && ! toolbars[1].visible() ) ) {
33 if ( ! state && toolbars[1].visible() ) {
37 each( toolbars, function( toolbar, i ) {
39 if ( state === 'hide' ) {
49 if ( pixels && ! initial ) {
50 // Resize iframe, not needed in iOS
51 if ( ! tinymce.Env.iOS ) {
52 iframe = editor.getContentAreaContainer().firstChild;
53 DOM.setStyle( iframe, 'height', iframe.clientHeight + pixels );
56 if ( state === 'hide' ) {
57 setUserSetting('hidetb', '0');
58 wpAdvButton && wpAdvButton.active( false );
60 setUserSetting('hidetb', '1');
61 wpAdvButton && wpAdvButton.active( true );
65 editor.fire( 'wp-toolbar-toggle' );
68 // Add the kitchen sink button :)
69 editor.addButton( 'wp_adv', {
70 tooltip: 'Toolbar Toggle',
72 onPostRender: function() {
74 wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' ? true : false );
78 // Hide the toolbars after loading
79 editor.on( 'PostRender', function() {
80 if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) {
81 toggleToolbars( 'hide' );
85 editor.addCommand( 'WP_Adv', function() {
89 editor.on( 'focus', function() {
90 window.wpActiveEditor = editor.id;
93 editor.on( 'BeforeSetContent', function( event ) {
96 if ( event.content ) {
97 if ( event.content.indexOf( '<!--more' ) !== -1 ) {
98 title = __( 'Read more...' );
100 event.content = event.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) {
101 return '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="more" data-wp-more-text="' + moretext + '" ' +
102 'class="wp-more-tag mce-wp-more" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />';
106 if ( event.content.indexOf( '<!--nextpage-->' ) !== -1 ) {
107 title = __( 'Page break' );
109 event.content = event.content.replace( /<!--nextpage-->/g,
110 '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="nextpage" class="wp-more-tag mce-wp-nextpage" ' +
111 'alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' );
114 if ( event.load && event.format !== 'raw' && hasWpautop ) {
115 event.content = wp.editor.autop( event.content );
118 if ( event.content.indexOf( '<script' ) !== -1 || event.content.indexOf( '<style' ) !== -1 ) {
119 event.content = event.content.replace( /<(script|style)[^>]*>[\s\S]*?<\/\1>/g, function( match, tag ) {
121 'src="' + tinymce.Env.transparentSrc + '" ' +
122 'data-wp-preserve="' + encodeURIComponent( match ) + '" ' +
123 'data-mce-resize="false" ' +
124 'data-mce-placeholder="1" '+
125 'class="mce-object" ' +
126 'width="20" height="20" '+
127 'alt="<' + tag + '>" ' +
128 'title="<' + tag + '>" ' +
133 // Remove spaces from empty paragraphs.
134 // Avoid backtracking, can freeze the editor. See #35890.
135 // (This is also quite faster than using only one regex.)
136 event.content = event.content.replace( /<p>([^<>]+)<\/p>/gi, function( tag, text ) {
137 if ( /^( |\s|\u00a0|\ufeff)+$/i.test( text ) ) {
138 return '<p><br /></p>';
146 editor.on( 'PostProcess', function( event ) {
148 event.content = event.content.replace(/<img[^>]+>/g, function( image ) {
153 if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) {
154 if ( match = image.match( /data-wp-more-text="([^"]+)"/ ) ) {
158 string = '<!--more' + moretext + '-->';
159 } else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) {
160 string = '<!--nextpage-->';
161 } else if ( image.indexOf( 'data-wp-preserve' ) !== -1 ) {
162 if ( match = image.match( / data-wp-preserve="([^"]+)"/ ) ) {
163 string = decodeURIComponent( match[1] );
167 return string || image;
172 // Display the tag name instead of img in element path
173 editor.on( 'ResolveName', function( event ) {
176 if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
182 editor.addCommand( 'WP_More', function( tag ) {
183 var parent, html, title,
184 classname = 'wp-more-tag',
186 node = editor.selection.getNode();
189 classname += ' mce-wp-' + tag;
190 title = tag === 'more' ? 'Read more...' : 'Next page';
192 html = '<img src="' + tinymce.Env.transparentSrc + '" alt="" title="' + title + '" class="' + classname + '" ' +
193 'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
196 if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) {
197 editor.insertContent( html );
201 // Get the top level parent node
202 parent = dom.getParent( node, function( found ) {
203 if ( found.parentNode && found.parentNode.nodeName === 'BODY' ) {
208 }, editor.getBody() );
211 if ( parent.nodeName === 'P' ) {
212 parent.appendChild( dom.create( 'p', null, html ).firstChild );
214 dom.insertAfter( dom.create( 'p', null, html ), parent );
217 editor.nodeChanged();
221 editor.addCommand( 'WP_Code', function() {
222 editor.formatter.toggle('code');
225 editor.addCommand( 'WP_Page', function() {
226 editor.execCommand( 'WP_More', 'nextpage' );
229 editor.addCommand( 'WP_Help', function() {
230 var access = tinymce.Env.mac ? __( 'Ctrl + Alt + letter:' ) : __( 'Shift + Alt + letter:' ),
231 meta = tinymce.Env.mac ? __( 'Cmd + letter:' ) : __( 'Ctrl + letter:' ),
234 header, html, dialog, $wrap;
237 { c: 'Copy', x: 'Cut' },
238 { v: 'Paste', a: 'Select all' },
239 { z: 'Undo', y: 'Redo' },
240 { b: 'Bold', i: 'Italic' },
241 { u: 'Underline', k: 'Insert/edit link' }
243 table1.push( tr( row ) );
247 { 1: 'Heading 1', 2: 'Heading 2' },
248 { 3: 'Heading 3', 4: 'Heading 4' },
249 { 5: 'Heading 5', 6: 'Heading 6' },
250 { l: 'Align left', c: 'Align center' },
251 { r: 'Align right', j: 'Justify' },
252 { d: 'Strikethrough', q: 'Blockquote' },
253 { u: 'Bullet list', o: 'Numbered list' },
254 { a: 'Insert/edit link', s: 'Remove link' },
255 { m: 'Insert/edit image', t: 'Insert Read More tag' },
256 { h: 'Keyboard Shortcuts', x: 'Code' },
257 { p: 'Insert Page Break tag', w: 'Distraction-free writing mode' }
259 table2.push( tr( row ) );
265 each( row, function( text, key ) {
267 out += '<td></td><td></td>';
269 out += '<td><kbd>' + key + '</kbd></td><td>' + __( text ) + '</td>';
273 return out + '</tr>';
276 header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ];
277 header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>';
279 html = '<div class="wp-editor-help">';
281 // Main section, default and additional shortcuts
283 '<h2>' + __( 'Default shortcuts,' ) + ' ' + meta + '</h2>' +
284 '<table class="wp-help-th-center fixed">' +
288 '<h2>' + __( 'Additional shortcuts,' ) + ' ' + access + '</h2>' +
289 '<table class="wp-help-th-center fixed">' +
294 if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) {
295 // Text pattern section
297 '<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>' +
298 '<table class="wp-help-th-center fixed">' +
299 tr({ '*': 'Bullet list', '1.': 'Numbered list' }) +
300 tr({ '-': 'Bullet list', '1)': 'Numbered list' }) +
304 '<h2>' + __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ) + '</h2>' +
305 '<table class="wp-help-single">' +
306 tr({ '>': 'Blockquote' }) +
307 tr({ '##': 'Heading 2' }) +
308 tr({ '###': 'Heading 3' }) +
309 tr({ '####': 'Heading 4' }) +
310 tr({ '#####': 'Heading 5' }) +
311 tr({ '######': 'Heading 6' }) +
312 tr({ '---': 'Horizontal line' }) +
316 // Focus management section
318 '<h2>' + __( 'Focus shortcuts:' ) + '</h2>' +
319 '<table class="wp-help-single">' +
320 tr({ 'Alt + F8': 'Inline toolbar (when an image, link or preview is selected)' }) +
321 tr({ 'Alt + F9': 'Editor menu (when enabled)' }) +
322 tr({ 'Alt + F10': 'Editor toolbar' }) +
323 tr({ 'Alt + F11': 'Elements path' }) +
325 '<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>';
329 dialog = editor.windowManager.open( {
330 title: 'Keyboard Shortcuts',
343 dialog.$el.find( 'div[role="application"]' ).attr( 'role', 'document' );
344 $wrap = dialog.$el.find( '.mce-wp-help' );
347 $wrap.attr( 'tabindex', '0' );
349 $wrap.on( 'keydown', function( event ) {
350 // Prevent use of: page up, page down, end, home, left arrow, up arrow, right arrow, down arrow
351 // in the dialog keydown handler.
352 if ( event.keyCode >= 33 && event.keyCode <= 40 ) {
353 event.stopPropagation();
360 editor.addCommand( 'WP_Medialib', function() {
361 if ( wp && wp.media && wp.media.editor ) {
362 wp.media.editor.open( editor.id );
367 editor.addButton( 'wp_more', {
368 tooltip: 'Insert Read More tag',
369 onclick: function() {
370 editor.execCommand( 'WP_More', 'more' );
374 editor.addButton( 'wp_page', {
375 tooltip: 'Page break',
376 onclick: function() {
377 editor.execCommand( 'WP_More', 'nextpage' );
381 editor.addButton( 'wp_help', {
382 tooltip: 'Keyboard Shortcuts',
386 editor.addButton( 'wp_code', {
389 stateSelector: 'code'
394 if ( wp && wp.media && wp.media.editor ) {
395 editor.addMenuItem( 'add_media', {
397 icon: 'wp-media-library',
403 // Insert "Read More..."
404 editor.addMenuItem( 'wp_more', {
405 text: 'Insert Read More tag',
408 onclick: function() {
409 editor.execCommand( 'WP_More', 'more' );
413 // Insert "Next Page"
414 editor.addMenuItem( 'wp_page', {
418 onclick: function() {
419 editor.execCommand( 'WP_More', 'nextpage' );
423 editor.on( 'BeforeExecCommand', function(e) {
424 if ( tinymce.Env.webkit && ( e.command === 'InsertUnorderedList' || e.command === 'InsertOrderedList' ) ) {
426 style = editor.dom.create( 'style', {'type': 'text/css'},
427 '#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}');
430 editor.getDoc().head.appendChild( style );
434 editor.on( 'ExecCommand', function( e ) {
435 if ( tinymce.Env.webkit && style &&
436 ( 'InsertUnorderedList' === e.command || 'InsertOrderedList' === e.command ) ) {
438 editor.dom.remove( style );
442 editor.on( 'init', function() {
443 var env = tinymce.Env,
444 bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css...
445 doc = editor.getDoc(),
449 dom.addClass( doc.documentElement, 'ios' );
452 if ( editor.getParam( 'directionality' ) === 'rtl' ) {
453 bodyClass.push('rtl');
454 dom.setAttrib( doc.documentElement, 'dir', 'rtl' );
457 dom.setAttrib( doc.documentElement, 'lang', editor.getParam( 'wp_lang_attr' ) );
460 if ( parseInt( env.ie, 10 ) === 9 ) {
461 bodyClass.push('ie9');
462 } else if ( parseInt( env.ie, 10 ) === 8 ) {
463 bodyClass.push('ie8');
464 } else if ( env.ie < 8 ) {
465 bodyClass.push('ie7');
467 } else if ( env.webkit ) {
468 bodyClass.push('webkit');
471 bodyClass.push('wp-editor');
473 each( bodyClass, function( cls ) {
475 dom.addClass( doc.body, cls );
479 // Remove invalid parent paragraphs when inserting HTML
480 editor.on( 'BeforeSetContent', function( event ) {
481 if ( event.content ) {
482 event.content = event.content.replace( /<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' )
483 .replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '</$1>' );
488 $( document ).triggerHandler( 'tinymce-editor-init', [editor] );
491 if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) {
492 dom.bind( doc, 'dragstart dragend dragover drop', function( event ) {
494 // Trigger the jQuery handlers.
495 $( document ).trigger( new $.Event( event ) );
500 if ( editor.getParam( 'wp_paste_filters', true ) ) {
501 editor.on( 'PastePreProcess', function( event ) {
502 // Remove trailing <br> added by WebKit browsers to the clipboard
503 event.content = event.content.replace( /<br class="?Apple-interchange-newline"?>/gi, '' );
505 // In WebKit this is handled by removeWebKitStyles()
506 if ( ! tinymce.Env.webkit ) {
507 // Remove all inline styles
508 event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
510 // Put back the internal styles
511 event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' );
515 editor.on( 'PastePostProcess', function( event ) {
516 // Remove empty paragraphs
517 each( dom.select( 'p', event.node ), function( node ) {
518 if ( dom.isEmpty( node ) ) {
526 editor.on( 'SaveContent', function( event ) {
527 // If editor is hidden, we just want the textarea's value to be saved
528 if ( ! editor.inline && editor.isHidden() ) {
529 event.content = event.element.value;
533 // Keep empty paragraphs :(
534 event.content = event.content.replace( /<p>(?:<br ?\/?>|\u00a0|\uFEFF| )*<\/p>/g, '<p> </p>' );
537 event.content = wp.editor.removep( event.content );
541 editor.on( 'preInit', function() {
542 var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' +
543 'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes.
544 'i,' + // Don't replace <i> with <em> and <b> with <strong> and don't remove them when empty.
546 'script[src|async|defer|type|charset|crossorigin|integrity]'; // Add support for <script>.
548 editor.schema.addValidElements( validElementsSetting );
550 if ( tinymce.Env.iOS ) {
551 editor.settings.height = 300;
560 u: 'InsertUnorderedList',
561 o: 'InsertOrderedList',
569 }, function( command, key ) {
570 editor.shortcuts.add( 'access+' + key, '', command );
573 editor.addShortcut( 'meta+s', '', function() {
574 if ( wp && wp.autosave ) {
575 wp.autosave.server.triggerSave();
579 if ( window.getUserSetting( 'editor_plain_text_paste_warning' ) > 1 ) {
580 editor.settings.paste_plaintext_inform = false;
583 // Change the editor iframe title on MacOS, add the correct help shortcut.
584 if ( tinymce.Env.mac ) {
585 tinymce.$( editor.iframeElement ).attr( 'title', __( 'Rich Text Area. Press Control-Option-H for help.' ) );
589 editor.on( 'PastePlainTextToggle', function( event ) {
590 // Warn twice, then stop.
591 if ( event.state === true ) {
592 var times = parseInt( window.getUserSetting( 'editor_plain_text_paste_warning' ), 10 ) || 0;
595 window.setUserSetting( 'editor_plain_text_paste_warning', ++times );
601 * Experimental: create a floating toolbar.
602 * This functionality will change in the next releases. Not recommended for use by plugins.
604 editor.on( 'preinit', function() {
605 var Factory = tinymce.ui.Factory,
606 settings = editor.settings,
610 container = editor.getContainer(),
611 wpAdminbar = document.getElementById( 'wpadminbar' ),
612 mceIframe = document.getElementById( editor.id + '_ifr' ),
618 mceToolbar = tinymce.$( '.mce-toolbar-grp', container )[0];
619 mceStatusbar = tinymce.$( '.mce-statusbar', container )[0];
622 if ( editor.id === 'content' ) {
623 wpStatusbar = document.getElementById( 'post-status-info' );
626 function create( buttons, bottom ) {
631 each( buttons, function( item ) {
634 function bindSelectorChanged() {
635 var selection = editor.selection;
637 if ( itemName === 'bullist' ) {
638 selection.selectorChanged( 'ul > li', function( state, args ) {
639 var i = args.parents.length,
643 nodeName = args.parents[ i ].nodeName;
645 if ( nodeName === 'OL' || nodeName == 'UL' ) {
650 item.active( state && nodeName === 'UL' );
654 if ( itemName === 'numlist' ) {
655 selection.selectorChanged( 'ol > li', function( state, args ) {
656 var i = args.parents.length,
660 nodeName = args.parents[ i ].nodeName;
662 if ( nodeName === 'OL' || nodeName === 'UL' ) {
667 item.active( state && nodeName === 'OL' );
671 if ( item.settings.stateSelector ) {
672 selection.selectorChanged( item.settings.stateSelector, function( state ) {
673 item.active( state );
677 if ( item.settings.disabledStateSelector ) {
678 selection.selectorChanged( item.settings.disabledStateSelector, function( state ) {
679 item.disabled( state );
684 if ( item === '|' ) {
687 if ( Factory.has( item ) ) {
692 if ( settings.toolbar_items_size ) {
693 item.size = settings.toolbar_items_size;
696 toolbarItems.push( item );
700 if ( ! buttonGroup ) {
706 toolbarItems.push( buttonGroup );
709 if ( editor.buttons[ item ] ) {
711 item = editor.buttons[ itemName ];
713 if ( typeof item === 'function' ) {
717 item.type = item.type || 'button';
719 if ( settings.toolbar_items_size ) {
720 item.size = settings.toolbar_items_size;
723 item = Factory.create( item );
725 buttonGroup.items.push( item );
727 if ( editor.initialized ) {
728 bindSelectorChanged();
730 editor.on( 'init', bindSelectorChanged );
737 toolbar = Factory.create( {
740 classes: 'toolbar-grp inline-toolbar-grp',
750 toolbar.bottom = bottom;
752 function reposition() {
753 if ( ! currentSelection ) {
757 var scrollX = window.pageXOffset || document.documentElement.scrollLeft,
758 scrollY = window.pageYOffset || document.documentElement.scrollTop,
759 windowWidth = window.innerWidth,
760 windowHeight = window.innerHeight,
761 iframeRect = mceIframe ? mceIframe.getBoundingClientRect() : {
764 bottom: windowHeight,
769 toolbar = this.getEl(),
770 toolbarWidth = toolbar.offsetWidth,
771 toolbarHeight = toolbar.clientHeight,
772 selection = currentSelection.getBoundingClientRect(),
773 selectionMiddle = ( selection.left + selection.right ) / 2,
775 spaceNeeded = toolbarHeight + buffer,
776 wpAdminbarBottom = wpAdminbar ? wpAdminbar.getBoundingClientRect().bottom : 0,
777 mceToolbarBottom = mceToolbar ? mceToolbar.getBoundingClientRect().bottom : 0,
778 mceStatusbarTop = mceStatusbar ? windowHeight - mceStatusbar.getBoundingClientRect().top : 0,
779 wpStatusbarTop = wpStatusbar ? windowHeight - wpStatusbar.getBoundingClientRect().top : 0,
780 blockedTop = Math.max( 0, wpAdminbarBottom, mceToolbarBottom, iframeRect.top ),
781 blockedBottom = Math.max( 0, mceStatusbarTop, wpStatusbarTop, windowHeight - iframeRect.bottom ),
782 spaceTop = selection.top + iframeRect.top - blockedTop,
783 spaceBottom = windowHeight - iframeRect.top - selection.bottom - blockedBottom,
784 editorHeight = windowHeight - blockedTop - blockedBottom,
790 if ( spaceTop >= editorHeight || spaceBottom >= editorHeight ) {
791 this.scrolling = true;
793 this.scrolling = false;
797 // Add offset in iOS to move the menu over the image, out of the way of the default iOS menu.
798 if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) {
800 iosOffsetBottom = 46;
804 if ( spaceBottom >= spaceNeeded ) {
805 className = ' mce-arrow-up';
806 top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom;
807 } else if ( spaceTop >= spaceNeeded ) {
808 className = ' mce-arrow-down';
809 top = selection.top + iframeRect.top + scrollY - toolbarHeight + iosOffsetTop;
812 if ( spaceTop >= spaceNeeded ) {
813 className = ' mce-arrow-down';
814 top = selection.top + iframeRect.top + scrollY - toolbarHeight + iosOffsetTop;
815 } else if ( spaceBottom >= spaceNeeded && editorHeight / 2 > selection.bottom + iframeRect.top - blockedTop ) {
816 className = ' mce-arrow-up';
817 top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom;
821 if ( typeof top === 'undefined' ) {
822 top = scrollY + blockedTop + buffer + iosOffsetBottom;
825 left = selectionMiddle - toolbarWidth / 2 + iframeRect.left + scrollX;
827 if ( selection.left < 0 || selection.right > iframeRect.width ) {
828 left = iframeRect.left + scrollX + ( iframeRect.width - toolbarWidth ) / 2;
829 } else if ( toolbarWidth >= windowWidth ) {
830 className += ' mce-arrow-full';
832 } else if ( ( left < 0 && selection.left + toolbarWidth > windowWidth ) || ( left + toolbarWidth > windowWidth && selection.right - toolbarWidth < 0 ) ) {
833 left = ( windowWidth - toolbarWidth ) / 2;
834 } else if ( left < iframeRect.left + scrollX ) {
835 className += ' mce-arrow-left';
836 left = selection.left + iframeRect.left + scrollX;
837 } else if ( left + toolbarWidth > iframeRect.width + iframeRect.left + scrollX ) {
838 className += ' mce-arrow-right';
839 left = selection.right - toolbarWidth + iframeRect.left + scrollX;
842 // No up/down arrows on the menu over images in iOS.
843 if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) {
844 className = className.replace( / ?mce-arrow-(up|down)/g, '' );
847 toolbar.className = toolbar.className.replace( / ?mce-arrow-[\w]+/g, '' ) + className;
849 DOM.setStyles( toolbar, {
857 toolbar.on( 'show', function() {
861 toolbar.on( 'keydown', function( event ) {
862 if ( event.keyCode === 27 ) {
868 editor.on( 'remove', function() {
872 toolbar.reposition = reposition;
873 toolbar.hide().renderTo( document.body );
878 editor.shortcuts.add( 'alt+119', '', function() {
881 if ( activeToolbar ) {
882 node = activeToolbar.find( 'toolbar' )[0];
883 node && node.focus( true );
887 editor.on( 'nodechange', function( event ) {
888 var collapsed = editor.selection.isCollapsed();
891 element: event.element,
892 parents: event.parents,
896 editor.fire( 'wptoolbar', args );
898 currentSelection = args.selection || args.element;
900 if ( activeToolbar && activeToolbar !== args.toolbar ) {
901 activeToolbar.hide();
904 if ( args.toolbar ) {
905 if ( activeToolbar !== args.toolbar ) {
906 activeToolbar = args.toolbar;
907 activeToolbar.show();
909 activeToolbar.reposition();
912 activeToolbar = false;
916 editor.on( 'focus', function() {
917 if ( activeToolbar ) {
918 activeToolbar.show();
922 function hide( event ) {
923 if ( activeToolbar ) {
924 if ( activeToolbar.tempHide || event.type === 'hide' ) {
925 activeToolbar.hide();
926 activeToolbar = false;
928 event.type === 'resizewindow' ||
929 event.type === 'scrollwindow' ||
930 event.type === 'resize' ||
931 event.type === 'scroll'
932 ) && ! activeToolbar.blockHide ) {
933 clearTimeout( timeout );
935 timeout = setTimeout( function() {
936 if ( activeToolbar && typeof activeToolbar.show === 'function' ) {
937 activeToolbar.scrolling = false;
938 activeToolbar.show();
942 activeToolbar.scrolling = true;
943 activeToolbar.hide();
948 // For full height editor.
949 editor.on( 'resizewindow scrollwindow', hide );
950 // For scrollable editor.
951 editor.dom.bind( editor.getWin(), 'resize scroll', hide );
953 editor.on( 'remove', function() {
954 editor.off( 'resizewindow scrollwindow', hide );
955 editor.dom.unbind( editor.getWin(), 'resize scroll', hide );
958 editor.on( 'blur hide', hide );
960 editor.wp = editor.wp || {};
961 editor.wp._createToolbar = create;
966 // Expose some functions (back-compat)
975 }( window.tinymce ));