431 |
ddelon |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for internet
|
|
|
3 |
* Copyright (C) 2003-2005 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 |
* File Name: fckcontextmenu_gecko.js
|
|
|
12 |
* Context Menu operations. (Gecko specific implementations)
|
|
|
13 |
*
|
|
|
14 |
* File Authors:
|
|
|
15 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
// The Context Menu CSS must be added to the parent document.
|
|
|
19 |
FCKTools.AppendStyleSheet( window.parent.document, FCKConfig.SkinPath + 'fck_contextmenu.css' ) ;
|
|
|
20 |
|
|
|
21 |
FCKContextMenu.Show = function( x, y )
|
|
|
22 |
{
|
|
|
23 |
if ( ! this._Document )
|
|
|
24 |
{
|
|
|
25 |
this._Document = window.parent.document ;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
// Create the context menu if needed.
|
|
|
29 |
if ( !this._IsLoaded )
|
|
|
30 |
{
|
|
|
31 |
this.Reload() ;
|
|
|
32 |
this._Div.style.zIndex = 10000 ;
|
|
|
33 |
this._Div.oncontextmenu = function() { return false ; }
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
this.RefreshState() ;
|
|
|
37 |
|
|
|
38 |
// Get the editor area and editor frames positions.
|
|
|
39 |
var oCoordsA = FCKTools.GetElementPosition( FCK.EditorWindow.frameElement ) ;
|
|
|
40 |
var oCoordsB = FCKTools.GetElementPosition( window.frameElement ) ;
|
|
|
41 |
|
|
|
42 |
x += oCoordsA.X + oCoordsB.X ;
|
|
|
43 |
y += oCoordsA.Y + oCoordsB.Y ;
|
|
|
44 |
|
|
|
45 |
// Verifies if the context menu is completely visible.
|
|
|
46 |
var iXSpace = x + this._Div.offsetWidth - this._Div.ownerDocument.defaultView.innerWidth ;
|
|
|
47 |
var iYSpace = y + this._Div.offsetHeight - this._Div.ownerDocument.defaultView.innerHeight ;
|
|
|
48 |
|
|
|
49 |
if ( iXSpace > 0 ) x -= this._Div.offsetWidth ;
|
|
|
50 |
if ( iYSpace > 0 ) y -= this._Div.offsetHeight ;
|
|
|
51 |
|
|
|
52 |
// Set the context menu DIV in the specified location.
|
|
|
53 |
this._Div.style.left = x + 'px' ;
|
|
|
54 |
this._Div.style.top = y + 'px' ;
|
|
|
55 |
|
|
|
56 |
// Watch the "OnClick" event for all windows to close the Context Menu.
|
|
|
57 |
var oActualWindow = FCK.EditorWindow ;
|
|
|
58 |
while ( oActualWindow )
|
|
|
59 |
{
|
|
|
60 |
oActualWindow.document.addEventListener( 'click', FCKContextMenu._OnDocumentClick, false ) ;
|
|
|
61 |
if ( oActualWindow != oActualWindow.parent )
|
|
|
62 |
oActualWindow = oActualWindow.parent ;
|
|
|
63 |
else if ( oActualWindow.opener == null )
|
|
|
64 |
oActualWindow = oActualWindow.opener ;
|
|
|
65 |
else
|
|
|
66 |
break ;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
// Show it.
|
|
|
70 |
this._Div.style.visibility = '' ;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
FCKContextMenu._OnDocumentClick = function( event )
|
|
|
74 |
{
|
|
|
75 |
var e = event.target ;
|
|
|
76 |
while ( e )
|
|
|
77 |
{
|
|
|
78 |
if ( e == FCKContextMenu._Div ) return ;
|
|
|
79 |
e = e.parentNode ;
|
|
|
80 |
}
|
|
|
81 |
FCKContextMenu.Hide() ;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
FCKContextMenu.Hide = function()
|
|
|
85 |
{
|
|
|
86 |
this._Div.style.visibility = 'hidden' ;
|
|
|
87 |
this._Div.style.left = this._Div.style.top = '1px' ;
|
|
|
88 |
}
|