Failsafe YACCS

For YACCS users who would rather not have their blog throw Javascript errors or even fail to load when Hossein’s server is down: Failsafe YACCS and a server-down example.

Right now it’s not as pretty as it could be, since I had to copy the whole function to form the link text out of the remote script, but I assume I can talk Hossein into splitting the yaccs() function in two, so that yaccs() calls yaccs_link_text(). Then all you have to keep outside the remote script is the commentcount() function, with a section to define your pre- and post-count text, so that the line that sets oSpanText.nodeValue can call yaccs_link_text() with your custom text.

Testing would be welcome, especially on OSes other than Windows. It works the way I expect on IE6/Win and Mozilla/Win, and fails the way I expect (no counts) in Opera 6/Win and NS4.79/Win. I presume it should work in IE5/Win, IE5/Mac, and NS6/Mozilla on all OSes, and fail to count but otherwise work in everything else. If not, let me know, before I talk Hossein into releasing it on an unsuspecting public.

Oddly enough, NS4.79/Win didn’t fail the way I expected on the failure test page. I was expecting it to redirect to a 404 page, but instead it just loaded the page without counts. Maybe they fixed that silly behavior of redirecting on 404ed scripts in 4.79. Anyone have an older 4.x version around?(Oops. My mistake. Now it breaks the way it should.)

8 Comments

Comment by Hossein #
2002-03-30 12:33:15

Phil, you rock :) I’ll add the get_yaccs_link ASAP.

It doesn’t mess up the page on netscape 4.08, but I’m assuming that’s because DNS resolution fails immediately and nothing gets loaded. When you put http://rateyourmusic.com/global/busy in the load script, all of a sudden the entire page becomes the server busy page, both on 4.08 and 4.79.

 
Comment by Hossein #
2002-03-30 12:49:41

Question about the yaccs_link_text: is this supposed to return ”document.write('<a href = …..>’)” or just ”<a href = …>”

 
Comment by Phil Ringnalda #
2002-03-30 13:31:12

Oops. That makes sense. I’ll fix it in second or two, so it fails properly in the scourge of the internet.

Return neither one: I’m just looking to replace my failsafe_yaccs_linktext(count) call with a call into the remote script, so it should take int:count plus all the pre and post strings and booleans that yaccs() takes, and return Comments[5] or what-have-you. I wouldn’t even bother except that failsafe_yaccs_linktext() makes such a long thing to scroll past in the template code, and it’s already there in the remote script. If you just make yaccs() call yaccs_link_text() to get the actual text, and then do its document.write, then both ways can share the same code to assemble the comment count: old-style calls yaccs() which calls yaccs_link_text() and then does a document.write, new-style calls yaccs_link_text() and assigns the return value to the span.

 
Comment by Hossein #
2002-03-31 21:51:45

Ok, take a look at the code now (here). Look at yaccs_fs_text. Is that what you need?

 
Comment by Phil Ringnalda #
2002-04-01 08:08:39

That’s it, exactly. Modified my example for version 0.9.9, which would have been 1.0 except that I realized I wasn’t handling zero comments the way I’d like. Because I don’t change the original link text for anything that YACCS doesn’t return a count for, if your first few posts don’t have comments, you don’t get any visual cue about whether or not YACCS is up, like you would if ”Add a comment” changed to ”Comments[0]”, and also it’s confusing that to make a change in how zero comments displays, you have to change what’s in the comment link, rather than the values for zero_pre and zero_suf. In fact, do you ever return a count of zero? Maybe after a comment has been deleted? Otherwise, my zero_pre and zero_suf don’t ever get used at all.

Hmm. Not sure of the solution. I don’t really want to have to get every single <span> on the page, and I don’t think you can getElementById with a wildcard (I want comment*). Too early in the morning. More thought later.

 
Comment by Hossein #
2002-04-01 18:26:37

Well, it looks like you’re traversing the comments array and trying to find an element with an ID that matches the comment. Can you do it the other way around? Can you say ”for each ID in the document, if the id starts with ”yaccsComment”, then parse the number out of the ID, pass it to yaccs_fs_text, and set the text to the value that yaccs_fs_text returns?

 
Comment by Hossein #
2002-04-01 18:39:24

sorry, I guess it would help if I read your comment before I replied :) I’ll let you know if I think of something.

 
Comment by Phil Ringnalda #
2002-04-01 19:00:51

That’s probably what I should do: getElementsByTag(”<SPAN>”), and run through them looking for yaccsComment (oops, bad Phil not to have stuck the yaccs in there), and then pass them off. I have a hard time remembering that most of today’s client machines would have made dandy servers a couple years ago (or less), and there’s really no reason not to make them work. Probably a few millisecond difference (or less, since getElementById isn’t really ripping fast), and only a bit more code. Worst part is, it’s new code, where the 0.9.9 (might have run the version number up a little too quick, eh?) way is almost all stuff that I’ve been using and distributing for about 8 months now without much trouble.

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <del datetime="" cite=""> <dd> <dl> <dt> <em> <i> <ins datetime="" cite=""> <kbd> <li> <ol> <p> <pre> <q cite=""> <samp> <strong> <sub> <sup> <ul> in your comment.