...

View Full Version : setting rel attributes



ewel
06-18-2008, 12:46 PM
I am trying to make something that will enable me to change links so as to have the sort of rel attributes that are needed for a Lightbox lookalike. What I need to add to the link is rel="{handler: 'iframe', size: {x: width, y: height}}" class="modal".

What I am doing is not working, so I would like to ask for some help in figuring out where it is going wrong. The obj is set in a loop going over all the document.getElementsByTagName("a"). I know that with the right rel and class added manually the Lightbox lookalike does work, so it is a matter of making the javascript to add the rel and class work. I also have the impression that the class is working, so then it comes down to the rel. Am I setting the rel in the right way?

My warm thanks in advance for any help you can give, because I am just not getting there alone!


function hasRel(element, relName) {
var rel = element.getAttribute("rel");
if (rel != false) {
if(rel.indexOf(" ")!=-1) {
var rels = rel.split(" ");
for (var i in rels) {
if (rels[i] == relName) {
return true;
}
}
} else {
if (rel == relName) {
return true;
}
}
}
return false;
}
function addRel(element, relName) {
if (!hasRel(element, relName)) {
element.setAttribute("rel", " " + relName);
} else {
element.setAttribute("rel", relName);
}
}
function hasClass(element, className) {
if (element.className) {
var classes = element.className.split(" ");
for (var i in classes) {
if (classes[i] == className) {
return true;
}
}
}
return false;
}
function addClass(element, className) {
if (!hasClass(element, className)) {
element.className = (element.className == "" ? className : element.className + " " + className);
}
}
var squeezeboxrel = "{handler: 'iframe', size: {x: 600, y: 400}}";
addRel(obj, squeezeboxrel);
var squeezeboxclass = "modal";
addClass(obj, squeezeboxclass);

ewel
06-19-2008, 10:33 AM
I have come a little further in getting things to work, and basically that is because I skipped everything for rel except element.setAttribute("rel", relName).

Is there anyone who knows how I can made a solid set of functions to check if a link tag has a rel and to add one or more rel attributes to it?

Without this all a href tags in the site have to be edited manually to add a rel if they are external, so it would be great to have this convenience...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum