<?php
/**
* @package linea21\plugins\l21_prettyDate
* @author $Author$ - Simon Georget <simon@linea21.com>
* @version $Id$ 
* @access public
* @license http://opensource.org/licenses/gpl-3.0.html
*/
_debug(__FILE__ . ' loaded');
global $plug;

// we load javascript file
// The file include 4 locales :  grunt embedLocales --embedLocales fr,it,es,en
footerAddJS($plug->getVar('relative_url').'js/moment-2.9.0/min/moment-with-customlocales-min.js');


// We prepare the JS content
$js = 	'moment.locale("'.U_L.'");

				 $( ".published_by" ).each(function( index ) {

				 		var $el 				=  $(this).find("span.published-on");
				 		var $el2 				=  $(this).find("span.date");

						var dateZ 			= 	$el2.text();
		
						// if dateZ does not exists we exit
						if(!dateZ) return;
		
						var prettyDate 	= 	moment(dateZ, "'.strtoupper(DATE_FORMAT).'").fromNow();

						$el.replaceWith("<span class=\"pretty-published-on\">'._t('statut', 'published_on'). '</span>");
						$el2.replaceWith("<span class=\"pretty-date\">" + prettyDate + "</span>");

				 		// finally we attach the original date as title to the span
						$(this).find("span.pretty-date").attr("title", dateZ);

				});

      	';

footerAddInlineJS($js);

?>