/*rth8*/
var MediaHub = {
"static_widget": function(feed_id, div) {
feed = this.get_feed(feed_id);
template = "static"
placeholders = { "image": feed.media[0] }
cutline = MediaHubRotator.get_cutline(placeholders['image']);
placeholders['cutline'] = cutline;
this.render_to_page(this.templates[template], placeholders, div);
},
"random_widget": function(feed_id) {
feed = this.get_feed(feed_id);
template = "static";
placeholders = { "image": this.pick_random_array_element(feed.media) }
cutline = MediaHubRotator.get_cutline(placeholders['image']);
placeholders['cutline'] = cutline;
this.render_to_page(this.templates[template], placeholders);
},
"rotator_widget": function(feed_id, div) {
feed = this.get_feed(feed_id);
template = "rotator";
media = feed.media;
//if(media.length > 4) {
//new_media = [];
//for(var i=0; i < 4; i++) {
//new_media[i] = media[i];
//}
//media = new_media;
//}
show_controls = true
if(media.length > 5){
show_controls = false
}
this.log("Media length: "+media.length+". Showing controls? "+show_controls);
labels = []
for(var i = 0; i < media.length; i++) {
labels[i+1] = i+1;
}
photo = media[0];
this.log("Media: "+media, "info", "rotator_widget");
cutline = MediaHubRotator.get_cutline(photo);
placeholders = {"feed_id": feed_id, "user_name": photo.user_name, "slideshow_filename": photo.slideshow_filename, "user_link": photo.user_link, "cutline": cutline, "photo_labels": labels, "media_link": photo.media_link, "show_controls": show_controls}
this.render_to_page(this.templates[template], placeholders, div);
widget = document.getElementById("mh_rotator_"+feed_id);
widget.mh_rotator_id = feed_id;
widget.current_photo = 1;
widget.max_photos = media.length;
widget.media_list = media;
widget.show_controls = show_controls;
this.log("Rotator "+widget.mh_rotator_id+" started. On photo: "+widget.current_photo+" / "+widget.max_photos);
logger = this.log
rotate_this_widget = function() {
to_show_next = widget.current_photo + 1;
if(to_show_next > widget.max_photos) {
to_show_next = 1;
}
logger("Rotating widget: "+widget.mh_rotator_id+" current: "+widget.current_photo+" next: "+to_show_next, "info", "rotate_this_widget:"+widget.mh_rotator_id);
MediaHubRotator.show(widget.mh_rotator_id, to_show_next);
widget.current_photo = to_show_next;
}
widget.rotation_controller_id = window.setInterval(rotate_this_widget, 9000)
},
"render_to_page": function(template_source, placeholders, div) {
var undef;
if(div == undef)
document.write(this.render(template_source, placeholders));
else
{
var thisDiv = document.getElementById(div);
thisDiv.innerHTML = this.render(template_source, placeholders);
}
},
"render": function(template_source, placeholders) {
rendered_content = template_source.process(placeholders);
this.log("Rendered: "+rendered_content, "info", "render");
return rendered_content;
/*removed 10/12/2006...
template = TrimPath.parseTemplate(template_source);
content = template.process(placeholders);
this.log("Rendered: "+content, "info", "render");
return content;
*/
},
"default_argument": function(arg, default_value) {
var undef;
if(arg == undef) {
return default_value;
}
},
"log": function(message, level, caller) {
source = "mediahub_widget.js";
var undef;
if(caller != undef) {
source = source + "::" + caller;
}
// YAHOO.log(message, level, source);
},
"parse_json": function(jsontext) {
return eval(jsontext);
},
"templates": {
//"static": '
',
"static": '',
"rotator": ""
},
"feeds": {},
"add_feed": function(jsonfeed) {
feed = eval(jsonfeed);
feed_id = feed["feed_id"];
this.log("Adding feed: key => "+feed_id, 'info', "add_feed");
MediaHub.feeds[feed_id] = feed;
},
"get_feed": function(feed_id) {
this.log("Fetching feed: key => "+feed_id, 'info', "get_feed");
feed = MediaHub.feeds[feed_id];
var undef;
if(feed != undef) {
this.log("Success!", 'info', "get_feed");
}
return feed
},
"pick_random_array_element": function(user_array) {
var ran = 60/user_array.length;
currentdate = new Date();
core = currentdate.getSeconds();
core = Math.floor(core/ran);
this.log("Random array index => "+core, 'info', 'pick_random_array_element');
return(user_array[core]);
}
}
var MediaHubRotator = {
"go_to": function(feed_id, theurl) {
this.log("go_to called: "+feed_id+" "+theurl);
widget = document.getElementById("mh_rotator_"+feed_id);
window.clearInterval(widget.rotation_controller_id);
this.log("Rotation stopped for "+widget.mh_rotator_id+" current photo: "+widget.current_photo);
this.log("go_to sending user to "+theurl);
window.location = theurl;
return false;
},
"switch_to": function(feed_id, photo_num) {
this.show(feed_id, photo_num);
widget = document.getElementById("mh_rotator_"+feed_id);
widget.current_photo = photo_num;
window.clearInterval(widget.rotation_controller_id);
this.log("Rotation stopped for "+widget.mh_rotator_id+" current photo: "+widget.current_photo);
},
"get_cutline": function(photo) {
if(photo.cutline.length > 0) {
new_cutline = photo.cutline;
}
else {
new_cutline = photo.title;
}
new_cutline = this.truncate_cutline(new_cutline);
return new_cutline;
},
"show": function(feed_id, photo_num) {
widget = document.getElementById("mh_rotator_"+feed_id);
this.log("show called: "+feed_id+" "+photo_num, "debug", "show");
photos = MediaHub.get_feed(feed_id).media;
this.log("Got photos: "+photos.length, "debug", "show");
photo = photos[photo_num-1];
this.log("Got photo: "+photo.id);
the_area = document.getElementById("mh_rotator_"+feed_id+"_img");
this.log("Got area: "+the_area.id+" background: "+the_area.style.background);
the_area.style.background = "transparent url("+photo.slideshow_filename+") no-repeat center center";
the_area.style.display = "block";
this.log("Changed area: "+the_area.id+" background: "+the_area.style.background);
cutline = document.getElementById("mh_rotator_"+feed_id+"_cutline");
this.log("Got cutline: "+cutline.innerHTML);
cutline.innerHTML = this.get_cutline(photo);
this.log("Changed cutline: "+cutline.innerHTML);
credit = document.getElementById("mh_rotator_"+feed_id+"_credit");
this.log("Got credit: "+credit.innerHTML);
credit.innerHTML = photo.user_name;
this.log("Changed credit: "+credit.innerHTML);
media_link = document.getElementById("mh_rotator_medialink_"+feed_id);
media_link.href = photo.media_link;
user_link = document.getElementById("mh_rotator_userlink_"+feed_id);
user_link.href = photo.user_link;
user_link.title = "Link to "+photo.user_name+" 's page";
if(widget.show_controls) {
for(var i=0; i < widget.media_list.length; i++) {
num = i+1;
the_link = document.getElementById("mh_rotator_switchlink"+num+"_"+feed_id);
the_link.className = "inactive";
}
the_link = document.getElementById("mh_rotator_switchlink"+photo_num+"_"+feed_id);
the_link.className = "active";
this.log("Changed link: "+the_link.id+" is now "+the_link.className);
}
},
"truncate_cutline": function(cutline) {
if(cutline.length > 53) {
cutline = cutline.replace(/<.+?>/g, "");
var result = cutline.match(/^(.{0,50}\w*?)\s/);
cutline = result[1] + "...";
return cutline;
//return cutline.slice(0,50) + "...";
}
else {
return cutline;
}
},
"log": MediaHub.log
}