Failsafe YACCS

archives


Saturday, March 30, 2002

 
Working hack, version 0.9:

Add defer="defer" to the script tag that calls YACCS, something like:


<script src="http://rateyourmusic.com/bc?b=90000009965" type="text/javascript" defer="defer"></script>


Add another big chunk of script to the <head> section of your template (this will get better once Hossein gives us a function in the remote script that we can call to get the link text):


<script type="text/javascript">
function failsafe_yaccs_linktext(count){
zero_pre = 'Comments ['
zero_suff = ']'
zero_show = 1
one_pre = 'Comments ['
one_suf = ']'
one_show = 1
many_pre = 'Comments ['
many_suf = ']'
many_show = 1
archived_text = 'archived'

prefix = ''
middle = ''
suffix = ''

if(count == -1)
{
prefix = archived_text
middle = ''
suffix = ''
}
else if(count == 0)
{
prefix = zero_pre
suffix = zero_suf

if(zero_show==1)
{
middle = count
}
}
else if (count==1)
{
prefix = one_pre
suffix = one_suf

if(one_show == 1)
{
middle=count
}
}
else
{
prefix = many_pre
suffix = many_suf

if(many_show==1)
{
middle = count
}
}
return prefix+middle+suffix
}



function countcomments(){
if (document.childNodes)
{
if(typeof(ycsx) != "undefined")
{
for (i=0;i<ycsx.length/2;i++)
{
oSpan = document.getElementById("comment"+ycsx[i*2]);
if(oSpan)
{
oSpanText = oSpan.firstChild;
while(oSpanText.nodeType != "3")
{
if(oSpanText.hasChildNodes)
{
oSpanText = oSpanText.firstChild;
}
else
{
return false;
}
}
oSpanText.nodeValue = failsafe_yaccs_linktext(ycsx[i*2+1]);
}
}
}
}
}
</script>


Add onload="countcomments();" to your body tag, something like:


<body onload="countcomments();">


Change your comment link to:


<a href="http://rateyourmusic.com/yaccs/comments?blog_id=90000009965&blog_entry_id=<$BlogItemNumber$>"
onclick="window.open(this.href, '_blank', 'scrollbars=yes,resizable=yes,height=400,width=370,left=80,top=80'); return false;"><span id="comment<$BlogItemNumber$>">Add a comment</span></a>


To see what happens when the remote script fails to load, go to my yaccsfailtest example.

posted by Phil Ringnalda 9:19 AM Add a comment


Friday, March 29, 2002

 
Then, autoinstall YACCS (damn, that's cool stuff!).
posted by Phil Ringnalda 8:58 PM Add a comment

 
First, we need a post.
posted by Phil Ringnalda 8:53 PM Add a comment


This page is powered by Blogger. Isn't yours?