Bios Password

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, March 20, 2010

GSD Recent Comment” Sidebar link references fixed

Posted on 12:48 PM by Unknown

For anyone who cares, I finally took the time to “fix” the html links in the “Recent Comments” sidebar.

While they look good, it has always annoyed me.

The format is this.

(poster name) on (post title) comment bits…(more).

Clicking on any of the HTML links just took you to the top of the post the comment was left on. Not the comment itself as expected.

While users could scroll down to the comment section, it just wasn’t as right or polite as I wanted.

I’m not really much of a coder, particularly JavaScript, but I decided it was time to try to fix it.

So I located the correct comment link HTML format from a post comment as a sample to examine.

http:// <blogtitlelinkurl> ?showComment= <numbersetA> #c <numbersetB>

This code correctly takes you directly to the respective comment under the post.

Then I copied the existing HTML codes the JavaScript was generating into my notepad text editor and set out to compare them all.

Very quickly I found that the original JavaScript code (included at the end of this post for the curious) was replacing the “#” symbol in the working comment HTML structure with a “#comment-“ string instead.  This routed the link-click to the post title when Blogger couldn’t figure it out.

Looking at the JavaScript code I found a line “ctlink = ctlink.replace("#", "#comment-");” and replaced it with “ctlink = ctlink.replace("#", "#");” which was a dirty way to not muck the code up but keep the variable structure the same.  (Note: “ctlink” variable name stands for “comment link” I think).

Testing finds that it works perfectly.

Clicking on either the (poster name) or (more) parts will now take to directly to the comment itself, not the post title.

While clicking on the (post title) link takes you to the top of the post itself.

The only thing I still needed to do (being a bit neurotic) is that while that worked, the (post title) HTML code was sloppy as the JavaScript generating it still seemed to either be tagging it with, or failing to remove the “?showComment=numbers”  bit at the end.  It did work, it’s just not pretty.

That still needed fixin’.

Trial and Editor

Luckily I had recently found the following W3Schools Online Web Tutorials site that also has their “Tryit Editor”.

This is really, really cool as it lets coding doofs like me copy/paste/tweak/test code and scripts into their editor and view the results without nuking my deployed blog until fully tested.

Once I think I have the solution down, I then upload the changes to my gsdtemplatetester blog page.  This is the proving ground where I can experiment with code and templates on a “real” Blogger deployment before moving those changes into production on the GSD blog page template proper.

So I set to work using the JavaScript descriptions there, picking apart more of the code elements and variables, and via trial and editor, found the line to fix.

Originally it was

var ptlink = ctlink.split("#");

Where the variable name “ptlink” stands for “post title link” I think.

Which I finally worked out needed to be

var ptlink = ctlink.split("?showComment=");

Replacing that finally resulted in the comment sidebar (post title) link returning the HTML code format

http:// <blogtitlelinkurl>

and not the incorrect (but still functional)

http:// <blogtitlelinkurl> ?showComment= <numbersetA>

Hurrah! The Recent Comment sidebar links now all work correctly and the HTML code is fully correct as well.

Hopefully this will make monitoring and following the recent comments a bit more enjoyable and efficient for readers.

Cheers!

--Claus V.

Note:

For posterity, here is the original (working but barely) and fixed (working great) JavaScript code I am using if anyone cares to study it more.  I’m clearly not the original author of the JavaScript.  It came from somewhere within this Now See This: Adding Comments to your Blogger sidebar GSD post back in 2008 (gosh has it been that long?!!).

Original (working but barely) JavaScript code

<ul><script style="text/JavaScript">
function showrecentcomments(json) {
for (var i = 0; i < 5; i++) {
var entry = json.feed.entry[i];
var ctlink;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
ctlink = entry.link[k].href;
break;
}
}
ctlink = ctlink.replace("#", "#comment-");
var ptlink = ctlink.split("#");
ptlink = ptlink[0];
var txtlink = ptlink.split("/");
txtlink = txtlink[5];
txtlink = txtlink.split(".html");
txtlink = txtlink[0];
var pttitle = txtlink.replace(/-/g," ");
pttitle = pttitle.link(ptlink);
if ("content" in entry) {
var comment = entry.content.$t;}
else
if ("summary" in entry) {
var comment = entry.summary.$t;}
else var comment = "";
var re = /<\S[^>]*>/g;
comment = comment.replace(re, "");
document.write('<li>');
document.write('<a href="' + ctlink + '">' + entry.author[0].name.$t + '</a>');
document.write(' on ' + pttitle);
document.write('<br/>');
if (comment.length < 120) {
document.write(comment);
document.write('<li>');document.write('<br/>');
}
else
{
comment = comment.substring(0, 120);
var quoteEnd = comment.lastIndexOf(" ");
comment = comment.substring(0, quoteEnd);
document.write(comment + '...<a href="' + ctlink + '">(more)</a>');
document.write('<li>');document.write('<br/>');
}
}
document.write('</li>');
document.write('<div style="font-size:95%;text-align:center"><a href="http://grandstreamdreams.blogspot.com/feeds/comments/full">GSD RSS Comment Feed link</a></div>');
}
</script>
<script src="http://grandstreamdreams.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script></ul>
<noscript>You need to enable JavaScript to read this.</noscript>

I’ve also linked to some of the JavaScript examples and actions at w3schools page as well for easy cross-reference to show what these various calls are doing.

Fully Working JavaScript code (changes in yellow)

<ul><script style="text/JavaScript">
function showrecentcomments(json) {
for (var i = 0; i < 5; i++) {
var entry = json.feed.entry[i];
var ctlink;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
ctlink = entry.link[k].href;
break;
}
}
ctlink = ctlink.replace("#", "#");
var ptlink = ctlink.split("?showComment=");
ptlink = ptlink[0];
var txtlink = ptlink.split("/");
txtlink = txtlink[5];
txtlink = txtlink.split(".html");
txtlink = txtlink[0];
var pttitle = txtlink.replace(/-/g," ");
pttitle = pttitle.link(ptlink);
if ("content" in entry) {
var comment = entry.content.$t;}
else
if ("summary" in entry) {
var comment = entry.summary.$t;}
else var comment = "";
var re = /<\S[^>]*>/g;
comment = comment.replace(re, "");
document.write('<li>');
document.write('<a href="' + ctlink + '">' + entry.author[0].name.$t + '</a>');
document.write(' on ' + pttitle);
document.write('<br/>');
if (comment.length < 120) {
document.write(comment);
document.write('<li>');document.write('<br/>');
}
else
{
comment = comment.substring(0, 120);
var quoteEnd = comment.lastIndexOf(" ");
comment = comment.substring(0, quoteEnd);
document.write(comment + '...<a href="' + ctlink + '">(more)</a>');
document.write('<li>');document.write('<br/>');
}
}
document.write('</li>');
document.write('<div style="font-size:95%;text-align:center"><a href="http://grandstreamdreams.blogspot.com/feeds/comments/full">GSD RSS Comment Feed link</a></div>');
}
</script>
<script src="http://grandstreamdreams.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script></ul>
<noscript>You need to enable JavaScript to read this.</noscript>

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Blogger, blogging | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Finally! Time to Post! New material list
    After a recent text from my bro reminding me it has been since March since I’ve done a blog post, I was finally able to clear the schedule a...
  • Oscar watch Linkpost
    Alvis and Lavie are watching the Oscars tonight and I’m along for the ride. I wasn’t able to come even close to getting out some of the pos...
  • New Year’s Day - First Post 2011
    Same day I came out with my first post after a long drought, I fell upon this article Blogging Seems To Have Peaked, Says Pew Report over a...
  • Utility Gumbo
    There’s a lot in this pot.  Probably something everyone can find to enjoy. I’m serving it up tonight out of the back of the truck on the s...
  • iodd : Multi-boot madness!
    Like many computer technicians and responders, I seem to always have at hand a collection of bootable media; CD’s, DVD’s, USB-HDD’s, flash m...
  • Ubuntu 13.10 Upgrade - Lessons Learned & VIDMA utility found
    A few weeks ago a new release of Ubuntu came out. Naturally that meant it was update time! I have been getting pretty good at this now so ...
  • Interesting Malware in Email Attempt - URL Scanner Links
    Last weekend I spent some time with extended family helping confirm for them that their on-line email account got hacked and had been used t...
  • Windows 8 Linkage: A Bit Behind the Ball
    CC attribution: behind the eight ball by Ed Schipul on flickr . OK. Confession time. I’m more than a bit exhausted this weekend. Besides a...
  • Lego MiniFig Extravaganza
    picture clipped from Wired’s clip from Gizmodo clip… Thanks in no small part to the Windows 7 RC release, XPM mode research, and a big “l...
  • This Week in Security and Forensics: Beware the cake!
    Cube Party! image used with permission from John Walker at "rockpapershotgun.com" Yeah, the cake is a Portal thing.  Let’s d...

Categories

  • Active Directory
  • anti-virus software
  • Apple
  • architecture
  • art
  • AVG
  • Blogger
  • blogging
  • books
  • boot-cd's
  • browsers
  • cars
  • cell-phones
  • cheat sheets
  • Chrome/Chromium
  • command-line interface
  • cooking
  • crafts
  • crazy
  • curmudgeon
  • DHC
  • Dr. Who
  • E-P1
  • Education
  • family
  • Firefox
  • firewalls
  • For the Gentleman
  • forensics
  • Gmail
  • Google
  • graphics
  • hacks
  • hardware
  • humor
  • hurricanes
  • imagex
  • Internet Explorer
  • iOS
  • iPhone
  • iPod
  • iTunes
  • Kindle
  • Learning
  • Link Fest
  • Linux
  • malware tools
  • Microsoft
  • movies
  • music
  • networking
  • NewsFox
  • NFAT
  • Nook
  • Opera
  • organization
  • PDF's
  • photography
  • politics
  • PowerShell
  • recipes
  • Remote Support
  • RSS
  • science
  • Scripting
  • search engines
  • security
  • Shuttle SFF
  • software
  • Texana
  • Thunderbird
  • troubleshooting
  • TrueCrypt
  • tutorials
  • utilities
  • VBscript
  • video
  • Virtual PC
  • virtualization
  • viruses
  • Vista
  • Vista mods
  • wallpapers
  • Win FE
  • Win PE
  • Win RE
  • Windows 7
  • Windows 8
  • Windows Home Server
  • Windows Live Writer
  • Windows Phone
  • writing
  • XP
  • XP mods
  • Xplico

Blog Archive

  • ►  2013 (83)
    • ►  November (8)
    • ►  October (8)
    • ►  September (14)
    • ►  August (6)
    • ►  July (10)
    • ►  June (10)
    • ►  April (11)
    • ►  March (6)
    • ►  February (7)
    • ►  January (3)
  • ►  2012 (96)
    • ►  December (8)
    • ►  November (4)
    • ►  October (9)
    • ►  September (8)
    • ►  August (12)
    • ►  July (4)
    • ►  June (3)
    • ►  May (7)
    • ►  April (13)
    • ►  March (3)
    • ►  February (5)
    • ►  January (20)
  • ►  2011 (41)
    • ►  December (8)
    • ►  November (7)
    • ►  September (4)
    • ►  August (4)
    • ►  July (2)
    • ►  June (6)
    • ►  March (5)
    • ►  February (1)
    • ►  January (4)
  • ▼  2010 (69)
    • ►  December (1)
    • ►  October (3)
    • ►  September (2)
    • ►  August (13)
    • ►  July (17)
    • ►  June (3)
    • ►  May (3)
    • ►  April (3)
    • ▼  March (11)
      • WinPE Multi-boot a Bootable USB Storage device
      • Dealing with the Dell … 2010 Edition
      • Not there yet, but if I click my heels together th...
      • A Census 2010 Drive By…
      • GSD Recent Comment” Sidebar link references fixed
      • Skipping Links in a Sunday Stream
      • WinPE and DISM/PEimg to boost Scratch Space (Ram D...
      • GSD Redesign (again)
      • March Madness Linkfest #3 – Forensic Fallout
      • March Madness Linkfest #2 – Windows Tips
      • March Madness Linkfest #1 – Freeware Apps
    • ►  February (1)
    • ►  January (12)
  • ►  2009 (177)
    • ►  December (20)
    • ►  November (11)
    • ►  October (7)
    • ►  September (7)
    • ►  August (21)
    • ►  July (17)
    • ►  June (7)
    • ►  May (18)
    • ►  April (9)
    • ►  March (17)
    • ►  February (23)
    • ►  January (20)
  • ►  2008 (35)
    • ►  December (23)
    • ►  November (12)
Powered by Blogger.

About Me

Unknown
View my complete profile