CKEDITOR.document.getBody().append( element ); }, watch: function( element, preventFunc ) { this.watched.push( { element: element, placeholder: new CKEDITOR.dom.element( 'div' ), isFixed: false, preventFunc: preventFunc } ); }, checkAll: function() { for ( var i = 0; i < this.watched.length; i++ ) { this.check( this.watched[ i ] ); } }, check: function( element ) { var isFixed = element.isFixed; var shouldBeFixed = this.shouldBeFixed( element ); // Nothing to be done. if ( isFixed === shouldBeFixed ) { return; } var placeholder = element.placeholder; if ( isFixed ) { // Unfixing. element.element.insertBefore( placeholder ); placeholder.remove(); element.element.removeStyle( 'margin' ); this.active.splice( CKEDITOR.tools.indexOf( this.active, element ), 1 ); } else { // Fixing. placeholder.setStyle( 'width', element.element.getSize( 'width' ) + 'px' ); placeholder.setStyle( 'height', element.element.getSize( 'height' ) + 'px' ); placeholder.setStyle( 'margin-bottom', element.element.getComputedStyle( 'margin-bottom' ) ); placeholder.setStyle( 'display', element.element.getComputedStyle( 'display' ) ); placeholder.insertAfter( element.element ); this.staticContainer.append( element.element ); this.active.push( element ); } element.isFixed = !element.isFixed; }, shouldBeFixed: function( element ) { if ( element.preventFunc && element.preventFunc() ) { return false; } // If element is already fixed we are checking it's placeholder. var related = ( element.isFixed ? element.placeholder : element.element ), clientRect = related.$.getBoundingClientRect(), staticHeight = this.staticContainer.getSize('height' ), elemHeight = element.element.getSize( 'height' ); if ( element.isFixed ) { return ( clientRect.top + elemHeight < staticHeight ); } else { return ( clientRect.top < staticHeight ); } } }; positionSticky.init(); CKEDITOR.document.getWindow().on( 'scroll', new CKEDITOR.tools.eventsBuffer( 100, positionSticky.checkAll, positionSticky ).input ); // Make the toolbar sticky. positionSticky.watch( CKEDITOR.document.findOne( '.editors-container' ) ); // Help button and help-content. ( function() { var helpButton = CKEDITOR.document.getById( 'help' ), helpContent = CKEDITOR.document.getById( 'help-content' ); // Don't show help button on IE8 because it's unsupported by Pico Modal. if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) { helpButton.hide(); } else { // Display help modal when the button is clicked. helpButton.on( 'click', function( evt ) { SF.modal( { // Clone modal content from DOM. content: helpContent.getHtml(), afterCreate: function( modal ) { // Enable modal content button to close the modal. new CKEDITOR.dom.element( modal.modalElem() ).findOne( '.help-content-close' ).once( 'click', modal.close ); } } ).show(); } ); } } )(); } )();