SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Maryland, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Custom Class suggestions.

    All,

    I have written a new breadcrumb script for my site, it is pretty much set up as a custom object. It allows you to specify custom links to display on the left and then parses the document.location for the links to the right. Right now, I am simply doing this when I call the write method of the script. I was thinking to possibly move it into the setCrumb portion of the script, but can't quite make it work. Here is what I have, it works, but I would welcome any suggestions.

    function crumb() {
    this.crumbs = new Array();
    this.setCrumb=setCrumb;
    this.getCrumbs = getCrumbs;
    this.writeCrumb = writeCrumb;
    String.prototype.setClass = setClass;
    function setCrumb (name, url) {
    this.name = name;
    this.url = url;
    this.name = this.name.setClass(this.name);
    this.name = this.name.link(url);
    }
    function getCrumbs() {
    for(i=0;i<=crumbs.length - 1;i++)
    alert("here is a crumb " + crumbs[i]);
    }
    function writeCrumb() {
    var crumb = new String;
    var routput = new String;
    var output = "<span class='left'>" + crumbs.join("span class='crumb'> | </span>" ) + "</span>";
    var currentPage = window.location;
    var urlParts = currentPage.split('/');
    for (i=0;i<(urlParts.length - 1);i++
    {
    if((i==0) && urlParts.length > 1) {
    crumb = "Home";
    crumb = crumb.setClass(crumb);
    crumb = crumb.link("/" );
    }
    else {
    crumb = urlParts[i];
    crumb = crumb.setClass(crumb);
    x = urlParts.slice 1,i+1);
    url = "/" + x.join("/" );
    crumb = crumb.link(url);
    }
    routput += "<span class='crumb'>" + crumb + " | </span>";
    }
    output += "span class='right'>" + routput + "</span>";
    document.write(output);
    }
    }

    on the document side it would look like this:

    <script>
    var a = new crumb();
    a.setCrumb("google","http://www.google.com" );
    a.setCrumb("altavista","http://www.altavista.com" );
    </script>
    Last edited by mrhatch; Jul 24, 2003 at 11:46.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I see what setClass() does?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Maryland, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beetle,
    Sorry about that it got overlooked. I will paraphrase as I do not have the code here at home, but it is something like this.
    function setClass() {
    return "<span class='crumb'>" + this + "</span>"
    }

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Maryland, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beetle,
    Back at work now, here is the exact code for setClass

    functionsetClass(){
    if (this.toString().match(/group1|group2|group3)/i)){
    return "<span class='groupcrumb'>" + this.toString() + "</span>"}
    else {
    return "<span class='crumb'>" + this.toString() + "</span>"
    }
    }

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm - I'm a tad confused. I'm mean, I'm all for making things as objects - but I don't see where you're going with some of this stuff.

    You never call getCrumbs() or writeCrumb(). You refer to a global variable crumbs that I don't see declared anywhere. You access another (apparent) string method you've prototyped called link() which I also don't see - several other things.

    Does this thing work? Can I see it in action online someplace?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Maryland, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beetle,
    It was being developed on an Intranet, so I had to set up a web space to put it on. You won't get the full effect of the stuff on the left as it is only a single page, but you should be able to get the idea.
    http://mywpages.comcast.net/smilingsara/


Bookmarks

Posting Permissions

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