fckmenublock.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:4k
源码类别:

OA系统

开发平台:

C#

  1. /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2006 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *  http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *  http://www.fckeditor.net/
  10.  * 
  11.  * "Support Open Source software. What about a donation today?"
  12.  * 
  13.  * File Name: fckmenublock.js
  14.  *  Renders a list of menu items.
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. var FCKMenuBlock = function()
  20. {
  21. this._Items = new Array() ;
  22. }
  23. FCKMenuBlock.prototype.Count = function()
  24. {
  25. return this._Items.length ;
  26. }
  27. FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
  28. {
  29. var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ;
  30. oItem.OnClick = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnClick, this ) ;
  31. oItem.OnActivate = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnActivate, this ) ;
  32. this._Items.push( oItem ) ;
  33. return oItem ;
  34. }
  35. FCKMenuBlock.prototype.AddSeparator = function()
  36. {
  37. this._Items.push( new FCKMenuSeparator() ) ;
  38. }
  39. FCKMenuBlock.prototype.RemoveAllItems = function()
  40. {
  41. this._Items = new Array() ;
  42. var eItemsTable = this._ItemsTable ;
  43. if ( eItemsTable )
  44. {
  45. while ( eItemsTable.rows.length > 0 )
  46. eItemsTable.deleteRow( 0 ) ;
  47. }
  48. }
  49. FCKMenuBlock.prototype.Create = function( parentElement )
  50. {
  51. if ( !this._ItemsTable )
  52. {
  53. if ( FCK.IECleanup )
  54. FCK.IECleanup.AddItem( this, FCKMenuBlock_Cleanup ) ;
  55. this._Window = FCKTools.GetElementWindow( parentElement ) ;
  56. var oDoc = FCKTools.GetElementDocument( parentElement ) ;
  57. var eTable = parentElement.appendChild( oDoc.createElement( 'table' ) ) ;
  58. eTable.cellPadding = 0 ;
  59. eTable.cellSpacing = 0 ;
  60. FCKTools.DisableSelection( eTable ) ;
  61. var oMainElement = eTable.insertRow(-1).insertCell(-1) ;
  62. oMainElement.className = 'MN_Menu' ;
  63. var eItemsTable = this._ItemsTable = oMainElement.appendChild( oDoc.createElement( 'table' ) ) ;
  64. eItemsTable.cellPadding = 0 ;
  65. eItemsTable.cellSpacing = 0 ;
  66. }
  67. for ( var i = 0 ; i < this._Items.length ; i++ )
  68. this._Items[i].Create( this._ItemsTable ) ;
  69. }
  70. /* Events */
  71. function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock )
  72. {
  73. FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ;
  74. }
  75. function FCKMenuBlock_Item_OnActivate( menuBlock )
  76. {
  77. var oActiveItem = menuBlock._ActiveItem ;
  78. if ( oActiveItem && oActiveItem != this )
  79. {
  80. // Set the focus to this menu block window (to fire OnBlur on opened panels).
  81. if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu )
  82. menuBlock._Window.focus() ;
  83. oActiveItem.Deactivate() ;
  84. }
  85. menuBlock._ActiveItem = this ;
  86. }
  87. function FCKMenuBlock_Cleanup()
  88. {
  89. this._Window = null ;
  90. this._ItemsTable = null ;
  91. }
  92. // ################# //
  93. var FCKMenuSeparator = function()
  94. {}
  95. FCKMenuSeparator.prototype.Create = function( parentTable )
  96. {
  97. var oDoc = FCKTools.GetElementDocument( parentTable ) ;
  98. var r = parentTable.insertRow(-1) ;
  99. var eCell = r.insertCell(-1) ;
  100. eCell.className = 'MN_Separator MN_Icon' ;
  101. eCell = r.insertCell(-1) ;
  102. eCell.className = 'MN_Separator' ;
  103. eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
  104. eCell = r.insertCell(-1) ;
  105. eCell.className = 'MN_Separator' ;
  106. eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
  107. }