adding category descriptions
bradpowellphoto
Registered Users Posts: 378 Major grins
I added this code to my javascript ao that I could add category descriptions to my site. I got one to work "events" but two of my custom categories just won't work. Any suggestions?
function addCategoryDescription() {
var categoryDescription = {
"My_Images_of_Vancouver_Island" : "from the surfers of Tofino to the lights of Victoria",
"Events" : "Parades, Rodeos, Bathtub Races and more!",
"Street_Scenes" : "from the mean streets of Vancouvers East End to Chinatown"
};
if ((YD.hasClass(document.body, "category")) && (!YD.hasClass(document.body, "subcategory"))) {
re = /category_(\S+)/i;
re.exec(document.body.className);
breadCrumb = YD.get("breadcrumb");
if (breadCrumb && categoryDescription[RegExp.$1]) {
divTag = document.createElement("div");
divTag.className = "categoryDescription";
divTag.appendChild(document.createTextNode(categor yDescription[RegExp.$1]));
breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
}
}
if (YD.hasClass(document.body, "homepage")) {
re = /\>([\w\-]+)<\/a>/i;
divTag = YD.get("categoriesBox");
if (divTag) {
divTags = YD.getElementsByClassName("albumTitle", "p", divTag);
for (i=0; i<divTags.length; i++) {
re.exec(divTags.innerHTML);
if (categoryDescription[RegExp.$1] != undefined) {
pTag = document.createElement("p");
pTag.className = "categoryDescription";
pTag.appendChild(document.createTextNode(categoryD escription[RegExp.$1]));
divTags.parentNode.insertBefore(pTag, divTags.nextSibling);
}
}
}
}
}
YE.addListener(window, "load", addCategoryDescription);
Thanks!
function addCategoryDescription() {
var categoryDescription = {
"My_Images_of_Vancouver_Island" : "from the surfers of Tofino to the lights of Victoria",
"Events" : "Parades, Rodeos, Bathtub Races and more!",
"Street_Scenes" : "from the mean streets of Vancouvers East End to Chinatown"
};
if ((YD.hasClass(document.body, "category")) && (!YD.hasClass(document.body, "subcategory"))) {
re = /category_(\S+)/i;
re.exec(document.body.className);
breadCrumb = YD.get("breadcrumb");
if (breadCrumb && categoryDescription[RegExp.$1]) {
divTag = document.createElement("div");
divTag.className = "categoryDescription";
divTag.appendChild(document.createTextNode(categor yDescription[RegExp.$1]));
breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
}
}
if (YD.hasClass(document.body, "homepage")) {
re = /\>([\w\-]+)<\/a>/i;
divTag = YD.get("categoriesBox");
if (divTag) {
divTags = YD.getElementsByClassName("albumTitle", "p", divTag);
for (i=0; i<divTags.length; i++) {
re.exec(divTags.innerHTML);
if (categoryDescription[RegExp.$1] != undefined) {
pTag = document.createElement("p");
pTag.className = "categoryDescription";
pTag.appendChild(document.createTextNode(categoryD escription[RegExp.$1]));
divTags.parentNode.insertBefore(pTag, divTags.nextSibling);
}
}
}
}
}
YE.addListener(window, "load", addCategoryDescription);
Thanks!
“Look, I'm not an intellectual - I just take pictures.” Helmut Newton
My Vancouver Island Photography Website http://bradpowellphoto.com
My Facebook Page http://www.facebook.com/bradpowellphoto
My Vancouver Island Photography Website http://bradpowellphoto.com
My Facebook Page http://www.facebook.com/bradpowellphoto
0
Comments
The reason why the code works fine for "Events" and not "My Images of Vancouver Island" or "Street Scenes", is that second two have spaces in their title, while your categoryDescription array is looking for values with underscores.
To fix this I would modify your code to the following...
Cheers,
David
SmugMug API Developer
My Photos
function addCategoryDescription() {
var categoryDescription = {
"My Images of Vancouver Island" : "from the surfers of Tofino to the lights of Victoria",
"Events" : "Parades, Rodeos, Bathtub Races, Pageants and more!",
"Street Scenes" : "from the mean streets of Vancouvers East End to Chinatown"
};
if ((YD.hasClass(document.body, "category")) && (!YD.hasClass(document.body, "subcategory"))) {
re = /category_(\S+)/i;
re.exec(document.body.className);
breadCrumb = YD.get("breadcrumb");
if (breadCrumb && categoryDescription[RegExp.$1]) {
divTag = document.createElement("div");
divTag.className = "categoryDescription";
divTag.appendChild(document.createTextNode(categoryDescription[RegExp.$1]));
breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
}
}
if (YD.hasClass(document.body, "homepage")) {
re = /\>([\w\-]+)<\/a>/i;
divTag = YD.get("categoriesBox");
if (divTag) {
divTags = YD.getElementsByClassName("albumTitle", "p", divTag);
for (i=0; i<divTags.length; i++) {
re.exec(divTags.innerHTML);
var category = RegExp.$1.replace(" ", "_");
if (categoryDescription[category] != undefined) {
pTag = document.createElement("p");
pTag.className = "categoryDescription";
pTag.appendChild(document.createTextNode(categoryDescription[category]));
divTags.parentNode.insertBefore(pTag, divTags.nextSibling);
}
}
}
}
}
YE.addListener(window, "load", addCategoryDescription);
My Vancouver Island Photography Website http://bradpowellphoto.com
My Facebook Page http://www.facebook.com/bradpowellphoto
Sorry there was a bug in my code, I have updated your version on your site...
I changed your addListener to onContentReady, so the category descriptions are added quicker, otherwise it has to wait for all the images to load before they are added.
Cheers,
David
SmugMug API Developer
My Photos
David
Thanks so much! That's perfect!
Brad
My Vancouver Island Photography Website http://bradpowellphoto.com
My Facebook Page http://www.facebook.com/bradpowellphoto