2 // Displays and hide pop-up menus.
3 // Pop-ups are displayed when left-clicking on an edition icon of a link.
4 // The HTML corresponding tags are supposed being the following:
6 // <a href="popupname"><img src="{path}icon.ed..." .../></a>
8 // Any other HTML construct will be ignored.
10 // Pop-ups can be used on a web page including java applets.
11 // If a pop-up hides an applet, this latter must be hidden when displaying the pop-up - as a limitation,
12 // the applet is supposed entirely hidden by the pop-up.
14 // - such pop-up must be named "toolpop" (<div id="toolpop"...></div><a href="toolpop">...</a>),
15 // - the applet must be named "perform" (<applet id="perform"...></applet>).
17 var _iconName = "icon.ed";
18 var _appletName = "perform";
19 var _hiddingPopup = "toolpop";
21 var _replaceContext = false; // replace the system context menu
22 var _mouseOverContext = false; // is the mouse over the context menu
23 var _divContext = null;
24 var _appletContext = null; // Applet hidden by the popup
28 function InitContext() {
29 // ----------------------
30 document.onmousedown = ContextMouseDown;
31 document.onclick = ContextShow;
34 // Call from the onMouseDown event, passing the event if standards compliant
35 function ContextMouseDown(event) {
36 // --------------------------------
37 if (_mouseOverContext) return;
41 // IE is evil and doesn't pass the event object
46 // We assume we have a standards compliant browser, but check if we have IE
47 var target = event.target != null ? event.target : event.srcElement;
49 // Only show the context menu if the right mouse button is pressed
50 // and a hyperlink on an edit icon has been clicked
51 if (_divContext != null) ContextHide(); // In case of another context menu previously shown
52 if (target.tagName.toLowerCase() == 'img') {
53 if (target.src.indexOf(_iconName) < 0) return;
54 target = target.parentNode;
56 if (event.button == leftbutton && target.tagName.toLowerCase() == 'a') {
57 _replaceContext = true;
58 if (target.getAttribute("href") == _hiddingPopup) _appletContext = document.getElementById(_appletName);
62 function ContextHide() {
63 // -----------------------
64 _divContext.style.display = 'none';
65 if (_appletContext != null) {
66 _appletContext.style.display = 'inline';
67 _appletContext = null;
71 // Call from the onContextMenu event, passing the event
72 // If this function returns false, the browser's context menu will not show up
73 function ContextShow(event) {
74 // ---------------------------
75 if (_mouseOverContext) return true;
77 // IE is evil and doesn't pass the event object
78 if (event == null) event = window.event;
80 // we assume we have a standards compliant browser, but check if we have IE
81 var target = event.target != null ? event.target : event.srcElement;
82 target = target.parentNode; // Gets the hyperlink
83 if (_replaceContext) {
84 _divContext = document.getElementById(target.attributes[0].nodeValue); // Popup involved (made of document index prefixed by "popup")
86 // document.body.scrollTop does not work in IE
87 var scrollTop = document.scrollTop ? document.scrollTop : document.documentElement.scrollTop;
88 var scrollLeft = document.scrollLeft ? document.scrollLeft : document.documentElement.scrollLeft;
90 // hide the menu first to avoid an "up-then-over" visual effect
91 _divContext.style.display = 'none';
92 _divContext.style.left = event.clientX + scrollLeft + 'px';
93 _divContext.style.top = event.clientY + scrollTop + 'px';
94 _divContext.style.display = 'block';
96 _replaceContext = false;
97 if (_appletContext != null) _appletContext.style.display = 'none';