OW2 Consortium telosys

Rev

Blame | Last modification | View Log | RSS feed

//----------------------------------------------------------------------
// Rich-Text Editor functions
//----------------------------------------------------------------------
function fwkRTEButtonMouseOver(obj, sImage )
{
        obj.style.borderWidth = "1px" ;
        obj.style.borderColor = "#999999" ;
        obj.style.margin      = "0px" ;  
        obj.src = sImage ;
}
//----------------------------------------------------------------------
function fwkRTEButtonMouseOut(obj, sImage )
{
        obj.style.borderWidth = "0px" ;
        obj.style.borderColor = "transparent" ;
        obj.style.margin      = "1px" ;   
        obj.src = sImage ;
}
//----------------------------------------------------------------------
function fwkRTEGetText( sId )
{
        var doc = fwkGetIFrameDocument( sId );
        if ( doc != null )
        {
                return doc.body.innerHTML ;
        }
}
//----------------------------------------------------------------------
function fwkRTESetText( sId, sText )
{
        var doc = fwkGetIFrameDocument( sId );
        if ( doc != null )
        {
                doc.body.innerHTML = sText ;
        }
}
//----------------------------------------------------------------------
function fwkRTEClearText( arg ) // IFRAME id or IFRAME object
{
        var doc = fwkGetIFrameDocument( arg );
        /**
        var doc = null ;
        if ( typeof arg == "string" )
        {
                doc = fwkGetIFrameDocument( arg );
        }
        else if ( arg.body )
        {
                doc = arg ;
        }
        else
        {
                fwkError ( "fwkRTEClearText() invalid argument type ! ( type = " + typeof arg + " )" ) ;
                return ;
        }
        **/
        if ( doc != null )
        {
                doc.body.innerHTML = "" ;               
        }
        else
        {
                fwkError ( "fwkRTEClearText() document is null !" ) ;
        }
}
//----------------------------------------------------------------------
function fwkRTEDisable( arg ) // IFRAME id or IFRAME object
{
        var doc = fwkGetIFrameDocument( arg );
        if ( doc != null )
        {
                alert ( "set designMode OFF" );
                doc.designMode = "off"; // IE and FF/Moz
        }
        else
        {
                fwkError ( "fwkRTEDisable() document is null !" ) ;
        }
}
//----------------------------------------------------------------------
function fwkRTEShowSource( sId )
{
        var doc = fwkGetIFrameDocument( sId );
        if ( doc != null )
        {
                alert ( doc.body.innerHTML ) ;
        }
}
//----------------------------------------------------------------------
function fwkRTEInit( sIFrameId, sContent )
{
        var doc = fwkGetIFrameDocument( sIFrameId );
        if ( doc != null )
        {
                doc.open();
                if ( sContent != null )
                {
                        doc.write( sContent );
                }
                else
                {
                        doc.write( "   " ); // NB : at least 2 blanks to avoid <PRE> with IE
                }
                doc.close();
        }
        // Make the iframe editable in both Mozilla and IE
        //doc.body.contentEditable = true; // IE ( not FF or Mozilla )
        doc.designMode = "on"; // IE and FF/Moz
}
//----------------------------------------------------------------------
function fwkRTESelectFontSize( oCombo, sIFrameId )
{
        var iIndex = oCombo.selectedIndex ;
        if ( iIndex > 0 )
        {
                oCombo.selectedIndex = 0 ; // Reset Combo
                var sFontSize  = oCombo.options[ iIndex ].value ;
                //alert ( oCombo.selectedIndex + " : " + sFontSize );
                fwkRTEFormatText('FontSize', sIFrameId, sFontSize );
        }
        else
        {
                fwkRTEFocus( sIFrameId ); // Set focus  ????
        }
}
//----------------------------------------------------------------------
function fwkRTESelectFontName( oCombo, sIFrameId )
{
        var iIndex = oCombo.selectedIndex ;
        if ( iIndex > 0 )
        {
                oCombo.selectedIndex = 0 ; // Reset Combo
                var sFontName  = oCombo.options[ iIndex ].value ;
                //alert ( oCombo.selectedIndex + " : " + sFontName );
                fwkRTEFormatText('FontName', sIFrameId, sFontName );
        }
        else
        {
                fwkRTEFocus( sIFrameId ); // Set focus  ????
        }
}
//----------------------------------------------------------------------
function fwkRTEFocus( sIFrameId )
{
        var oFrame = document.getElementById(sIFrameId)
        if (oFrame != null)
        {
                oFrame.contentWindow.focus();
        }
        else
        {
                fwkError ( "fwkRTEFocus() : Cannot found the frame with id = " + sIFrameId ) ;
        }
}
//----------------------------------------------------------------------


//----------------------------------------------------------------------
function fwkRTEFormatText(sCommand, sIFrameId, sCommandParam) 
{
        // When user clicks toolbar button make sure it always targets its respective WYSIWYG
        document.getElementById(sIFrameId).contentWindow.focus();
        
        var doc = fwkGetIFrameDocument( sIFrameId );

        if ( sCommand == 'BackColor' ) // FireFox/Mozilla compatibility : replace 'BackColor' by 'hilitecolor'
        {
                //alert ("sCommand is 'BackColor' ");
                //if ( ! ( "contentEditable" in doc.body ) ) // not IE ( => FF or Mozilla )
                if ( navigator.appName == "Netscape" ) // FF or Mozilla
                {
                        sCommand = 'hilitecolor' ;  // FireFox/Mozilla command for partial Background Color 
                }
        }
        
        // Commands with parameter 
        if ( sCommand == "FontSize" || sCommand == "FontName" || sCommand == 'ForeColor' || sCommand == 'BackColor' || sCommand == 'hilitecolor' ) 
        {
                doc.execCommand(sCommand, false, sCommandParam);
        }       
        else // Every other command
        {
                doc.execCommand(sCommand, false, null);
        }
};

//----------------------------------------------------------------------------------
// Class ColorPicker
//----------------------------------------------------------------------------------
function ColorPicker( sIdEditorFrame, sIdDivColor, sIdFieldColor, sIdFieldCode )
{
        //------------------------------------------------------------------------------
        // PRIVATE INSTANCE ATTRIBUTE(S)
        //------------------------------------------------------------------------------
        var _sIdEditorFrame = sIdEditorFrame ;
        var _oDivColor   = document.getElementById(sIdDivColor) ;
        var _oFieldColor = document.getElementById(sIdFieldColor) ;
        var _oFieldCode  = document.getElementById(sIdFieldCode) ;
        var _sCommand    = null ;
        var _bPositionSet = false ;

        if ( _oDivColor == null )
        {
                fwkError("Color Picker : Cannot found DIV for color picker ! Id = " + sIdDivColor );
        }
        if ( _oFieldColor == null )
        {
                fwkError("Color Picker : Cannot found field for color preview ! Id = " + sIdFieldColor );
        }
        if ( _oFieldCode == null )
        {
                fwkError("Color Picker : Cannot found field for color code ! Id = " + sIdFieldCode );
        }

        //------------------------------------------------------------------------------
        // METHODS
        //------------------------------------------------------------------------------
        this.preview = function(color)
        {
                if ( _oFieldColor != null && _oFieldCode != null )
                {
                        _oFieldColor.style.backgroundColor = color;
                        _oFieldCode.value = color;
                }
                else
                {
                        fwkError("ColorPicker.preview() : fields are not initialized !");
                }
        }
        //----------------------------------------------------------------------
        this.open = function(sCommand, oFrom) 
        {
                if ( sCommand == null )
                {
                        fwkError("ColorPicker.open() : No 'command' argument !");
                        return ;
                }
                if ( oFrom == null )
                {
                        fwkError("ColorPicker.open() : No 'from' argument !");
                        return ;
                }
                if ( ! _bPositionSet )
                {
                        var position = fwkGetXY(oFrom); // X,Y of the caller object 
                        if ( position != null )
                        {
                                var x = position[0];
                                var y = position[1];
                                _oDivColor.style.left = x - 100 ;
                                _oDivColor.style.top  = y + 22 ;
                        }
                        _bPositionSet = true ;
                }
                
                _sCommand = sCommand ; // 'ForeColor' or 'BackColor'
                // Open (show) the color picker
                if ( _oDivColor != null )
                {
                        _oFieldColor.style.backgroundColor = "#FFFFFF";
                        _oFieldCode.value = "";
                        _oDivColor.style.zIndex = 9999;
                        _oDivColor.style.visibility = "visible" ;                       
                        _oFieldCode.focus(); // Just to set the focus on the DIV 
                }
        }
        //----------------------------------------------------------------------
        this.close = function() 
        {
                // Close (hide) the color picker
                if ( _oDivColor != null )
                {
                        _oDivColor.style.visibility = "hidden" ;
                }
                fwkRTEFocus( _sIdEditorFrame );
        }
        //----------------------------------------------------------------------
        this.select = function(color) 
        {
                // Close (hide) the color picker
                if ( _oDivColor != null )
                {
                        _oDivColor.style.visibility = "hidden" ;
                }
                
                // Format the text in the editor with the given color
                //fwkRTEFormatText('ForeColor', _sIdEditorFrame, color);
                fwkRTEFormatText(_sCommand, _sIdEditorFrame, color); // 'ForeColor' or 'BackColor'

                //var doc = fwkGetIFrameDocument( _sIdEditorFrame );
                //doc.execCommand('ForeColor', false, color);
                
                //window.event.cancelBubble = true ; // for IE and FF   
        }
}
//----------------------------------------------------------------------------------

Generated by GNU enscript 1.6.4.