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 // Replace Read More/Next Page tags with images
94 editor.on( 'BeforeSetContent', function( event ) {
97 if ( event.content ) {
98 if ( event.content.indexOf( '<!--more' ) !== -1 ) {
99 title = __( 'Read more...' );
101 event.content = event.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) {
102 return '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="more" data-wp-more-text="' + moretext + '" ' +
103 'class="wp-more-tag mce-wp-more" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />';
107 if ( event.content.indexOf( '<!--nextpage-->' ) !== -1 ) {
108 title = __( 'Page break' );
110 event.content = event.content.replace( /<!--nextpage-->/g,
111 '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="nextpage" class="wp-more-tag mce-wp-nextpage" ' +
112 'alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' );
115 if ( event.load && event.format !== 'raw' && hasWpautop ) {
116 event.content = wp.editor.autop( event.content );
119 // Remove spaces from empty paragraphs.
120 // Avoid backtracking, can freeze the editor. See #35890.
121 // (This is also quite faster than using only one regex.)
122 event.content = event.content.replace( /<p>([^<>]+)<\/p>/gi, function( tag, text ) {
123 if ( /^( |\s|\u00a0|\ufeff)+$/i.test( text ) ) {
124 return '<p><br /></p>';
132 // Replace images with tags
133 editor.on( 'PostProcess', function( e ) {
135 e.content = e.content.replace(/<img[^>]+>/g, function( image ) {
136 var match, moretext = '';
138 if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) {
139 if ( match = image.match( /data-wp-more-text="([^"]+)"/ ) ) {
143 image = '<!--more' + moretext + '-->';
144 } else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) {
145 image = '<!--nextpage-->';
153 // Display the tag name instead of img in element path
154 editor.on( 'ResolveName', function( event ) {
157 if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
163 editor.addCommand( 'WP_More', function( tag ) {
164 var parent, html, title,
165 classname = 'wp-more-tag',
167 node = editor.selection.getNode();
170 classname += ' mce-wp-' + tag;
171 title = tag === 'more' ? 'Read more...' : 'Next page';
173 html = '<img src="' + tinymce.Env.transparentSrc + '" alt="" title="' + title + '" class="' + classname + '" ' +
174 'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
177 if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) {
178 editor.insertContent( html );
182 // Get the top level parent node
183 parent = dom.getParent( node, function( found ) {
184 if ( found.parentNode && found.parentNode.nodeName === 'BODY' ) {
189 }, editor.getBody() );
192 if ( parent.nodeName === 'P' ) {
193 parent.appendChild( dom.create( 'p', null, html ).firstChild );
195 dom.insertAfter( dom.create( 'p', null, html ), parent );
198 editor.nodeChanged();
202 editor.addCommand( 'WP_Code', function() {
203 editor.formatter.toggle('code');
206 editor.addCommand( 'WP_Page', function() {
207 editor.execCommand( 'WP_More', 'nextpage' );
210 editor.addCommand( 'WP_Help', function() {
211 var access = tinymce.Env.mac ? __( 'Ctrl + Alt + letter:' ) : __( 'Shift + Alt + letter:' ),
212 meta = tinymce.Env.mac ? __( 'Cmd + letter:' ) : __( 'Ctrl + letter:' ),
215 header, html, dialog, $wrap;
218 { c: 'Copy', x: 'Cut' },
219 { v: 'Paste', a: 'Select all' },
220 { z: 'Undo', y: 'Redo' },
221 { b: 'Bold', i: 'Italic' },
222 { u: 'Underline', k: 'Insert/edit link' }
224 table1.push( tr( row ) );
228 { 1: 'Heading 1', 2: 'Heading 2' },
229 { 3: 'Heading 3', 4: 'Heading 4' },
230 { 5: 'Heading 5', 6: 'Heading 6' },
231 { l: 'Align left', c: 'Align center' },
232 { r: 'Align right', j: 'Justify' },
233 { d: 'Strikethrough', q: 'Blockquote' },
234 { u: 'Bullet list', o: 'Numbered list' },
235 { a: 'Insert/edit link', s: 'Remove link' },
236 { m: 'Insert/edit image', t: 'Insert Read More tag' },
237 { h: 'Keyboard Shortcuts', x: 'Code' },
238 { p: 'Insert Page Break tag', w: 'Distraction-free writing mode' }
240 table2.push( tr( row ) );
246 each( row, function( text, key ) {
248 out += '<td></td><td></td>';
250 out += '<td><kbd>' + key + '</kbd></td><td>' + __( text ) + '</td>';
254 return out + '</tr>';
257 header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ];
258 header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>';
260 html = '<div class="wp-editor-help">';
262 // Main section, default and additional shortcuts
264 '<h2>' + __( 'Default shortcuts,' ) + ' ' + meta + '</h2>' +
265 '<table class="wp-help-th-center fixed">' +
269 '<h2>' + __( 'Additional shortcuts,' ) + ' ' + access + '</h2>' +
270 '<table class="wp-help-th-center fixed">' +
275 if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) {
276 // Text pattern section
278 '<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>' +
279 '<table class="wp-help-th-center fixed">' +
280 tr({ '*': 'Bullet list', '1.': 'Numbered list' }) +
281 tr({ '-': 'Bullet list', '1)': 'Numbered list' }) +
285 '<h2>' + __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ) + '</h2>' +
286 '<table class="wp-help-single">' +
287 tr({ '>': 'Blockquote' }) +
288 tr({ '##': 'Heading 2' }) +
289 tr({ '###': 'Heading 3' }) +
290 tr({ '####': 'Heading 4' }) +
291 tr({ '#####': 'Heading 5' }) +
292 tr({ '######': 'Heading 6' }) +
293 tr({ '---': 'Horizontal line' }) +
297 // Focus management section
299 '<h2>' + __( 'Focus shortcuts:' ) + '</h2>' +
300 '<table class="wp-help-single">' +
301 tr({ 'Alt + F8': 'Inline toolbar (when an image, link or preview is selected)' }) +
302 tr({ 'Alt + F9': 'Editor menu (when enabled)' }) +
303 tr({ 'Alt + F10': 'Editor toolbar' }) +
304 tr({ 'Alt + F11': 'Elements path' }) +
306 '<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>';
310 dialog = editor.windowManager.open( {
311 title: 'Keyboard Shortcuts',
324 dialog.$el.find( 'div[role="application"]' ).attr( 'role', 'document' );
325 $wrap = dialog.$el.find( '.mce-wp-help' );
328 $wrap.attr( 'tabindex', '0' );
330 $wrap.on( 'keydown', function( event ) {
331 // Prevent use of: page up, page down, end, home, left arrow, up arrow, right arrow, down arrow
332 // in the dialog keydown handler.
333 if ( event.keyCode >= 33 && event.keyCode <= 40 ) {
334 event.stopPropagation();
341 editor.addCommand( 'WP_Medialib', function() {
342 if ( wp && wp.media && wp.media.editor ) {
343 wp.media.editor.open( editor.id );
348 editor.addButton( 'wp_more', {
349 tooltip: 'Insert Read More tag',
350 onclick: function() {
351 editor.execCommand( 'WP_More', 'more' );
355 editor.addButton( 'wp_page', {
356 tooltip: 'Page break',
357 onclick: function() {
358 editor.execCommand( 'WP_More', 'nextpage' );
362 editor.addButton( 'wp_help', {
363 tooltip: 'Keyboard Shortcuts',
367 editor.addButton( 'wp_code', {
370 stateSelector: 'code'
375 if ( wp && wp.media && wp.media.editor ) {
376 editor.addMenuItem( 'add_media', {
378 icon: 'wp-media-library',
384 // Insert "Read More..."
385 editor.addMenuItem( 'wp_more', {
386 text: 'Insert Read More tag',
389 onclick: function() {
390 editor.execCommand( 'WP_More', 'more' );
394 // Insert "Next Page"
395 editor.addMenuItem( 'wp_page', {
399 onclick: function() {
400 editor.execCommand( 'WP_More', 'nextpage' );
404 editor.on( 'BeforeExecCommand', function(e) {
405 if ( tinymce.Env.webkit && ( e.command === 'InsertUnorderedList' || e.command === 'InsertOrderedList' ) ) {
407 style = editor.dom.create( 'style', {'type': 'text/css'},
408 '#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}');
411 editor.getDoc().head.appendChild( style );
415 editor.on( 'ExecCommand', function( e ) {
416 if ( tinymce.Env.webkit && style &&
417 ( 'InsertUnorderedList' === e.command || 'InsertOrderedList' === e.command ) ) {
419 editor.dom.remove( style );
423 editor.on( 'init', function() {
424 var env = tinymce.Env,
425 bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css...
426 doc = editor.getDoc(),
430 dom.addClass( doc.documentElement, 'ios' );
433 if ( editor.getParam( 'directionality' ) === 'rtl' ) {
434 bodyClass.push('rtl');
435 dom.setAttrib( doc.documentElement, 'dir', 'rtl' );
438 dom.setAttrib( doc.documentElement, 'lang', editor.getParam( 'wp_lang_attr' ) );
441 if ( parseInt( env.ie, 10 ) === 9 ) {
442 bodyClass.push('ie9');
443 } else if ( parseInt( env.ie, 10 ) === 8 ) {
444 bodyClass.push('ie8');
445 } else if ( env.ie < 8 ) {
446 bodyClass.push('ie7');
448 } else if ( env.webkit ) {
449 bodyClass.push('webkit');
452 bodyClass.push('wp-editor');
454 each( bodyClass, function( cls ) {
456 dom.addClass( doc.body, cls );
460 // Remove invalid parent paragraphs when inserting HTML
461 editor.on( 'BeforeSetContent', function( event ) {
462 if ( event.content ) {
463 event.content = event.content.replace( /<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' )
464 .replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '</$1>' );
469 $( document ).triggerHandler( 'tinymce-editor-init', [editor] );
472 if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) {
473 dom.bind( doc, 'dragstart dragend dragover drop', function( event ) {
475 // Trigger the jQuery handlers.
476 $( document ).trigger( new $.Event( event ) );
481 if ( editor.getParam( 'wp_paste_filters', true ) ) {
482 editor.on( 'PastePreProcess', function( event ) {
483 // Remove trailing <br> added by WebKit browsers to the clipboard
484 event.content = event.content.replace( /<br class="?Apple-interchange-newline"?>/gi, '' );
486 // In WebKit this is handled by removeWebKitStyles()
487 if ( ! tinymce.Env.webkit ) {
488 // Remove all inline styles
489 event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
491 // Put back the internal styles
492 event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' );
496 editor.on( 'PastePostProcess', function( event ) {
497 // Remove empty paragraphs
498 each( dom.select( 'p', event.node ), function( node ) {
499 if ( dom.isEmpty( node ) ) {
507 editor.on( 'SaveContent', function( event ) {
508 // If editor is hidden, we just want the textarea's value to be saved
509 if ( ! editor.inline && editor.isHidden() ) {
510 event.content = event.element.value;
514 // Keep empty paragraphs :(
515 event.content = event.content.replace( /<p>(?:<br ?\/?>|\u00a0|\uFEFF| )*<\/p>/g, '<p> </p>' );
518 event.content = wp.editor.removep( event.content );
522 editor.on( 'preInit', function() {
523 var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' +
524 'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes.
525 'i,' + // Don't replace <i> with <em> and <b> with <strong> and don't remove them when empty.
527 'script[src|async|defer|type|charset|crossorigin|integrity]'; // Add support for <script>.
529 editor.schema.addValidElements( validElementsSetting );
531 if ( tinymce.Env.iOS ) {
532 editor.settings.height = 300;
541 u: 'InsertUnorderedList',
542 o: 'InsertOrderedList',
551 }, function( command, key ) {
552 editor.shortcuts.add( 'access+' + key, '', command );
555 editor.addShortcut( 'meta+s', '', function() {
556 if ( wp && wp.autosave ) {
557 wp.autosave.server.triggerSave();
561 if ( window.getUserSetting( 'editor_plain_text_paste_warning' ) > 1 ) {
562 editor.settings.paste_plaintext_inform = false;
566 editor.on( 'PastePlainTextToggle', function( event ) {
567 // Warn twice, then stop.
568 if ( event.state === true ) {
569 var times = parseInt( window.getUserSetting( 'editor_plain_text_paste_warning' ), 10 ) || 0;
572 window.setUserSetting( 'editor_plain_text_paste_warning', ++times );
578 * Experimental: create a floating toolbar.
579 * This functionality will change in the next releases. Not recommended for use by plugins.
581 editor.on( 'preinit', function() {
582 var Factory = tinymce.ui.Factory,
583 settings = editor.settings,
587 container = editor.getContainer(),
588 wpAdminbar = document.getElementById( 'wpadminbar' ),
589 mceIframe = document.getElementById( editor.id + '_ifr' ),
595 mceToolbar = tinymce.$( '.mce-toolbar-grp', container )[0];
596 mceStatusbar = tinymce.$( '.mce-statusbar', container )[0];
599 if ( editor.id === 'content' ) {
600 wpStatusbar = document.getElementById( 'post-status-info' );
603 function create( buttons, bottom ) {
608 each( buttons, function( item ) {
611 function bindSelectorChanged() {
612 var selection = editor.selection;
614 if ( itemName === 'bullist' ) {
615 selection.selectorChanged( 'ul > li', function( state, args ) {
616 var i = args.parents.length,
620 nodeName = args.parents[ i ].nodeName;
622 if ( nodeName === 'OL' || nodeName == 'UL' ) {
627 item.active( state && nodeName === 'UL' );
631 if ( itemName === 'numlist' ) {
632 selection.selectorChanged( 'ol > li', function( state, args ) {
633 var i = args.parents.length,
637 nodeName = args.parents[ i ].nodeName;
639 if ( nodeName === 'OL' || nodeName === 'UL' ) {
644 item.active( state && nodeName === 'OL' );
648 if ( item.settings.stateSelector ) {
649 selection.selectorChanged( item.settings.stateSelector, function( state ) {
650 item.active( state );
654 if ( item.settings.disabledStateSelector ) {
655 selection.selectorChanged( item.settings.disabledStateSelector, function( state ) {
656 item.disabled( state );
661 if ( item === '|' ) {
664 if ( Factory.has( item ) ) {
669 if ( settings.toolbar_items_size ) {
670 item.size = settings.toolbar_items_size;
673 toolbarItems.push( item );
677 if ( ! buttonGroup ) {
683 toolbarItems.push( buttonGroup );
686 if ( editor.buttons[ item ] ) {
688 item = editor.buttons[ itemName ];
690 if ( typeof item === 'function' ) {
694 item.type = item.type || 'button';
696 if ( settings.toolbar_items_size ) {
697 item.size = settings.toolbar_items_size;
700 item = Factory.create( item );
702 buttonGroup.items.push( item );
704 if ( editor.initialized ) {
705 bindSelectorChanged();
707 editor.on( 'init', bindSelectorChanged );
714 toolbar = Factory.create( {
717 classes: 'toolbar-grp inline-toolbar-grp',
727 toolbar.bottom = bottom;
729 function reposition() {
730 if ( ! currentSelection ) {
734 var scrollX = window.pageXOffset || document.documentElement.scrollLeft,
735 scrollY = window.pageYOffset || document.documentElement.scrollTop,
736 windowWidth = window.innerWidth,
737 windowHeight = window.innerHeight,
738 iframeRect = mceIframe ? mceIframe.getBoundingClientRect() : {
741 bottom: windowHeight,
746 toolbar = this.getEl(),
747 toolbarWidth = toolbar.offsetWidth,
748 toolbarHeight = toolbar.offsetHeight,
749 selection = currentSelection.getBoundingClientRect(),
750 selectionMiddle = ( selection.left + selection.right ) / 2,
753 spaceNeeded = toolbarHeight + margin + buffer,
754 wpAdminbarBottom = wpAdminbar ? wpAdminbar.getBoundingClientRect().bottom : 0,
755 mceToolbarBottom = mceToolbar ? mceToolbar.getBoundingClientRect().bottom : 0,
756 mceStatusbarTop = mceStatusbar ? windowHeight - mceStatusbar.getBoundingClientRect().top : 0,
757 wpStatusbarTop = wpStatusbar ? windowHeight - wpStatusbar.getBoundingClientRect().top : 0,
758 blockedTop = Math.max( 0, wpAdminbarBottom, mceToolbarBottom, iframeRect.top ),
759 blockedBottom = Math.max( 0, mceStatusbarTop, wpStatusbarTop, windowHeight - iframeRect.bottom ),
760 spaceTop = selection.top + iframeRect.top - blockedTop,
761 spaceBottom = windowHeight - iframeRect.top - selection.bottom - blockedBottom,
762 editorHeight = windowHeight - blockedTop - blockedBottom,
768 if ( spaceTop >= editorHeight || spaceBottom >= editorHeight ) {
769 this.scrolling = true;
771 this.scrolling = false;
775 // Add offset in iOS to move the menu over the image, out of the way of the default iOS menu.
776 if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) {
778 iosOffsetBottom = 46;
782 if ( spaceBottom >= spaceNeeded ) {
783 className = ' mce-arrow-up';
784 top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom;
785 } else if ( spaceTop >= spaceNeeded ) {
786 className = ' mce-arrow-down';
787 top = selection.top + iframeRect.top + scrollY - toolbarHeight - margin + iosOffsetTop;
790 if ( spaceTop >= spaceNeeded ) {
791 className = ' mce-arrow-down';
792 top = selection.top + iframeRect.top + scrollY - toolbarHeight - margin + iosOffsetTop;
793 } else if ( spaceBottom >= spaceNeeded && editorHeight / 2 > selection.bottom + iframeRect.top - blockedTop ) {
794 className = ' mce-arrow-up';
795 top = selection.bottom + iframeRect.top + scrollY - iosOffsetBottom;
799 if ( typeof top === 'undefined' ) {
800 top = scrollY + blockedTop + buffer + iosOffsetBottom;
803 left = selectionMiddle - toolbarWidth / 2 + iframeRect.left + scrollX;
805 if ( selection.left < 0 || selection.right > iframeRect.width ) {
806 left = iframeRect.left + scrollX + ( iframeRect.width - toolbarWidth ) / 2;
807 } else if ( toolbarWidth >= windowWidth ) {
808 className += ' mce-arrow-full';
810 } else if ( ( left < 0 && selection.left + toolbarWidth > windowWidth ) || ( left + toolbarWidth > windowWidth && selection.right - toolbarWidth < 0 ) ) {
811 left = ( windowWidth - toolbarWidth ) / 2;
812 } else if ( left < iframeRect.left + scrollX ) {
813 className += ' mce-arrow-left';
814 left = selection.left + iframeRect.left + scrollX;
815 } else if ( left + toolbarWidth > iframeRect.width + iframeRect.left + scrollX ) {
816 className += ' mce-arrow-right';
817 left = selection.right - toolbarWidth + iframeRect.left + scrollX;
820 // No up/down arrows on the menu over images in iOS.
821 if ( tinymce.Env.iOS && currentSelection.nodeName === 'IMG' ) {
822 className = className.replace( / ?mce-arrow-(up|down)/g, '' );
825 toolbar.className = toolbar.className.replace( / ?mce-arrow-[\w]+/g, '' ) + className;
827 DOM.setStyles( toolbar, {
835 toolbar.on( 'show', function() {
839 toolbar.on( 'keydown', function( event ) {
840 if ( event.keyCode === 27 ) {
846 editor.on( 'remove', function() {
850 toolbar.reposition = reposition;
851 toolbar.hide().renderTo( document.body );
856 editor.shortcuts.add( 'alt+119', '', function() {
859 if ( activeToolbar ) {
860 node = activeToolbar.find( 'toolbar' )[0];
861 node && node.focus( true );
865 editor.on( 'nodechange', function( event ) {
866 var collapsed = editor.selection.isCollapsed();
869 element: event.element,
870 parents: event.parents,
874 editor.fire( 'wptoolbar', args );
876 currentSelection = args.selection || args.element;
878 if ( activeToolbar && activeToolbar !== args.toolbar ) {
879 activeToolbar.hide();
882 if ( args.toolbar ) {
883 if ( activeToolbar !== args.toolbar ) {
884 activeToolbar = args.toolbar;
885 activeToolbar.show();
887 activeToolbar.reposition();
890 activeToolbar = false;
894 editor.on( 'focus', function() {
895 if ( activeToolbar ) {
896 activeToolbar.show();
900 function hide( event ) {
901 if ( activeToolbar ) {
902 if ( activeToolbar.tempHide || event.type === 'hide' ) {
903 activeToolbar.hide();
904 activeToolbar = false;
905 } else if ( ( event.type === 'resize' || event.type === 'scroll' ) && ! activeToolbar.blockHide ) {
906 clearTimeout( timeout );
908 timeout = setTimeout( function() {
909 if ( activeToolbar && typeof activeToolbar.show === 'function' ) {
910 activeToolbar.scrolling = false;
911 activeToolbar.show();
915 activeToolbar.scrolling = true;
916 activeToolbar.hide();
921 DOM.bind( window, 'resize scroll', hide );
922 editor.dom.bind( editor.getWin(), 'resize scroll', hide );
924 editor.on( 'remove', function() {
925 DOM.unbind( window, 'resize scroll', hide );
926 editor.dom.unbind( editor.getWin(), 'resize scroll', hide );
929 editor.on( 'blur hide', hide );
931 editor.wp = editor.wp || {};
932 editor.wp._createToolbar = create;
937 // Expose some functions (back-compat)
946 }( window.tinymce ));