Subversion Repositories Applications.papyrus

Rev

Rev 1371 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1075 ddelon 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: fckcontextmenu.js
14
 * 	FCKContextMenu Class: renders an control a context menu.
15
 *
16
 * File Authors:
17
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
18
 */
19
 
20
var FCKContextMenu = function( parentWindow, mouseClickWindow, langDir )
21
{
22
	var oPanel = this._Panel = new FCKPanel( parentWindow, true ) ;
23
	oPanel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ;
24
	oPanel.IsContextMenu = true ;
25
 
26
	var oMenuBlock = this._MenuBlock = new FCKMenuBlock() ;
27
	oMenuBlock.Panel = oPanel ;
28
	oMenuBlock.OnClick = FCKTools.CreateEventListener( FCKContextMenu_MenuBlock_OnClick, this ) ;
29
 
30
	this._Redraw = true ;
31
 
32
	this.SetMouseClickWindow( mouseClickWindow || parentWindow ) ;
33
}
34
 
35
 
36
FCKContextMenu.prototype.SetMouseClickWindow = function( mouseClickWindow )
37
{
38
	if ( !FCKBrowserInfo.IsIE )
39
	{
40
		this._Document = mouseClickWindow.document ;
41
		this._Document.addEventListener( 'contextmenu', FCKContextMenu_Document_OnContextMenu, false ) ;
42
	}
43
}
44
 
45
FCKContextMenu.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
46
{
47
	var oItem = this._MenuBlock.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled) ;
48
	this._Redraw = true ;
49
	return oItem ;
50
}
51
 
52
FCKContextMenu.prototype.AddSeparator = function()
53
{
54
	this._MenuBlock.AddSeparator() ;
55
	this._Redraw = true ;
56
}
57
 
58
FCKContextMenu.prototype.RemoveAllItems = function()
59
{
60
	this._MenuBlock.RemoveAllItems() ;
61
	this._Redraw = true ;
62
}
63
 
64
FCKContextMenu.prototype.AttachToElement = function( element )
65
{
66
	if ( FCKBrowserInfo.IsIE )
67
		FCKTools.AddEventListenerEx( element, 'contextmenu', FCKContextMenu_AttachedElement_OnContextMenu, this ) ;
68
	else
69
		element._FCKContextMenu = this ;
70
 
71
//	element.onmouseup		= FCKContextMenu_AttachedElement_OnMouseUp ;
72
}
73
 
74
function FCKContextMenu_Document_OnContextMenu( e )
75
{
76
	var el = e.target ;
77
 
78
	while ( el )
79
	{
80
		if ( el._FCKContextMenu )
81
		{
82
			FCKTools.CancelEvent( e ) ;
83
			FCKContextMenu_AttachedElement_OnContextMenu( e, el._FCKContextMenu, el ) ;
84
		}
85
		el = el.parentNode ;
86
	}
87
}
88
 
89
function FCKContextMenu_AttachedElement_OnContextMenu( ev, fckContextMenu, el )
90
{
91
//	var iButton = e ? e.which - 1 : event.button ;
92
 
93
//	if ( iButton != 2 )
94
//		return ;
95
 
96
	var eTarget = el || this ;
97
 
98
	if ( fckContextMenu.OnBeforeOpen )
99
		fckContextMenu.OnBeforeOpen.call( fckContextMenu, eTarget ) ;
100
 
101
	if ( fckContextMenu._MenuBlock.Count() == 0 )
102
		return false ;
103
 
104
	if ( fckContextMenu._Redraw )
105
	{
106
		fckContextMenu._MenuBlock.Create( fckContextMenu._Panel.MainNode ) ;
107
		fckContextMenu._Redraw = false ;
108
	}
109
 
110
	fckContextMenu._Panel.Show(
111
		ev.pageX || ev.screenX,
112
		ev.pageY || ev.screenY,
113
		ev.currentTarget || null
114
	) ;
115
 
116
	return false ;
117
}
118
 
119
function FCKContextMenu_MenuBlock_OnClick( menuItem, contextMenu )
120
{
121
	contextMenu._Panel.Hide() ;
122
	FCKTools.RunFunction( contextMenu.OnItemClick, contextMenu, menuItem ) ;
123
}