Changeset 244

Show
Ignore:
Timestamp:
2007-04-09 20:12:02 (20 months 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 ;