[ Index ] |
|
Code source de FCKeditor 2.4 |
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 * File Name: fck_contextmenu.js 22 * Defines the FCK.ContextMenu object that is responsible for all 23 * Context Menu operations in the editing area. 24 * 25 * File Authors: 26 * Frederico Caldeira Knabben (www.fckeditor.net) 27 * Alfonso Martinez de Lizarrondo - Uritec (alfonso at uritec dot net) 28 */ 29 30 FCK.ContextMenu = new Object() ; 31 FCK.ContextMenu.Listeners = new Array() ; 32 33 FCK.ContextMenu.RegisterListener = function( listener ) 34 { 35 if ( listener ) 36 this.Listeners.push( listener ) ; 37 } 38 39 function FCK_ContextMenu_Init() 40 { 41 var oInnerContextMenu = FCK.ContextMenu._InnerContextMenu = new FCKContextMenu( FCKBrowserInfo.IsIE ? window : window.parent, FCKLang.Dir ) ; 42 oInnerContextMenu.OnBeforeOpen = FCK_ContextMenu_OnBeforeOpen ; 43 oInnerContextMenu.OnItemClick = FCK_ContextMenu_OnItemClick ; 44 45 // Get the registering function. 46 var oMenu = FCK.ContextMenu ; 47 48 // Register all configured context menu listeners. 49 for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ ) 50 oMenu.RegisterListener( FCK_ContextMenu_GetListener( FCKConfig.ContextMenu[i] ) ) ; 51 } 52 53 function FCK_ContextMenu_GetListener( listenerName ) 54 { 55 switch ( listenerName ) 56 { 57 case 'Generic' : 58 return { 59 AddItems : function( menu, tag, tagName ) 60 { 61 menu.AddItem( 'Cut' , FCKLang.Cut , 7, FCKCommands.GetCommand( 'Cut' ).GetState() == FCK_TRISTATE_DISABLED ) ; 62 menu.AddItem( 'Copy' , FCKLang.Copy , 8, FCKCommands.GetCommand( 'Copy' ).GetState() == FCK_TRISTATE_DISABLED ) ; 63 menu.AddItem( 'Paste' , FCKLang.Paste , 9, FCKCommands.GetCommand( 'Paste' ).GetState() == FCK_TRISTATE_DISABLED ) ; 64 }} ; 65 66 case 'Table' : 67 return { 68 AddItems : function( menu, tag, tagName ) 69 { 70 var bIsTable = ( tagName == 'TABLE' ) ; 71 var bIsCell = ( !bIsTable && FCKSelection.HasAncestorNode( 'TABLE' ) ) ; 72 73 if ( bIsCell ) 74 { 75 menu.AddSeparator() ; 76 var oItem = menu.AddItem( 'Cell' , FCKLang.CellCM ) ; 77 oItem.AddItem( 'TableInsertCell' , FCKLang.InsertCell, 58 ) ; 78 oItem.AddItem( 'TableDeleteCells' , FCKLang.DeleteCells, 59 ) ; 79 oItem.AddItem( 'TableMergeCells' , FCKLang.MergeCells, 60 ) ; 80 oItem.AddItem( 'TableSplitCell' , FCKLang.SplitCell, 61 ) ; 81 oItem.AddSeparator() ; 82 oItem.AddItem( 'TableCellProp' , FCKLang.CellProperties, 57 ) ; 83 84 menu.AddSeparator() ; 85 oItem = menu.AddItem( 'Row' , FCKLang.RowCM ) ; 86 oItem.AddItem( 'TableInsertRow' , FCKLang.InsertRow, 62 ) ; 87 oItem.AddItem( 'TableDeleteRows' , FCKLang.DeleteRows, 63 ) ; 88 89 menu.AddSeparator() ; 90 oItem = menu.AddItem( 'Column' , FCKLang.ColumnCM ) ; 91 oItem.AddItem( 'TableInsertColumn' , FCKLang.InsertColumn, 64 ) ; 92 oItem.AddItem( 'TableDeleteColumns' , FCKLang.DeleteColumns, 65 ) ; 93 } 94 95 if ( bIsTable || bIsCell ) 96 { 97 menu.AddSeparator() ; 98 menu.AddItem( 'TableDelete' , FCKLang.TableDelete ) ; 99 menu.AddItem( 'TableProp' , FCKLang.TableProperties, 39 ) ; 100 } 101 }} ; 102 103 case 'Link' : 104 return { 105 AddItems : function( menu, tag, tagName ) 106 { 107 var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ; 108 109 if ( bInsideLink || FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED ) 110 { 111 // Go up to the anchor to test its properties 112 var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ; 113 var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ; 114 // If it isn't a link then don't add the Link context menu 115 if ( bIsAnchor ) 116 return ; 117 118 menu.AddSeparator() ; 119 if ( bInsideLink ) 120 menu.AddItem( 'Link', FCKLang.EditLink , 34 ) ; 121 menu.AddItem( 'Unlink' , FCKLang.RemoveLink , 35 ) ; 122 } 123 }} ; 124 125 case 'Image' : 126 return { 127 AddItems : function( menu, tag, tagName ) 128 { 129 if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) ) 130 { 131 menu.AddSeparator() ; 132 menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ; 133 } 134 }} ; 135 136 case 'Anchor' : 137 return { 138 AddItems : function( menu, tag, tagName ) 139 { 140 // Go up to the anchor to test its properties 141 var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ; 142 var bIsAnchor = ( oLink && oLink.name.length > 0 ) ; 143 144 if ( bIsAnchor || ( tagName == 'IMG' && tag.getAttribute( '_fckanchor' ) ) ) 145 { 146 menu.AddSeparator() ; 147 menu.AddItem( 'Anchor', FCKLang.AnchorProp, 36 ) ; 148 } 149 }} ; 150 151 case 'Flash' : 152 return { 153 AddItems : function( menu, tag, tagName ) 154 { 155 if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) ) 156 { 157 menu.AddSeparator() ; 158 menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ; 159 } 160 }} ; 161 162 case 'Form' : 163 return { 164 AddItems : function( menu, tag, tagName ) 165 { 166 if ( FCKSelection.HasAncestorNode('FORM') ) 167 { 168 menu.AddSeparator() ; 169 menu.AddItem( 'Form', FCKLang.FormProp, 48 ) ; 170 } 171 }} ; 172 173 case 'Checkbox' : 174 return { 175 AddItems : function( menu, tag, tagName ) 176 { 177 if ( tagName == 'INPUT' && tag.type == 'checkbox' ) 178 { 179 menu.AddSeparator() ; 180 menu.AddItem( 'Checkbox', FCKLang.CheckboxProp, 49 ) ; 181 } 182 }} ; 183 184 case 'Radio' : 185 return { 186 AddItems : function( menu, tag, tagName ) 187 { 188 if ( tagName == 'INPUT' && tag.type == 'radio' ) 189 { 190 menu.AddSeparator() ; 191 menu.AddItem( 'Radio', FCKLang.RadioButtonProp, 50 ) ; 192 } 193 }} ; 194 195 case 'TextField' : 196 return { 197 AddItems : function( menu, tag, tagName ) 198 { 199 if ( tagName == 'INPUT' && ( tag.type == 'text' || tag.type == 'password' ) ) 200 { 201 menu.AddSeparator() ; 202 menu.AddItem( 'TextField', FCKLang.TextFieldProp, 51 ) ; 203 } 204 }} ; 205 206 case 'HiddenField' : 207 return { 208 AddItems : function( menu, tag, tagName ) 209 { 210 if ( tagName == 'INPUT' && tag.type == 'hidden' ) 211 { 212 menu.AddSeparator() ; 213 menu.AddItem( 'HiddenField', FCKLang.HiddenFieldProp, 56 ) ; 214 } 215 }} ; 216 217 case 'ImageButton' : 218 return { 219 AddItems : function( menu, tag, tagName ) 220 { 221 if ( tagName == 'INPUT' && tag.type == 'image' ) 222 { 223 menu.AddSeparator() ; 224 menu.AddItem( 'ImageButton', FCKLang.ImageButtonProp, 55 ) ; 225 } 226 }} ; 227 228 case 'Button' : 229 return { 230 AddItems : function( menu, tag, tagName ) 231 { 232 if ( tagName == 'INPUT' && ( tag.type == 'button' || tag.type == 'submit' || tag.type == 'reset' ) ) 233 { 234 menu.AddSeparator() ; 235 menu.AddItem( 'Button', FCKLang.ButtonProp, 54 ) ; 236 } 237 }} ; 238 239 case 'Select' : 240 return { 241 AddItems : function( menu, tag, tagName ) 242 { 243 if ( tagName == 'SELECT' ) 244 { 245 menu.AddSeparator() ; 246 menu.AddItem( 'Select', FCKLang.SelectionFieldProp, 53 ) ; 247 } 248 }} ; 249 250 case 'Textarea' : 251 return { 252 AddItems : function( menu, tag, tagName ) 253 { 254 if ( tagName == 'TEXTAREA' ) 255 { 256 menu.AddSeparator() ; 257 menu.AddItem( 'Textarea', FCKLang.TextareaProp, 52 ) ; 258 } 259 }} ; 260 261 case 'BulletedList' : 262 return { 263 AddItems : function( menu, tag, tagName ) 264 { 265 if ( FCKSelection.HasAncestorNode('UL') ) 266 { 267 menu.AddSeparator() ; 268 menu.AddItem( 'BulletedList', FCKLang.BulletedListProp, 27 ) ; 269 } 270 }} ; 271 272 case 'NumberedList' : 273 return { 274 AddItems : function( menu, tag, tagName ) 275 { 276 if ( FCKSelection.HasAncestorNode('OL') ) 277 { 278 menu.AddSeparator() ; 279 menu.AddItem( 'NumberedList', FCKLang.NumberedListProp, 26 ) ; 280 } 281 }} ; 282 } 283 return null ; 284 } 285 286 function FCK_ContextMenu_OnBeforeOpen() 287 { 288 // Update the UI. 289 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 290 291 // Get the actual selected tag (if any). 292 var oTag, sTagName ; 293 294 // The extra () is to avoid a warning with strict error checking. This is ok. 295 if ( (oTag = FCKSelection.GetSelectedElement()) ) 296 sTagName = oTag.tagName ; 297 298 // Cleanup the current menu items. 299 var oMenu = FCK.ContextMenu._InnerContextMenu ; 300 oMenu.RemoveAllItems() ; 301 302 // Loop through the listeners. 303 var aListeners = FCK.ContextMenu.Listeners ; 304 for ( var i = 0 ; i < aListeners.length ; i++ ) 305 aListeners[i].AddItems( oMenu, oTag, sTagName ) ; 306 } 307 308 function FCK_ContextMenu_OnItemClick( item ) 309 { 310 FCK.Focus() ; 311 FCKCommands.GetCommand( item.Name ).Execute() ; 312 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |