1 (function($, rf) { 2 rf.ui = rf.ui || {}; 3 4 var defaultOptions = { 5 showEvent : 'contextmenu', 6 cssRoot : "ctx", 7 cssClasses : {}, 8 attached : true 9 }; 10 11 // constructor definition 12 rf.ui.ContextMenu = function(componentId, options) { 13 this.options = {}; 14 $.extend(this.options, defaultOptions, options || {}); 15 $super.constructor.call(this, componentId, this.options); 16 this.id = componentId; 17 this.namespace = this.namespace || "." + rf.Event.createNamespace(this.name, this.id); 18 rf.Event.bind('body', 'click' + this.namespace, $.proxy(this.__leaveHandler, this)); 19 rf.Event.bindById(this.id, 'click' + this.namespace, $.proxy(this.__clilckHandler, this)); 20 } 21 22 rf.ui.Menu.extend(rf.ui.ContextMenu); 23 24 // define super class link 25 var $super = rf.ui.ContextMenu.$super; 26 27 $.extend(rf.ui.ContextMenu.prototype, (function() { 28 return { 29 name : "ContextMenu", 30 31 getTarget : function() { 32 if (!this.options.attached) { 33 return null; 34 } 35 var target = typeof this.options.target === 'undefined' ? 36 this.element.parentNode.id : this.options.target; 37 return target; 38 }, 39 40 __showHandler : function(e) { 41 if (this.__isShown()) { 42 this.hide(); 43 } 44 return $super.__showHandler.call(this, e); 45 }, 46 47 show : function(e) { 48 if (this.menuManager.openedMenu != this.id) { 49 this.menuManager.shutdownMenu(); 50 this.menuManager.addMenuId(this.id); 51 this.__showPopup(e); // include the event to position the popup at the cursor 52 var parent = rf.component(this.target); 53 if (parent && parent.contextMenuShow) { 54 parent.contextMenuShow(this, e); 55 } 56 } 57 }, 58 59 __clilckHandler : function (event) { 60 event.preventDefault(); 61 event.stopPropagation(); 62 }, 63 64 destroy : function() { 65 rf.Event.unbind('body', 'click' + this.namespace); 66 rf.Event.unbindById(this.id, 'click' + this.namespace); 67 68 // call parent's destroy method 69 $super.destroy.call(this); 70 } 71 72 73 }; 74 })()); 75 76 })(RichFaces.jQuery, RichFaces);