fckmenuitem.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: fckmenuitem.js
  14.  *  Defines and renders a menu items in a menu block.
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. var FCKMenuItem = function( parentMenuBlock, name, label, iconPathOrStripInfoArray, isDisabled )
  20. {
  21. this.Name = name ;
  22. this.Label = label || name ;
  23. this.IsDisabled = isDisabled ;
  24. this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
  25. this.SubMenu = new FCKMenuBlockPanel() ;
  26. this.SubMenu.Parent = parentMenuBlock ;
  27. this.SubMenu.OnClick = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnClick, this ) ;
  28. if ( FCK.IECleanup )
  29. FCK.IECleanup.AddItem( this, FCKMenuItem_Cleanup ) ;
  30. }
  31. FCKMenuItem.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
  32. {
  33. this.HasSubMenu = true ;
  34. return this.SubMenu.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ;
  35. }
  36. FCKMenuItem.prototype.AddSeparator = function()
  37. {
  38. this.SubMenu.AddSeparator() ;
  39. }
  40. FCKMenuItem.prototype.Create = function( parentTable )
  41. {
  42. var bHasSubMenu = this.HasSubMenu ;
  43. var oDoc = FCKTools.GetElementDocument( parentTable ) ;
  44. // Add a row in the table to hold the menu item.
  45. var r = this.MainElement = parentTable.insertRow(-1) ;
  46. r.className = this.IsDisabled ? 'MN_Item_Disabled' : 'MN_Item' ;
  47. // Set the row behavior.
  48. if ( !this.IsDisabled )
  49. {
  50. FCKTools.AddEventListenerEx( r, 'mouseover', FCKMenuItem_OnMouseOver, [ this ] ) ;
  51. FCKTools.AddEventListenerEx( r, 'click', FCKMenuItem_OnClick, [ this ] ) ;
  52. if ( !bHasSubMenu )
  53. FCKTools.AddEventListenerEx( r, 'mouseout', FCKMenuItem_OnMouseOut, [ this ] ) ;
  54. }
  55. // Create the icon cell.
  56. var eCell = r.insertCell(-1) ;
  57. eCell.className = 'MN_Icon' ;
  58. eCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
  59. // Create the label cell.
  60. eCell = r.insertCell(-1) ;
  61. eCell.className = 'MN_Label' ;
  62. eCell.noWrap = true ;
  63. eCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
  64. // Create the arrow cell and setup the sub menu panel (if needed).
  65. eCell = r.insertCell(-1) ;
  66. if ( bHasSubMenu )
  67. {
  68. eCell.className = 'MN_Arrow' ;
  69. // The arrow is a fixed size image.
  70. var eArrowImg = eCell.appendChild( oDoc.createElement( 'IMG' ) ) ;
  71. eArrowImg.src = FCK_IMAGES_PATH + 'arrow_' + FCKLang.Dir + '.gif' ;
  72. eArrowImg.width  = 4 ;
  73. eArrowImg.height = 7 ;
  74. this.SubMenu.Create() ;
  75. this.SubMenu.Panel.OnHide = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnHide, this ) ;
  76. }
  77. }
  78. FCKMenuItem.prototype.Activate = function()
  79. {
  80. this.MainElement.className = 'MN_Item_Over' ;
  81. if ( this.HasSubMenu )
  82. {
  83. // Show the child menu block. The ( +2, -2 ) correction is done because
  84. // of the padding in the skin. It is not a good solution because one
  85. // could change the skin and so the final result would not be accurate.
  86. // For now it is ok because we are controlling the skin.
  87. this.SubMenu.Show( this.MainElement.offsetWidth + 2, -2, this.MainElement ) ;
  88. }
  89. FCKTools.RunFunction( this.OnActivate, this ) ;
  90. }
  91. FCKMenuItem.prototype.Deactivate = function()
  92. {
  93. this.MainElement.className = 'MN_Item' ;
  94. if ( this.HasSubMenu )
  95. this.SubMenu.Hide() ;
  96. }
  97. /* Events */
  98. function FCKMenuItem_SubMenu_OnClick( clickedItem, listeningItem )
  99. {
  100. FCKTools.RunFunction( listeningItem.OnClick, listeningItem, [ clickedItem ] ) ;
  101. }
  102. function FCKMenuItem_SubMenu_OnHide( menuItem )
  103. {
  104. menuItem.Deactivate() ;
  105. }
  106. function FCKMenuItem_OnClick( ev, menuItem )
  107. {
  108. if ( menuItem.HasSubMenu )
  109. menuItem.Activate() ;
  110. else
  111. {
  112. menuItem.Deactivate() ;
  113. FCKTools.RunFunction( menuItem.OnClick, menuItem, [ menuItem ] ) ;
  114. }
  115. }
  116. function FCKMenuItem_OnMouseOver( ev, menuItem )
  117. {
  118. menuItem.Activate() ;
  119. }
  120. function FCKMenuItem_OnMouseOut( ev, menuItem )
  121. {
  122. menuItem.Deactivate() ;
  123. }
  124. function FCKMenuItem_Cleanup()
  125. {
  126. this.MainElement = null ;
  127. }