PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/UniqueStudio.Admin/admin/editor/fckeditor/editor/dialog/fck_link/fck_link.js

http://uniquestudiocms.googlecode.com/
JavaScript | 893 lines | 632 code | 153 blank | 108 comment | 159 complexity | 9fd85d3c0ba1c37441af28c934bfcd86 MD5 | raw file
  1. /*
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2008 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 dialog = window.parent ;
  24. var oEditor = dialog.InnerDialogLoaded() ;
  25. var FCK = oEditor.FCK ;
  26. var FCKLang = oEditor.FCKLang ;
  27. var FCKConfig = oEditor.FCKConfig ;
  28. var FCKRegexLib = oEditor.FCKRegexLib ;
  29. var FCKTools = oEditor.FCKTools ;
  30. //#### Dialog Tabs
  31. // Set the dialog tabs.
  32. dialog.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ;
  33. if ( !FCKConfig.LinkDlgHideTarget )
  34. dialog.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ;
  35. if ( FCKConfig.LinkUpload )
  36. dialog.AddTab( 'Upload', FCKLang.DlgLnkUpload, true ) ;
  37. if ( !FCKConfig.LinkDlgHideAdvanced )
  38. dialog.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ;
  39. // Function called when a dialog tag is selected.
  40. function OnDialogTabChange( tabCode )
  41. {
  42. ShowE('divInfo' , ( tabCode == 'Info' ) ) ;
  43. ShowE('divTarget' , ( tabCode == 'Target' ) ) ;
  44. ShowE('divUpload' , ( tabCode == 'Upload' ) ) ;
  45. ShowE('divAttribs' , ( tabCode == 'Advanced' ) ) ;
  46. dialog.SetAutoSize( true ) ;
  47. }
  48. //#### Regular Expressions library.
  49. var oRegex = new Object() ;
  50. oRegex.UriProtocol = /^(((http|https|ftp|news):\/\/)|mailto:)/gi ;
  51. oRegex.UrlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi ;
  52. oRegex.UrlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi ;
  53. oRegex.ReserveTarget = /^_(blank|self|top|parent)$/i ;
  54. oRegex.PopupUri = /^javascript:void\(\s*window.open\(\s*'([^']+)'\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*\)\s*$/ ;
  55. // Accessible popups
  56. oRegex.OnClickPopup = /^\s*on[cC]lick="\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*"$/ ;
  57. oRegex.PopupFeatures = /(?:^|,)([^=]+)=(\d+|yes|no)/gi ;
  58. //#### Parser Functions
  59. var oParser = new Object() ;
  60. // This method simply returns the two inputs in numerical order. You can even
  61. // provide strings, as the method would parseInt() the values.
  62. oParser.SortNumerical = function(a, b)
  63. {
  64. return parseInt( a, 10 ) - parseInt( b, 10 ) ;
  65. }
  66. oParser.ParseEMailParams = function(sParams)
  67. {
  68. // Initialize the oEMailParams object.
  69. var oEMailParams = new Object() ;
  70. oEMailParams.Subject = '' ;
  71. oEMailParams.Body = '' ;
  72. var aMatch = sParams.match( /(^|^\?|&)subject=([^&]+)/i ) ;
  73. if ( aMatch ) oEMailParams.Subject = decodeURIComponent( aMatch[2] ) ;
  74. aMatch = sParams.match( /(^|^\?|&)body=([^&]+)/i ) ;
  75. if ( aMatch ) oEMailParams.Body = decodeURIComponent( aMatch[2] ) ;
  76. return oEMailParams ;
  77. }
  78. // This method returns either an object containing the email info, or FALSE
  79. // if the parameter is not an email link.
  80. oParser.ParseEMailUri = function( sUrl )
  81. {
  82. // Initializes the EMailInfo object.
  83. var oEMailInfo = new Object() ;
  84. oEMailInfo.Address = '' ;
  85. oEMailInfo.Subject = '' ;
  86. oEMailInfo.Body = '' ;
  87. var aLinkInfo = sUrl.match( /^(\w+):(.*)$/ ) ;
  88. if ( aLinkInfo && aLinkInfo[1] == 'mailto' )
  89. {
  90. // This seems to be an unprotected email link.
  91. var aParts = aLinkInfo[2].match( /^([^\?]+)\??(.+)?/ ) ;
  92. if ( aParts )
  93. {
  94. // Set the e-mail address.
  95. oEMailInfo.Address = aParts[1] ;
  96. // Look for the optional e-mail parameters.
  97. if ( aParts[2] )
  98. {
  99. var oEMailParams = oParser.ParseEMailParams( aParts[2] ) ;
  100. oEMailInfo.Subject = oEMailParams.Subject ;
  101. oEMailInfo.Body = oEMailParams.Body ;
  102. }
  103. }
  104. return oEMailInfo ;
  105. }
  106. else if ( aLinkInfo && aLinkInfo[1] == 'javascript' )
  107. {
  108. // This may be a protected email.
  109. // Try to match the url against the EMailProtectionFunction.
  110. var func = FCKConfig.EMailProtectionFunction ;
  111. if ( func != null )
  112. {
  113. try
  114. {
  115. // Escape special chars.
  116. func = func.replace( /([\/^$*+.?()\[\]])/g, '\\$1' ) ;
  117. // Define the possible keys.
  118. var keys = new Array('NAME', 'DOMAIN', 'SUBJECT', 'BODY') ;
  119. // Get the order of the keys (hold them in the array <pos>) and
  120. // the function replaced by regular expression patterns.
  121. var sFunc = func ;
  122. var pos = new Array() ;
  123. for ( var i = 0 ; i < keys.length ; i ++ )
  124. {
  125. var rexp = new RegExp( keys[i] ) ;
  126. var p = func.search( rexp ) ;
  127. if ( p >= 0 )
  128. {
  129. sFunc = sFunc.replace( rexp, '\'([^\']*)\'' ) ;
  130. pos[pos.length] = p + ':' + keys[i] ;
  131. }
  132. }
  133. // Sort the available keys.
  134. pos.sort( oParser.SortNumerical ) ;
  135. // Replace the excaped single quotes in the url, such they do
  136. // not affect the regexp afterwards.
  137. aLinkInfo[2] = aLinkInfo[2].replace( /\\'/g, '###SINGLE_QUOTE###' ) ;
  138. // Create the regexp and execute it.
  139. var rFunc = new RegExp( '^' + sFunc + '$' ) ;
  140. var aMatch = rFunc.exec( aLinkInfo[2] ) ;
  141. if ( aMatch )
  142. {
  143. var aInfo = new Array();
  144. for ( var i = 1 ; i < aMatch.length ; i ++ )
  145. {
  146. var k = pos[i-1].match(/^\d+:(.+)$/) ;
  147. aInfo[k[1]] = aMatch[i].replace(/###SINGLE_QUOTE###/g, '\'') ;
  148. }
  149. // Fill the EMailInfo object that will be returned
  150. oEMailInfo.Address = aInfo['NAME'] + '@' + aInfo['DOMAIN'] ;
  151. oEMailInfo.Subject = decodeURIComponent( aInfo['SUBJECT'] ) ;
  152. oEMailInfo.Body = decodeURIComponent( aInfo['BODY'] ) ;
  153. return oEMailInfo ;
  154. }
  155. }
  156. catch (e)
  157. {
  158. }
  159. }
  160. // Try to match the email against the encode protection.
  161. var aMatch = aLinkInfo[2].match( /^location\.href='mailto:'\+(String\.fromCharCode\([\d,]+\))\+'(.*)'$/ ) ;
  162. if ( aMatch )
  163. {
  164. // The link is encoded
  165. oEMailInfo.Address = eval( aMatch[1] ) ;
  166. if ( aMatch[2] )
  167. {
  168. var oEMailParams = oParser.ParseEMailParams( aMatch[2] ) ;
  169. oEMailInfo.Subject = oEMailParams.Subject ;
  170. oEMailInfo.Body = oEMailParams.Body ;
  171. }
  172. return oEMailInfo ;
  173. }
  174. }
  175. return false;
  176. }
  177. oParser.CreateEMailUri = function( address, subject, body )
  178. {
  179. // Switch for the EMailProtection setting.
  180. switch ( FCKConfig.EMailProtection )
  181. {
  182. case 'function' :
  183. var func = FCKConfig.EMailProtectionFunction ;
  184. if ( func == null )
  185. {
  186. if ( FCKConfig.Debug )
  187. {
  188. alert('EMailProtection alert!\nNo function defined. Please set "FCKConfig.EMailProtectionFunction"') ;
  189. }
  190. return '';
  191. }
  192. // Split the email address into name and domain parts.
  193. var aAddressParts = address.split( '@', 2 ) ;
  194. if ( aAddressParts[1] == undefined )
  195. {
  196. aAddressParts[1] = '' ;
  197. }
  198. // Replace the keys by their values (embedded in single quotes).
  199. func = func.replace(/NAME/g, "'" + aAddressParts[0].replace(/'/g, '\\\'') + "'") ;
  200. func = func.replace(/DOMAIN/g, "'" + aAddressParts[1].replace(/'/g, '\\\'') + "'") ;
  201. func = func.replace(/SUBJECT/g, "'" + encodeURIComponent( subject ).replace(/'/g, '\\\'') + "'") ;
  202. func = func.replace(/BODY/g, "'" + encodeURIComponent( body ).replace(/'/g, '\\\'') + "'") ;
  203. return 'javascript:' + func ;
  204. case 'encode' :
  205. var aParams = [] ;
  206. var aAddressCode = [] ;
  207. if ( subject.length > 0 )
  208. aParams.push( 'subject='+ encodeURIComponent( subject ) ) ;
  209. if ( body.length > 0 )
  210. aParams.push( 'body=' + encodeURIComponent( body ) ) ;
  211. for ( var i = 0 ; i < address.length ; i++ )
  212. aAddressCode.push( address.charCodeAt( i ) ) ;
  213. return 'javascript:location.href=\'mailto:\'+String.fromCharCode(' + aAddressCode.join( ',' ) + ')+\'?' + aParams.join( '&' ) + '\'' ;
  214. }
  215. // EMailProtection 'none'
  216. var sBaseUri = 'mailto:' + address ;
  217. var sParams = '' ;
  218. if ( subject.length > 0 )
  219. sParams = '?subject=' + encodeURIComponent( subject ) ;
  220. if ( body.length > 0 )
  221. {
  222. sParams += ( sParams.length == 0 ? '?' : '&' ) ;
  223. sParams += 'body=' + encodeURIComponent( body ) ;
  224. }
  225. return sBaseUri + sParams ;
  226. }
  227. //#### Initialization Code
  228. // oLink: The actual selected link in the editor.
  229. var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
  230. if ( oLink )
  231. FCK.Selection.SelectNode( oLink ) ;
  232. window.onload = function()
  233. {
  234. // Translate the dialog box texts.
  235. oEditor.FCKLanguageManager.TranslatePage(document) ;
  236. // Fill the Anchor Names and Ids combos.
  237. LoadAnchorNamesAndIds() ;
  238. // Load the selected link information (if any).
  239. LoadSelection() ;
  240. // Update the dialog box.
  241. SetLinkType( GetE('cmbLinkType').value ) ;
  242. // Show/Hide the "Browse Server" button.
  243. GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ;
  244. // Show the initial dialog content.
  245. GetE('divInfo').style.display = '' ;
  246. // Set the actual uploader URL.
  247. if ( FCKConfig.LinkUpload )
  248. GetE('frmUpload').action = FCKConfig.LinkUploadURL ;
  249. // Set the default target (from configuration).
  250. SetDefaultTarget() ;
  251. // Activate the "OK" button.
  252. dialog.SetOkButton( true ) ;
  253. // Select the first field.
  254. switch( GetE('cmbLinkType').value )
  255. {
  256. case 'url' :
  257. SelectField( 'txtUrl' ) ;
  258. break ;
  259. case 'email' :
  260. SelectField( 'txtEMailAddress' ) ;
  261. break ;
  262. case 'anchor' :
  263. if ( GetE('divSelAnchor').style.display != 'none' )
  264. SelectField( 'cmbAnchorName' ) ;
  265. else
  266. SelectField( 'cmbLinkType' ) ;
  267. }
  268. }
  269. var bHasAnchors ;
  270. function LoadAnchorNamesAndIds()
  271. {
  272. // Since version 2.0, the anchors are replaced in the DOM by IMGs so the user see the icon
  273. // to edit them. So, we must look for that images now.
  274. var aAnchors = new Array() ;
  275. var i ;
  276. var oImages = oEditor.FCK.EditorDocument.getElementsByTagName( 'IMG' ) ;
  277. for( i = 0 ; i < oImages.length ; i++ )
  278. {
  279. if ( oImages[i].getAttribute('_fckanchor') )
  280. aAnchors[ aAnchors.length ] = oEditor.FCK.GetRealElement( oImages[i] ) ;
  281. }
  282. // Add also real anchors
  283. var oLinks = oEditor.FCK.EditorDocument.getElementsByTagName( 'A' ) ;
  284. for( i = 0 ; i < oLinks.length ; i++ )
  285. {
  286. if ( oLinks[i].name && ( oLinks[i].name.length > 0 ) )
  287. aAnchors[ aAnchors.length ] = oLinks[i] ;
  288. }
  289. var aIds = FCKTools.GetAllChildrenIds( oEditor.FCK.EditorDocument.body ) ;
  290. bHasAnchors = ( aAnchors.length > 0 || aIds.length > 0 ) ;
  291. for ( i = 0 ; i < aAnchors.length ; i++ )
  292. {
  293. var sName = aAnchors[i].name ;
  294. if ( sName && sName.length > 0 )
  295. FCKTools.AddSelectOption( GetE('cmbAnchorName'), sName, sName ) ;
  296. }
  297. for ( i = 0 ; i < aIds.length ; i++ )
  298. {
  299. FCKTools.AddSelectOption( GetE('cmbAnchorId'), aIds[i], aIds[i] ) ;
  300. }
  301. ShowE( 'divSelAnchor' , bHasAnchors ) ;
  302. ShowE( 'divNoAnchor' , !bHasAnchors ) ;
  303. }
  304. function LoadSelection()
  305. {
  306. if ( !oLink ) return ;
  307. var sType = 'url' ;
  308. // Get the actual Link href.
  309. var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
  310. if ( sHRef == null )
  311. sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
  312. // Look for a popup javascript link.
  313. var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ;
  314. if( oPopupMatch )
  315. {
  316. GetE('cmbTarget').value = 'popup' ;
  317. sHRef = oPopupMatch[1] ;
  318. FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ;
  319. SetTarget( 'popup' ) ;
  320. }
  321. // Accessible popups, the popup data is in the onclick attribute
  322. if ( !oPopupMatch )
  323. {
  324. var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
  325. if ( onclick )
  326. {
  327. // Decode the protected string
  328. onclick = decodeURIComponent( onclick ) ;
  329. oPopupMatch = oRegex.OnClickPopup.exec( onclick ) ;
  330. if( oPopupMatch )
  331. {
  332. GetE( 'cmbTarget' ).value = 'popup' ;
  333. FillPopupFields( oPopupMatch[1], oPopupMatch[2] ) ;
  334. SetTarget( 'popup' ) ;
  335. }
  336. }
  337. }
  338. // Search for the protocol.
  339. var sProtocol = oRegex.UriProtocol.exec( sHRef ) ;
  340. // Search for a protected email link.
  341. var oEMailInfo = oParser.ParseEMailUri( sHRef );
  342. if ( oEMailInfo )
  343. {
  344. sType = 'email' ;
  345. GetE('txtEMailAddress').value = oEMailInfo.Address ;
  346. GetE('txtEMailSubject').value = oEMailInfo.Subject ;
  347. GetE('txtEMailBody').value = oEMailInfo.Body ;
  348. }
  349. else if ( sProtocol )
  350. {
  351. sProtocol = sProtocol[0].toLowerCase() ;
  352. GetE('cmbLinkProtocol').value = sProtocol ;
  353. // Remove the protocol and get the remaining URL.
  354. var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ;
  355. sType = 'url' ;
  356. GetE('txtUrl').value = sUrl ;
  357. }
  358. else if ( sHRef.substr(0,1) == '#' && sHRef.length > 1 ) // It is an anchor link.
  359. {
  360. sType = 'anchor' ;
  361. GetE('cmbAnchorName').value = GetE('cmbAnchorId').value = sHRef.substr(1) ;
  362. }
  363. else // It is another type of link.
  364. {
  365. sType = 'url' ;
  366. GetE('cmbLinkProtocol').value = '' ;
  367. GetE('txtUrl').value = sHRef ;
  368. }
  369. if ( !oPopupMatch )
  370. {
  371. // Get the target.
  372. var sTarget = oLink.target ;
  373. if ( sTarget && sTarget.length > 0 )
  374. {
  375. if ( oRegex.ReserveTarget.test( sTarget ) )
  376. {
  377. sTarget = sTarget.toLowerCase() ;
  378. GetE('cmbTarget').value = sTarget ;
  379. }
  380. else
  381. GetE('cmbTarget').value = 'frame' ;
  382. GetE('txtTargetFrame').value = sTarget ;
  383. }
  384. }
  385. // Get Advances Attributes
  386. GetE('txtAttId').value = oLink.id ;
  387. GetE('txtAttName').value = oLink.name ;
  388. GetE('cmbAttLangDir').value = oLink.dir ;
  389. GetE('txtAttLangCode').value = oLink.lang ;
  390. GetE('txtAttAccessKey').value = oLink.accessKey ;
  391. GetE('txtAttTabIndex').value = oLink.tabIndex <= 0 ? '' : oLink.tabIndex ;
  392. GetE('txtAttTitle').value = oLink.title ;
  393. GetE('txtAttContentType').value = oLink.type ;
  394. GetE('txtAttCharSet').value = oLink.charset ;
  395. var sClass ;
  396. if ( oEditor.FCKBrowserInfo.IsIE )
  397. {
  398. sClass = oLink.getAttribute('className',2) || '' ;
  399. // Clean up temporary classes for internal use:
  400. sClass = sClass.replace( FCKRegexLib.FCK_Class, '' ) ;
  401. GetE('txtAttStyle').value = oLink.style.cssText ;
  402. }
  403. else
  404. {
  405. sClass = oLink.getAttribute('class',2) || '' ;
  406. GetE('txtAttStyle').value = oLink.getAttribute('style',2) || '' ;
  407. }
  408. GetE('txtAttClasses').value = sClass ;
  409. // Update the Link type combo.
  410. GetE('cmbLinkType').value = sType ;
  411. }
  412. //#### Link type selection.
  413. function SetLinkType( linkType )
  414. {
  415. ShowE('divLinkTypeUrl' , (linkType == 'url') ) ;
  416. ShowE('divLinkTypeAnchor' , (linkType == 'anchor') ) ;
  417. ShowE('divLinkTypeEMail' , (linkType == 'email') ) ;
  418. if ( !FCKConfig.LinkDlgHideTarget )
  419. dialog.SetTabVisibility( 'Target' , (linkType == 'url') ) ;
  420. if ( FCKConfig.LinkUpload )
  421. dialog.SetTabVisibility( 'Upload' , (linkType == 'url') ) ;
  422. if ( !FCKConfig.LinkDlgHideAdvanced )
  423. dialog.SetTabVisibility( 'Advanced' , (linkType != 'anchor' || bHasAnchors) ) ;
  424. if ( linkType == 'email' )
  425. dialog.SetAutoSize( true ) ;
  426. }
  427. //#### Target type selection.
  428. function SetTarget( targetType )
  429. {
  430. GetE('tdTargetFrame').style.display = ( targetType == 'popup' ? 'none' : '' ) ;
  431. GetE('tdPopupName').style.display =
  432. GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ;
  433. switch ( targetType )
  434. {
  435. case "_blank" :
  436. case "_self" :
  437. case "_parent" :
  438. case "_top" :
  439. GetE('txtTargetFrame').value = targetType ;
  440. break ;
  441. case "" :
  442. GetE('txtTargetFrame').value = '' ;
  443. break ;
  444. }
  445. if ( targetType == 'popup' )
  446. dialog.SetAutoSize( true ) ;
  447. }
  448. //#### Called while the user types the URL.
  449. function OnUrlChange()
  450. {
  451. var sUrl = GetE('txtUrl').value ;
  452. var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ;
  453. if ( sProtocol )
  454. {
  455. sUrl = sUrl.substr( sProtocol[0].length ) ;
  456. GetE('txtUrl').value = sUrl ;
  457. GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ;
  458. }
  459. else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) )
  460. {
  461. GetE('cmbLinkProtocol').value = '' ;
  462. }
  463. }
  464. //#### Called while the user types the target name.
  465. function OnTargetNameChange()
  466. {
  467. var sFrame = GetE('txtTargetFrame').value ;
  468. if ( sFrame.length == 0 )
  469. GetE('cmbTarget').value = '' ;
  470. else if ( oRegex.ReserveTarget.test( sFrame ) )
  471. GetE('cmbTarget').value = sFrame.toLowerCase() ;
  472. else
  473. GetE('cmbTarget').value = 'frame' ;
  474. }
  475. // Accessible popups
  476. function BuildOnClickPopup()
  477. {
  478. var sWindowName = "'" + GetE('txtPopupName').value.replace(/\W/gi, "") + "'" ;
  479. var sFeatures = '' ;
  480. var aChkFeatures = document.getElementsByName( 'chkFeature' ) ;
  481. for ( var i = 0 ; i < aChkFeatures.length ; i++ )
  482. {
  483. if ( i > 0 ) sFeatures += ',' ;
  484. sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ;
  485. }
  486. if ( GetE('txtPopupWidth').value.length > 0 ) sFeatures += ',width=' + GetE('txtPopupWidth').value ;
  487. if ( GetE('txtPopupHeight').value.length > 0 ) sFeatures += ',height=' + GetE('txtPopupHeight').value ;
  488. if ( GetE('txtPopupLeft').value.length > 0 ) sFeatures += ',left=' + GetE('txtPopupLeft').value ;
  489. if ( GetE('txtPopupTop').value.length > 0 ) sFeatures += ',top=' + GetE('txtPopupTop').value ;
  490. if ( sFeatures != '' )
  491. sFeatures = sFeatures + ",status" ;
  492. return ( "window.open(this.href," + sWindowName + ",'" + sFeatures + "'); return false" ) ;
  493. }
  494. //#### Fills all Popup related fields.
  495. function FillPopupFields( windowName, features )
  496. {
  497. if ( windowName )
  498. GetE('txtPopupName').value = windowName ;
  499. var oFeatures = new Object() ;
  500. var oFeaturesMatch ;
  501. while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null )
  502. {
  503. var sValue = oFeaturesMatch[2] ;
  504. if ( sValue == ( 'yes' || '1' ) )
  505. oFeatures[ oFeaturesMatch[1] ] = true ;
  506. else if ( ! isNaN( sValue ) && sValue != 0 )
  507. oFeatures[ oFeaturesMatch[1] ] = sValue ;
  508. }
  509. // Update all features check boxes.
  510. var aChkFeatures = document.getElementsByName('chkFeature') ;
  511. for ( var i = 0 ; i < aChkFeatures.length ; i++ )
  512. {
  513. if ( oFeatures[ aChkFeatures[i].value ] )
  514. aChkFeatures[i].checked = true ;
  515. }
  516. // Update position and size text boxes.
  517. if ( oFeatures['width'] ) GetE('txtPopupWidth').value = oFeatures['width'] ;
  518. if ( oFeatures['height'] ) GetE('txtPopupHeight').value = oFeatures['height'] ;
  519. if ( oFeatures['left'] ) GetE('txtPopupLeft').value = oFeatures['left'] ;
  520. if ( oFeatures['top'] ) GetE('txtPopupTop').value = oFeatures['top'] ;
  521. }
  522. //#### The OK button was hit.
  523. function Ok()
  524. {
  525. var sUri, sInnerHtml ;
  526. oEditor.FCKUndo.SaveUndoStep() ;
  527. switch ( GetE('cmbLinkType').value )
  528. {
  529. case 'url' :
  530. sUri = GetE('txtUrl').value ;
  531. if ( sUri.length == 0 )
  532. {
  533. alert( FCKLang.DlnLnkMsgNoUrl ) ;
  534. return false ;
  535. }
  536. sUri = GetE('cmbLinkProtocol').value + sUri ;
  537. break ;
  538. case 'email' :
  539. sUri = GetE('txtEMailAddress').value ;
  540. if ( sUri.length == 0 )
  541. {
  542. alert( FCKLang.DlnLnkMsgNoEMail ) ;
  543. return false ;
  544. }
  545. sUri = oParser.CreateEMailUri(
  546. sUri,
  547. GetE('txtEMailSubject').value,
  548. GetE('txtEMailBody').value ) ;
  549. break ;
  550. case 'anchor' :
  551. var sAnchor = GetE('cmbAnchorName').value ;
  552. if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ;
  553. if ( sAnchor.length == 0 )
  554. {
  555. alert( FCKLang.DlnLnkMsgNoAnchor ) ;
  556. return false ;
  557. }
  558. sUri = '#' + sAnchor ;
  559. break ;
  560. }
  561. // If no link is selected, create a new one (it may result in more than one link creation - #220).
  562. var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri, true ) ;
  563. // If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
  564. var aHasSelection = ( aLinks.length > 0 ) ;
  565. if ( !aHasSelection )
  566. {
  567. sInnerHtml = sUri;
  568. // Built a better text for empty links.
  569. switch ( GetE('cmbLinkType').value )
  570. {
  571. // anchor: use old behavior --> return true
  572. case 'anchor':
  573. sInnerHtml = sInnerHtml.replace( /^#/, '' ) ;
  574. break ;
  575. // url: try to get path
  576. case 'url':
  577. var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ;
  578. var asLinkPath = oLinkPathRegEx.exec( sUri ) ;
  579. if (asLinkPath != null)
  580. sInnerHtml = asLinkPath[1]; // use matched path
  581. break ;
  582. // mailto: try to get email address
  583. case 'email':
  584. sInnerHtml = GetE('txtEMailAddress').value ;
  585. break ;
  586. }
  587. // Create a new (empty) anchor.
  588. aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
  589. }
  590. for ( var i = 0 ; i < aLinks.length ; i++ )
  591. {
  592. oLink = aLinks[i] ;
  593. if ( aHasSelection )
  594. sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL).
  595. oLink.href = sUri ;
  596. SetAttribute( oLink, '_fcksavedurl', sUri ) ;
  597. var onclick;
  598. // Accessible popups
  599. if( GetE('cmbTarget').value == 'popup' )
  600. {
  601. onclick = BuildOnClickPopup() ;
  602. // Encode the attribute
  603. onclick = encodeURIComponent( " onclick=\"" + onclick + "\"" ) ;
  604. SetAttribute( oLink, 'onclick_fckprotectedatt', onclick ) ;
  605. }
  606. else
  607. {
  608. // Check if the previous onclick was for a popup:
  609. // In that case remove the onclick handler.
  610. onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
  611. if ( onclick )
  612. {
  613. // Decode the protected string
  614. onclick = decodeURIComponent( onclick ) ;
  615. if( oRegex.OnClickPopup.test( onclick ) )
  616. SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ;
  617. }
  618. }
  619. oLink.innerHTML = sInnerHtml ; // Set (or restore) the innerHTML
  620. // Target
  621. if( GetE('cmbTarget').value != 'popup' )
  622. SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
  623. else
  624. SetAttribute( oLink, 'target', null ) ;
  625. // Let's set the "id" only for the first link to avoid duplication.
  626. if ( i == 0 )
  627. SetAttribute( oLink, 'id', GetE('txtAttId').value ) ;
  628. // Advances Attributes
  629. SetAttribute( oLink, 'name' , GetE('txtAttName').value ) ;
  630. SetAttribute( oLink, 'dir' , GetE('cmbAttLangDir').value ) ;
  631. SetAttribute( oLink, 'lang' , GetE('txtAttLangCode').value ) ;
  632. SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ;
  633. SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ;
  634. SetAttribute( oLink, 'title' , GetE('txtAttTitle').value ) ;
  635. SetAttribute( oLink, 'type' , GetE('txtAttContentType').value ) ;
  636. SetAttribute( oLink, 'charset' , GetE('txtAttCharSet').value ) ;
  637. if ( oEditor.FCKBrowserInfo.IsIE )
  638. {
  639. var sClass = GetE('txtAttClasses').value ;
  640. // If it's also an anchor add an internal class
  641. if ( GetE('txtAttName').value.length != 0 )
  642. sClass += ' FCK__AnchorC' ;
  643. SetAttribute( oLink, 'className', sClass ) ;
  644. oLink.style.cssText = GetE('txtAttStyle').value ;
  645. }
  646. else
  647. {
  648. SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ;
  649. SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ;
  650. }
  651. }
  652. // Select the (first) link.
  653. oEditor.FCKSelection.SelectNode( aLinks[0] );
  654. return true ;
  655. }
  656. function BrowseServer()
  657. {
  658. OpenFileBrowser( FCKConfig.LinkBrowserURL, FCKConfig.LinkBrowserWindowWidth, FCKConfig.LinkBrowserWindowHeight ) ;
  659. }
  660. function SetUrl( url )
  661. {
  662. GetE('txtUrl').value = url ;
  663. OnUrlChange() ;
  664. dialog.SetSelectedTab( 'Info' ) ;
  665. }
  666. function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
  667. {
  668. // Remove animation
  669. window.parent.Throbber.Hide() ;
  670. GetE( 'divUpload' ).style.display = '' ;
  671. switch ( errorNumber )
  672. {
  673. case 0 : // No errors
  674. alert( 'Your file has been successfully uploaded' ) ;
  675. break ;
  676. case 1 : // Custom error
  677. alert( customMsg ) ;
  678. return ;
  679. case 101 : // Custom warning
  680. alert( customMsg ) ;
  681. break ;
  682. case 201 :
  683. alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
  684. break ;
  685. case 202 :
  686. alert( 'Invalid file type' ) ;
  687. return ;
  688. case 203 :
  689. alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
  690. return ;
  691. case 500 :
  692. alert( 'The connector is disabled' ) ;
  693. break ;
  694. default :
  695. alert( 'Error on file upload. Error number: ' + errorNumber ) ;
  696. return ;
  697. }
  698. SetUrl( fileUrl ) ;
  699. GetE('frmUpload').reset() ;
  700. }
  701. var oUploadAllowedExtRegex = new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ;
  702. var oUploadDeniedExtRegex = new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ;
  703. function CheckUpload()
  704. {
  705. var sFile = GetE('txtUploadFile').value ;
  706. if ( sFile.length == 0 )
  707. {
  708. alert( 'Please select a file to upload' ) ;
  709. return false ;
  710. }
  711. if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
  712. ( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
  713. {
  714. OnUploadCompleted( 202 ) ;
  715. return false ;
  716. }
  717. // Show animation
  718. window.parent.Throbber.Show( 100 ) ;
  719. GetE( 'divUpload' ).style.display = 'none' ;
  720. return true ;
  721. }
  722. function SetDefaultTarget()
  723. {
  724. var target = FCKConfig.DefaultLinkTarget || '' ;
  725. if ( oLink || target.length == 0 )
  726. return ;
  727. switch ( target )
  728. {
  729. case '_blank' :
  730. case '_self' :
  731. case '_parent' :
  732. case '_top' :
  733. GetE('cmbTarget').value = target ;
  734. break ;
  735. default :
  736. GetE('cmbTarget').value = 'frame' ;
  737. break ;
  738. }
  739. GetE('txtTargetFrame').value = target ;
  740. }