| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|---|
| 2 | <!-- |
|---|
| 3 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
|---|
| 4 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
|---|
| 5 | * |
|---|
| 6 | * == BEGIN LICENSE == |
|---|
| 7 | * |
|---|
| 8 | * Licensed under the terms of any of the following licenses at your |
|---|
| 9 | * choice: |
|---|
| 10 | * |
|---|
| 11 | * - GNU General Public License Version 2 or later (the "GPL") |
|---|
| 12 | * http://www.gnu.org/licenses/gpl.html |
|---|
| 13 | * |
|---|
| 14 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
|---|
| 15 | * http://www.gnu.org/licenses/lgpl.html |
|---|
| 16 | * |
|---|
| 17 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
|---|
| 18 | * http://www.mozilla.org/MPL/MPL-1.1.html |
|---|
| 19 | * |
|---|
| 20 | * == END LICENSE == |
|---|
| 21 | * |
|---|
| 22 | * Link dialog window. |
|---|
| 23 | --> |
|---|
| 24 | <html> |
|---|
| 25 | <head> |
|---|
| 26 | <title>Link Properties</title> |
|---|
| 27 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 28 | <meta name="robots" content="noindex, nofollow" /> |
|---|
| 29 | <script type="text/javascript"> |
|---|
| 30 | |
|---|
| 31 | var oEditor = window.parent.InnerDialogLoaded() ; |
|---|
| 32 | var FCK = oEditor.FCK ; |
|---|
| 33 | var FCKLang = oEditor.FCKLang ; |
|---|
| 34 | var FCKConfig = oEditor.FCKConfig ; |
|---|
| 35 | var FCKRegexLib = oEditor.FCKRegexLib ; |
|---|
| 36 | var FCKTools = oEditor.FCKTools ; |
|---|
| 37 | |
|---|
| 38 | document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ; |
|---|
| 39 | |
|---|
| 40 | </script> |
|---|
| 41 | <script type="text/javascript"> |
|---|
| 42 | |
|---|
| 43 | // oLink: The actual selected link in the editor. |
|---|
| 44 | var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; |
|---|
| 45 | if ( oLink ) |
|---|
| 46 | FCK.Selection.SelectNode( oLink ) ; |
|---|
| 47 | |
|---|
| 48 | window.onload = function() |
|---|
| 49 | { |
|---|
| 50 | // Translate the dialog box texts. |
|---|
| 51 | oEditor.FCKLanguageManager.TranslatePage(document) ; |
|---|
| 52 | |
|---|
| 53 | // Load the selected link information (if any). |
|---|
| 54 | LoadSelection() ; |
|---|
| 55 | |
|---|
| 56 | // Activate the "OK" button. |
|---|
| 57 | window.parent.SetOkButton( true ) ; |
|---|
| 58 | window.parent.SetAutoSize( true ) ; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | function LoadSelection() |
|---|
| 62 | { |
|---|
| 63 | if ( !oLink ) return ; |
|---|
| 64 | |
|---|
| 65 | // Get the actual Link href. |
|---|
| 66 | var sHRef = oLink.getAttribute( '_fcksavedurl' ) ; |
|---|
| 67 | if ( sHRef == null ) |
|---|
| 68 | sHRef = oLink.getAttribute( 'href' , 2 ) || '' ; |
|---|
| 69 | |
|---|
| 70 | GetE('txtUrl').value = sHRef ; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | var searchTimer ; |
|---|
| 74 | |
|---|
| 75 | //#### Called while the user types the URL. |
|---|
| 76 | function OnUrlChange() |
|---|
| 77 | { |
|---|
| 78 | var link = GetE('txtUrl').value.Trim() ; |
|---|
| 79 | |
|---|
| 80 | if ( searchTimer ) |
|---|
| 81 | window.clearTimeout( searchTimer ) ; |
|---|
| 82 | |
|---|
| 83 | if ( link.StartsWith( '#' ) ) |
|---|
| 84 | { |
|---|
| 85 | SetSearchMessage( FCKLang.wikiLnkNoSearchAnchor ) ; |
|---|
| 86 | return ; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if ( link.StartsWith( 'mailto:' ) ) |
|---|
| 90 | { |
|---|
| 91 | SetSearchMessage( FCKLang.wikiLnkNoSearchMail ) ; |
|---|
| 92 | return ; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | if( /^\w+:\/\//.test( link ) ) |
|---|
| 96 | { |
|---|
| 97 | SetSearchMessage( FCKLang.wikiLnkNoSearchExt ) ; |
|---|
| 98 | return ; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | if ( link.length < 3 ) |
|---|
| 102 | { |
|---|
| 103 | ClearSearch() ; |
|---|
| 104 | |
|---|
| 105 | if ( link.length == 0 ) |
|---|
| 106 | SetSearchMessage( FCKLang.wikiLnkStartTyping ) ; |
|---|
| 107 | else |
|---|
| 108 | SetSearchMessage( FCKLang.wikiLnkTooShort ) ; |
|---|
| 109 | return ; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | SetSearchMessage( FCKLang.wikiLnkStopTyping ) ; |
|---|
| 113 | searchTimer = window.setTimeout( StartSearch, 500 ) ; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | function StartSearch() |
|---|
| 117 | { |
|---|
| 118 | var link = GetE('txtUrl').value.Trim() ; |
|---|
| 119 | |
|---|
| 120 | if ( link.length < 3 ) |
|---|
| 121 | return ; |
|---|
| 122 | |
|---|
| 123 | SetSearchMessage( FCKLang.wikiLnkSearching ) ; |
|---|
| 124 | |
|---|
| 125 | // Make an Ajax search for the pages. |
|---|
| 126 | oEditor.window.parent.sajax_request_type = 'GET' ; |
|---|
| 127 | oEditor.window.parent.sajax_do_call( 'wfSajaxSearchArticleFCKeditor', [link], LoadSearchResults ) ; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | function plural( thingsToCount, found0, found1, foundSeveral, foundMore ) { /* english: use the same foundSeveral and foundMore */ |
|---|
| 131 | var cnt = thingsToCount.length; |
|---|
| 132 | |
|---|
| 133 | if ( cnt == 0 || ( cnt == 1 && thingsToCount[0].length == 0 ) ) |
|---|
| 134 | return ( found0 ); |
|---|
| 135 | |
|---|
| 136 | if ( cnt == 1 ) |
|---|
| 137 | return ( found1 ); |
|---|
| 138 | |
|---|
| 139 | var foundMsg = foundMore; |
|---|
| 140 | switch ( cnt % 10 ) { |
|---|
| 141 | case 2: |
|---|
| 142 | case 3: |
|---|
| 143 | case 4: |
|---|
| 144 | if ( cnt / 10 % 10 != 1) |
|---|
| 145 | foundMsg = foundSeveral; |
|---|
| 146 | break; |
|---|
| 147 | default: |
|---|
| 148 | break; |
|---|
| 149 | } |
|---|
| 150 | return ( foundMsg.replace( '%s', cnt ) ); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | function LoadSearchResults( result ) |
|---|
| 154 | { |
|---|
| 155 | var results = result.responseText.Trim().split( '\n' ) ; |
|---|
| 156 | var select = GetE( 'xWikiResults' ) ; |
|---|
| 157 | |
|---|
| 158 | ClearSearch() ; |
|---|
| 159 | |
|---|
| 160 | SetSearchMessage( plural( results, |
|---|
| 161 | FCKLang.wikiLnkSearchNothing, |
|---|
| 162 | FCKLang.wikiLnkSearch1Found, |
|---|
| 163 | FCKLang.wikiLnkSearchSeveral, |
|---|
| 164 | FCKLang.wikiLnkSearchALot ) ); |
|---|
| 165 | for ( var i = 0 ; i < results.length ; i++ ) |
|---|
| 166 | FCKTools.AddSelectOption( select, results[i], results[i] ) ; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | function ClearSearch() |
|---|
| 170 | { |
|---|
| 171 | var select = GetE( 'xWikiResults' ) ; |
|---|
| 172 | |
|---|
| 173 | while ( select.options.length > 0 ) |
|---|
| 174 | select.remove( 0 ) |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | function SetSearchMessage( message ) |
|---|
| 178 | { |
|---|
| 179 | GetE('xWikiSearchStatus').innerHTML = message ; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | function SetUrl( url ) |
|---|
| 183 | { |
|---|
| 184 | GetE('txtUrl').value = url ; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | //#### The OK button was hit. |
|---|
| 188 | function Ok() |
|---|
| 189 | { |
|---|
| 190 | var sUri = GetE('txtUrl').value ; |
|---|
| 191 | var sInnerHtml ; |
|---|
| 192 | |
|---|
| 193 | // If no link is selected, create a new one (it may result in more than one link creation - #220). |
|---|
| 194 | var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ; |
|---|
| 195 | |
|---|
| 196 | // If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26) |
|---|
| 197 | var aHasSelection = ( aLinks.length > 0 ) ; |
|---|
| 198 | if ( !aHasSelection ) |
|---|
| 199 | { |
|---|
| 200 | sInnerHtml = sUri; |
|---|
| 201 | |
|---|
| 202 | var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ; |
|---|
| 203 | var asLinkPath = oLinkPathRegEx.exec( sUri ) ; |
|---|
| 204 | if (asLinkPath != null) |
|---|
| 205 | sInnerHtml = asLinkPath[1]; // use matched path |
|---|
| 206 | |
|---|
| 207 | // Create a new (empty) anchor. |
|---|
| 208 | aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | oEditor.FCKUndo.SaveUndoStep() ; |
|---|
| 212 | |
|---|
| 213 | for ( var i = 0 ; i < aLinks.length ; i++ ) |
|---|
| 214 | { |
|---|
| 215 | oLink = aLinks[i] ; |
|---|
| 216 | |
|---|
| 217 | if ( aHasSelection ) |
|---|
| 218 | sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL). |
|---|
| 219 | |
|---|
| 220 | oLink.href = sUri ; |
|---|
| 221 | SetAttribute( oLink, '_fcksavedurl', sUri ) ; |
|---|
| 222 | |
|---|
| 223 | oLink.innerHTML = sInnerHtml ; // Set (or restore) the innerHTML |
|---|
| 224 | |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | // Select the (first) link. |
|---|
| 228 | oEditor.FCKSelection.SelectNode( aLinks[0] ); |
|---|
| 229 | |
|---|
| 230 | return true ; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | </script> |
|---|
| 234 | </head> |
|---|
| 235 | <body scroll="no" style="overflow: hidden"> |
|---|
| 236 | <div id="divInfo"> |
|---|
| 237 | <div id="divLinkTypeUrl"> |
|---|
| 238 | <span fcklang="wikiLnk"></span><br /> |
|---|
| 239 | <input id="txtUrl" style="width: 100%" type="text" onkeyup="OnUrlChange();" /> |
|---|
| 240 | <br /> |
|---|
| 241 | <span fcklang="wikiLnkAutomatic"></span> (<span fcklang="wikiLnkStartTyping" id="xWikiSearchStatus"></span>)<br /> |
|---|
| 242 | <select id="xWikiResults" size="10" style="width: 100%; height:150px" onclick="SetUrl( this.value );"> |
|---|
| 243 | </select> |
|---|
| 244 | </div> |
|---|
| 245 | </div> |
|---|
| 246 | </body> |
|---|
| 247 | </html> |
|---|