Posts Tagged ‘plugin’

Content Expirator – jQuery Content Expiration Plugin

Saturday, March 27th, 2010

Content ExpiratorContent Expirator is a jQuery utility plugin that provides an easy way to give DOM elements an expiration date. If the element is found to be expired, its 'display' parameter is set to 'none'. A better approach would be to perform this function server side with a server side language, but this is a quick and easy way to implement it client side.

Download: jquery.content_expirator-0.1.0.js

 

Let's say your client has given you a flyer to put on their website for an event.

<img src="easter_flyer_2010.jpg" class="aligncenter" alt="Easter Flyer" />

After Easter is over, you're going to want to take this flyer off of their site. Instead of manually editing the site on the Monday after Easter to take it down, you can give it an expiration date so that it isn't displayed after Easter.

<img src="easter_flyer_2010.jpg" class="exp-2010-04-04 aligncenter" alt="Easter Flyer" />

The Content Expirator looks for an element containing a class name (must be the first one listed) containing the prefix 'exp'. When it comes across one, it compares the date (formatted year-month-day) with the current day to decide if the element's 'display' (style) parameter should be set to 'none'.

Calling The Function:

default:

$(document).ready(function(){
    jQuery.contentExpirator();
});
// looks for -> 'exp-year-month-day'

custom prefix:

$(document).ready(function(){
    jQuery.contentExpirator('end');
});
// looks for -> 'end-year-month-day'
<script> <html> Result:

Run