Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting rel attributes

    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!

    Code:
    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);
    Last edited by Kor; 06-18-2008 at 03:21 PM. Reason: wrap the code [code][/code]

  • #2
    New Coder
    Join Date
    Oct 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •