PageRenderTime 40ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/fckeditor/editor/dialog/fck_link/fck_link.js

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