Ticket #146: fck_image.js.patch

File fck_image.js.patch, 5.1 KB (added by Alfonso Martínez de Lizarrondo, 17 years ago)
  • fck_image.js

    RCS file: /usr/local/cvs/cm4/web/editor/dialog/fck_image/fck_image.js,v
    retrieving revision 1.3
    diff -u -r1.3 fck_image.js
     
    3939if ( !FCKConfig.ImageDlgHideAdvanced )
    4040        window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ;
    4141
     42window.parent.AddTab( 'Map', FCKLang.DlgImgMapTab ) ;
     43
    4244// Function called when a dialog tag is selected.
    4345function OnDialogTabChange( tabCode )
    4446{
     
    4648        ShowE('divLink'         , ( tabCode == 'Link' ) ) ;
    4749        ShowE('divUpload'       , ( tabCode == 'Upload' ) ) ;
    4850        ShowE('divAdvanced'     , ( tabCode == 'Advanced' ) ) ;
     51        ShowE('divMap'          , ( tabCode == 'Map' ) ) ;
    4952}
    5053
    5154// Get the selected image (if available).
     
    163166        GetE('txtAttClasses').value             = oImage.getAttribute('class',2) || '' ;
    164167        GetE('txtLongDesc').value               = oImage.longDesc ;
    165168
     169        // Image Map Attributes
     170        if( oImage.getAttribute('usemap') )
     171        {
     172                GetE('txtMapName').value = oImage.getAttribute('usemap',2).substr(1) ;
     173                // get map element
     174                var aMaps = FCK.EditorDocument.getElementsByTagName( 'MAP' ) ;
     175                var oMaps;
     176                for ( var i = 0 ; i < aMaps.length ; i++ )
     177                {
     178                        if ( aMaps[i].name == oImage.getAttribute('usemap',2).substr(1) )
     179                        {
     180                                oMaps = aMaps[i];
     181                        }
     182                }
     183                // get area elements
     184                if( oMaps.getElementsByTagName( 'AREA' ).length > 0 )
     185                {
     186                        var aAreas = oMaps.getElementsByTagName( 'AREA' );
     187                        for ( var i = 1 ; i < aAreas.length+1 ; i++ )
     188                        {
     189                                var oAreas = aAreas[i-1];
     190                                GetE('txtAreaCoords'+i).value = oAreas.getAttribute('coords',2);
     191                                GetE('txtAreaShape'+i).value = oAreas.getAttribute('shape',2);
     192                                GetE('txtAreaAlt'+i).value = oAreas.getAttribute('alt',2);
     193                                GetE('txtAreaURL'+i).value = oAreas.getAttribute('href',2);
     194                        }
     195                }
     196        }
     197
    166198        if ( oEditor.FCKBrowserInfo.IsIE )
    167199                GetE('txtAttStyle').value       = oImage.style.cssText ;
    168200        else
     
    252284                SetAttribute( oLink, 'target', GetE('cmbLnkTarget').value ) ;
    253285        }
    254286
     287        // Image Map Attributes
     288        var aMaps = FCK.EditorDocument.getElementsByTagName( 'MAP' ) ;
     289        if( GetE('txtMapName').value || aMaps.length)
     290        {
     291                // update existing
     292                if( aMaps.length > 0  && oImage.getAttribute('usemap') )
     293                {
     294                        var oMaps;
     295                        for ( var i = 0 ; i < aMaps.length ; i++ )
     296                        {
     297                                if ( aMaps[i].name == oImage.getAttribute('usemap').substr(1) )
     298                                        oMaps = aMaps[i];
     299                        }
     300                        // delete image map if name removed
     301                        if( !GetE('txtMapName').value )
     302                        {
     303                                oImage.removeAttribute('usemap');
     304                                oEditor.FCKSelection.SelectNode( oMaps );
     305                                oEditor.FCKSelection.Delete();
     306                                oEditor.FCKSelection.SelectNode( oImage );
     307                        }
     308                        else
     309                        {
     310                                SetAttribute( oImage, 'usemap', '#' + GetE('txtMapName').value ) ;
     311                                SetAttribute( oMaps, 'name', GetE('txtMapName').value ) ;
     312                                // get area elements
     313                                if( oMaps.getElementsByTagName( 'AREA' ).length > 0 )
     314                                {
     315                                        var aAreas = oMaps.getElementsByTagName( 'AREA' ) ;
     316                                        for( var i = 1 ; i < 6 ; i++ )
     317                                        {
     318                                                var oAreas = aAreas[i-1] ;
     319                                                // update existing area
     320                                                if( oAreas )
     321                                                {
     322                                                        // delete area if url and coords removed
     323                                                        if( GetE('txtAreaCoords'+i).value == '' && GetE('txtAreaURL'+i).value == '' )
     324                                                        {
     325                                                                oMaps.removeChild( oAreas );
     326                                                                i--;
     327                                                        }
     328                                                        else
     329                                                        {
     330                                                                SetAttribute( oAreas, 'coords', GetE('txtAreaCoords'+i).value ) ;
     331                                                                SetAttribute( oAreas, 'shape', GetE('txtAreaShape'+i).value ) ;
     332                                                                SetAttribute( oAreas, 'alt', GetE('txtAreaAlt'+i).value ) ;
     333                                                                SetAttribute( oAreas, 'href', GetE('txtAreaURL'+i).value ) ;
     334                                                        }
     335                                                }
     336                                                else
     337                                                {
     338                                                        // create new area
     339                                                        if( GetE('txtAreaCoords'+i).value )
     340                                                        {
     341                                                                var oArea = FCK.EditorDocument.createElement( 'AREA' ) ;
     342                                                                SetAttribute( oArea, 'coords', GetE('txtAreaCoords'+i).value ) ;
     343                                                                SetAttribute( oArea, 'shape', GetE('txtAreaShape'+i).value ) ;
     344                                                                SetAttribute( oArea, 'alt', GetE('txtAreaAlt'+i).value ) ;
     345                                                                SetAttribute( oArea, 'href', GetE('txtAreaURL'+i).value ) ;
     346                                                                oMaps.appendChild( oArea );
     347                                                        }
     348                                                }
     349                                        }
     350                                }
     351                        }
     352                }
     353                else
     354                {
     355                        oEditor.FCKSelection.Collapse( false ) ;
     356                        // create new image map
     357                        var oMap = FCK.CreateElement( 'MAP' ) ;
     358                        SetAttribute( oMap, 'name', GetE('txtMapName').value ) ;
     359                        for( var i = 1 ; i < 6 ; i++ )
     360                        {
     361                                if( GetE('txtAreaCoords'+i).value )
     362                                {
     363                                        var oArea = FCK.EditorDocument.createElement( 'AREA' ) ;
     364                                        SetAttribute( oArea, 'coords', GetE('txtAreaCoords'+i).value ) ;
     365                                        SetAttribute( oArea, 'shape', GetE('txtAreaShape'+i).value ) ;
     366                                        SetAttribute( oArea, 'alt', GetE('txtAreaAlt'+i).value ) ;
     367                                        SetAttribute( oArea, 'href', GetE('txtAreaURL'+i).value ) ;
     368                                        oMap.appendChild( oArea );
     369                                }
     370                        }
     371                        oEditor.FCKSelection.SelectNode(oImage);
     372                        SetAttribute( oImage, 'usemap', '#' + GetE('txtMapName').value ) ;
     373                }
     374        }
     375
    255376        return true ;
    256377}
    257378
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy