[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/fckeditor/editor/_source/internals/ -> fck_contextmenu.js (source)

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


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics