v1.0 Release – Getting the Localize Dates Link Working with the New Entries Loaded On Scroll

One of my goals for this release was getting the localize dates link working with the new entries loaded on scroll. This wasn’t happening beforehand. Only the entries that were displayed with the initial page load worked with the localize dates link.

I examined why this was happening by looking at how the dates are localized. The following is the code for this functionality:

// add click handler to the localize dates link
$('#localize').show().click(function () {
   $('.date').each(function (i) {
     $(this).text(new Date($(this).text()).toLocaleString());
   return false;

As you can see above when the localize date link is clicked the function goes through each element that has a class called ‘date’ and transforms the text within the element to a local date string via toLocalString(). Now my problem was that none of the new entries loaded on scroll have any elements that contain a class called ‘date’. Thus, none of the dates for the new entries got translated into their local versions.

In order to rectify this situation I decided to make the following change within loadEntries():

// user column
$('<td>' + pushData[i].user + '<br /><span class="date">' + pushData[i].formattedDate + '</span></td>')

So basically now I put the date text within a a span. This span has a class called ‘date’ thus when the To Local link is clicked it will go through all the elements that have the class date, which now includes the new entries. There we have it, problem fixed!

This entry was posted in DPS911, Mercurial Project, Open Source and tagged , , . Bookmark the permalink.

2 Responses to v1.0 Release – Getting the Localize Dates Link Working with the New Entries Loaded On Scroll

  1. kolorowanki says:

    Thanks a lot for this information! it is very useful, Thanks man.

  2. Very helful. Bih thansk!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>