Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a working code... jsFiddle: <a href="http://jsfiddle.net/KrTNJ/1/" rel="nofollow">http://jsfiddle.net/KrTNJ/1/</a></p> <p>Three functions are implemented:</p> <p><strong>sortEvents</strong></p> <p>Sorts the lists in order of end date and adds an id to each li element.</p> <p><strong>removeOldEvents</strong></p> <p>Removes the events which are ending until today. You can call this in a timer or something, or during startup. This ONLY works if sortEvents have been already executed.</p> <p><strong>displaySome(count)</strong></p> <p>Displays only "count" entries. This ONLY works if sortEvents have been already executed.</p> <hr> <pre><code>// Uses jQuery $(document).ready(function(){ var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var month_index = function(target) { target = target.toLocaleLowerCase(); return jQuery.inArray(true, jQuery.map(months, function(s) { return s.toLocaleLowerCase().indexOf(target) &gt; -1; })) + 1; }; function getKeys(obj) { var keys = []; for(var key in obj) { if(obj.hasOwnProperty(key)) { keys.push(key); } } return keys; } function sortEvents() { eventList = new Object(); $("#event ul li").each(function(index, value) { dates = $(this).children("p")[0]; dates = $(dates).text().split(",")[1].trim(); m = dates.split(" "); if(dates.search("-") != -1) { m.splice(1, 2); } m[1] = m[1].substring(0, m[1].length - 2); month = month_index(m[0]) id = m[2] + "-" + (month &lt; 10 ? "0" + month : month) + "-" + (m[1] &lt; 10 ? "0" + m[1] : m[1]); eventList[id] = "&lt;li id='" + id + "'&gt;" + $(this).html() + "&lt;/li&gt;"; }); eventKeys = getKeys(eventList).sort(); $("#event ul").empty(); for(i = 0; i &lt; eventKeys.length; i++) { $("#event ul").append(eventList[eventKeys[i]]); } } function removeOldEvents() { $("#event ul li").each(function(index, value) { a = $(this).attr('id').split("-"); d = new Date(a[0], (a[1] - 1), a[2]); g = new Date(); g.setHours(0,0,0,0); c = (d &gt; g) - (g &gt; d); if(c &lt; 1) { // Remove $(this).remove(); } }); displaySome(6); } function displaySome(count) { $("#event ul").find('li:gt(' + (count - 1) + ')').hide(); } sortEvents(); removeOldEvents(); displaySome(6); }); </code></pre> <p>Hope this helps...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload