/hypervm/httpdocs/htmllib/fckeditor/editor/dialog/common/fck_dialog_common.js

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