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

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: fck_contextmenu.js
  14.  *  Defines the FCK.ContextMenu object that is responsible for all
  15.  *  Context Menu operations in the editing area.
  16.  * 
  17.  * File Authors:
  18.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  19.  */
  20. FCK.ContextMenu = new Object() ;
  21. FCK.ContextMenu.Listeners = new Array() ;
  22. FCK.ContextMenu.RegisterListener = function( listener )
  23. {
  24. if ( listener )
  25. this.Listeners.push( listener ) ;
  26. }
  27. function FCK_ContextMenu_Init()
  28. {
  29. var oInnerContextMenu = FCK.ContextMenu._InnerContextMenu = new FCKContextMenu( FCKBrowserInfo.IsIE ? window : window.parent, FCK.EditorWindow, FCKLang.Dir ) ;
  30. oInnerContextMenu.OnBeforeOpen = FCK_ContextMenu_OnBeforeOpen ;
  31. oInnerContextMenu.OnItemClick = FCK_ContextMenu_OnItemClick ;
  32. // Get the registering function.
  33. var oMenu = FCK.ContextMenu ;
  34. // Register all configured context menu listeners.
  35. for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ )
  36. oMenu.RegisterListener( FCK_ContextMenu_GetListener( FCKConfig.ContextMenu[i] ) ) ;
  37. }
  38. function FCK_ContextMenu_GetListener( listenerName )
  39. {
  40. switch ( listenerName )
  41. {
  42. case 'Generic' :
  43. return {
  44. AddItems : function( menu, tag, tagName )
  45. {
  46. menu.AddItem( 'Cut' , FCKLang.Cut , 7, FCKCommands.GetCommand( 'Cut' ).GetState() == FCK_TRISTATE_DISABLED ) ;
  47. menu.AddItem( 'Copy' , FCKLang.Copy , 8, FCKCommands.GetCommand( 'Copy' ).GetState() == FCK_TRISTATE_DISABLED ) ;
  48. menu.AddItem( 'Paste' , FCKLang.Paste , 9, FCKCommands.GetCommand( 'Paste' ).GetState() == FCK_TRISTATE_DISABLED ) ;
  49. }} ;
  50. case 'Table' :
  51. return {
  52. AddItems : function( menu, tag, tagName )
  53. {
  54. var bIsTable = ( tagName == 'TABLE' ) ;
  55. var bIsCell = ( !bIsTable && FCKSelection.HasAncestorNode( 'TABLE' ) ) ;
  56. if ( bIsCell )
  57. {
  58. menu.AddSeparator() ;
  59. var oItem = menu.AddItem( 'Cell' , FCKLang.CellCM ) ;
  60. oItem.AddItem( 'TableInsertCell' , FCKLang.InsertCell, 58 ) ;
  61. oItem.AddItem( 'TableDeleteCells' , FCKLang.DeleteCells, 59 ) ;
  62. oItem.AddItem( 'TableMergeCells' , FCKLang.MergeCells, 60 ) ;
  63. oItem.AddItem( 'TableSplitCell' , FCKLang.SplitCell, 61 ) ;
  64. oItem.AddSeparator() ;
  65. oItem.AddItem( 'TableCellProp' , FCKLang.CellProperties, 57 ) ;
  66. menu.AddSeparator() ;
  67. oItem = menu.AddItem( 'Row' , FCKLang.RowCM ) ;
  68. oItem.AddItem( 'TableInsertRow' , FCKLang.InsertRow, 62 ) ;
  69. oItem.AddItem( 'TableDeleteRows' , FCKLang.DeleteRows, 63 ) ;
  70. menu.AddSeparator() ;
  71. oItem = menu.AddItem( 'Column' , FCKLang.ColumnCM ) ;
  72. oItem.AddItem( 'TableInsertColumn' , FCKLang.InsertColumn, 64 ) ;
  73. oItem.AddItem( 'TableDeleteColumns' , FCKLang.DeleteColumns, 65 ) ;
  74. }
  75. if ( bIsTable || bIsCell )
  76. {
  77. menu.AddSeparator() ;
  78. menu.AddItem( 'TableDelete' , FCKLang.TableDelete ) ;
  79. menu.AddItem( 'TableProp' , FCKLang.TableProperties, 39 ) ;
  80. }
  81. }} ;
  82. case 'Link' :
  83. return {
  84. AddItems : function( menu, tag, tagName )
  85. {
  86. var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
  87. if ( bInsideLink || FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED )
  88. {
  89. menu.AddSeparator() ;
  90. if ( bInsideLink )
  91. menu.AddItem( 'Link', FCKLang.EditLink , 34 ) ;
  92. menu.AddItem( 'Unlink' , FCKLang.RemoveLink , 35 ) ;
  93. }
  94. }} ;
  95. case 'Image' :
  96. return {
  97. AddItems : function( menu, tag, tagName )
  98. {
  99. if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) )
  100. {
  101. menu.AddSeparator() ;
  102. menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ;
  103. }
  104. }} ;
  105. case 'Anchor' :
  106. return {
  107. AddItems : function( menu, tag, tagName )
  108. {
  109. if ( tagName == 'IMG' && tag.getAttribute( '_fckanchor' ) )
  110. {
  111. menu.AddSeparator() ;
  112. menu.AddItem( 'Anchor', FCKLang.AnchorProp, 36 ) ;
  113. }
  114. }} ;
  115. case 'Flash' :
  116. return {
  117. AddItems : function( menu, tag, tagName )
  118. {
  119. if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) )
  120. {
  121. menu.AddSeparator() ;
  122. menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ;
  123. }
  124. }} ;
  125. case 'Form' :
  126. return {
  127. AddItems : function( menu, tag, tagName )
  128. {
  129. if ( FCKSelection.HasAncestorNode('FORM') )
  130. {
  131. menu.AddSeparator() ;
  132. menu.AddItem( 'Form', FCKLang.FormProp, 48 ) ;
  133. }
  134. }} ;
  135. case 'Checkbox' :
  136. return {
  137. AddItems : function( menu, tag, tagName )
  138. {
  139. if ( tagName == 'INPUT' && tag.type == 'checkbox' )
  140. {
  141. menu.AddSeparator() ;
  142. menu.AddItem( 'Checkbox', FCKLang.CheckboxProp, 49 ) ;
  143. }
  144. }} ;
  145. case 'Radio' :
  146. return {
  147. AddItems : function( menu, tag, tagName )
  148. {
  149. if ( tagName == 'INPUT' && tag.type == 'radio' )
  150. {
  151. menu.AddSeparator() ;
  152. menu.AddItem( 'Radio', FCKLang.RadioButtonProp, 50 ) ;
  153. }
  154. }} ;
  155. case 'TextField' :
  156. return {
  157. AddItems : function( menu, tag, tagName )
  158. {
  159. if ( tagName == 'INPUT' && ( tag.type == 'text' || tag.type == 'password' ) )
  160. {
  161. menu.AddSeparator() ;
  162. menu.AddItem( 'TextField', FCKLang.TextFieldProp, 51 ) ;
  163. }
  164. }} ;
  165. case 'HiddenField' :
  166. return {
  167. AddItems : function( menu, tag, tagName )
  168. {
  169. if ( tagName == 'INPUT' && tag.type == 'hidden' )
  170. {
  171. menu.AddSeparator() ;
  172. menu.AddItem( 'HiddenField', FCKLang.HiddenFieldProp, 56 ) ;
  173. }
  174. }} ;
  175. case 'ImageButton' :
  176. return {
  177. AddItems : function( menu, tag, tagName )
  178. {
  179. if ( tagName == 'INPUT' && tag.type == 'image' )
  180. {
  181. menu.AddSeparator() ;
  182. menu.AddItem( 'ImageButton', FCKLang.ImageButtonProp, 55 ) ;
  183. }
  184. }} ;
  185. case 'Button' :
  186. return {
  187. AddItems : function( menu, tag, tagName )
  188. {
  189. if ( tagName == 'INPUT' && ( tag.type == 'button' || tag.type == 'submit' || tag.type == 'reset' ) )
  190. {
  191. menu.AddSeparator() ;
  192. menu.AddItem( 'Button', FCKLang.ButtonProp, 54 ) ;
  193. }
  194. }} ;
  195. case 'Select' :
  196. return {
  197. AddItems : function( menu, tag, tagName )
  198. {
  199. if ( tagName == 'SELECT' )
  200. {
  201. menu.AddSeparator() ;
  202. menu.AddItem( 'Select', FCKLang.SelectionFieldProp, 53 ) ;
  203. }
  204. }} ;
  205. case 'Textarea' :
  206. return {
  207. AddItems : function( menu, tag, tagName )
  208. {
  209. if ( tagName == 'TEXTAREA' )
  210. {
  211. menu.AddSeparator() ;
  212. menu.AddItem( 'Textarea', FCKLang.TextareaProp, 52 ) ;
  213. }
  214. }} ;
  215. case 'BulletedList' :
  216. return {
  217. AddItems : function( menu, tag, tagName )
  218. {
  219. if ( FCKSelection.HasAncestorNode('UL') )
  220. {
  221. menu.AddSeparator() ;
  222. menu.AddItem( 'BulletedList', FCKLang.BulletedListProp, 27 ) ;
  223. }
  224. }} ;
  225. case 'NumberedList' :
  226. return {
  227. AddItems : function( menu, tag, tagName )
  228. {
  229. if ( FCKSelection.HasAncestorNode('OL') )
  230. {
  231. menu.AddSeparator() ;
  232. menu.AddItem( 'NumberedList', FCKLang.NumberedListProp, 26 ) ;
  233. }
  234. }} ;
  235. }
  236. }
  237. function FCK_ContextMenu_OnBeforeOpen()
  238. {
  239. // Update the UI.
  240. FCK.Events.FireEvent( "OnSelectionChange" ) ;
  241.    // Get the actual selected tag (if any).
  242. var oTag, sTagName ;
  243. if ( oTag = FCKSelection.GetSelectedElement() )
  244. sTagName = oTag.tagName ;
  245. // Cleanup the current menu items.
  246. var oMenu = FCK.ContextMenu._InnerContextMenu ;
  247. oMenu.RemoveAllItems() ;
  248. // Loop through the listeners.
  249. var aListeners = FCK.ContextMenu.Listeners ;
  250. for ( var i = 0 ; i < aListeners.length ; i++ )
  251. aListeners[i].AddItems( oMenu, oTag, sTagName ) ;
  252. }
  253. function FCK_ContextMenu_OnItemClick( item )
  254. {
  255. FCK.Focus() ;
  256. FCKCommands.GetCommand( item.Name ).Execute() ;
  257. }