+ if ( windowPos + adminbarHeight > minTop ) {
+ minTop = windowPos + adminbarHeight;
+ }
+ }
+
+ if ( top && minTop && ( minTop + buffer > top ) ) {
+ top = minTop + buffer;
+ className = '';
+ }
+
+ left = boundaryMiddle - toolbarHalf;
+ left += iframePos.x;
+
+ if ( boundary.left < 0 || boundary.right > iframeWidth ) {
+ left = iframePos.x + ( iframeWidth - toolbarWidth ) / 2;
+ } else if ( toolbarWidth >= windowWidth ) {
+ className += ' mce-arrow-full';
+ left = 0;
+ } else if ( ( left < 0 && boundary.left + toolbarWidth > windowWidth ) ||
+ ( left + toolbarWidth > windowWidth && boundary.right - toolbarWidth < 0 ) ) {
+
+ left = ( windowWidth - toolbarWidth ) / 2;
+ } else if ( left < iframePos.x ) {
+ className += ' mce-arrow-left';
+ left = boundary.left + iframePos.x;
+ } else if ( left + toolbarWidth > iframeWidth + iframePos.x ) {
+ className += ' mce-arrow-right';
+ left = boundary.right - toolbarWidth + iframePos.x;
+ }
+
+ toolbarNode.className = toolbarNode.className.replace( / ?mce-arrow-[\w]+/g, '' );
+ toolbarNode.className += className;
+
+ DOM.setStyles( toolbarNode, { 'left': left, 'top': top } );
+
+ return this;
+ }
+
+ toolbar.on( 'show', function() {
+ currentToolbar = this;
+ this.reposition();
+ } );
+
+ toolbar.on( 'hide', function() {
+ currentToolbar = false;
+ } );
+
+ toolbar.on( 'keydown', function( event ) {
+ if ( event.keyCode === 27 ) {
+ this.hide();
+ editor.focus();
+ }
+ } );
+
+ toolbar.on( 'remove', function() {
+ DOM.unbind( window, 'resize scroll', hide );
+ editor.dom.unbind( editor.getWin(), 'resize scroll', hide );
+ editor.off( 'blur hide', hide );
+ } );
+
+ editor.once( 'init', function() {
+ DOM.bind( window, 'resize scroll', hide );
+ editor.dom.bind( editor.getWin(), 'resize scroll', hide );
+ editor.on( 'blur hide', hide );
+ } );
+
+ toolbar.reposition = reposition;
+ toolbar.hide().renderTo( document.body );
+
+ return toolbar;
+ }
+
+ editor.shortcuts.add( 'alt+119', '', function() {
+ var node;
+
+ if ( currentToolbar ) {
+ node = currentToolbar.find( 'toolbar' )[0];
+ node && node.focus( true );
+ }
+ } );
+
+ editor.on( 'nodechange', function( event ) {
+ var collapsed = editor.selection.isCollapsed();
+
+ var args = {
+ element: event.element,
+ parents: event.parents,
+ collapsed: collapsed
+ };
+
+ editor.fire( 'wptoolbar', args );
+
+ currentSelection = args.selection || args.element;
+
+ currentToolbar && currentToolbar.hide();
+ args.toolbar && args.toolbar.show();
+ } );
+
+ editor.wp = editor.wp || {};
+ editor.wp._createToolbar = create;
+ }());
+
+ function noop() {}