mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-02-17 00:20:32 -05:00
Cleanup of tests and docs
This commit is contained in:
parent
c2f185f7c8
commit
8a208c8a32
4 changed files with 81 additions and 77 deletions
|
@ -15,7 +15,7 @@ Now, let's attach it to your timestamps on DOM ready:
|
|||
|
||||
<pre>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('abbr[class*=timeago]').timeago();
|
||||
jQuery('abbr.timeago').timeago();
|
||||
});
|
||||
</pre>
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
<title>timeago: a jQuery plugin</title>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
|
||||
<script src="jquery.timeago.js" type="text/javascript"></script>
|
||||
<script src="test.js" type="text/javascript"></script>
|
||||
<script src="test/test_helpers.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
$('abbr[class*=timeago]').timeago();
|
||||
$('abbr.timeago').timeago();
|
||||
|
||||
$("#prog_date").text(jQuery.timeago(new Date()));
|
||||
$("#prog_string").text(jQuery.timeago("2008-07-17"));
|
||||
|
@ -84,7 +84,7 @@
|
|||
</p>
|
||||
<pre>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('abbr[class*=timeago]').timeago();
|
||||
jQuery('abbr.timeago').timeago();
|
||||
});</pre>
|
||||
<p class="how">
|
||||
This will turn all <tt>abbr</tt> elements with a class
|
||||
|
|
|
@ -166,82 +166,10 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<script src="test_helpers.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
(function ($) {
|
||||
function zeropad(num) {
|
||||
return ((num < 10) ? '0' : '') + num;
|
||||
}
|
||||
|
||||
function iso8601(date) {
|
||||
return date.getUTCFullYear()
|
||||
+ '-' + zeropad(date.getUTCMonth() + 1)
|
||||
+ '-' + zeropad(date.getUTCDate())
|
||||
+ 'T' + zeropad(date.getUTCHours())
|
||||
+ ':' + zeropad(date.getUTCMinutes())
|
||||
+ ':' + zeropad(date.getUTCSeconds()) + 'Z';
|
||||
}
|
||||
|
||||
function loadPigLatin() {
|
||||
$.timeago.settings.strings = {
|
||||
suffixAgo : 'ago-hay',
|
||||
suffixFromNow: 'omNow-fray',
|
||||
seconds : 'ess-lay an-thay a-hay inute-may',
|
||||
minute : 'about-hay a-hay inute-may',
|
||||
minutes : '%d inutes-may',
|
||||
hour : 'about-hay an-hay hour-hay',
|
||||
hours : 'about-hay %d hours-hay',
|
||||
day : 'a-hay ay-day',
|
||||
days : '%d ays-day',
|
||||
month : 'about-hay a-hay onth-may',
|
||||
months : '%d onths-may',
|
||||
year : 'about-hay a-hay ear-yay',
|
||||
years : '%d years-yay'
|
||||
};
|
||||
}
|
||||
|
||||
function loadRussian() {
|
||||
(function() {
|
||||
function numpf(n, f, s, t) {
|
||||
// f - 1, 21, 31, ...
|
||||
// s - 2-4, 22-24, 32-34 ...
|
||||
// t - 5-20, 25-30, ...
|
||||
var n10 = n % 10;
|
||||
if ((n10 == 1) && ((n == 1) || (n > 20) )) {
|
||||
return f;
|
||||
} else if ((n10 > 1) && (n10 < 5) && ((n > 20) || (n < 10))) {
|
||||
return s;
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
$.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: 'через',
|
||||
suffixAgo: 'назад',
|
||||
suffixFromNow: null,
|
||||
seconds: 'меньше минуты',
|
||||
minute: 'минуту',
|
||||
minutes: function(value) { return numpf(value, '%d минута', '%d минуты', '%d минут'); },
|
||||
hour: 'час',
|
||||
hours: function(value) { return numpf(value, '%d час', '%d часа', '%d часов'); },
|
||||
day: 'день',
|
||||
days: function(value) { return numpf(value, '%d день', '%d дня', '%d дней'); },
|
||||
month: 'месяц',
|
||||
months: function(value) { return numpf(value, '%d месяц', '%d месяца', '%d месяцев'); },
|
||||
year: 'год',
|
||||
years: function(value) { return numpf(value, '%d год', '%d года', '%d лет'); }
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
function loadYoungOldYears() {
|
||||
$.extend($.timeago.settings.strings, {
|
||||
years: function(value) { return (value < 21) ? '%d young years' : '%d old years'; }
|
||||
});
|
||||
}
|
||||
|
||||
function testElements(selector, test) {
|
||||
var elements = $(selector);
|
||||
var numberOfTests = elements.length;
|
||||
|
|
76
test/test_helpers.js
Normal file
76
test/test_helpers.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
var zeropad = function (num) {
|
||||
return ((num < 10) ? '0' : '') + num;
|
||||
};
|
||||
var iso8601 = function (date) {
|
||||
return date.getUTCFullYear()
|
||||
+ "-" + zeropad(date.getUTCMonth()+1)
|
||||
+ "-" + zeropad(date.getUTCDate())
|
||||
+ "T" + zeropad(date.getUTCHours())
|
||||
+ ":" + zeropad(date.getUTCMinutes())
|
||||
+ ":" + zeropad(date.getUTCSeconds()) + "Z";
|
||||
};
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
$('abbr.loaded').attr("title", iso8601(new Date()));
|
||||
$('abbr.modified').attr("title", iso8601(new Date(document.lastModified)));
|
||||
});
|
||||
|
||||
function loadPigLatin() {
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: "ago-hay",
|
||||
suffixFromNow: "omNow-fray",
|
||||
seconds: "ess-lay an-thay a-hay inute-may",
|
||||
minute: "about-hay a-hay inute-may",
|
||||
minutes: "%d inutes-may",
|
||||
hour: "about-hay an-hay hour-hay",
|
||||
hours: "about-hay %d hours-hay",
|
||||
day: "a-hay ay-day",
|
||||
days: "%d ays-day",
|
||||
month: "about-hay a-hay onth-may",
|
||||
months: "%d onths-may",
|
||||
year: "about-hay a-hay ear-yay",
|
||||
years: "%d years-yay"
|
||||
};
|
||||
}
|
||||
|
||||
function loadRussian() {
|
||||
(function() {
|
||||
function numpf(n, f, s, t) {
|
||||
// f - 1, 21, 31, ...
|
||||
// s - 2-4, 22-24, 32-34 ...
|
||||
// t - 5-20, 25-30, ...
|
||||
var n10 = n % 10;
|
||||
if ( (n10 == 1) && ( (n == 1) || (n > 20) ) ) {
|
||||
return f;
|
||||
} else if ( (n10 > 1) && (n10 < 5) && ( (n > 20) || (n < 10) ) ) {
|
||||
return s;
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: "через",
|
||||
suffixAgo: "назад",
|
||||
suffixFromNow: null,
|
||||
seconds: "меньше минуты",
|
||||
minute: "минуту",
|
||||
minutes: function(value) { return numpf(value, "%d минута", "%d минуты", "%d минут"); },
|
||||
hour: "час",
|
||||
hours: function(value) { return numpf(value, "%d час", "%d часа", "%d часов"); },
|
||||
day: "день",
|
||||
days: function(value) { return numpf(value, "%d день", "%d дня", "%d дней"); },
|
||||
month: "месяц",
|
||||
months: function(value) { return numpf(value, "%d месяц", "%d месяца", "%d месяцев"); },
|
||||
year: "год",
|
||||
years: function(value) { return numpf(value, "%d год", "%d года", "%d лет"); }
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
function loadYoungOldYears() {
|
||||
jQuery.extend(jQuery.timeago.settings.strings, {
|
||||
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue