| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.plugins.add( 'contextmenu', 7 { 8 requires : [ 'menu' ], 9 10 beforeInit : function( editor ) 11 { 12 editor.contextMenu = new CKEDITOR.plugins.contextMenu( editor ); 13 14 editor.addCommand( 'contextMenu', 15 { 16 exec : function() 17 { 18 editor.contextMenu.show( editor.document.getBody() ); 19 } 20 }); 21 } 22 }); 23 24 CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( 25 { 26 $ : function( editor ) 27 { 28 this.id = 'cke_' + CKEDITOR.tools.getNextNumber(); 29 this.editor = editor; 30 this._.listeners = []; 31 this._.functionId = CKEDITOR.tools.addFunction( function( commandName ) 32 { 33 this._.panel.hide(); 34 editor.focus(); 35 editor.execCommand( commandName ); 36 }, 37 this); 38 39 this.definition = 40 { 41 panel: 42 { 43 className : editor.skinClass + ' cke_contextmenu', 44 attributes : 45 { 46 'aria-label' : editor.lang.contextmenu.options 47 } 48 } 49 }; 50 }, 51 52 _ : 53 { 54 onMenu : function( offsetParent, corner, offsetX, offsetY ) 55 { 56 var menu = this._.menu, 57 editor = this.editor; 58 59 if ( menu ) 60 { 61 menu.hide(); 62 menu.removeAll(); 63 } 64 else 65 { 66 menu = this._.menu = new CKEDITOR.menu( editor, this.definition ); 67 menu.onClick = CKEDITOR.tools.bind( function( item ) 68 { 69 menu.hide(); 70 71 if ( item.onClick ) 72 item.onClick(); 73 else if ( item.command ) 74 editor.execCommand( item.command ); 75 76 }, this ); 77 78 menu.onEscape = function( keystroke ) 79 { 80 var parent = this.parent; 81 // 1. If it's sub-menu, restore the last focused item 82 // of upper level menu. 83 // 2. In case of a top-menu, close it. 84 if ( parent ) 85 { 86 parent._.panel.hideChild(); 87 // Restore parent block item focus. 88 var parentBlock = parent._.panel._.panel._.currentBlock, 89 parentFocusIndex = parentBlock._.focusIndex; 90 parentBlock._.markItem( parentFocusIndex ); 91 } 92 else if ( keystroke == 27 ) 93 { 94 this.hide(); 95 editor.focus(); 96 } 97 return false; 98 }; 99 } 100 101 var listeners = this._.listeners, 102 includedItems = []; 103 104 var selection = this.editor.getSelection(), 105 element = selection && selection.getStartElement(); 106 107 menu.onHide = CKEDITOR.tools.bind( function() 108 { 109 menu.onHide = null; 110 111 if ( CKEDITOR.env.ie ) 112 { 113 var selection = editor.getSelection(); 114 selection && selection.unlock(); 115 } 116 117 this.onHide && this.onHide(); 118 }, 119 this ); 120 121 // Call all listeners, filling the list of items to be displayed. 122 for ( var i = 0 ; i < listeners.length ; i++ ) 123 { 124 var listenerItems = listeners[ i ]( element, selection ); 125 126 if ( listenerItems ) 127 { 128 for ( var itemName in listenerItems ) 129 { 130 var item = this.editor.getMenuItem( itemName ); 131 132 if ( item ) 133 { 134 item.state = listenerItems[ itemName ]; 135 menu.add( item ); 136 } 137 } 138 } 139 } 140 141 // Don't show context menu with zero items. 142 menu.items.length && menu.show( offsetParent, corner || ( editor.lang.dir == 'rtl' ? 2 : 1 ), offsetX, offsetY ); 143 } 144 }, 145 146 proto : 147 { 148 addTarget : function( element, nativeContextMenuOnCtrl ) 149 { 150 // Opera doesn't support 'contextmenu' event, we have duo approaches employed here: 151 // 1. Inherit the 'button override' hack we introduced in v2 (#4530), while this require the Opera browser 152 // option 'Allow script to detect context menu/right click events' to be always turned on. 153 // 2. Considering the fact that ctrl/meta key is not been occupied 154 // for multiple range selecting (like Gecko), we use this key 155 // combination as a fallback for triggering context-menu. (#4530) 156 if ( CKEDITOR.env.opera ) 157 { 158 var contextMenuOverrideButton; 159 element.on( 'mousedown', function( evt ) 160 { 161 evt = evt.data; 162 if ( evt.$.button != 2 ) 163 { 164 if ( evt.getKeystroke() == CKEDITOR.CTRL + 1 ) 165 element.fire( 'contextmenu', evt ); 166 return; 167 } 168 169 if ( nativeContextMenuOnCtrl 170 && ( CKEDITOR.env.mac ? evt.$.metaKey : evt.$.ctrlKey ) ) 171 return; 172 173 var target = evt.getTarget(); 174 175 if ( !contextMenuOverrideButton ) 176 { 177 var ownerDoc = target.getDocument(); 178 contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ; 179 contextMenuOverrideButton.$.type = 'button' ; 180 ownerDoc.getBody().append( contextMenuOverrideButton ) ; 181 } 182 183 contextMenuOverrideButton.setAttribute( 'style', 'position:absolute;top:' + ( evt.$.clientY - 2 ) + 184 'px;left:' + ( evt.$.clientX - 2 ) + 185 'px;width:5px;height:5px;opacity:0.01' ); 186 187 } ); 188 189 element.on( 'mouseup', function ( evt ) 190 { 191 if ( contextMenuOverrideButton ) 192 { 193 contextMenuOverrideButton.remove(); 194 contextMenuOverrideButton = undefined; 195 // Simulate 'contextmenu' event. 196 element.fire( 'contextmenu', evt.data ); 197 } 198 } ); 199 } 200 201 element.on( 'contextmenu', function( event ) 202 { 203 var domEvent = event.data; 204 205 if ( nativeContextMenuOnCtrl && 206 // Safari on Windows always show 'ctrlKey' as true in 'contextmenu' event, 207 // which make this property unreliable. (#4826) 208 ( CKEDITOR.env.webkit ? holdCtrlKey : ( CKEDITOR.env.mac ? domEvent.$.metaKey : domEvent.$.ctrlKey ) ) ) 209 return; 210 211 212 // Cancel the browser context menu. 213 domEvent.preventDefault(); 214 215 var offsetParent = domEvent.getTarget().getDocument().getDocumentElement(), 216 offsetX = domEvent.$.clientX, 217 offsetY = domEvent.$.clientY; 218 219 CKEDITOR.tools.setTimeout( function() 220 { 221 this.show( offsetParent, null, offsetX, offsetY ); 222 }, 223 0, this ); 224 }, 225 this ); 226 227 if ( CKEDITOR.env.webkit ) 228 { 229 var holdCtrlKey, 230 onKeyDown = function( event ) 231 { 232 holdCtrlKey = CKEDITOR.env.mac ? event.data.$.metaKey : event.data.$.ctrlKey ; 233 }, 234 resetOnKeyUp = function() 235 { 236 holdCtrlKey = 0; 237 }; 238 239 element.on( 'keydown', onKeyDown ); 240 element.on( 'keyup', resetOnKeyUp ); 241 element.on( 'contextmenu', resetOnKeyUp ); 242 } 243 }, 244 245 addListener : function( listenerFn ) 246 { 247 this._.listeners.push( listenerFn ); 248 }, 249 250 show : function( offsetParent, corner, offsetX, offsetY ) 251 { 252 this.editor.focus(); 253 254 // Selection will be unavailable after context menu shows up 255 // in IE, lock it now. 256 if ( CKEDITOR.env.ie ) 257 { 258 var selection = this.editor.getSelection(); 259 selection && selection.lock(); 260 } 261 262 this._.onMenu( offsetParent || CKEDITOR.document.getDocumentElement(), corner, offsetX || 0, offsetY || 0 ); 263 } 264 } 265 }); 266 267 /** 268 * Whether to show the browser native context menu when the CTRL or the 269 * META (Mac) key is pressed while opening the context menu. 270 * @name CKEDITOR.config.browserContextMenuOnCtrl 271 * @since 3.0.2 272 * @type Boolean 273 * @default true 274 * @example 275 * config.browserContextMenuOnCtrl = false; 276 */
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |