PDA

View Full Version : Resolved anylink menu- js link locations & images



maxsbonsai
02-07-2009, 11:57 PM
Hi there. I just got anylink drop down menu up and running for my site, and it works great!

Here's where to find it:
http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm

I want to create one more dropdown, however, with a bunch of buttons so visitors can bookmark my page on delicious, or open a popup, among other things.

My button for delicious, for example, would have a link location like:


javascript:(function(){f='http://delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&v=5&';a=function(){if(!window.open(f+'noui=1&jump=doclose','deliciousuiv5','location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()

The button would also use an image instead of text. In this example, we have:

http://delicious.com/favicon.ico

Pasting these values into menucontents.js doesn't work. I have a feeling this is because (1)the values in menucontents.js are not full links, and (2) these values are defined within qoutation marks (the program looks for values between the " " ).


I took a peek at anylinkmenu.js, and here is the section that generates the html links for the menu. The program creates links by pasting the link url and corresponding link text into a sort of link template.



getmenuHTML:function(menuobj){
var menucontent=[]
var frag=""
for (var i=0; i<menuobj.items.length; i++){
frag+='<li><a href="' + menuobj.items[i][1] + '" target="' + menuobj.linktarget + '">' + menuobj.items[i][0] + '</a></li>\n'
if (menuobj.items[i][2]=="efc" || i==menuobj.items.length-1){
menucontent.push(frag)
frag=""
}
}
if (typeof menuobj.cols=="undefined")
return '<ul>\n' + menucontent.join('') + '\n</ul>'
else{
frag=""
for (var i=0; i<menucontent.length; i++){
frag+='<div class="' + menuobj.cols.divclass + '" style="' + menuobj.cols.inlinestyle + '">\n<ul>\n' + menucontent[i] + '</ul>\n</div>\n'
}
return frag
}
},


What I'm considering is to have my links saved in menucontents.js as entire links, just one list- not two columns. Next, I would change the above code to just paste the entire link from menucontents.js.

What do you think? Suggestions? Is there anything I missed? Will you please help me implement these changes? I'm decent with computers, but not much of a javascript guy. Thanks in advance. Your help and comments are much appreciated.
-Max

maxsbonsai
02-08-2009, 12:45 AM
moderator, please forgive me. I am new here, and just read the sticky about how i should post in the other forum.

jscheuer1
02-08-2009, 08:15 AM
moderator, please forgive me. I am new here, and just read the sticky about how i should post in the other forum.

No prob Bob, I moved it for you. Just don't do it again, please.

maxsbonsai
02-08-2009, 08:25 PM
Hi again. I got it working with pictures on my own. Here's the hack for anylinkmenu.js:

getmenuHTML:function(menuobj){
var menucontent=[]
var frag=""
for (var i=0; i<menuobj.items.length; i++){
if (menuobj.items[i][3]=="img"){
frag+='<li><a href="' + menuobj.items[i][1] + '" target="' + menuobj.linktarget + '"><img src="' + menuobj.items[i][0] + '"></a></li>\n'
}
else{
frag+='<li><a href="' + menuobj.items[i][1] + '" target="' + menuobj.linktarget + '">' + menuobj.items[i][0] + '</a></li>\n'
}

if (menuobj.items[i][2]=="efc" || i==menuobj.items.length-1){
menucontent.push(frag)
frag=""
}
}
if (typeof menuobj.cols=="undefined")
return '<ul>\n' + menucontent.join('') + '\n</ul>'
else{
frag=""
for (var i=0; i<menucontent.length; i++){
frag+='<div class="' + menuobj.cols.divclass + '" style="' + menuobj.cols.inlinestyle + '">\n<ul>\n' + menucontent[i] + '</ul>\n</div>\n'
}
return frag
}
},


What i did here was add an if statement to check for the presence of the phrase "img" on a 4th colum (represented by menuobj.items[i][3] in above the code). If [i][3]==img, then the program prints the image url located in [i][0] into a linked image template. Otherwise, it generates the normal text link.



Here's a sample of what a normal link looks like in menucontents.js:

["Dynamic Drive", "http://www.dynamicdrive.com/"],


Here's a sample of what a link that starts a new row looks like in menucontents.js:

["Dynamic Drive", "http://www.dynamicdrive.com/", "efc"],
Notice the third column menuobj.items[i][2]==efc to signal new row

Now here's a sample of what a linked image looks like in menucontents.js:

["http://www.dynamicdrive.com/favicon.ico", "http://www.dynamicdrive.com/","","img"],
Notice menuobj.items[i][2] is needed to create menuobj.items[i][3]==img

Thanks for looking. I will post a link to my site once i've got my menu finished, so you can all see what it looks like.