Changeset 244

Show
Ignore:
Timestamp:
2007-04-09 20:12:02 (3 years ago)
Author:
mjk
Message:

added unified Find/Replace, iframe-based source view, find/replace in Source view

Location:
FCKeditor/branches/developers/mjk/editor
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/branches/developers/mjk/editor/dialog/fck_anchor.html

    r132 r244  
    6565        if ( oAnchor ) 
    6666                GetE('txtName').value = oAnchor.name ; 
    67         else 
    68                 oAnchor = null ; 
     67        else if (FCK.Selection.GetType() == 'Text') 
     68        //for text anchors, use the selected text as default anchor name 
     69        if (FCK.Selection.SelectedText()) 
     70            GetE('txtName').value = FCK.Selection.SelectedText(); 
     71 
    6972 
    7073        window.parent.SetOkButton( true ) ; 
  • FCKeditor/branches/developers/mjk/editor/dialog/fck_find.html

    r132 r244  
    2424<html xmlns="http://www.w3.org/1999/xhtml"> 
    2525<head> 
    26         <title></title> 
     26        <title>Find and Replace</title> 
    2727        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    2828        <meta content="noindex, nofollow" name="robots" /> 
     29    <script src="common/fck_dialog_common.js" type="text/javascript"></script> 
     30    <link href="common/fck_dialog_common.css" rel="stylesheet" type="text/css" /> 
    2931        <script type="text/javascript"> 
    3032 
    3133var oEditor = window.parent.InnerDialogLoaded() ; 
     34var FCK                 = oEditor.FCK ; 
     35var FCKLang             = oEditor.FCKLang ; 
     36var FCKConfig   = oEditor.FCKConfig ; 
     37var strFind     = ''; 
     38var bFirstFind  = true; 
     39 
     40window.parent.AddTab( 'Find', FCKLang.DlgFindTitle) ; 
     41window.parent.AddTab( 'Replace', FCKLang.DlgReplaceTitle) ; 
     42 
     43//show the tabs and hide the buttons -- because we draw buttons on the tabs 
     44parent.document.getElementById("TabsRow").style.display = ""; 
     45parent.document.getElementById("Buttons").style.display = "none"; 
     46 
     47// Function called when a dialog tag is selected. 
     48function OnDialogTabChange( tabCode ) 
     49{ 
     50        document.getElementById('replace').style.display = (tabCode == 'Find') ? 'none' : ''; 
     51    document.getElementById('replaceButtons').style.display = (tabCode == 'Find') ? 'none' : ''; 
     52    //fixme: allow hide/show of regex based on user privs 
     53    document.getElementById('regex').style.display = (tabCode == 'Replace') ? '' : 'none'; 
     54     
     55} 
    3256 
    3357function OnLoad() 
    3458{ 
    35         // Whole word is available on IE only. 
    36         if ( oEditor.FCKBrowserInfo.IsIE ) 
    37                 document.getElementById('divWord').style.display = '' ; 
    38  
    3959        // First of all, translate the dialog box texts. 
    4060        oEditor.FCKLanguageManager.TranslatePage( document ) ; 
    4161 
    4262        window.parent.SetAutoSize( true ) ; 
     63    if ( document.location.search.substr(1) == 'rep') 
     64        window.parent.SetSelectedTab('Replace'); 
    4365} 
    4466 
     
    4870                ( document.getElementById('txtFind').value.length == 0 ) ; 
    4971} 
    50  
    51 function ReplaceTextNodes( parentNode, regex, replaceValue, replaceAll ) 
    52 { 
    53         for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) 
    54         { 
    55                 var oNode = parentNode.childNodes[i] ; 
    56                 if ( oNode.nodeType == 3 ) 
    57                 { 
    58                         var sReplaced = oNode.nodeValue.replace( regex, replaceValue ) ; 
    59                         if ( oNode.nodeValue != sReplaced ) 
    60                         { 
    61                                 oNode.nodeValue = sReplaced ; 
    62                                 if ( ! replaceAll ) 
    63                                         return true ; 
    64                         } 
    65                 } 
    66                 else 
    67                 { 
    68                         if ( ReplaceTextNodes( oNode, regex, replaceValue ) ) 
    69                                 return true ; 
    70                 } 
    71         } 
    72         return false ; 
    73 } 
    74  
    75 function GetRegexExpr() 
    76 { 
    77         var sExpr ; 
    78  
    79         if ( document.getElementById('chkWord').checked ) 
    80                 sExpr = '\\b' + document.getElementById('txtFind').value + '\\b' ; 
    81         else 
    82                 sExpr = document.getElementById('txtFind').value ; 
    83  
    84         return sExpr ; 
    85 } 
    86  
    87 function GetCase() 
    88 { 
    89         return ( document.getElementById('chkCase').checked ? '' : 'i' ) ; 
    90 } 
    91  
    92 function Ok() 
    93 { 
    94         if ( document.getElementById('txtFind').value.length == 0 ) 
    95                 return ; 
    96  
    97         if ( oEditor.FCKBrowserInfo.IsIE ) 
    98                 FindIE() ; 
    99         else 
    100                 FindGecko() ; 
    101 } 
    102  
     72function Find(bDB) 
     73{ 
     74    //start finding at the top -- IE does this automagically 
     75    if (bFirstFind) 
     76    { 
     77        FCK.Selection.SelectNode(oEditor.FCK.EditorDocument.body); 
     78        FCK.Selection.Collapse(); 
     79    } 
     80    if ( document.getElementById('txtFind').value.length == 0 ) 
     81        return false; 
     82    var bOut; 
     83    if ( oEditor.FCKBrowserInfo.IsIE ) 
     84        bOut = FindIE(document.getElementById('txtFind').value, 
     85                document.getElementById('chkCase').checked, 
     86                document.getElementById('chkWord').checked) ; 
     87    else 
     88        bOut = FindGecko(document.getElementById('txtFind').value, 
     89                document.getElementById('chkCase').checked, 
     90                document.getElementById('chkWord').checked) ; 
     91    if (!bOut && bDB) alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ; 
     92    bFirstFind = false; 
     93    return bOut; 
     94} 
     95 
     96function Replace()          //replace -- or if nothing selected, Find Next 
     97{ 
     98    if (document.getElementById('chkRegex').checked) 
     99        return ReplaceAllRegex(); 
     100     
     101    if (FCK.Selection.SelectedHTML()) 
     102        FCK.InsertHtml(filterReplaceText()); 
     103    Find(true); 
     104} 
     105 
     106function ReplaceAll() 
     107{ 
     108    if (document.getElementById('chkRegex').checked) 
     109        return ReplaceAllRegex(); 
     110    while (Find(false) && FCK.Selection.SelectedHTML()) 
     111    { 
     112      FCK.InsertHtml(filterReplaceText()); 
     113    } 
     114} 
     115 
     116function ReplaceAllRegex() 
     117{ 
     118    var strXHTML = FCK.GetXHTML(false); 
     119    strXHTML = strXHTML.replace(new RegExp(document.getElementById('txtFind').value, 
     120                                document.getElementById('chkCase').checked ? 'g' : 'gi'), 
     121                        document.getElementById('txtReplace').value); 
     122    FCK.SetHTML(strXHTML); 
     123} 
     124 
     125function filterReplaceText() 
     126{ 
     127    var sHtml = document.getElementById('txtReplace').value; 
     128        sHtml = sHtml.replace(/&/ig,'&amp;'); 
     129        sHtml = sHtml.replace(/</ig,'&lt;'); 
     130        sHtml = sHtml.replace(/>/ig,'&gt;'); 
     131    return sHtml     
     132} 
    103133var oRange ; 
    104134 
     
    106136        oRange = oEditor.FCK.EditorDocument.body.createTextRange() ; 
    107137 
    108 function FindIE() 
     138function FindIE(strText, bCase, bWord) 
    109139{ 
    110140        var iFlags = 0 ; 
    111141 
    112         if ( chkCase.checked ) 
     142        if (bCase) 
    113143                iFlags = iFlags | 4 ; 
    114144 
    115         if ( chkWord.checked ) 
     145        if (bWord) 
    116146                iFlags = iFlags | 2 ; 
    117  
    118         var bFound = oRange.findText( document.getElementById('txtFind').value, 1, iFlags ) ; 
    119  
    120         if ( bFound ) 
    121         { 
     147        var bFound = oRange.findText(strText, 1, iFlags ) ; 
     148 
     149        if ( bFound )   { 
    122150                oRange.scrollIntoView() ; 
    123151                oRange.select() ; 
    124152                oRange.collapse(false) ; 
    125153                oLastRangeFound = oRange ; 
     154        return true; 
    126155        } 
    127156        else 
    128157        { 
    129158                oRange = oEditor.FCK.EditorDocument.body.createTextRange() ; 
    130                 alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ; 
    131159        } 
    132 } 
    133  
    134 function FindGecko() 
     160    return false; 
     161} 
     162 
     163function FindGecko(strText, bCase, bWord) 
    135164{ 
    136165        var bCase = document.getElementById('chkCase').checked ; 
     
    138167 
    139168        // window.find( searchString, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog ) ; 
    140         if ( !oEditor.FCK.EditorWindow.find( document.getElementById('txtFind').value, bCase, false, false, bWord, false, false ) ) 
    141                 alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ; 
    142 } 
    143         </script> 
     169        var bFound = oEditor.FCK.EditorWindow.find( document.getElementById('txtFind').value, bCase, false, false, bWord, false, false ); 
     170         
     171    return (bFound); 
     172} 
     173 
     174function toggleRegex() 
     175{ 
     176    bRegex = document.getElementById('chkRegex').checked ; 
     177    document.getElementById('btnReplace').disabled = bRegex; 
     178    document.getElementById('btnFind').disabled = bRegex; 
     179} 
     180    </script> 
    144181</head> 
    145182<body onload="OnLoad()" style="overflow: hidden"> 
    146         <table cellspacing="3" cellpadding="2" width="100%" border="0"> 
     183        <table cellspacing="3" cellpadding="2" width="100%" border="0" height="130"> 
    147184                <tr> 
    148185                        <td nowrap="nowrap"> 
     
    151188                        </td> 
    152189                        <td width="100%"> 
    153                                 <input id="txtFind" style="width: 100%" tabindex="1" type="text" /> 
    154                         </td> 
    155                         <td> 
    156                                 <input id="btnFind" style="padding-right: 5px; padding-left: 5px" onclick="Ok();" 
    157                                         type="button" value="Find" fcklang="DlgFindFindBtn" /> 
     190                                <input id="txtFind" style="width: 100%" tabindex="1" type="text" 
     191                       onkeyup = "document.getElementById('btnFind').disabled = ( document.getElementById('txtFind').value.length == 0 || document.getElementById('chkRegex').checked );" /> 
     192                        </td> 
     193                </tr> 
     194                <tr id="replace" style="display:none"> 
     195                        <td valign="top" nowrap="nowrap"> 
     196                                <label for="txtReplace" fcklang="DlgReplaceReplaceLbl"> 
     197                                        Replace with:</label> 
     198                        </td> 
     199                        <td valign="top"> 
     200                                <input id="txtReplace" style="width: 100%" tabindex="2" type="text" /> 
    158201                        </td> 
    159202                </tr> 
    160203                <tr> 
    161                         <td valign="bottom" colspan="3"> 
    162                                 &nbsp;<input id="chkCase" tabindex="3" type="checkbox" /><label for="chkCase" fcklang="DlgReplaceCaseChk">Match 
    163                                         case</label> 
    164                                 <br /> 
    165                                 <div id="divWord" style="display: none"> 
    166                                         &nbsp;<input id="chkWord" tabindex="4" type="checkbox" /><label for="chkWord" fcklang="DlgReplaceWordChk">Match 
    167                                                 whole word</label> 
    168                                 </div> 
     204                        <td valign="middle" colspan="2"> 
     205                <table border="0"> 
     206                    <tr> 
     207                        <td> 
     208                        &nbsp;<input id="chkCase" tabindex="3" type="checkbox" /><label for="chkCase" fcklang="DlgReplaceCaseChk">Match 
     209                            case</label> 
     210                        <br /> 
     211                        &nbsp;<input id="chkWord" tabindex="4" type="checkbox" /><label for="chkWord" fcklang="DlgReplaceWordChk">Match 
     212                                whole word</label> 
     213                        </td> 
     214                        <td id="regex" valign="top" style="display:none"> 
     215                            <input id="chkRegex" tabindex="5" type="checkbox" onclick="toggleRegex()"/><label for="chkRegex">Regex</label> 
     216                        </td> 
     217                    </tr> 
     218                </table> 
    169219                        </td> 
    170220                </tr> 
    171221        </table> 
     222    <div style="text-align: right; margin-right: 5px"> 
     223        <span id="replaceButtons" style="display:none"> 
     224        <input type="button" id="btnReplaceAll" class="button" value="Replace All" onclick="ReplaceAll()"  fcklang="DlgReplaceReplaceAllBtn" /> 
     225        <input type="button" id="btnReplace" class="button" value="Replace" onclick="Replace()"  fcklang="DlgReplaceReplaceBtn" /></span> 
     226        <input type="button" id="btnFind" class="button" value="Find Next" onclick="Find()"  disabled="disabled" /> 
     227        <input type="button" id="btnCancel" class="button" value="Close" onclick="top.Cancel()" /> 
     228    </div> 
    172229</body> 
    173230</html> 
  • FCKeditor/branches/developers/mjk/editor/dialog/fck_table.html

    r132 r244  
    6666                        document.getElementById('selWidthType').value = "percent" ; 
    6767                } 
    68                 else if (iWidth.indexOf('px') >= 0)             // Style Pixel = px 
     68                else                                                                    // Style Pixel = px, or width=nn 
    6969                {                                                                                                                                                                                                                 // 
    7070                        iWidth = iWidth.substr(0,iWidth.length - 2); 
     
    8989                document.getElementById('txtColumns').disabled = true ; 
    9090        } 
    91  
    92         window.parent.SetOkButton( true ) ; 
    93         window.parent.SetAutoSize( true ) ; 
     91        window.parent.SetOkButton( true ) ;      
     92        window.parent.SetAutoSize( true ) ;      
    9493} 
    9594 
  • FCKeditor/branches/developers/mjk/editor/fckdialog.html

    r153 r244  
    132132        SetSelectedTab( this.TabCode ) ; 
    133133} 
    134  
    135 function AddTab( tabCode, tabText, startHidden ) 
     134                   
     135function AddTab( tabCode, tabText, startHidden, bNoTabRow ) 
    136136{ 
    137137        if ( typeof( oTabs[ tabCode ] ) != 'undefined' ) 
     
    162162 
    163163                oDiv.className = 'PopupTabSelected' ; 
    164                 eTabsRow.style.display = '' ; 
     164                if (!bNoTabRow) eTabsRow.style.display = '' ; 
    165165 
    166166                if ( ! window.dialogArguments.Editor.FCKBrowserInfo.IsIE ) 
     
    183183        if ( typeof( window.frames["frmMain"].OnDialogTabChange ) == 'function' ) 
    184184                window.frames["frmMain"].OnDialogTabChange( tabCode ) ; 
     185} 
     186 
     187function GetSelectedTab() 
     188{ 
     189        for ( var sCode in oTabs ) 
     190        { 
     191                if (oTabs[sCode].className == 'PopupTabSelected') 
     192                        return sCode; 
     193        } 
    185194} 
    186195 
     
    210219                switch ( e.keyCode ) 
    211220                { 
    212                         case 13 :               // ENTER 
     221            case 76 :       // Ctrl+Alt+L: become lowercase 
     222                if (e.altKey && e.ctrlKey) 
     223                { 
     224                    var oTarget = e.srcElement || e.target ; 
     225                    if (oTarget.value) oTarget.value = oTarget.value.toLowerCase(); 
     226                    return false; 
     227                } 
     228                break; 
     229            case 82 :       // Ctrl+Alt+R: become Propercase 
     230                if (e.altKey && e.ctrlKey) 
     231                { 
     232                    var oTarget = e.srcElement || e.target ; 
     233                    if (oTarget.value) oTarget.value = oTarget.value.toLowerCase().replace(/(\S)(\S*\s*)/g, 
     234                                                function(str,p1,p2) {return p1.toUpperCase()+p2}); 
     235                    return false; 
     236                } 
     237                break; 
     238            case 85 :       // Ctrl+Alt+U: become UPPERCASE 
     239                if (e.altKey && e.ctrlKey) 
     240                { 
     241                    var oTarget = e.srcElement || e.target ; 
     242                    if (oTarget.value) oTarget.value = oTarget.value.toUpperCase(); 
     243                    return false; 
     244                } 
     245                break; 
     246                     
     247                case 13 :               // ENTER 
    213248                                var oTarget = e.srcElement || e.target ; 
    214249                                if ( oTarget.tagName == 'TEXTAREA' ) 
     
    306341                                </td> 
    307342                        </tr> 
    308                         <tr> 
     343                        <tr id="Buttons"> 
    309344                                <td class="PopupButtons"> 
    310                                         <table border="0" cellpadding="0" cellspacing="0"> 
     345                                        <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
    311346                                                <tr> 
    312                                                         <td width="100%">&nbsp;</td> 
    313                                                         <td nowrap="nowrap"> 
    314                                                                 <input id="btnOk" style="VISIBILITY: hidden;" type="button" value="Ok" class="Button" onclick="Ok();" fckLang="DlgBtnOK" /> 
     347                                                        <td nowrap="nowrap" align="right" width="100%"> 
     348                                                                <span id="runtimeButtons"></span> 
     349                                <input id="btnOk" style="VISIBILITY: hidden;" type="button" value="Ok" class="Button" onclick="Ok();" fckLang="DlgBtnOK" /> 
    315350                                                                &nbsp;  
    316351                                                                <input id="btnCancel" type="button" value="Cancel" class="Button" onclick="Cancel();" fckLang="DlgBtnCancel" /> 
  • FCKeditor/branches/developers/mjk/editor/lang/en.js

    r174 r244  
    124124FlashProperties         : "Flash Properties", 
    125125 
     126AnchorDelete            : "Remove Anchor", 
    126127AnchorProp                      : "Anchor Properties", 
    127128ButtonProp                      : "Button Properties", 
  • FCKeditor/branches/developers/mjk/editor/_source/classes/fckeditingarea.js

    r205 r244  
    4949                eTargetElement.removeChild( eTargetElement.childNodes[0] ) ; 
    5050 
    51         if ( this.Mode == FCK_EDITMODE_WYSIWYG ) 
    52         { 
     51 
     52 
    5353                // Create the editing area IFRAME. 
    5454                var oIFrame = this.IFrame = oTargetDocument.createElement( 'iframe' ) ; 
     
    120120                else 
    121121                        FCKEditingArea_CompleteStart.call( this.Window ) ; 
    122         } 
    123         else 
    124         { 
    125                 var eTextarea = this.Textarea = oTargetDocument.createElement( 'textarea' ) ; 
    126                 eTextarea.className = 'SourceField' ; 
    127                 eTextarea.dir = 'ltr' ; 
    128                 eTextarea.style.width = eTextarea.style.height = '100%' ; 
    129                 eTextarea.style.border = 'none' ; 
    130                 eTargetElement.appendChild( eTextarea ) ; 
    131  
    132                 eTextarea.value = html  ; 
    133  
    134                 // Fire the "OnLoad" event. 
    135                 FCKTools.RunFunction( this.OnLoad ) ; 
    136         } 
     122 
     123 
    137124} 
    138125 
     
    214201        try 
    215202        { 
    216                 if ( this.Mode == FCK_EDITMODE_WYSIWYG ) 
    217                 { 
    218                         // The following check is important to avoid IE entering in a focus loop. Ref: 
    219                         // http://sourceforge.net/tracker/index.php?func=detail&aid=1567060&group_id=75348&atid=543653 
    220                         if ( FCKBrowserInfo.IsIE && this.Document.hasFocus() ) 
    221                                 return ; 
    222  
    223                         if ( FCKBrowserInfo.IsSafari ) 
    224                                 this.IFrame.focus() ; 
    225                         else 
    226                         { 
    227                                 this.Window.focus() ; 
    228                         } 
    229                 } 
     203                // The following check is important to avoid IE entering in a focus loop. Ref: 
     204                // http://sourceforge.net/tracker/index.php?func=detail&aid=1567060&group_id=75348&atid=543653 
     205                if ( FCKBrowserInfo.IsIE && this.Document.hasFocus() ) 
     206                        return ; 
     207                if ( FCKBrowserInfo.IsSafari ) 
     208                        this.IFrame.focus() ; 
    230209                else 
    231210                { 
    232                         var oDoc = FCKTools.GetElementDocument( this.Textarea ) ; 
    233                         if ( (!oDoc.hasFocus || oDoc.hasFocus() ) && oDoc.activeElement == this.Textarea ) 
    234                                 return ; 
    235  
    236                         this.Textarea.focus() ; 
     211                        this.Window.focus() ; 
    237212                } 
    238213        } 
  • FCKeditor/branches/developers/mjk/editor/_source/commandclasses/fck_othercommands.js

    r243 r244  
    339339 
    340340// FCKSelectAllCommand 
     341// mjk: since source is in the main frame, this command is now 
     342// redundant and probably should be removed. 
    341343var FCKSelectAllCommand = function() 
    342344{ 
     
    346348FCKSelectAllCommand.prototype.Execute = function() 
    347349{ 
    348         if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) 
    349         { 
    350                 FCK.ExecuteNamedCommand( 'SelectAll' ) ; 
    351         } 
    352         else 
    353         { 
    354                 // Select the contents of the textarea 
    355                 var textarea = FCK.EditingArea.Textarea ; 
    356                 if ( FCKBrowserInfo.IsIE ) 
    357                 { 
    358                         textarea.createTextRange().execCommand( 'SelectAll' ) ; 
    359                 } 
    360                 else 
    361                 { 
    362                         textarea.selectionStart = 0; 
    363                         textarea.selectionEnd = textarea.value.length ; 
    364                 } 
    365                 textarea.focus() ; 
    366         } 
     350        FCK.ExecuteNamedCommand( 'SelectAll' ) ; 
    367351} 
    368352 
  • FCKeditor/branches/developers/mjk/editor/_source/internals/fckcommands.js

    r243 r244  
    5050 
    5151                case 'Find'                     : oCommand = new FCKDialogCommand( 'Find'               , FCKLang.DlgFindTitle                  , 'dialog/fck_find.html'                , 340, 170 ) ; break ; 
    52                 case 'Replace'          : oCommand = new FCKDialogCommand( 'Replace'    , FCKLang.DlgReplaceTitle               , 'dialog/fck_replace.html'             , 340, 200 ) ; break ; 
     52                case 'Replace'          : oCommand = new FCKDialogCommand( 'Replace'    , FCKLang.DlgReplaceTitle               , 'dialog/fck_find.html?rep'    , 340, 200 ) ; break ; 
    5353 
    5454                case 'Image'            : oCommand = new FCKDialogCommand( 'Image'              , FCKLang.DlgImgTitle                   , 'dialog/fck_image.html'               , 450, 400 ) ; break ; 
  • FCKeditor/branches/developers/mjk/editor/_source/internals/fck.js

    r219 r244  
    4949        { 
    5050                if ( this.EditMode == FCK_EDITMODE_SOURCE ) 
    51                         return ( this.StartupValue != this.EditingArea.Textarea.value ) ; 
     51                        return ( this.StartupValue != FCK._fromRawHTML(this.EditorDocument.body.innerHTML)); 
    5252                else 
    5353                        return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ; 
     
    5757        { 
    5858                if ( this.EditMode == FCK_EDITMODE_SOURCE ) 
    59                         this.StartupValue = this.EditingArea.Textarea.value ; 
     59                        this.StartupValue = FCK._fromRawHTML(this.EditorDocument.body.innerHTML); 
    6060                else if ( this.EditorDocument.body ) 
    6161                        this.StartupValue = this.EditorDocument.body.innerHTML ; 
     
    196196                // represent the exact contents of the source, as the user wanted it to be. 
    197197                if ( FCK.EditMode == FCK_EDITMODE_SOURCE ) 
    198                                 return FCK.EditingArea.Textarea.value ; 
     198                                return FCK._fromRawHTML(FCK.EditorDocument.body.innerHTML); 
    199199 
    200200                this.FixBody() ; 
     
    257257        { 
    258258                FCKDocumentProcessor.Process( FCK.EditorDocument ) ; 
     259                //Put the cursor where we left it when moving into or 
     260                //out of Source view -- or somewhere close to it. 
     261                if (FCK.MoveToMarker) 
     262                { 
     263                        if (FCKBrowserInfo.IsIE) 
     264                        { 
     265                                var oRange = FCK.EditorDocument.body.createTextRange(); 
     266                                oRange.findText("__FCK_RAW_Marker__",1); 
     267                                oRange.select(); 
     268                                FCK.InsertHtml(''); 
     269                                oRange.scrollIntoView(); 
     270                        } 
     271                        else 
     272                        { 
     273                                FCK.Selection.SelectNode(FCK.EditorDocument.body); 
     274                                FCK.Selection.Collapse(); 
     275                                FCK.EditorWindow.find("__FCK_RAW_Marker__", true, false, false, false, false, false ); 
     276                                var oSel = FCKSelection.Delete() ; 
     277                                var oRange = oSel.getRangeAt(0) ;        
     278                                oRange.Select() ; 
     279                        } 
     280                        FCK.MoveToMarker = null; 
     281                } 
    259282                FCKUndo.SaveUndoStep() ; 
    260283 
     
    327350                this.EditingArea.Mode = FCK.EditMode ; 
    328351 
    329                 if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) 
    330                 { 
    331                         html = FCKConfig.ProtectedSource.Protect( html ) ; 
    332  
    333                         // Fix for invalid self-closing tags (see #152). 
    334                         html = html.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ; 
    335  
    336                         html = FCK.ProtectEvents( html ) ; 
    337                         html = FCK.ProtectUrls( html ) ; 
    338                         html = FCK.ProtectTags( html ) ; 
    339  
    340                         // Firefox can't handle correctly the editing of the STRONG and EM tags. 
    341                         // We must replace them with B and I. 
    342                         if ( FCKBrowserInfo.IsGecko ) 
     352                html = FCKConfig.ProtectedSource.Protect( html ) ; 
     353 
     354                // Fix for invalid self-closing tags (see #152). 
     355                html = html.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ; 
     356 
     357                html = FCK.ProtectEvents( html ) ; 
     358                html = FCK.ProtectUrls( html ) ; 
     359                html = FCK.ProtectTags( html ) ; 
     360 
     361                // Firefox can't handle correctly the editing of the STRONG and EM tags. 
     362                // We must replace them with B and I. 
     363                if ( FCKBrowserInfo.IsGecko ) 
     364                { 
     365                        html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ; 
     366                        html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ; 
     367                        html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ; 
     368                        html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ; 
     369                } 
     370 
     371                this._ForceResetIsDirty = ( resetIsDirty === true ) ; 
     372 
     373                var sHtml = '' ; 
     374 
     375                if ( FCKConfig.FullPage ) 
     376                { 
     377                        // The HTML must be fixed if the <head> is not available. 
     378                        if ( !FCKRegexLib.HeadOpener.test( html ) ) 
    343379                        { 
    344                                 html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ; 
    345                                 html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ; 
    346                                 html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ; 
    347                                 html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ; 
     380                                // Check if the <html> is available. 
     381                                if ( !FCKRegexLib.HtmlOpener.test( html ) ) 
     382                                        html = '<html dir="' + FCKConfig.ContentLangDirection + '">' + html + '</html>' ; 
     383 
     384                                // Add the <head>. 
     385                                html = html.replace( FCKRegexLib.HtmlOpener, '$&<head></head>' ) ; 
    348386                        } 
    349387 
    350                         this._ForceResetIsDirty = ( resetIsDirty === true ) ; 
    351  
    352                         var sHtml = '' ; 
    353  
    354                         if ( FCKConfig.FullPage ) 
    355                         { 
    356                                 // The HTML must be fixed if the <head> is not available. 
    357                                 if ( !FCKRegexLib.HeadOpener.test( html ) ) 
    358                                 { 
    359                                         // Check if the <html> is available. 
    360                                         if ( !FCKRegexLib.HtmlOpener.test( html ) ) 
    361                                                 html = '<html dir="' + FCKConfig.ContentLangDirection + '">' + html + '</html>' ; 
    362  
    363                                         // Add the <head>. 
    364                                         html = html.replace( FCKRegexLib.HtmlOpener, '$&<head></head>' ) ; 
    365                                 } 
    366  
    367                                 // Save the DOCTYPE. 
    368                                 FCK.DocTypeDeclaration = html.match( FCKRegexLib.DocTypeTag ) ; 
    369  
    370                                 if ( FCKBrowserInfo.IsIE ) 
    371                                         sHtml = FCK._GetBehaviorsStyle() ; 
    372                                 else if ( FCKConfig.ShowBorders ) 
    373                                         sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
    374  
    375                                 sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
    376  
    377                                 // Attention: do not change it before testing it well (sample07)! 
    378                                 // This is tricky... if the head ends with <meta ... content type>, 
    379                                 // Firefox will break. But, it works if we include the temporary 
    380                                 // links as the last elements in the HEAD. 
    381                                 sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ; 
    382  
    383                                 // Insert the base tag (FCKConfig.BaseHref), if not exists in the source. 
    384                                 // The base must be the first tag in the HEAD, to get relative 
    385                                 // links on styles, for example. 
    386                                 if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) ) 
    387                                         sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ; 
    388                         } 
     388                        // Save the DOCTYPE. 
     389                        FCK.DocTypeDeclaration = html.match( FCKRegexLib.DocTypeTag ) ; 
     390 
     391                        if ( FCKBrowserInfo.IsIE ) 
     392                                sHtml = FCK._GetBehaviorsStyle() ; 
     393                        else if ( FCKConfig.ShowBorders ) 
     394                                sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
     395 
     396                        sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
     397 
     398                        // Attention: do not change it before testing it well (sample07)! 
     399                        // This is tricky... if the head ends with <meta ... content type>, 
     400                        // Firefox will break. But, it works if we include the temporary 
     401                        // links as the last elements in the HEAD. 
     402                        sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ; 
     403 
     404                        // Insert the base tag (FCKConfig.BaseHref), if not exists in the source. 
     405                        // The base must be the first tag in the HEAD, to get relative 
     406                        // links on styles, for example. 
     407                        if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) ) 
     408                                sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ; 
     409                } 
     410                else 
     411                { 
     412                        sHtml = 
     413                                FCKConfig.DocType + 
     414                                '<html dir="' + FCKConfig.ContentLangDirection + '"' ; 
     415 
     416                        // On IE, if you are use a DOCTYPE differenft of HTML 4 (like 
     417                        // XHTML), you must force the vertical scroll to show, otherwise 
     418                        // the horizontal one may appear when the page needs vertical scrolling. 
     419                        if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) ) 
     420                                sHtml += ' style="overflow-y: scroll"' ; 
     421 
     422                        sHtml += 
     423                                '><head><title></title>' + 
     424                                _FCK_GetEditorAreaStyleTags() + 
     425                                '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
     426 
     427                        if ( FCKBrowserInfo.IsIE ) 
     428                                sHtml += FCK._GetBehaviorsStyle() ; 
     429                        else if ( FCKConfig.ShowBorders ) 
     430                                sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
     431 
     432                        sHtml += FCK.TempBaseTag ; 
     433 
     434                        // Add ID and Class to the body 
     435                        var sBodyTag = '<body' ; 
     436                        if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 ) 
     437                                sBodyTag += ' id="' + FCKConfig.BodyId + '"' ; 
     438                        if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 ) 
     439                                sBodyTag += ' class="' + FCKConfig.BodyClass + '"' ; 
     440                        sHtml += '</head>' + sBodyTag + '>' ; 
     441 
     442                        if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) ) 
     443                                sHtml += GECKO_BOGUS ; 
    389444                        else 
    390                         { 
    391                                 sHtml = 
    392                                         FCKConfig.DocType + 
    393                                         '<html dir="' + FCKConfig.ContentLangDirection + '"' ; 
    394  
    395                                 // On IE, if you are use a DOCTYPE differenft of HTML 4 (like 
    396                                 // XHTML), you must force the vertical scroll to show, otherwise 
    397                                 // the horizontal one may appear when the page needs vertical scrolling. 
    398                                 if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) ) 
    399                                         sHtml += ' style="overflow-y: scroll"' ; 
    400  
    401                                 sHtml += 
    402                                         '><head><title></title>' + 
    403                                         _FCK_GetEditorAreaStyleTags() + 
    404                                         '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
    405  
    406                                 if ( FCKBrowserInfo.IsIE ) 
    407                                         sHtml += FCK._GetBehaviorsStyle() ; 
    408                                 else if ( FCKConfig.ShowBorders ) 
    409                                         sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ; 
    410  
    411                                 sHtml += FCK.TempBaseTag ; 
    412  
    413                                 // Add ID and Class to the body 
    414                                 var sBodyTag = '<body' ; 
    415                                 if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 ) 
    416                                         sBodyTag += ' id="' + FCKConfig.BodyId + '"' ; 
    417                                 if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 ) 
    418                                         sBodyTag += ' class="' + FCKConfig.BodyClass + '"' ; 
    419                                 sHtml += '</head>' + sBodyTag + '>' ; 
    420  
    421                                 if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) ) 
    422                                         sHtml += GECKO_BOGUS ; 
    423                                 else 
    424                                         sHtml += html ; 
    425  
    426                                 sHtml += '</body></html>' ; 
    427                         } 
    428  
    429                         this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ; 
    430                         this.EditingArea.Start( sHtml ) ; 
    431                 } 
    432                 else 
    433                 { 
    434                         // Remove the references to the following elements, as the editing area 
    435                         // IFRAME will be removed. 
    436                         FCK.EditorWindow        = null ; 
    437                         FCK.EditorDocument      = null ; 
    438  
    439                         this.EditingArea.OnLoad = null ; 
    440                         this.EditingArea.Start( html ) ; 
    441  
    442                         // Enables the context menu in the textarea. 
    443                         this.EditingArea.Textarea._FCKShowContextMenu = true ; 
    444  
    445                         // Removes the enter key handler. 
    446                         FCK.EnterKeyHandler = null ; 
    447  
    448                         if ( resetIsDirty ) 
    449                                 this.ResetIsDirty() ; 
    450  
    451                         // Listen for keystroke events. 
    452                         FCK.KeystrokeHandler.AttachToElement( this.EditingArea.Textarea ) ; 
    453  
    454                         this.EditingArea.Textarea.focus() ; 
    455  
    456                         FCK.Events.FireEvent( 'OnAfterSetHTML' ) ; 
    457                 } 
     445                                sHtml += html ; 
     446 
     447                        sHtml += '</body></html>' ; 
     448                } 
     449 
     450                this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ; 
     451                this.EditingArea.Start( sHtml ) ; 
    458452 
    459453                if ( FCKBrowserInfo.IsGecko ) 
     
    566560                var bIsDirty = FCK.IsDirty() ; 
    567561 
    568                 var sHtml ; 
    569  
    570562                // Update the HTML in the view output to show. 
    571563                if ( bIsWysiwyg ) 
     
    573565                        if ( !noUndo && FCKBrowserInfo.IsIE ) 
    574566                                FCKUndo.SaveUndoStep() ; 
    575  
    576                         sHtml = FCK.GetXHTML( FCKConfig.FormatSource ) ; 
    577  
    578                         if ( sHtml == null ) 
    579                                 return false ; 
     567         
     568                        //drop a marker so we can find where we were 
     569                        if (FCK.Selection.GetType() != 'None') FCK.Selection.Collapse(); 
     570                        FCK.InsertHtml("__FCK_RAW_Marker__"); 
     571                        sHtml = FCK._toRawHTML(FCK.GetXHTML( FCKConfig.FormatSource )); 
     572                        FCK.MoveToMarker = true; 
    580573                } 
    581574                else 
    582                         sHtml = this.EditingArea.Textarea.value ; 
    583  
     575                { 
     576                        sHtml = FCK.GetXHTML( FCKConfig.FormatSource ); 
     577                        //set this before SetHTML so we get HTML out rather than raw out 
     578                        FCK.EditMode = FCK_EDITMODE_WYSIWYG; 
     579                } 
     580         
     581                FCK.SetHTML( sHtml ) ; 
     582         
    584583                FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ; 
    585  
    586                 FCK.SetHTML( sHtml, !bIsDirty ) ; 
    587  
     584         
    588585                // Set the Focus. 
    589586                FCK.Focus() ; 
    590  
     587         
    591588                // Update the toolbar (Running it directly causes IE to fail). 
    592589                FCKTools.RunFunction( FCK.ToolbarSet.RefreshModeState, FCK.ToolbarSet ) ; 
    593  
     590         
    594591                return true ; 
    595592        }, 
     
    618615                } 
    619616                return null ; 
     617        }, 
     618         
     619        // Handle text processing when moving into or out of Source view. 
     620        // per mjk's patches, Source is no longer a separate textarea but 
     621        // a differently formatted view inside the main editor iframe. 
     622        // Consequently, we get some redundant source formatting that we need 
     623        // to simply remove before returning to WYSIWYG view. 
     624        // TODO: Add syntax coloring support. 
     625        _fromRawHTML : function(sIn) 
     626        { 
     627                var sHtml = sIn; 
     628                sHtml = sHtml.replace(/<[\/]*pre>/ig,''); 
     629                sHtml = sHtml.replace(/<p>/ig,'\n'); 
     630                sHtml = sHtml.replace(/<[\/]*b>/ig,''); 
     631                sHtml = sHtml.replace(/<\/p>/ig,''); 
     632                sHtml = sHtml.replace(/<br[^>]*>/ig,'\n'); 
     633                sHtml = sHtml.replace(/&gt;/ig,'>'); 
     634                sHtml = sHtml.replace(/&lt;/ig,'<'); 
     635                sHtml = sHtml.replace(/&amp;/ig,'&'); 
     636                return sHtml; 
     637        }, 
     638 
     639        _toRawHTML : function (sIn) 
     640        { 
     641                sHtml = sIn; 
     642                sHtml = sHtml.replace(/&/ig,'&amp;'); 
     643                sHtml = sHtml.replace(/</ig,'&lt;'); 
     644                sHtml = sHtml.replace(/>/ig,'&gt;'); 
     645                sHtml = '<pre>' + sHtml + '</pre>'; 
     646                return sHtml; 
    620647        } 
    621648 
  • FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbaritems.js

    r152 r244  
    4747                case 'About'                    : oItem = new FCKToolbarButton( 'About'         , FCKLang.About, null, null, true, null, 47  ) ; break ; 
    4848 
    49                 case 'Cut'                              : oItem = new FCKToolbarButton( 'Cut'           , FCKLang.Cut, null, null, false, true, 7 ) ; break ; 
    50                 case 'Copy'                             : oItem = new FCKToolbarButton( 'Copy'          , FCKLang.Copy, null, null, false, true, 8 ) ; break ; 
    51                 case 'Paste'                    : oItem = new FCKToolbarButton( 'Paste'         , FCKLang.Paste, null, null, false, true, 9 ) ; break ; 
     49                case 'Cut'                              : oItem = new FCKToolbarButton( 'Cut'           , FCKLang.Cut, null, null, true, true, 7 ) ; break ; 
     50                case 'Copy'                             : oItem = new FCKToolbarButton( 'Copy'          , FCKLang.Copy, null, null, true, true, 8 ) ; break ; 
     51                case 'Paste'                    : oItem = new FCKToolbarButton( 'Paste'         , FCKLang.Paste, null, null, true, true, 9 ) ; break ; 
    5252                case 'PasteText'                : oItem = new FCKToolbarButton( 'PasteText'     , FCKLang.PasteText, null, null, false, true, 10 ) ; break ; 
    5353                case 'PasteWord'                : oItem = new FCKToolbarButton( 'PasteWord'     , FCKLang.PasteWord, null, null, false, true, 11 ) ; break ; 
    54                 case 'Print'                    : oItem = new FCKToolbarButton( 'Print'         , FCKLang.Print, null, null, false, true, 12 ) ; break ; 
     54                case 'Print'                    : oItem = new FCKToolbarButton( 'Print'         , FCKLang.Print, null, null, true, true, 12 ) ; break ; 
    5555                case 'SpellCheck'               : oItem = new FCKToolbarButton( 'SpellCheck', FCKLang.SpellCheck, null, null, null, null, 13 ) ; break ; 
    5656                case 'Undo'                             : oItem = new FCKToolbarButton( 'Undo'          , FCKLang.Undo, null, null, false, true, 14 ) ; break ; 
     
    9898                case 'BGColor'                  : oItem = new FCKToolbarPanelButton( 'BGColor'  , FCKLang.BGColor, null, null, 46 ) ; break ; 
    9999 
    100                 case 'Find'                             : oItem = new FCKToolbarButton( 'Find'          , FCKLang.Find, null, null, null, null, 16 ) ; break ; 
    101                 case 'Replace'                  : oItem = new FCKToolbarButton( 'Replace'       , FCKLang.Replace, null, null, null, null, 17 ) ; break ; 
     100                case 'Find'                             : oItem = new FCKToolbarButton( 'Find'          , FCKLang.Find, null, null, null, true, 16 ) ; break ; 
     101                case 'Replace'                  : oItem = new FCKToolbarButton( 'Replace'       , FCKLang.Replace, null, null, null, true, 17 ) ; break ; 
    102102 
    103103                case 'Form'                             : oItem = new FCKToolbarButton( 'Form'                  , FCKLang.Form, null, null, null, null, 48 ) ; break ; 
  • FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbarset.js

    r132 r244  
    355355 
    356356        for ( var i = 0 ; i < aItems.length ; i++ ) 
    357                 aItems[i].RefreshState() ; 
    358 } 
     357        { 
     358                if (FCK.EditMode == FCK_EDITMODE_WYSIWYG || 
     359                        aItems[i].SourceView) 
     360                        aItems[i].RefreshState() ; 
     361        } 
     362}