source: branches/1.2/workflow/js/fckeditor/editor/_source/classes/fckcontextmenu.js @ 1349

Revision 1349, 3.7 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
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 * FCKContextMenu Class: renders an control a context menu.
22 */
23
24var FCKContextMenu = function( parentWindow, langDir )
25{
26        var oPanel = this._Panel = new FCKPanel( parentWindow, true ) ;
27        oPanel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ;
28        oPanel.IsContextMenu = true ;
29
30        // The FCKTools.DisableSelection doesn't seems to work to avoid dragging of the icons in Mozilla
31        // so we stop the start of the dragging
32        if ( FCKBrowserInfo.IsGecko )
33                oPanel.Document.addEventListener( 'draggesture', function(e) {e.preventDefault(); return false;}, true ) ;
34
35        var oMenuBlock = this._MenuBlock = new FCKMenuBlock() ;
36        oMenuBlock.Panel = oPanel ;
37        oMenuBlock.OnClick = FCKTools.CreateEventListener( FCKContextMenu_MenuBlock_OnClick, this ) ;
38
39        this._Redraw = true ;
40}
41
42
43FCKContextMenu.prototype.SetMouseClickWindow = function( mouseClickWindow )
44{
45        if ( !FCKBrowserInfo.IsIE )
46        {
47                this._Document = mouseClickWindow.document ;
48                this._Document.addEventListener( 'contextmenu', FCKContextMenu_Document_OnContextMenu, false ) ;
49        }
50}
51
52FCKContextMenu.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
53{
54        var oItem = this._MenuBlock.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled) ;
55        this._Redraw = true ;
56        return oItem ;
57}
58
59FCKContextMenu.prototype.AddSeparator = function()
60{
61        this._MenuBlock.AddSeparator() ;
62        this._Redraw = true ;
63}
64
65FCKContextMenu.prototype.RemoveAllItems = function()
66{
67        this._MenuBlock.RemoveAllItems() ;
68        this._Redraw = true ;
69}
70
71FCKContextMenu.prototype.AttachToElement = function( element )
72{
73        if ( FCKBrowserInfo.IsIE )
74                FCKTools.AddEventListenerEx( element, 'contextmenu', FCKContextMenu_AttachedElement_OnContextMenu, this ) ;
75        else
76                element._FCKContextMenu = this ;
77
78//      element.onmouseup               = FCKContextMenu_AttachedElement_OnMouseUp ;
79}
80
81function FCKContextMenu_Document_OnContextMenu( e )
82{
83        var el = e.target ;
84
85        while ( el )
86        {
87                if ( el._FCKContextMenu )
88                {
89                        FCKTools.CancelEvent( e ) ;
90                        FCKContextMenu_AttachedElement_OnContextMenu( e, el._FCKContextMenu, el ) ;
91                }
92                el = el.parentNode ;
93        }
94}
95
96function FCKContextMenu_AttachedElement_OnContextMenu( ev, fckContextMenu, el )
97{
98//      var iButton = e ? e.which - 1 : event.button ;
99
100//      if ( iButton != 2 )
101//              return ;
102
103        var eTarget = el || this ;
104
105        if ( fckContextMenu.OnBeforeOpen )
106                fckContextMenu.OnBeforeOpen.call( fckContextMenu, eTarget ) ;
107
108        if ( fckContextMenu._MenuBlock.Count() == 0 )
109                return false ;
110
111        if ( fckContextMenu._Redraw )
112        {
113                fckContextMenu._MenuBlock.Create( fckContextMenu._Panel.MainNode ) ;
114                fckContextMenu._Redraw = false ;
115        }
116       
117        // This will avoid that the content of the context menu can be dragged in IE
118        // as the content of the panel is recreated we need to do it every time
119        FCKTools.DisableSelection( fckContextMenu._Panel.Document.body ) ;
120
121        fckContextMenu._Panel.Show(
122                ev.pageX || ev.screenX,
123                ev.pageY || ev.screenY,
124                ev.currentTarget || null
125        ) ;
126
127        return false ;
128}
129
130function FCKContextMenu_MenuBlock_OnClick( menuItem, contextMenu )
131{
132        contextMenu._Panel.Hide() ;
133        FCKTools.RunFunction( contextMenu.OnItemClick, contextMenu, menuItem ) ;
134}
Note: See TracBrowser for help on using the repository browser.