/* * This piece of software has been created for Chamilo LMS * Mail: info@chamilo.org * * Copyright (c) 2008-2010 Ivan Tcholakov * Copyright (c) 2008-2009 Julio Montoya Armas * * For a full list of contributors detaining copyrights over parts of * the Chamilo software, see "documentation/credits.html". * The full license can be read in "documentation/license.html". * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * See the GNU General Public License for more details. */ /* * This plugin uses also fragments of the original source code of * FCKeditor version 2.6.4. * * FCKeditor - The text editor for Internet - http://www.fckeditor.net * Copyright (C) 2003-2009 Frederico Caldeira Knabben * * == BEGIN LICENSE == * * Licensed under the terms of any of the following licenses at your * choice: * * - GNU General Public License Version 2 or later (the "GPL") * http://www.gnu.org/licenses/gpl.html * * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") * http://www.gnu.org/licenses/lgpl.html * * - Mozilla Public License Version 1.1 or later (the "MPL") * http://www.mozilla.org/MPL/MPL-1.1.html * * == END LICENSE == */ /* ************************************************************************************** * Validation and initialization of configuration data. ************************************************************************************** */ // Data about available toolbar sets should be unserialized when it comes from php-side. if ( typeof FCKConfig.ToolbarSets == 'string' || FCKConfig.ToolbarSets instanceof ( String ) ) { FCKConfig.ToolbarSets = eval( '(' + FCKConfig.ToolbarSets + ')' ) ; } // Reading a setting which tells whether simple or advanced file manager is to be used. FCKConfig.AdvancedFileManager = null ; if ( FCKConfig.AdvancedFileManager ) { FCKConfig.AdvancedFileManager = FCKConfig.AdvancedFileManager.toString().toLowerCase() == 'true' ? true : false ; } else { // If this setting has been omited, let us try to detect it indirectly. FCKConfig.AdvancedFileManager = false ; if ( ( FCKConfig.ImageBrowserURL && FCKConfig.ImageBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) || ( FCKConfig.FlashBrowserURL && FCKConfig.FlashBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) || ( FCKConfig.MP3BrowserURL && FCKConfig.MP3BrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) || ( FCKConfig.VideoBrowserURL && FCKConfig.VideoBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) || ( FCKConfig.LinkBrowserURL && FCKConfig.LinkBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) || ( FCKConfig.MediaBrowserURL && FCKConfig.MediaBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) ) { FCKConfig.AdvancedFileManager = true ; } } // A flag to see whether a course documents repository is to be used. if ( FCKConfig.InDocument ) { FCKConfig.InDocument = FCKConfig.InDocument.toString().toLowerCase() == 'true' ? true : false ; } else { FCKConfig.InDocument = false ; } // Absolute URL to document repository root. if ( !FCKConfig.CreateDocumentWebDir ) { FCKConfig.CreateDocumentWebDir = '' ; } // Relative path from the document to the repository root. if ( !FCKConfig.CreateDocumentDir ) { FCKConfig.CreateDocumentDir = '' ; } // This is the base of the reltive URLs that are used by the dialog system. if ( !FCKConfig.BaseHref || FCKConfig.BaseHref.toString().length == 0 ) { if ( FCKConfig.BaseHref.toString().length == 0 ) { FCKConfig.BaseHref = FCKConfig.CreateDocumentWebDir ; } } if ( !FCKConfig.BaseHref ) { if ( typeof ( FCKConfig.BaseHref ) != 'string' ) { FCKConfig.BaseHref = FCKConfig.CreateDocumentWebDir ; } } FCKConfig.BaseHref = FCKConfig.BaseHref.toString(); if ( FCKConfig.BaseHref.length > 0 ) { if ( FCKConfig.BaseHref.substr( FCKConfig.BaseHref.length - 1 ) != '/' ) { FCKConfig.BaseHref = FCKConfig.BaseHref + '/' ; } } // The icon for the image properties button/command. if ( !FCKConfig.ImagesIcon ) { // This is the original icon from a chosen skin. //FCKConfig.ImagesIcon = 37 ; // We will use a better icon by default. FCKConfig.ImagesIcon = FCKConfig.PluginsPath + 'customizations/images/images_icon.gif' ; } /* ************************************************************************************** * Plugins. ************************************************************************************** */ // Checks whether a specified plugin has been loaded. FCK.Plugins.IsLoaded = function( name ) { if ( name ) { for ( var i = 0 ; i < FCKConfig.Plugins.Items.length ; i++ ) { if ( FCKConfig.Plugins.Items[i][0] == name ) { return true ; } } } return false ; } /* ************************************************************************************** * Customizations by Julio Montoya for enabling the external template selection dialog. * December, 2008 ************************************************************************************** */ FCKToolbarButton.prototype.ClickFrame = function() { var A = this._ToolbarButton || this; return FCK.ToolbarSet.CurrentInstance.Commands.GetCommand(A.CommandName).ExecuteFrame() ; }; FCKDialogCommand.prototype.ExecuteFrame = function() { return FCKDialog.OpenDialogFrame( 'FCKDialog_' + this.Name, this.Title, this.Url, this.Width, this.Height, this.CustomValue, this.Resizable ) ; }; var FCKDialog = ( function() { var topDialog ; var baseZIndex ; var cover ; // The document that holds the dialog. var topWindow = window.parent ; while ( topWindow.parent && topWindow.parent != topWindow ) { try { if ( topWindow.parent.document.domain != document.domain ) break ; if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 ) break ; } catch ( e ) { break ; } topWindow = topWindow.parent ; } var topDocument = topWindow.document ; var getZIndex = function() { if ( !baseZIndex ) baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ; return ++baseZIndex ; } // TODO : This logic is not actually working when reducing the window, only // when enlarging it. var resizeHandler = function() { if ( !cover ) return ; var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ; FCKDomTools.SetElementStyles( cover, { 'width' : Math.max( relElement.scrollWidth, relElement.clientWidth, topDocument.scrollWidth || 0 ) - 1 + 'px', 'height' : Math.max( relElement.scrollHeight, relElement.clientHeight, topDocument.scrollHeight || 0 ) - 1 + 'px' } ) ; } return { /** * Opens a dialog window using the standard dialog template. */ OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, resizable ) { if ( !topDialog ) this.DisplayMainCover() ; // Setup the dialog info to be passed to the dialog. var dialogInfo = { Title : dialogTitle, Page : dialogPage, Editor : window, CustomValue : customValue, // Optional TopWindow : topWindow } FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ; // Calculate the dialog position, centering it on the screen. var viewSize = FCKTools.GetViewPaneSize( topWindow ) ; var scrollPosition = { 'X' : 0, 'Y' : 0 } ; var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ; if ( useAbsolutePosition ) scrollPosition = FCKTools.GetScrollPosition( topWindow ) ; var iTop = Math.max( scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ; var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - width - 20 ) / 2, 0 ) ; // Setup the IFRAME that will hold the dialog. var dialog = topDocument.createElement( 'iframe' ) ; FCKTools.ResetStyles( dialog ) ; dialog.src = FCKConfig.BasePath + 'fckdialog.html' ; // Dummy URL for testing whether the code in fckdialog.js alone leaks memory. // dialog.src = 'about:blank'; dialog.frameBorder = 0 ; dialog.allowTransparency = true ; FCKDomTools.SetElementStyles( dialog, { 'position' : ( useAbsolutePosition ) ? 'absolute' : 'fixed', 'top' : iTop + 'px', 'left' : iLeft + 'px', 'width' : width + 'px', 'height' : height + 'px', 'zIndex' : getZIndex() } ) ; // Save the dialog info to be used by the dialog page once loaded. dialog._DialogArguments = dialogInfo ; // Append the IFRAME to the target document. topDocument.body.appendChild( dialog ) ; // Keep record of the dialog's parent/child relationships. dialog._ParentDialog = topDialog ; topDialog = dialog ; }, /* * Added by Julio Montoya for enabling the external template selection dialog. *************************************************************************************** */ OpenDialogFrame: function( dialogName, dialogTitle, dialogPage, width, height, customValue, resizable ) { //if ( !topDialog ) // this.DisplayMainCover() ; var dialogInfo = { Title: dialogTitle, Page: dialogPage, Editor: window, CustomValue: customValue, TopWindow : topWindow } ; // Disabled by Ivan Tcholakov, 09-JUL-2010. // Makes a problem on IE (see task #541). //FCK.ToolbarSet.CurrentInstance.Selection.Save(); //FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ; // var viewSize = FCKTools.GetViewPaneSize( topWindow ) ; var scrollPosition = { 'X': 0, 'Y': 0 } ; var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ; if (useAbsolutePosition) scrollPosition = FCKTools.GetScrollPosition( topWindow ) ; var iTop = Math.max(scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ; var iLeft = Math.max(scrollPosition.X + ( viewSize.Width - width - 20 ) / 2, 0 ) ; var dialog = topDocument.createElement( 'iframe' ) ; //FCKTools.ResetStyles( dialog ); dialog.src = FCKConfig.BasePath + 'fckdialogframe.html' ; dialog.frameBorder = 0 ; dialog.allowTransparency = true ; FCKDomTools.SetElementStyles(dialog, { 'position' : (useAbsolutePosition) ? 'absolute' : 'fixed', 'top' : iTop + 'px', 'left' : iLeft + 'px', 'width' : width + 'px', 'height' : height + 'px', 'zIndex' : getZIndex() }) ; dialog._DialogArguments = dialogInfo ; //E.body.appendChild( dialog ) ; // Removed by Ivan Tcholakov. // These statements are not relevant to the case, also they cause errors. //dialog._ParentDialog = topDialog ; //topDialog = dialog ; return dialogInfo ; }, /* *************************************************************************************** */ /** * (For internal use) * Called when the top dialog is closed. */ OnDialogClose : function( dialogWindow ) { var dialog = dialogWindow.frameElement ; FCKDomTools.RemoveNode( dialog ) ; if ( dialog._ParentDialog ) // Nested Dialog. { topDialog = dialog._ParentDialog ; // Modified by Ivan Tcholakov, caused errors during tests. //dialog._ParentDialog.contentWindow.SetEnabled( true ) ; try { dialog._ParentDialog.contentWindow.SetEnabled( true ) ; } catch ( ex ) { } // } else // First Dialog. { // Set the Focus in the browser, so the "OnBlur" event is not // fired. In IE, there is no need to do that because the dialog // already moved the selection to the editing area before // closing (EnsureSelection). Also, the Focus() call here // causes memory leak on IE7 (weird). if ( !FCKBrowserInfo.IsIE ) FCK.Focus() ; this.HideMainCover() ; // Bug #1918: Assigning topDialog = null directly causes IE6 to crash. setTimeout( function(){ topDialog = null ; }, 0 ) ; // Release the previously saved selection. FCK.ToolbarSet.CurrentInstance.Selection.Release() ; } }, DisplayMainCover : function() { // Setup the DIV that will be used to cover. cover = topDocument.createElement( 'div' ) ; FCKTools.ResetStyles( cover ) ; FCKDomTools.SetElementStyles( cover, { 'position' : 'absolute', 'zIndex' : getZIndex(), 'top' : '0px', 'left' : '0px', 'backgroundColor' : FCKConfig.BackgroundBlockerColor } ) ; FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ; // For IE6-, we need to fill the cover with a transparent IFRAME, // to properly block