/source/Plug-in/fck/editor/dialog/common/fck_dialog_common.js

http://prosporous.googlecode.com/ · JavaScript · 165 lines · 106 code · 27 blank · 32 comment · 33 complexity · 1b95b29e9d2e8567bea05d850f4f71ae MD5 · raw file

  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. * Useful functions used by almost all dialog window pages.
  22. */
  23. // Gets a element by its Id. Used for shorter coding.
  24. function GetE( elementId )
  25. {
  26. return document.getElementById( elementId ) ;
  27. }
  28. function ShowE( element, isVisible )
  29. {
  30. if ( typeof( element ) == 'string' )
  31. element = GetE( element ) ;
  32. element.style.display = isVisible ? '' : 'none' ;
  33. }
  34. function SetAttribute( element, attName, attValue )
  35. {
  36. if ( attValue == null || attValue.length == 0 )
  37. element.removeAttribute( attName, 0 ) ; // 0 : Case Insensitive
  38. else
  39. element.setAttribute( attName, attValue, 0 ) ; // 0 : Case Insensitive
  40. }
  41. function GetAttribute( element, attName, valueIfNull )
  42. {
  43. var oAtt = element.attributes[attName] ;
  44. if ( oAtt == null || !oAtt.specified )
  45. return valueIfNull ? valueIfNull : '' ;
  46. var oValue = element.getAttribute( attName, 2 ) ;
  47. if ( oValue == null )
  48. oValue = oAtt.nodeValue ;
  49. return ( oValue == null ? valueIfNull : oValue ) ;
  50. }
  51. var KeyIdentifierMap =
  52. {
  53. End : 35,
  54. Home : 36,
  55. Left : 37,
  56. Right : 39,
  57. 'U+00007F' : 46 // Delete
  58. }
  59. // Functions used by text fields to accept numbers only.
  60. function IsDigit( e )
  61. {
  62. if ( !e )
  63. e = event ;
  64. var iCode = ( e.keyCode || e.charCode ) ;
  65. if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )
  66. iCode = KeyIdentifierMap[ e.keyIdentifier ] ;
  67. return (
  68. ( iCode >= 48 && iCode <= 57 ) // Numbers
  69. || (iCode >= 35 && iCode <= 40) // Arrows, Home, End
  70. || iCode == 8 // Backspace
  71. || iCode == 46 // Delete
  72. || iCode == 9 // Tab
  73. ) ;
  74. }
  75. String.prototype.Trim = function()
  76. {
  77. return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
  78. }
  79. String.prototype.StartsWith = function( value )
  80. {
  81. return ( this.substr( 0, value.length ) == value ) ;
  82. }
  83. String.prototype.Remove = function( start, length )
  84. {
  85. var s = '' ;
  86. if ( start > 0 )
  87. s = this.substring( 0, start ) ;
  88. if ( start + length < this.length )
  89. s += this.substring( start + length , this.length ) ;
  90. return s ;
  91. }
  92. String.prototype.ReplaceAll = function( searchArray, replaceArray )
  93. {
  94. var replaced = this ;
  95. for ( var i = 0 ; i < searchArray.length ; i++ )
  96. {
  97. replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
  98. }
  99. return replaced ;
  100. }
  101. function OpenFileBrowser( url, width, height )
  102. {
  103. // oEditor must be defined.
  104. var iLeft = ( oEditor.FCKConfig.ScreenWidth - width ) / 2 ;
  105. var iTop = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
  106. var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
  107. sOptions += ",width=" + width ;
  108. sOptions += ",height=" + height ;
  109. sOptions += ",left=" + iLeft ;
  110. sOptions += ",top=" + iTop ;
  111. // The "PreserveSessionOnFileBrowser" because the above code could be
  112. // blocked by popup blockers.
  113. if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
  114. {
  115. // The following change has been made otherwise IE will open the file
  116. // browser on a different server session (on some cases):
  117. // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
  118. // by Simone Chiaretta.
  119. var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
  120. if ( oWindow )
  121. {
  122. // Detect Yahoo popup blocker.
  123. try
  124. {
  125. var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
  126. oWindow.opener = window ;
  127. }
  128. catch(e)
  129. {
  130. alert( oEditor.FCKLang.BrowseServerBlocked ) ;
  131. }
  132. }
  133. else
  134. alert( oEditor.FCKLang.BrowseServerBlocked ) ;
  135. }
  136. else
  137. window.open( url, 'FCKBrowseWindow', sOptions ) ;
  138. }