From b2b30809d66bb8036d7c58a1efc11b069c7c3613 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Wed, 8 Jul 2009 07:39:55 +0200 Subject: [PATCH] [svn r21869] FS#2867 - The FCKEditor: Functionality has been implemented for providing differnt toolbars for normal-sized and maximized editor. --- .../plugins/customizations/fckplugin.js | 194 ++++++++++++++++++ main/inc/lib/fckeditor/fckeditor.php | 3 +- .../lib/fckeditor/toolbars/introduction.php | 6 + 3 files changed, 201 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/fckeditor/editor/plugins/customizations/fckplugin.js b/main/inc/lib/fckeditor/editor/plugins/customizations/fckplugin.js index 017e72f81a..82b22a0d6a 100644 --- a/main/inc/lib/fckeditor/editor/plugins/customizations/fckplugin.js +++ b/main/inc/lib/fckeditor/editor/plugins/customizations/fckplugin.js @@ -695,6 +695,200 @@ FCKSaveCommand.prototype.Execute = function() oForm.submit.click() ; } +// This is a modification of the FitWindow command. +// Functionality has been implemented for providing differnt toolbars for normal-sized and maximized editor. +FCKFitWindow.prototype.Execute = function() +{ + var eEditorFrame = window.frameElement ; + var eEditorFrameStyle = eEditorFrame.style ; + + var eMainWindow = parent ; + var eDocEl = eMainWindow.document.documentElement ; + var eBody = eMainWindow.document.body ; + var eBodyStyle = eBody.style ; + var eParent ; + + // Save the current selection and scroll position. + var oRange, oEditorScrollPos ; + if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) + { + oRange = new FCKDomRange( FCK.EditorWindow ) ; + oRange.MoveToSelection() ; + oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ; + } + else + { + var eTextarea = FCK.EditingArea.Textarea ; + oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ; + oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ; + } + + // No original style properties known? Go fullscreen. + if ( !this.IsMaximized ) + { + // Registering an event handler when the window gets resized. + if( FCKBrowserInfo.IsIE ) + eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ; + else + eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ; + + // Save the scrollbars position. + this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ; + + // Save and reset the styles for the entire node tree. They could interfere in the result. + eParent = eEditorFrame ; + // The extra () is to avoid a warning with strict error checking. This is ok. + while( (eParent = eParent.parentNode) ) + { + if ( eParent.nodeType == 1 ) + { + eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ; + eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ; + } + } + + // Hide IE scrollbars (in strict mode). + if ( FCKBrowserInfo.IsIE ) + { + this.documentElementOverflow = eDocEl.style.overflow ; + eDocEl.style.overflow = 'hidden' ; + eBodyStyle.overflow = 'hidden' ; + } + else + { + // Hide the scroolbars in Firefox. + eBodyStyle.overflow = 'hidden' ; + eBodyStyle.width = '0px' ; + eBodyStyle.height = '0px' ; + } + + // Save the IFRAME styles. + this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ; + + // Resize. + var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ; + + eEditorFrameStyle.position = "absolute"; + eEditorFrame.offsetLeft ; // Kludge for Safari 3.1 browser bug, do not remove. See #2066. + eEditorFrameStyle.zIndex = FCKConfig.FloatingPanelsZIndex - 1; + eEditorFrameStyle.left = "0px"; + eEditorFrameStyle.top = "0px"; + eEditorFrameStyle.width = oViewPaneSize.Width + "px"; + eEditorFrameStyle.height = oViewPaneSize.Height + "px"; + + // Giving the frame some (huge) borders on his right and bottom + // side to hide the background that would otherwise show when the + // editor is in fullsize mode and the window is increased in size + // not for IE, because IE immediately adapts the editor on resize, + // without showing any of the background oddly in firefox, the + // editor seems not to fill the whole frame, so just setting the + // background of it to white to cover the page laying behind it anyway. + if ( !FCKBrowserInfo.IsIE ) + { + eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ; + eEditorFrameStyle.backgroundColor = "white"; + } + + // Scroll to top left. + eMainWindow.scrollTo(0, 0); + + // Is the editor still not on the top left? Let's find out and fix that as well. (Bug #174) + var editorPos = FCKTools.GetWindowPosition( eMainWindow, eEditorFrame ) ; + if ( editorPos.x != 0 ) + eEditorFrameStyle.left = ( -1 * editorPos.x ) + "px" ; + if ( editorPos.y != 0 ) + eEditorFrameStyle.top = ( -1 * editorPos.y ) + "px" ; + + // Added code: Loading a toolbar for maximized editor. + var toolbar = FCKURLParams['Toolbar'] + 'Maximized' ; + if ( FCKConfig.ToolbarSets[toolbar] ) + { + var oEditor = FCKeditorAPI.GetInstance(FCK.Name) ; + if ( toolbar != oEditor.ToolbarSet.Name ) + { + oEditor.ToolbarSet.Load( toolbar ) ; + } + } + // + + this.IsMaximized = true ; + } + else // Resize to original size. + { + // Added code: Loading a toolbar for editor with "normal" sizes. + var toolbar = FCKURLParams['Toolbar'] ; + if ( FCKConfig.ToolbarSets[toolbar] ) + { + var oEditor = FCKeditorAPI.GetInstance(FCK.Name) ; + if ( toolbar != oEditor.ToolbarSet.Name ) + { + oEditor.ToolbarSet.Load( toolbar ) ; + } + } + // + + // Remove the event handler of window resizing. + if( FCKBrowserInfo.IsIE ) + eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ; + else + eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ; + + // Restore the CSS position for the entire node tree. + eParent = eEditorFrame ; + // The extra () is to avoid a warning with strict error checking. This is ok. + while( (eParent = eParent.parentNode) ) + { + if ( eParent._fckSavedStyles ) + { + FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ; + eParent._fckSavedStyles = null ; + } + } + + // Restore IE scrollbars + if ( FCKBrowserInfo.IsIE ) + eDocEl.style.overflow = this.documentElementOverflow ; + + // Restore original size + FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ; + + // Restore the window scroll position. + eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ; + + this.IsMaximized = false ; + } + + FCKToolbarItems.GetItem('FitWindow').RefreshState() ; + + // It seams that Firefox restarts the editing area when making this changes. + // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special + //configuration, like DisableFFTableHandles and DisableObjectResizing get + //lost, so we must reset it. Also, the cursor position and selection are + //also lost, even if you comment the following line (MakeEditable). + // if ( FCKBrowserInfo.IsGecko10 ) // Initially I thought it was a FF 1.0 only problem. + if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) + FCK.EditingArea.MakeEditable() ; + + FCK.Focus() ; + + // Restore the selection and scroll position of inside the document. + if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) + { + oRange.Select() ; + FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ; + } + else + { + if ( !FCKBrowserInfo.IsIE ) + { + eTextarea.selectionStart = oRange[0] ; + eTextarea.selectionEnd = oRange[1] ; + } + eTextarea.scrollLeft = oEditorScrollPos[0] ; + eTextarea.scrollTop = oEditorScrollPos[1] ; + } +} + /* ************************************************************************************** diff --git a/main/inc/lib/fckeditor/fckeditor.php b/main/inc/lib/fckeditor/fckeditor.php index d225710fc4..48956e443c 100644 --- a/main/inc/lib/fckeditor/fckeditor.php +++ b/main/inc/lib/fckeditor/fckeditor.php @@ -364,11 +364,10 @@ class FCKeditor if (!empty($toolbar_set) && $toolbar_set != 'Default') { if (is_array($value)) { foreach ($value as $toolbar_name => $toolbar_data) { - if ($toolbar_set == $toolbar_name || $toolbar_set_maximized == $toolbar_name) { + if ($toolbar_set == $toolbar_name || $toolbar_set_maximized == $toolbar_name) { if (!isset($this->Config[$key][$toolbar_name])) { $this->Config[$key][$toolbar_name] = $toolbar_data; } - break; } } } diff --git a/main/inc/lib/fckeditor/toolbars/introduction.php b/main/inc/lib/fckeditor/toolbars/introduction.php index fbd53f6219..7ceabaeb11 100644 --- a/main/inc/lib/fckeditor/toolbars/introduction.php +++ b/main/inc/lib/fckeditor/toolbars/introduction.php @@ -12,3 +12,9 @@ $config['ToolbarSets']['Introduction'] = array( array('Bold','Italic','Underline'), array('JustifyLeft','JustifyCenter','JustifyRight') ); +/* +$config['ToolbarSets']['IntroductionMaximized'] = array( + array('NewPage','FitWindow','-','PasteWord','-','Undo','Redo','-','SelectAll'), + ... +); +*/