(function() {
var writeLine = function(e)
{
alert('Clicked');
return false;
};
new ContextMenu($('my_test_obj'), [
{
name: "Copy"
, items: [
new EventKey("Copy a random number", writeLine)
, new EventKey("Copy a random character", writeLine)
]
}
, {
name: "Group1"
, items: [
{
name: "SubGroup1"
, items: [
new EventKey("Subitem1", writeLine)
, new EventKey("Subitem2", writeLine)
, new EventKey("Subitem3", writeLine)
]
}
,{
name: "SubGroup2"
, items: [
new EventKey("SubsubItem4", writeLine)
, new EventKey("SubsubItem5", writeLine)
]
}
, new EventKey("Item6", writeLine)
]
}
, new EventKey("Item1", writeLine)
, new EventKey("Item2", writeLine)
, new EventKey("Item3", writeLine)
, new EventKey("Item4", writeLine)
], 'RMB');
})();
.
.
.
stepSubListeners = function (target)
{
var lockedOn = null, j, overedOn
, nodes = target.childNodes
;
// Collapse menu chain, each chain is a route
// Like dominoes
target.chainRoute = target.chainRoute || [];
for(var i in nodes)
{
j = nodes[i];
if(!(j && j.nodeType == 1)) continue;
// If this item has a submenu item
if(j.lastChild.nodeType == 1)
{
target.chainRoute[target.chainRoute.length] = {menu: j.lastChild, next: stepSubListeners(j.lastChild)};
}
IDOMElement(j).addEventListener(
new EventKey("MouseOver", function ()
{
// record "this (overed)" item
overedOn = this;
var subItem = this.lastChild;
registerDelay(function ()
{
// Hide last displayed submenu if submenu is available
if(lockedOn && lockedOn != subItem)
{
_chainHide ? _chainHide(lockedOn) : (lockedOn.style.display = "none");
// bind the chains into chain reactor
chainReactor.bind(lockedOn)();
}
// if mouse is still on "this (overed)" item
if(overedOn == this)
{
// and if this item has sub item
if(subItem.nodeType == 1)
{
lockedOn = this.lastChild;
_chainShow ? _chainShow(subItem) : (subItem.style.display = "");
}
}
// 延遲300毫秒
}.bind(this), 300);
}.bind(j))
);
}
return target.chainRoute.length ? chainReactor.bind(target) : null;
}
, chainReactor = function ()
{
if(this && this.chainRoute)
for(var i in this.chainRoute)
{
_chainHide ? _chainHide(this.chainRoute[i].menu) : (this.chainRoute[i].menu.style.display = "none");
if(this.chainRoute[i].next) this.chainRoute[i].next();
}
}
.
.
.