Converted asset context menus to YUI menus

This commit is contained in:
Graham Knop 2008-07-22 17:44:17 +00:00
parent 8ef9e3e39e
commit cb21f13d9f
5 changed files with 160 additions and 226 deletions

View file

@ -1,37 +1,9 @@
.contextMenu_skin {
position:absolute;
border:2px outset #eeeeee;
font-family: helvetica, arial, sans-serif;
line-height:18px;
width: 100px;
cursor: default;
font-size:10px;
z-index:100;
visibility:hidden;
padding: 4px;
font-weight: normal;
text-align: left;
background-color:#F0F0F0;
border-bottom: 3px groove #999999;
border-top: 0px groove #999999;
border-right: 3px groove #999999;
border-left: 0px groove #999999;
}
.contextMenu_skin A, .contextMenu_skin A:link, .contextMenu_skin A:visited {
font-weight: normal;
width: 100%;
color: black;
text-decoration: none;
margin: 1px;
font-size: 10px;
}
.contextMenu_skin A:hover {
text-decoration: none;
font-weight: normal;
color: #154c66;
margin: 0px;
background-color: #c3cfd4;
border: 1px solid #F0F0F0;
width: 100%;
.wg-contextmenu {
position: absolute;
visibility: hidden;
font-family: helvetica, arial, sans-serif;
}
.wg-contextmenu .yuimenuitemlabel {
font-size: 10px
}

View file

@ -1,107 +1,21 @@
var ie5=document.all&&document.getElementById
var contextMenu_items = new Array();
if (contextMenu_old == undefined)
{
var contextMenu_old = (document.onclick) ? document.onclick : function () {};
document.onclick= function () {contextMenu_old();contextMenu_hide();};
}
function contextMenu_renderLeftClick(menuId,e) {
contextMenu_hide(e);
contextMenu_show(menuId,e);
e.cancelBubble=true;
e.returnValue=false;
return false;
}
function contextMenu_show(menuId,e){
var menuobj=document.getElementById(menuId)
var posx = 0;
var posy = 0;
var yoffset = 0;
var xoffset = 0;
var firedobj = ie5?e.srcElement:e.target;
while (firedobj!=null && firedobj.tagName!="HTML"){
//this is a hack, need to revisit
if (firedobj.tagName == "DIV") {
xoffset+=firedobj.offsetLeft;
yoffset+=firedobj.offsetTop;}
firedobj=firedobj.offsetParent;
}
var el = (document.documentElement && document.documentElement.scrollTop)
? document.documentElement : document.body;
posx = e.clientX - xoffset + (ie5? el.scrollLeft : window.pageXOffset);
posy = e.clientY - yoffset + (ie5? el.scrollTop : window.pageYOffset);
menuobj.style.left=posx + "px";
menuobj.style.top=posy + "px";
menuobj.style.visibility="visible"
return false
}
function contextMenu_hide(){
for (i=0;i<contextMenu_items.length;i++) {
document.getElementById("contextMenu_"+contextMenu_items[i]+"_menu").style.visibility="hidden"
}
return false;
}
function contextMenu_createWithImage(imagePath, id, name, addContext){
contextMenu_items.push(id);
this.id = id;
this.name = name;
this.addContext = addContext;
this.type = "image";
this.imagePath=imagePath;
this.linkLabels = new Array();
this.linkUrls = new Array();
this.draw = contextMenu_draw;
this.print = contextMenu_print;
this.addLink = contextMenu_addLink;
}
function contextMenu_createWithLink(id, name){
contextMenu_items.push(id);
this.id = id;
this.name = name;
this.type = "link";
this.linkLabels = new Array();
this.linkUrls = new Array();
this.draw = contextMenu_draw;
this.print = contextMenu_print;
this.addLink = contextMenu_addLink;
}
function contextMenu_draw(){
var output = "";
output += '<div id="contextMenu_' + this.id + '_menu" class="contextMenu_skin">';
for (i=0;i<this.linkUrls.length;i++) {
output += "<a style=\"color: black;\" href=\"" + this.linkUrls[i] + "\">" + this.linkLabels[i] + "</a><br />";
}
output += '</div>';
if (this.type == "image") {
if (this.addContext)
output += '<p class="toolbarIcon" style="display: inline; vertical-align: middle;"><a href="javascript:void(0)">';
output += '<img src="' + this.imagePath + '" id="contextMenu_' + this.id + '_2" onclick="return contextMenu_renderLeftClick(\'contextMenu_' + this.id + '_menu\',event)" alt="' + this.name + '" title="' + this.name + '" align="absmiddle" ';
if (this.addContext)
output += 'style="border: 0px none; vertical-align: middle;"';
output += ' />';
if (this.addContext)
output += '</a></p>';
} else {
output += '<a href="#" id="contextMenu_' + this.id + '" onclick="return contextMenu_renderLeftClick(\'contextMenu_' + this.id + '_menu\',event)">' + this.name + '</a>';
}
return output;
}
function contextMenu_print(){
document.write(this.draw());
}
function contextMenu_addLink(linkUrl,linkLabel){
this.linkUrls.push(linkUrl);
this.linkLabels.push(linkLabel);
}
function initWGContextMenus() {
var menus = YAHOO.util.Dom.getElementsByClassName('wg-contextmenu');
for (var i = menus.length; i--; ) {
var menu = menus[i];
if (menu.initialized) {
continue;
}
var ctx = menu.previousSibling;
var myMenu = new YAHOO.widget.Menu(menu, {
context : [ctx, "tl", "bl"]
});
myMenu.render();
YAHOO.util.Event.addListener(ctx, "click", function (e, menu) {
YAHOO.util.Event.preventDefault(e);
menu.align("tl", "bl");
menu.show();
}, myMenu);
}
}
YAHOO.util.Event.onDOMReady(initWGContextMenus);