/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to includes/dhtmlx1/dhtmlxmenubar_cp.js

  • Committer: Suren A. Chilingaryan
  • Date: 2008-10-29 03:02:24 UTC
  • Revision ID: csa@dside.dyndns.org-20081029030224-yc3wy2dti4htlfxf
New version of dhtmlxmenu and dhtmlxtree is added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//v.1.0 build 71114
 
2
 
 
3
/*
 
4
Copyright DHTMLX LTD. http://www.dhtmlx.com
 
5
You allowed to use this component or parts of it under GPL terms
 
6
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
 
7
*/
 
8
 
 
9
                /**
 
10
          *     @desc: context menu object
 
11
          *     @type: public
 
12
                  *     @param: width - menu width
 
13
                  *     @param: height - menu height
 
14
                  *     @param: gfxPath - path to gfx (must be specified in https mode)
 
15
          *     @param: httpsdummy - dummy html page, which will be used for invisible iframes (necessary only for https mode)
 
16
              *     @topic: 0
 
17
          */
 
18
function dhtmlXContextMenuObject(width,height,gfxPath,httpsdummy){
 
19
        this.menu=new dhtmlXMenuBarObject(document.body,width,height,"",1,gfxPath,httpsdummy);
 
20
        this.menu.setMenuMode("popup");
 
21
        this.menu.hideBar();
 
22
        this.menu.contextMenu=this;
 
23
        this.menu.enableWindowOpenMode(false);
 
24
        this.menu.setOnClickHandler(this._innerOnClick);
 
25
    this.aframes=new Array();
 
26
    this.registerFrame(window);
 
27
 
 
28
    return this;
 
29
};
 
30
 
 
31
dhtmlXContextMenuObject.prototype.registerFrame=function(awin){
 
32
    this.aframes[this.aframes.length]=awin;
 
33
}
 
34
 
 
35
 
 
36
 
 
37
                /**
 
38
          *     @desc: set onClick context menu handler
 
39
          *     @type: public
 
40
                  *     @param: func - user defined function
 
41
              *     @topic: 0
 
42
          */
 
43
dhtmlXContextMenuObject.prototype.setContextMenuHandler=function(func){
 
44
  if (typeof(func)=="function") this.onClickHandler=func; else this.onClickHandler=eval(func);
 
45
}
 
46
                /**
 
47
          *     @desc: open menu at specified position
 
48
          *     @type: public
 
49
                  *     @param: x - x position
 
50
                  *     @param: y - y position            
 
51
                  *     @param: id - context id
 
52
                  *     @param: smartPosition - enable/disable correction of position
 
53
              *     @topic: 0
 
54
          */
 
55
dhtmlXContextMenuObject.prototype.openAt=function(x,y,id,smartPosition){
 
56
    this.espc=convertStringToBoolean(smartPosition);
 
57
        var f=new Object;
 
58
        f.button=2;
 
59
        f.clientX=parseInt(x);
 
60
        f.clientY=parseInt(y);
 
61
        var start=new Object;
 
62
        start.contextMenuId=id;
 
63
        start.contextMenu=this;
 
64
        start.a=this._contextStart;
 
65
        start.a(document.body,f);
 
66
    this.espc=null;
 
67
}
 
68
 
 
69
 
 
70
                /**
 
71
          *     @desc: disable/enable context menu
 
72
          *     @type: public
 
73
                  *     @param: mode  - true/false as disable/enable
 
74
              *     @topic: 0
 
75
          */
 
76
dhtmlXContextMenuObject.prototype.disableMenu=function(mode){
 
77
    this._dsbd=convertStringToBoolean(mode);
 
78
  }
 
79
  
 
80
                /**
 
81
          *     @desc: set onShow context menu handler
 
82
          *     @type: public
 
83
                  *     @param: func - user defined function
 
84
              *     @topic: 0
 
85
          */
 
86
dhtmlXContextMenuObject.prototype.setOnShowMenuHandler=function(func){
 
87
  if (typeof(func)=="function") this.onShowHandler=func; else this.onShowHandler=eval(func);
 
88
  }
 
89
 
 
90
 
 
91
/**
 
92
*     @desc: set zIndex value for menu object
 
93
*     @param: left - (integer) left position shift
 
94
*     @param: top - (integer) top position shift
 
95
*     @type: public
 
96
*     @topic: 0
 
97
*/
 
98
dhtmlXContextMenuObject.prototype.setContextMenuPosition=function(left,top){
 
99
        this._msTop=parseInt(top);
 
100
        this._msLeft=parseInt(left);
 
101
}
 
102
 
 
103
/**
 
104
*     @desc: default menu onclick precessor
 
105
*     @type: private
 
106
*     @param: id - clicked node id
 
107
*     @topic: 0
 
108
*/
 
109
dhtmlXContextMenuObject.prototype._innerOnClick=function(id){
 
110
        //debugger;
 
111
        var that=document.body.contextMenu;
 
112
        if (that.contextZone.ownerDocument){
 
113
                if (that.contextZone.ownerDocument.body.onclick) that.contextZone.ownerDocument.body.onclick();
 
114
        } else if (document.body.onclick) document.body.onclick();
 
115
        if (that.onClickHandler) return that.onClickHandler(id,that.zoneId,that.contextZone);
 
116
        return true;
 
117
}
 
118
 
 
119
                /**
 
120
          *     @desc: set context zones
 
121
          *     @type: public
 
122
                  *     @param: htmlObject - id of html tag or html object
 
123
                  *     @param: zoneId - id of zone
 
124
              *     @topic: 0  
 
125
          */
 
126
dhtmlXContextMenuObject.prototype.setContextZone=function(htmlObject,zoneId){
 
127
        if (typeof(htmlObject)!="object") 
 
128
                htmlObject=document.getElementById(htmlObject);
 
129
 
 
130
    if (!htmlObject.contextMenu)
 
131
        htmlObject.contextOnclick=htmlObject.onmouseup;
 
132
        htmlObject.selfobj = this;//nb
 
133
        htmlObject[_isMacOS?"oncontextmenu":"onmouseup"]= function(e){ this.selfobj._contextStart(this,e); };//nb
 
134
//      htmlObject.onmousedown= this._contextStart;
 
135
        htmlObject.contextMenu=this;
 
136
        htmlObject.contextMenuId=zoneId;
 
137
}
 
138
                /**
 
139
          *     @desc: open context menu
 
140
          *     @type: private
 
141
                  *     @param: e - event object
 
142
              *     @topic: 0
 
143
          */
 
144
dhtmlXContextMenuObject.prototype._contextStart=function(obj,e){
 
145
   if ((_isIE)&&(window.event))
 
146
        event.srcElement.oncontextmenu = function(){ event.cancelBubble=true; return false; };
 
147
    if (e && e.preventDefault) e.preventDefault();
 
148
    
 
149
 
 
150
        if(!this.contextMenu)//nb
 
151
                this.contextMenu = this;
 
152
        var win = obj.ownerDocument?obj.ownerDocument.parentWindow:window;
 
153
        if(!win){
 
154
                win = obj.ownerDocument.defaultView;
 
155
        }
 
156
 
 
157
        var a=this.contextMenu.menu.topNod;
 
158
        a.style.position="absolute";
 
159
        
 
160
        if (!e){
 
161
                e=win.event;
 
162
        }
 
163
        if (document.body.onclick) document.body.onclick();
 
164
 
 
165
        if ((!_isMacOS)&&((!e)||(e.button!=2)))
 
166
        {
 
167
                if (obj.contextOnclick) obj.contextOnclick();
 
168
                return true;
 
169
        }
 
170
        else {
 
171
        if (this.contextMenu._dsbd) return true;
 
172
                if (this.contextMenu.onShowHandler){
 
173
                        var z=this.contextMenu.onShowHandler(obj.contextMenuId);
 
174
                        if ((typeof(z)=="boolean")&&(!z)) return;
 
175
                }
 
176
 
 
177
                this.contextMenu.menu.showBar();
 
178
        }
 
179
 
 
180
        var winScreenTop = window.screenTop;
 
181
        if ((!winScreenTop)&&(winScreenTop!=0)){
 
182
                winScreenTop = window.screenY+window.outerHeight-window.innerHeight;//-(window.statusbar.visible?20:0);
 
183
                //nb
 
184
                //winScreenTop = top.screenY+top.outerHeight-top.innerHeight;//-(window.statusbar.visible?20:0);
 
185
                
 
186
                //alert(window.screenY+"+"+window.outerHeight+"-"+window.innerHeight)
 
187
        }
 
188
        var winScreenLeft = window.screenLeft;
 
189
        if((!winScreenLeft)&&(winScreenLeft!=0)){
 
190
                winScreenLeft = window.screenX+window.outerWidth-window.innerWidth-4;
 
191
                //nb
 
192
                //alert(window.pageXOffset)
 
193
                //winScreenLeft = top.screenX+top.outerWidth-top.innerWidth-4;
 
194
        }
 
195
        var dEl0=window.document.documentElement;
 
196
        var dEl1=window.document.body;
 
197
        if(e.screenY-winScreenTop+a.offsetHeight-(dEl0.scrollTop||dEl1.scrollTop) > (dEl0.clientHeight||dEl1.clientHeight)){//-e.offsetY
 
198
                var verCor = a.offsetHeight
 
199
        }else
 
200
                var verCor = ((this.contextMenu._msTop*(-1))||0);
 
201
 
 
202
        var corrector = new Array((dEl0.scrollLeft||dEl1.scrollLeft)+(this.contextMenu._msLeft||0),verCor-(dEl0.scrollTop||dEl1.scrollTop));
 
203
        
 
204
 
 
205
        //      a.style.left=e.clientX*1+document.body.scrollLeft;
 
206
        //      a.style.top=e.clientY*1+document.body.scrollTop;
 
207
        //  this.contextMenu.menu.showBar();
 
208
        //  alert(a.style.left);
 
209
 
 
210
 
 
211
 
 
212
    if ((!e.screenY)&&(e.clientX))
 
213
    {
 
214
        a.style.top = e.clientY+"px";
 
215
        a.style.left = e.clientX+"px";
 
216
    }   else
 
217
    {
 
218
        a.style.top = e.screenY-winScreenTop-corrector[1]+"px";//-e.offsetY
 
219
        a.style.left = e.screenX-winScreenLeft+corrector[0]+"px";//-e.offsetX
 
220
    }
 
221
 
 
222
        //nb: (to work correctly in frames in mozilla)
 
223
        if(!_isIE){
 
224
                a.style.top = e.clientY-corrector[1]+"px";
 
225
                a.style.left = e.clientX+corrector[0]+"px";
 
226
        }
 
227
        this.contextMenu.correctMenuPosition(a);
 
228
 
 
229
    if (a.ieFix){
 
230
        a.ieFix.style.top=a.style.top;
 
231
        a.ieFix.style.left=a.style.left;
 
232
    }
 
233
 
 
234
        win.document.body.oncontextmenu=new Function("document.body.oncontextmenu=new Function('if (document.body.onclick) document.body.onclick(); return false;'); return false; ");
 
235
 
 
236
    for (var i=0; i<this.contextMenu.aframes.length; i++){
 
237
        if (this.contextMenu.aframes[i].document)
 
238
            this.contextMenu.aframes[i].document.body.selfobj = this;
 
239
                this.contextMenu.aframes[i].document.body.onclick=function(e){this.selfobj.contextMenu._contextEnd(e)};
 
240
        }
 
241
 
 
242
        document.body.contextMenu=this.contextMenu;
 
243
        this.contextMenu.contextZone=obj;
 
244
        this.contextMenu.zoneId=obj.contextMenuId;//this.contextMenu.zoneId=this.contextMenuId;
 
245
        return false;
 
246
}
 
247
 
 
248
/**  
 
249
*     @desc: correct context menu position
 
250
*     @type: private
 
251
*     @param: panel - html menu object
 
252
*     @param: panel - recurse flag
 
253
*     @topic: 0  
 
254
*/
 
255
dhtmlXContextMenuObject.prototype.correctMenuPosition=function(panel,mode){ 
 
256
                        var xs=document.body.offsetWidth+document.body.scrollLeft;
 
257
                        var ys=document.body.offsetHeight-15+document.body.scrollTop;
 
258
                        //now check is panel real visible
 
259
                        if ((panel.offsetWidth+parseInt(panel.style.left))>xs)
 
260
                        {
 
261
                                        var z=parseInt(panel.style.left)-panel.offsetWidth;
 
262
                                        if ((z<0)||(this.espc))
 
263
                                                z=xs-panel.offsetWidth;
 
264
                                        if (z<0) z=0;
 
265
                                        panel.style.left=z+"px";
 
266
                                        if (panel.ieFix) panel.ieFix.style.left=z+"px";
 
267
                        }
 
268
 
 
269
                        if ((panel.offsetHeight+parseInt(panel.style.top))>ys)
 
270
                        {
 
271
                                        var z=parseInt(panel.style.top) - panel.offsetHeight;
 
272
                                        if ((z<0)||(this.espc))
 
273
                                        z=ys-panel.offsetHeight;
 
274
                                        if (z<0) z=0;
 
275
                                        panel.style.top=z+"px";
 
276
                                        if (panel.ieFix) panel.ieFix.style.top=z+"px";
 
277
                        }
 
278
                        
 
279
                        if (!mode) this.correctMenuPosition(panel,1);
 
280
                }
 
281
/**  
 
282
          *     @desc: correct context menu position
 
283
          *     @type: public
 
284
              *     @topic: 0
 
285
          */            
 
286
dhtmlXMenuBarObject.prototype.correctMenuPosition=dhtmlXContextMenuObject.prototype.correctMenuPosition;
 
287
 
 
288
                
 
289
                /**  
 
290
          *     @desc: close context menu
 
291
          *     @type: private
 
292
                  *     @param: e - event object
 
293
              *     @topic: 0  
 
294
          */
 
295
dhtmlXContextMenuObject.prototype._contextEnd=function(e){
 
296
        var menu=this.menu;
 
297
        menu._closePanel(menu);
 
298
        menu.lastOpenedPanel="";
 
299
        menu.lastSelectedItem=0;
 
300
        menu.hideBar();
 
301
    for (var i=0; i<this.aframes.length; i++)
 
302
       if (this.aframes[i].document){
 
303
                this.aframes[i].document.body.onclick=null;
 
304
                this.aframes[i].document.body.oncontextmenu=null;
 
305
            }
 
306
        return false;   
 
307
}
 
308
 
 
309
//(c)dhtmlx ltd. www.dhtmlx.com
 
310