[903] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * == BEGIN LICENSE == |
---|
| 6 | * |
---|
| 7 | * Licensed under the terms of any of the following licenses at your |
---|
| 8 | * choice: |
---|
| 9 | * |
---|
| 10 | * - GNU General Public License Version 2 or later (the "GPL") |
---|
| 11 | * http://www.gnu.org/licenses/gpl.html |
---|
| 12 | * |
---|
| 13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
| 14 | * http://www.gnu.org/licenses/lgpl.html |
---|
| 15 | * |
---|
| 16 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
| 17 | * http://www.mozilla.org/MPL/MPL-1.1.html |
---|
| 18 | * |
---|
| 19 | * == END LICENSE == |
---|
| 20 | * |
---|
| 21 | * Scripts related to the Link dialog window (see fck_link.html). |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | var oEditor = window.parent.InnerDialogLoaded() ; |
---|
| 25 | var FCK = oEditor.FCK ; |
---|
| 26 | var FCKLang = oEditor.FCKLang ; |
---|
| 27 | var FCKConfig = oEditor.FCKConfig ; |
---|
| 28 | var FCKRegexLib = oEditor.FCKRegexLib ; |
---|
| 29 | |
---|
| 30 | //#### Dialog Tabs |
---|
| 31 | |
---|
| 32 | // Set the dialog tabs. |
---|
| 33 | window.parent.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ; |
---|
| 34 | |
---|
| 35 | if ( !FCKConfig.LinkDlgHideTarget ) |
---|
| 36 | window.parent.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ; |
---|
| 37 | |
---|
| 38 | if ( FCKConfig.LinkUpload ) |
---|
| 39 | window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload, true ) ; |
---|
| 40 | |
---|
| 41 | if ( !FCKConfig.LinkDlgHideAdvanced ) |
---|
| 42 | window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ; |
---|
| 43 | |
---|
| 44 | // Function called when a dialog tag is selected. |
---|
| 45 | function OnDialogTabChange( tabCode ) |
---|
| 46 | { |
---|
| 47 | ShowE('divInfo' , ( tabCode == 'Info' ) ) ; |
---|
| 48 | ShowE('divTarget' , ( tabCode == 'Target' ) ) ; |
---|
| 49 | ShowE('divUpload' , ( tabCode == 'Upload' ) ) ; |
---|
| 50 | ShowE('divAttribs' , ( tabCode == 'Advanced' ) ) ; |
---|
| 51 | |
---|
| 52 | window.parent.SetAutoSize( true ) ; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | //#### Regular Expressions library. |
---|
| 56 | var oRegex = new Object() ; |
---|
| 57 | |
---|
| 58 | oRegex.UriProtocol = /^(((http|https|ftp|news):\/\/)|mailto:)/gi ; |
---|
| 59 | |
---|
| 60 | oRegex.UrlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi ; |
---|
| 61 | |
---|
| 62 | oRegex.UrlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi ; |
---|
| 63 | |
---|
| 64 | oRegex.ReserveTarget = /^_(blank|self|top|parent)$/i ; |
---|
| 65 | |
---|
| 66 | oRegex.PopupUri = /^javascript:void\(\s*window.open\(\s*'([^']+)'\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*\)\s*$/ ; |
---|
| 67 | |
---|
| 68 | // Accessible popups |
---|
| 69 | oRegex.OnClickPopup = /^\s*on[cC]lick="\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*"$/ ; |
---|
| 70 | |
---|
| 71 | oRegex.PopupFeatures = /(?:^|,)([^=]+)=(\d+|yes|no)/gi ; |
---|
| 72 | |
---|
| 73 | //#### Parser Functions |
---|
| 74 | |
---|
| 75 | var oParser = new Object() ; |
---|
| 76 | |
---|
| 77 | oParser.ParseEMailUrl = function( emailUrl ) |
---|
| 78 | { |
---|
| 79 | // Initializes the EMailInfo object. |
---|
| 80 | var oEMailInfo = new Object() ; |
---|
| 81 | oEMailInfo.Address = '' ; |
---|
| 82 | oEMailInfo.Subject = '' ; |
---|
| 83 | oEMailInfo.Body = '' ; |
---|
| 84 | |
---|
| 85 | var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ; |
---|
| 86 | if ( oParts ) |
---|
| 87 | { |
---|
| 88 | // Set the e-mail address. |
---|
| 89 | oEMailInfo.Address = oParts[1] ; |
---|
| 90 | |
---|
| 91 | // Look for the optional e-mail parameters. |
---|
| 92 | if ( oParts[2] ) |
---|
| 93 | { |
---|
| 94 | var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ; |
---|
| 95 | if ( oMatch ) oEMailInfo.Subject = decodeURIComponent( oMatch[2] ) ; |
---|
| 96 | |
---|
| 97 | oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ; |
---|
| 98 | if ( oMatch ) oEMailInfo.Body = decodeURIComponent( oMatch[2] ) ; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | return oEMailInfo ; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | oParser.CreateEMailUri = function( address, subject, body ) |
---|
| 106 | { |
---|
| 107 | var sBaseUri = 'mailto:' + address ; |
---|
| 108 | |
---|
| 109 | var sParams = '' ; |
---|
| 110 | |
---|
| 111 | if ( subject.length > 0 ) |
---|
| 112 | sParams = '?subject=' + encodeURIComponent( subject ) ; |
---|
| 113 | |
---|
| 114 | if ( body.length > 0 ) |
---|
| 115 | { |
---|
| 116 | sParams += ( sParams.length == 0 ? '?' : '&' ) ; |
---|
| 117 | sParams += 'body=' + encodeURIComponent( body ) ; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | return sBaseUri + sParams ; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | //#### Initialization Code |
---|
| 124 | |
---|
| 125 | // oLink: The actual selected link in the editor. |
---|
| 126 | var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; |
---|
| 127 | if ( oLink ) |
---|
| 128 | FCK.Selection.SelectNode( oLink ) ; |
---|
| 129 | |
---|
| 130 | window.onload = function() |
---|
| 131 | { |
---|
| 132 | // Translate the dialog box texts. |
---|
| 133 | oEditor.FCKLanguageManager.TranslatePage(document) ; |
---|
| 134 | |
---|
| 135 | // Fill the Anchor Names and Ids combos. |
---|
| 136 | LoadAnchorNamesAndIds() ; |
---|
| 137 | |
---|
| 138 | // Load the selected link information (if any). |
---|
| 139 | LoadSelection() ; |
---|
| 140 | |
---|
| 141 | // Update the dialog box. |
---|
| 142 | SetLinkType( GetE('cmbLinkType').value ) ; |
---|
| 143 | |
---|
| 144 | // Show/Hide the "Browse Server" button. |
---|
| 145 | GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ; |
---|
| 146 | |
---|
| 147 | // Show the initial dialog content. |
---|
| 148 | GetE('divInfo').style.display = '' ; |
---|
| 149 | |
---|
| 150 | // Set the actual uploader URL. |
---|
| 151 | if ( FCKConfig.LinkUpload ) |
---|
| 152 | GetE('frmUpload').action = FCKConfig.LinkUploadURL ; |
---|
| 153 | |
---|
| 154 | // Activate the "OK" button. |
---|
| 155 | window.parent.SetOkButton( true ) ; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | var bHasAnchors ; |
---|
| 159 | |
---|
| 160 | function LoadAnchorNamesAndIds() |
---|
| 161 | { |
---|
| 162 | // Since version 2.0, the anchors are replaced in the DOM by IMGs so the user see the icon |
---|
| 163 | // to edit them. So, we must look for that images now. |
---|
| 164 | var aAnchors = new Array() ; |
---|
| 165 | var i ; |
---|
| 166 | var oImages = oEditor.FCK.EditorDocument.getElementsByTagName( 'IMG' ) ; |
---|
| 167 | for( i = 0 ; i < oImages.length ; i++ ) |
---|
| 168 | { |
---|
| 169 | if ( oImages[i].getAttribute('_fckanchor') ) |
---|
| 170 | aAnchors[ aAnchors.length ] = oEditor.FCK.GetRealElement( oImages[i] ) ; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | // Add also real anchors |
---|
| 174 | var oLinks = oEditor.FCK.EditorDocument.getElementsByTagName( 'A' ) ; |
---|
| 175 | for( i = 0 ; i < oLinks.length ; i++ ) |
---|
| 176 | { |
---|
| 177 | if ( oLinks[i].name && ( oLinks[i].name.length > 0 ) ) |
---|
| 178 | aAnchors[ aAnchors.length ] = oLinks[i] ; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | var aIds = oEditor.FCKTools.GetAllChildrenIds( oEditor.FCK.EditorDocument.body ) ; |
---|
| 182 | |
---|
| 183 | bHasAnchors = ( aAnchors.length > 0 || aIds.length > 0 ) ; |
---|
| 184 | |
---|
| 185 | for ( i = 0 ; i < aAnchors.length ; i++ ) |
---|
| 186 | { |
---|
| 187 | var sName = aAnchors[i].name ; |
---|
| 188 | if ( sName && sName.length > 0 ) |
---|
| 189 | oEditor.FCKTools.AddSelectOption( GetE('cmbAnchorName'), sName, sName ) ; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | for ( i = 0 ; i < aIds.length ; i++ ) |
---|
| 193 | { |
---|
| 194 | oEditor.FCKTools.AddSelectOption( GetE('cmbAnchorId'), aIds[i], aIds[i] ) ; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | ShowE( 'divSelAnchor' , bHasAnchors ) ; |
---|
| 198 | ShowE( 'divNoAnchor' , !bHasAnchors ) ; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | function LoadSelection() |
---|
| 202 | { |
---|
| 203 | if ( !oLink ) return ; |
---|
| 204 | |
---|
| 205 | var sType = 'url' ; |
---|
| 206 | |
---|
| 207 | // Get the actual Link href. |
---|
| 208 | var sHRef = oLink.getAttribute( '_fcksavedurl' ) ; |
---|
| 209 | if ( sHRef == null ) |
---|
| 210 | sHRef = oLink.getAttribute( 'href' , 2 ) || '' ; |
---|
| 211 | |
---|
| 212 | // Look for a popup javascript link. |
---|
| 213 | var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ; |
---|
| 214 | if( oPopupMatch ) |
---|
| 215 | { |
---|
| 216 | GetE('cmbTarget').value = 'popup' ; |
---|
| 217 | sHRef = oPopupMatch[1] ; |
---|
| 218 | FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ; |
---|
| 219 | SetTarget( 'popup' ) ; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // Accesible popups, the popup data is in the onclick attribute |
---|
| 223 | if ( !oPopupMatch ) { |
---|
| 224 | var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; |
---|
| 225 | oPopupMatch = oRegex.OnClickPopup.exec( onclick ) ; |
---|
| 226 | if( oPopupMatch ) |
---|
| 227 | { |
---|
| 228 | GetE( 'cmbTarget' ).value = 'popup' ; |
---|
| 229 | FillPopupFields( oPopupMatch[1], oPopupMatch[2] ) ; |
---|
| 230 | SetTarget( 'popup' ) ; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | // Search for the protocol. |
---|
| 235 | var sProtocol = oRegex.UriProtocol.exec( sHRef ) ; |
---|
| 236 | |
---|
| 237 | if ( sProtocol ) |
---|
| 238 | { |
---|
| 239 | sProtocol = sProtocol[0].toLowerCase() ; |
---|
| 240 | GetE('cmbLinkProtocol').value = sProtocol ; |
---|
| 241 | |
---|
| 242 | // Remove the protocol and get the remainig URL. |
---|
| 243 | var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ; |
---|
| 244 | |
---|
| 245 | if ( sProtocol == 'mailto:' ) // It is an e-mail link. |
---|
| 246 | { |
---|
| 247 | sType = 'email' ; |
---|
| 248 | |
---|
| 249 | var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ; |
---|
| 250 | GetE('txtEMailAddress').value = oEMailInfo.Address ; |
---|
| 251 | GetE('txtEMailSubject').value = oEMailInfo.Subject ; |
---|
| 252 | GetE('txtEMailBody').value = oEMailInfo.Body ; |
---|
| 253 | } |
---|
| 254 | else // It is a normal link. |
---|
| 255 | { |
---|
| 256 | sType = 'url' ; |
---|
| 257 | GetE('txtUrl').value = sUrl ; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | else if ( sHRef.substr(0,1) == '#' && sHRef.length > 1 ) // It is an anchor link. |
---|
| 261 | { |
---|
| 262 | sType = 'anchor' ; |
---|
| 263 | GetE('cmbAnchorName').value = GetE('cmbAnchorId').value = sHRef.substr(1) ; |
---|
| 264 | } |
---|
| 265 | else // It is another type of link. |
---|
| 266 | { |
---|
| 267 | sType = 'url' ; |
---|
| 268 | |
---|
| 269 | GetE('cmbLinkProtocol').value = '' ; |
---|
| 270 | GetE('txtUrl').value = sHRef ; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | if ( !oPopupMatch ) |
---|
| 274 | { |
---|
| 275 | // Get the target. |
---|
| 276 | var sTarget = oLink.target ; |
---|
| 277 | |
---|
| 278 | if ( sTarget && sTarget.length > 0 ) |
---|
| 279 | { |
---|
| 280 | if ( oRegex.ReserveTarget.test( sTarget ) ) |
---|
| 281 | { |
---|
| 282 | sTarget = sTarget.toLowerCase() ; |
---|
| 283 | GetE('cmbTarget').value = sTarget ; |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | GetE('cmbTarget').value = 'frame' ; |
---|
| 287 | GetE('txtTargetFrame').value = sTarget ; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | // Get Advances Attributes |
---|
| 292 | GetE('txtAttId').value = oLink.id ; |
---|
| 293 | GetE('txtAttName').value = oLink.name ; |
---|
| 294 | GetE('cmbAttLangDir').value = oLink.dir ; |
---|
| 295 | GetE('txtAttLangCode').value = oLink.lang ; |
---|
| 296 | GetE('txtAttAccessKey').value = oLink.accessKey ; |
---|
| 297 | GetE('txtAttTabIndex').value = oLink.tabIndex <= 0 ? '' : oLink.tabIndex ; |
---|
| 298 | GetE('txtAttTitle').value = oLink.title ; |
---|
| 299 | GetE('txtAttContentType').value = oLink.type ; |
---|
| 300 | GetE('txtAttCharSet').value = oLink.charset ; |
---|
| 301 | |
---|
| 302 | var sClass ; |
---|
| 303 | if ( oEditor.FCKBrowserInfo.IsIE ) |
---|
| 304 | { |
---|
| 305 | sClass = oLink.getAttribute('className',2) || '' ; |
---|
| 306 | // Clean up temporary classes for internal use: |
---|
| 307 | sClass = sClass.replace( FCKRegexLib.FCK_Class, '' ) ; |
---|
| 308 | |
---|
| 309 | GetE('txtAttStyle').value = oLink.style.cssText ; |
---|
| 310 | } |
---|
| 311 | else |
---|
| 312 | { |
---|
| 313 | sClass = oLink.getAttribute('class',2) || '' ; |
---|
| 314 | GetE('txtAttStyle').value = oLink.getAttribute('style',2) || '' ; |
---|
| 315 | } |
---|
| 316 | GetE('txtAttClasses').value = sClass ; |
---|
| 317 | |
---|
| 318 | // Update the Link type combo. |
---|
| 319 | GetE('cmbLinkType').value = sType ; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | //#### Link type selection. |
---|
| 323 | function SetLinkType( linkType ) |
---|
| 324 | { |
---|
| 325 | ShowE('divLinkTypeUrl' , (linkType == 'url') ) ; |
---|
| 326 | ShowE('divLinkTypeAnchor' , (linkType == 'anchor') ) ; |
---|
| 327 | ShowE('divLinkTypeEMail' , (linkType == 'email') ) ; |
---|
| 328 | |
---|
| 329 | if ( !FCKConfig.LinkDlgHideTarget ) |
---|
| 330 | window.parent.SetTabVisibility( 'Target' , (linkType == 'url') ) ; |
---|
| 331 | |
---|
| 332 | if ( FCKConfig.LinkUpload ) |
---|
| 333 | window.parent.SetTabVisibility( 'Upload' , (linkType == 'url') ) ; |
---|
| 334 | |
---|
| 335 | if ( !FCKConfig.LinkDlgHideAdvanced ) |
---|
| 336 | window.parent.SetTabVisibility( 'Advanced' , (linkType != 'anchor' || bHasAnchors) ) ; |
---|
| 337 | |
---|
| 338 | if ( linkType == 'email' ) |
---|
| 339 | window.parent.SetAutoSize( true ) ; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | //#### Target type selection. |
---|
| 343 | function SetTarget( targetType ) |
---|
| 344 | { |
---|
| 345 | GetE('tdTargetFrame').style.display = ( targetType == 'popup' ? 'none' : '' ) ; |
---|
| 346 | GetE('tdPopupName').style.display = |
---|
| 347 | GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ; |
---|
| 348 | |
---|
| 349 | switch ( targetType ) |
---|
| 350 | { |
---|
| 351 | case "_blank" : |
---|
| 352 | case "_self" : |
---|
| 353 | case "_parent" : |
---|
| 354 | case "_top" : |
---|
| 355 | GetE('txtTargetFrame').value = targetType ; |
---|
| 356 | break ; |
---|
| 357 | case "" : |
---|
| 358 | GetE('txtTargetFrame').value = '' ; |
---|
| 359 | break ; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | if ( targetType == 'popup' ) |
---|
| 363 | window.parent.SetAutoSize( true ) ; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | //#### Called while the user types the URL. |
---|
| 367 | function OnUrlChange() |
---|
| 368 | { |
---|
| 369 | var sUrl = GetE('txtUrl').value ; |
---|
| 370 | var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ; |
---|
| 371 | |
---|
| 372 | if ( sProtocol ) |
---|
| 373 | { |
---|
| 374 | sUrl = sUrl.substr( sProtocol[0].length ) ; |
---|
| 375 | GetE('txtUrl').value = sUrl ; |
---|
| 376 | GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ; |
---|
| 377 | } |
---|
| 378 | else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) ) |
---|
| 379 | { |
---|
| 380 | GetE('cmbLinkProtocol').value = '' ; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | //#### Called while the user types the target name. |
---|
| 385 | function OnTargetNameChange() |
---|
| 386 | { |
---|
| 387 | var sFrame = GetE('txtTargetFrame').value ; |
---|
| 388 | |
---|
| 389 | if ( sFrame.length == 0 ) |
---|
| 390 | GetE('cmbTarget').value = '' ; |
---|
| 391 | else if ( oRegex.ReserveTarget.test( sFrame ) ) |
---|
| 392 | GetE('cmbTarget').value = sFrame.toLowerCase() ; |
---|
| 393 | else |
---|
| 394 | GetE('cmbTarget').value = 'frame' ; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | // Accesible popups |
---|
| 398 | function BuildOnClickPopup() |
---|
| 399 | { |
---|
| 400 | var sWindowName = "'" + GetE('txtPopupName').value.replace(/\W/gi, "") + "'" ; |
---|
| 401 | |
---|
| 402 | var sFeatures = '' ; |
---|
| 403 | var aChkFeatures = document.getElementsByName( 'chkFeature' ) ; |
---|
| 404 | for ( var i = 0 ; i < aChkFeatures.length ; i++ ) |
---|
| 405 | { |
---|
| 406 | if ( i > 0 ) sFeatures += ',' ; |
---|
| 407 | sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | if ( GetE('txtPopupWidth').value.length > 0 ) sFeatures += ',width=' + GetE('txtPopupWidth').value ; |
---|
| 411 | if ( GetE('txtPopupHeight').value.length > 0 ) sFeatures += ',height=' + GetE('txtPopupHeight').value ; |
---|
| 412 | if ( GetE('txtPopupLeft').value.length > 0 ) sFeatures += ',left=' + GetE('txtPopupLeft').value ; |
---|
| 413 | if ( GetE('txtPopupTop').value.length > 0 ) sFeatures += ',top=' + GetE('txtPopupTop').value ; |
---|
| 414 | |
---|
| 415 | if ( sFeatures != '' ) |
---|
| 416 | sFeatures = sFeatures + ",status" ; |
---|
| 417 | |
---|
| 418 | return ( "window.open(this.href," + sWindowName + ",'" + sFeatures + "'); return false" ) ; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | //#### Fills all Popup related fields. |
---|
| 422 | function FillPopupFields( windowName, features ) |
---|
| 423 | { |
---|
| 424 | if ( windowName ) |
---|
| 425 | GetE('txtPopupName').value = windowName ; |
---|
| 426 | |
---|
| 427 | var oFeatures = new Object() ; |
---|
| 428 | var oFeaturesMatch ; |
---|
| 429 | while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null ) |
---|
| 430 | { |
---|
| 431 | var sValue = oFeaturesMatch[2] ; |
---|
| 432 | if ( sValue == ( 'yes' || '1' ) ) |
---|
| 433 | oFeatures[ oFeaturesMatch[1] ] = true ; |
---|
| 434 | else if ( ! isNaN( sValue ) && sValue != 0 ) |
---|
| 435 | oFeatures[ oFeaturesMatch[1] ] = sValue ; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | // Update all features check boxes. |
---|
| 439 | var aChkFeatures = document.getElementsByName('chkFeature') ; |
---|
| 440 | for ( var i = 0 ; i < aChkFeatures.length ; i++ ) |
---|
| 441 | { |
---|
| 442 | if ( oFeatures[ aChkFeatures[i].value ] ) |
---|
| 443 | aChkFeatures[i].checked = true ; |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | // Update position and size text boxes. |
---|
| 447 | if ( oFeatures['width'] ) GetE('txtPopupWidth').value = oFeatures['width'] ; |
---|
| 448 | if ( oFeatures['height'] ) GetE('txtPopupHeight').value = oFeatures['height'] ; |
---|
| 449 | if ( oFeatures['left'] ) GetE('txtPopupLeft').value = oFeatures['left'] ; |
---|
| 450 | if ( oFeatures['top'] ) GetE('txtPopupTop').value = oFeatures['top'] ; |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | //#### The OK button was hit. |
---|
| 454 | function Ok() |
---|
| 455 | { |
---|
| 456 | var sUri, sInnerHtml ; |
---|
| 457 | |
---|
| 458 | switch ( GetE('cmbLinkType').value ) |
---|
| 459 | { |
---|
| 460 | case 'url' : |
---|
| 461 | sUri = GetE('txtUrl').value ; |
---|
| 462 | |
---|
| 463 | if ( sUri.length == 0 ) |
---|
| 464 | { |
---|
| 465 | alert( FCKLang.DlnLnkMsgNoUrl ) ; |
---|
| 466 | return false ; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | sUri = GetE('cmbLinkProtocol').value + sUri ; |
---|
| 470 | |
---|
| 471 | break ; |
---|
| 472 | |
---|
| 473 | case 'email' : |
---|
| 474 | sUri = GetE('txtEMailAddress').value ; |
---|
| 475 | |
---|
| 476 | if ( sUri.length == 0 ) |
---|
| 477 | { |
---|
| 478 | alert( FCKLang.DlnLnkMsgNoEMail ) ; |
---|
| 479 | return false ; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | sUri = oParser.CreateEMailUri( |
---|
| 483 | sUri, |
---|
| 484 | GetE('txtEMailSubject').value, |
---|
| 485 | GetE('txtEMailBody').value ) ; |
---|
| 486 | break ; |
---|
| 487 | |
---|
| 488 | case 'anchor' : |
---|
| 489 | var sAnchor = GetE('cmbAnchorName').value ; |
---|
| 490 | if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ; |
---|
| 491 | |
---|
| 492 | if ( sAnchor.length == 0 ) |
---|
| 493 | { |
---|
| 494 | alert( FCKLang.DlnLnkMsgNoAnchor ) ; |
---|
| 495 | return false ; |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | sUri = '#' + sAnchor ; |
---|
| 499 | break ; |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | // No link selected, so try to create one. |
---|
| 503 | if ( !oLink ) |
---|
| 504 | oLink = oEditor.FCK.CreateLink( sUri ) ; |
---|
| 505 | |
---|
| 506 | if ( oLink ) |
---|
| 507 | sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL). |
---|
| 508 | else |
---|
| 509 | { |
---|
| 510 | // If no selection, use the uri as the link text (by dom, 2006-05-26) |
---|
| 511 | |
---|
| 512 | sInnerHtml = sUri; |
---|
| 513 | |
---|
| 514 | // Built a better text for empty links. |
---|
| 515 | switch ( GetE('cmbLinkType').value ) |
---|
| 516 | { |
---|
| 517 | // anchor: use old behavior --> return true |
---|
| 518 | case 'anchor': |
---|
| 519 | sInnerHtml = sInnerHtml.replace( /^#/, '' ) ; |
---|
| 520 | break ; |
---|
| 521 | |
---|
| 522 | // url: try to get path |
---|
| 523 | case 'url': |
---|
| 524 | var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ; |
---|
| 525 | var asLinkPath = oLinkPathRegEx.exec( sUri ) ; |
---|
| 526 | if (asLinkPath != null) |
---|
| 527 | sInnerHtml = asLinkPath[1]; // use matched path |
---|
| 528 | break ; |
---|
| 529 | |
---|
| 530 | // mailto: try to get email address |
---|
| 531 | case 'email': |
---|
| 532 | sInnerHtml = GetE('txtEMailAddress').value ; |
---|
| 533 | break ; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | // Create a new (empty) anchor. |
---|
| 537 | oLink = oEditor.FCK.CreateElement( 'a' ) ; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | oEditor.FCKUndo.SaveUndoStep() ; |
---|
| 541 | |
---|
| 542 | oLink.href = sUri ; |
---|
| 543 | SetAttribute( oLink, '_fcksavedurl', sUri ) ; |
---|
| 544 | |
---|
| 545 | // Accesible popups |
---|
| 546 | if( GetE('cmbTarget').value == 'popup' ) |
---|
| 547 | { |
---|
| 548 | SetAttribute( oLink, 'onclick_fckprotectedatt', " onclick=\"" + BuildOnClickPopup() + "\"") ; |
---|
| 549 | } |
---|
| 550 | else |
---|
| 551 | { |
---|
| 552 | // Check if the previous onclick was for a popup: |
---|
| 553 | // In that case remove the onclick handler. |
---|
| 554 | var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; |
---|
| 555 | if( oRegex.OnClickPopup.test( onclick ) ) |
---|
| 556 | SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ; |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | oLink.innerHTML = sInnerHtml ; // Set (or restore) the innerHTML |
---|
| 560 | |
---|
| 561 | // Target |
---|
| 562 | if( GetE('cmbTarget').value != 'popup' ) |
---|
| 563 | SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ; |
---|
| 564 | else |
---|
| 565 | SetAttribute( oLink, 'target', null ) ; |
---|
| 566 | |
---|
| 567 | // Advances Attributes |
---|
| 568 | SetAttribute( oLink, 'id' , GetE('txtAttId').value ) ; |
---|
| 569 | SetAttribute( oLink, 'name' , GetE('txtAttName').value ) ; |
---|
| 570 | SetAttribute( oLink, 'dir' , GetE('cmbAttLangDir').value ) ; |
---|
| 571 | SetAttribute( oLink, 'lang' , GetE('txtAttLangCode').value ) ; |
---|
| 572 | SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ; |
---|
| 573 | SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ; |
---|
| 574 | SetAttribute( oLink, 'title' , GetE('txtAttTitle').value ) ; |
---|
| 575 | SetAttribute( oLink, 'type' , GetE('txtAttContentType').value ) ; |
---|
| 576 | SetAttribute( oLink, 'charset' , GetE('txtAttCharSet').value ) ; |
---|
| 577 | |
---|
| 578 | if ( oEditor.FCKBrowserInfo.IsIE ) |
---|
| 579 | { |
---|
| 580 | var sClass = GetE('txtAttClasses').value ; |
---|
| 581 | // If it's also an anchor add an internal class |
---|
| 582 | if ( GetE('txtAttName').value.length != 0 ) |
---|
| 583 | sClass += ' FCK__AnchorC' ; |
---|
| 584 | SetAttribute( oLink, 'className', sClass ) ; |
---|
| 585 | |
---|
| 586 | oLink.style.cssText = GetE('txtAttStyle').value ; |
---|
| 587 | } |
---|
| 588 | else |
---|
| 589 | { |
---|
| 590 | SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ; |
---|
| 591 | SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | // Select the link. |
---|
| 595 | oEditor.FCKSelection.SelectNode(oLink); |
---|
| 596 | |
---|
| 597 | return true ; |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | function BrowseServer() |
---|
| 601 | { |
---|
| 602 | OpenFileBrowser( FCKConfig.LinkBrowserURL, FCKConfig.LinkBrowserWindowWidth, FCKConfig.LinkBrowserWindowHeight ) ; |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | function SetUrl( url ) |
---|
| 606 | { |
---|
| 607 | document.getElementById('txtUrl').value = url ; |
---|
| 608 | OnUrlChange() ; |
---|
| 609 | window.parent.SetSelectedTab( 'Info' ) ; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg ) |
---|
| 613 | { |
---|
| 614 | switch ( errorNumber ) |
---|
| 615 | { |
---|
| 616 | case 0 : // No errors |
---|
| 617 | alert( 'Your file has been successfully uploaded' ) ; |
---|
| 618 | break ; |
---|
| 619 | case 1 : // Custom error |
---|
| 620 | alert( customMsg ) ; |
---|
| 621 | return ; |
---|
| 622 | case 101 : // Custom warning |
---|
| 623 | alert( customMsg ) ; |
---|
| 624 | break ; |
---|
| 625 | case 201 : |
---|
| 626 | alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ; |
---|
| 627 | break ; |
---|
| 628 | case 202 : |
---|
| 629 | alert( 'Invalid file type' ) ; |
---|
| 630 | return ; |
---|
| 631 | case 203 : |
---|
| 632 | alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; |
---|
| 633 | return ; |
---|
| 634 | default : |
---|
| 635 | alert( 'Error on file upload. Error number: ' + errorNumber ) ; |
---|
| 636 | return ; |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | SetUrl( fileUrl ) ; |
---|
| 640 | GetE('frmUpload').reset() ; |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | var oUploadAllowedExtRegex = new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ; |
---|
| 644 | var oUploadDeniedExtRegex = new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ; |
---|
| 645 | |
---|
| 646 | function CheckUpload() |
---|
| 647 | { |
---|
| 648 | var sFile = GetE('txtUploadFile').value ; |
---|
| 649 | |
---|
| 650 | if ( sFile.length == 0 ) |
---|
| 651 | { |
---|
| 652 | alert( 'Please select a file to upload' ) ; |
---|
| 653 | return false ; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) || |
---|
| 657 | ( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) ) |
---|
| 658 | { |
---|
| 659 | OnUploadCompleted( 202 ) ; |
---|
| 660 | return false ; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | return true ; |
---|
| 664 | } |
---|