阅读更多
dojo.lang.extend(dojo.widget.PopupMenu2, {
onOpen: function(e){
this.openEvent = e;
var x = e.pageX, y = e.pageY;
var win = dojo.html.getElementWindow(e.target);
var iframe = win._frameElement || win.frameElement;
if(iframe){
var cood = dojo.html.abs(iframe, true);
x += cood.x - dojo.withGlobal(win, dojo.html.getScroll).left;
//override the onOpen to reslove the problem the context popup menu open under the selected TreeNode.
if (!(e.type == "contextmenu" && dojo.render.html.ie))
y += cood.y - dojo.withGlobal(win, dojo.html.getScroll).top;
}
this.open(x,y, null, [x, y]);
e.preventDefault();
e.stopPropagation();
}
});
这样我们就是复写了dojo.widget.PopupMenu2类的onOpen方法。如果我们想调用覆盖以前的方法。
//backup the old function
dojo.widget.TreeBasicControllerV3.prototype.oldOnKey =dojo.widget.TreeBasicControllerV3.prototype.onKey;
dojo.lang.extend(dojo.widget.TreeBasicControllerV3, {
onClick: function(e) {
if (e.target.tagName == "INPUT")
return ;
// default click handler just sets the focus
var treeWidget = this.getWidgetByNode(e.currentTarget);
if (!treeWidget || !treeWidget.isTree) { return; }
var nodeWidget = this.getWidgetByNode(e.target);
if (!nodeWidget || !nodeWidget.isTreeNode) { return; }
this._focusLabel(treeWidget, nodeWidget);
},
onKey: function (e){
if (e.target.tagName == "INPUT")
return ;
this.oldOnKey(e);
}
});
dojo.lang.extend这个方式是多么的方便。我们可以用这个方法方便的扩展或修改以有的代码。
看看dojo的dojo.lang.common 里面包括了对象间的一些操作。如dojo.lang.inherits, dojo.lang.mixin etc