mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-04-03 08:09:42 -04:00
Compare commits
77 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b5a364d3a2 | ||
|
05a85b77f9 | ||
|
0d2a2145b2 | ||
|
0399e804db | ||
|
98d000543c | ||
|
c8b5b9365c | ||
|
14ff438930 | ||
|
2409c9f88d | ||
|
74736c8d07 | ||
|
4af2cf7135 | ||
|
f7c9c359cd | ||
|
bf9d361e4e | ||
|
66d0ef5277 | ||
|
dd17e5598f | ||
|
6822da82d9 | ||
|
cb1b0fe977 | ||
|
9b32f8cba6 | ||
|
2245c795d0 | ||
|
ec51ad8132 | ||
|
570327cf15 | ||
|
3a73f0fab1 | ||
|
5d7684fbf8 | ||
|
dc570fed47 | ||
|
9fac817b07 | ||
|
b374bd6dfb | ||
|
81f072ebb2 | ||
|
dceed3b1d9 | ||
|
fc90536dac | ||
|
61baa07698 | ||
|
4138f62c2b | ||
|
c72634b73d | ||
|
cca5898e18 | ||
|
2780816e44 | ||
|
300555d699 | ||
|
ed44a62689 | ||
|
500b808f7b | ||
|
c4a132d6b2 | ||
|
d0e161a164 | ||
|
9d6c2c6b64 | ||
|
873f0f7c10 | ||
|
8946a5eb49 | ||
|
f6c1dd4d0f | ||
|
61e23e15a7 | ||
|
96d4406fcc | ||
|
ef0ffa0df0 | ||
|
54a466d81b | ||
|
9128386996 | ||
|
ad8e3d0e64 | ||
|
694074d374 | ||
|
e3c239d5a4 | ||
|
36f4640018 | ||
|
5b7b9f7c85 | ||
|
eb71dbca5b | ||
|
a6bf461d1f | ||
|
2f2260cee8 | ||
|
c7251759fd | ||
|
d5ab36adcb | ||
|
9dc7ae6c8e | ||
|
53a64c0322 | ||
|
f512100060 | ||
|
5a989f4b2b | ||
|
38de8b99a9 | ||
|
a018eaa5f0 | ||
|
ea347d24c6 | ||
|
61980c6e22 | ||
|
1a763d5e46 | ||
|
3b895714a6 | ||
|
49aeb6bf07 | ||
|
60369ec505 | ||
|
ea26675d40 | ||
|
f799625f8d | ||
|
658893df50 | ||
|
f41cfd0c6c | ||
|
9dab7dbc5a | ||
|
30d5b47d5b | ||
|
eee58806aa | ||
|
d52af89018 |
25 changed files with 570 additions and 119 deletions
CONTRIBUTING.mdREADME.markdownbower.json
contrib
index.htmljquery.timeago.jslocales
jquery.timeago.cs.jsjquery.timeago.cz.jsjquery.timeago.es-short.jsjquery.timeago.et.jsjquery.timeago.gl.jsjquery.timeago.he.jsjquery.timeago.id.jsjquery.timeago.is.jsjquery.timeago.jv.jsjquery.timeago.pt-br.jsjquery.timeago.ro.jsjquery.timeago.rs.jsjquery.timeago.tr.jsjquery.timeago.vi.jsjquery.timeago.zh-CN.jsjquery.timeago.zh-TW.js
test
timeago.jquery.json
37
CONTRIBUTING.md
Normal file
37
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
## Want to Contribute?
|
||||
|
||||
Found an issue? Thank you for helping out by reporting it. Please describe the
|
||||
problem, what you tried, what you expected to see, and what you actually
|
||||
experienced. Please [re-read the documentation](http://timeago.yarp.com/) to
|
||||
make sure you're using the API as designed, but if you found something that's
|
||||
broken, we really appreciate your efforts in letting us know. Bonus points for
|
||||
submitting a failing test case to help us diagnose and potentially fix the
|
||||
issue.
|
||||
|
||||
## Want to Contribute?
|
||||
|
||||
Awesome. We love help, but before getting started, please read:
|
||||
|
||||
**[Don't "Push" Your Pull Requests](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)**
|
||||
|
||||
## Ready for a Pull-Request?
|
||||
|
||||
1. Fork the repo.
|
||||
|
||||
2. Run the tests. Run `rake` or open `open test/index.html`. We only take pull
|
||||
requests with passing tests, and it's great to know that you started from a
|
||||
clean slate.
|
||||
|
||||
3. Add a test for your change. Only refactoring and documentation change
|
||||
require no new tests. If you are adding functionality or fixing a bug, we
|
||||
need a test!
|
||||
|
||||
4. Make the test pass.
|
||||
|
||||
5. Push to your fork (hopefully this comes from a topical branch) and submit a
|
||||
pull request.
|
||||
|
||||
At this point you're waiting on us. Please keep in mind that OSS maintainers
|
||||
are often very busy. We'll do our best to at least comment on issues and
|
||||
pull-requests as soon as possible, but sometimes life gets in the way. We may
|
||||
also suggest some changes or improvements or alternatives.
|
|
@ -4,10 +4,26 @@ Timeago is a jQuery plugin that makes it easy to support automatically updating
|
|||
fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601
|
||||
formatted dates and times embedded in your HTML (à la microformats).
|
||||
|
||||
**If you like this project, please help by donating.**
|
||||
## How You Can Help
|
||||
|
||||
* Gittip: https://www.gittip.com/rmm5t/
|
||||
* Bitcoin: `1wzBnMjWVZfpiFMc5i2nzKT7sCBaZNfLK`
|
||||
**If you like this project, please help. [Donate via Gittip][gittip] or [buy me a coffee with Bitcoin][bitcoin].**<br>
|
||||
[][gittip]
|
||||
[][bitcoin]
|
||||
|
||||
**[Bitcoin][bitcoin]**: `1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m`<br>
|
||||
[![Bitcoin Donation][bitcoin-qr-small]][bitcoin-qr-big]
|
||||
|
||||
## Need Help?
|
||||
|
||||
**You can [book a session with me on Codementor][codementor].**<br>
|
||||
[][codementor]
|
||||
|
||||
[gittip]: https://www.gittip.com/rmm5t/ "Donate to rmm5t for open source!"
|
||||
[bitcoin]: https://blockchain.info/address/1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m "Buy rmm5t a coffee for open source!"
|
||||
[bitcoin-scheme]: bitcoin:1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m?amount=0.01&label=Coffee%20to%20rmm5t%20for%20Open%20Source "Buy rmm5t a coffee for open source!"
|
||||
[bitcoin-qr-small]: http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
|
||||
[bitcoin-qr-big]: http://chart.apis.google.com/chart?cht=qr&chs=500x500&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
|
||||
[codementor]: https://www.codementor.io/rmm5t?utm_campaign=profile&utm_source=button-rmm5t&utm_medium=shields "Book a session with rmm5t on Codementor!"
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -57,18 +73,22 @@ As time passes, the timestamps will automatically update.
|
|||
|
||||
## Changes
|
||||
|
||||
| Version | Notes |
|
||||
|---------|------------------------------------------------------------------|
|
||||
| 1.2.x | ([compare][compare-1.2]) Added cutoff setting |
|
||||
| 1.1.x | ([compare][compare-1.1]) Added update function |
|
||||
| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper |
|
||||
| 0.11.x | ([compare][compare-0.11]) natural rounding; locale updates; |
|
||||
| 0.10.x | ([compare][compare-0.10]) locale updates |
|
||||
| 0.9.x | ([compare][compare-0.9]) microsecond support; bug fixes |
|
||||
| 0.8.x | ([compare][compare-0.8]) `<time>` element support; bug fixes |
|
||||
| 0.7.x | ([compare][compare-0.7]) locale function overrides; unit tests |
|
||||
| ... | ... |
|
||||
| Version | Notes |
|
||||
|---------|---------------------------------------------------------------------------------|
|
||||
| 1.4.x | ([compare][compare-1.4]) Added allowPast setting |
|
||||
| 1.3.x | ([compare][compare-1.3]) Added updateFromDOM function; bug fixes; bower support |
|
||||
| 1.2.x | ([compare][compare-1.2]) Added cutoff setting |
|
||||
| 1.1.x | ([compare][compare-1.1]) Added update function |
|
||||
| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper |
|
||||
| 0.11.x | ([compare][compare-0.11]) natural rounding; locale updates; |
|
||||
| 0.10.x | ([compare][compare-0.10]) locale updates |
|
||||
| 0.9.x | ([compare][compare-0.9]) microsecond support; bug fixes |
|
||||
| 0.8.x | ([compare][compare-0.8]) `<time>` element support; bug fixes |
|
||||
| 0.7.x | ([compare][compare-0.7]) locale function overrides; unit tests |
|
||||
| ... | ... |
|
||||
|
||||
[compare-1.4]: https://github.com/rmm5t/jquery-timeago/compare/v1.3.2...v1.4.1
|
||||
[compare-1.3]: https://github.com/rmm5t/jquery-timeago/compare/v1.2.0...v1.3.2
|
||||
[compare-1.2]: https://github.com/rmm5t/jquery-timeago/compare/v1.1.0...v1.2.0
|
||||
[compare-1.1]: https://github.com/rmm5t/jquery-timeago/compare/v1.0.2...v1.1.0
|
||||
[compare-1.0]: https://github.com/rmm5t/jquery-timeago/compare/v0.11.4...v1.0.2
|
||||
|
|
13
bower.json
Normal file
13
bower.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "jquery-timeago",
|
||||
"version": "1.4.1",
|
||||
"license": "MIT",
|
||||
"main": "jquery.timeago.js",
|
||||
"ignore": [
|
||||
"test",
|
||||
"vendor"
|
||||
],
|
||||
"dependencies": {
|
||||
"jquery": ">=1.4"
|
||||
}
|
||||
}
|
14
contrib/timeago-koext.js
Normal file
14
contrib/timeago-koext.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
ko.bindingHandlers.timeago = {
|
||||
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
||||
var value = valueAccessor();
|
||||
var valueUnwrapped = ko.unwrap(value);
|
||||
element.title = moment(valueUnwrapped).toISOString();
|
||||
$(element).timeago();
|
||||
},
|
||||
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
||||
var value = valueAccessor();
|
||||
var valueUnwrapped = ko.unwrap(value);
|
||||
element.title = moment(valueUnwrapped).toISOString();
|
||||
$(element).timeago('update', element.title);
|
||||
}
|
||||
}
|
|
@ -116,6 +116,15 @@ jQuery.timeago(jQuery("abbr#some_id")); //=> "<span id="prog_element"></spa
|
|||
<pre>
|
||||
jQuery.timeago.settings.allowFuture = true;</pre>
|
||||
|
||||
<p class="how">
|
||||
To disable timestamps in the past, use the <tt>allowPast</tt> setting.
|
||||
This setting is set to true by default. When set to false, if the time is in the past then instead of displaying a message like "5 minutes ago" a static message will be displayed.
|
||||
The staic message displayed can be configured with the <tt>strings.inPast</tt> setting:
|
||||
</p>
|
||||
<pre>
|
||||
jQuery.timeago.settings.strings.inPast = "time has elapsed";
|
||||
jQuery.timeago.settings.allowPast = false;</pre>
|
||||
|
||||
<h3>Excusez-moi?</h3>
|
||||
<p>
|
||||
Yes, timeago has locale/i18n/language support. Here are some <a href="https://github.com/rmm5t/jquery-timeago/tree/master/locales">configuration examples</a>. Please submit a <a href="https://github.com/rmm5t/jquery-timeago">GitHub pull request</a> for corrections or additional languages.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
||||
*
|
||||
* @name timeago
|
||||
* @version 1.2.0
|
||||
* @version 1.4.1
|
||||
* @requires jQuery v1.2.3+
|
||||
* @author Ryan McGeary
|
||||
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||
|
@ -39,6 +39,7 @@
|
|||
$.extend($.timeago, {
|
||||
settings: {
|
||||
refreshMillis: 60000,
|
||||
allowPast: true,
|
||||
allowFuture: false,
|
||||
localeTitle: false,
|
||||
cutoff: 0,
|
||||
|
@ -47,6 +48,7 @@
|
|||
prefixFromNow: null,
|
||||
suffixAgo: "ago",
|
||||
suffixFromNow: "from now",
|
||||
inPast: 'any moment now',
|
||||
seconds: "less than a minute",
|
||||
minute: "about a minute",
|
||||
minutes: "%d minutes",
|
||||
|
@ -62,7 +64,12 @@
|
|||
numbers: []
|
||||
}
|
||||
},
|
||||
|
||||
inWords: function(distanceMillis) {
|
||||
if(!this.settings.allowPast && ! this.settings.allowFuture) {
|
||||
throw 'timeago allowPast and allowFuture settings can not both be set to false.';
|
||||
}
|
||||
|
||||
var $l = this.settings.strings;
|
||||
var prefix = $l.prefixAgo;
|
||||
var suffix = $l.suffixAgo;
|
||||
|
@ -73,6 +80,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
if(!this.settings.allowPast && distanceMillis >= 0) {
|
||||
return this.settings.strings.inPast;
|
||||
}
|
||||
|
||||
var seconds = Math.abs(distanceMillis) / 1000;
|
||||
var minutes = seconds / 60;
|
||||
var hours = minutes / 60;
|
||||
|
@ -101,12 +112,14 @@
|
|||
if ($l.wordSeparator === undefined) { separator = " "; }
|
||||
return $.trim([prefix, words, suffix].join(separator));
|
||||
},
|
||||
|
||||
parse: function(iso8601) {
|
||||
var s = $.trim(iso8601);
|
||||
s = s.replace(/\.\d+/,""); // remove milliseconds
|
||||
s = s.replace(/-/,"/").replace(/-/,"/");
|
||||
s = s.replace(/T/," ").replace(/Z/," UTC");
|
||||
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
||||
s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
|
||||
return new Date(s);
|
||||
},
|
||||
datetime: function(elem) {
|
||||
|
@ -128,12 +141,24 @@
|
|||
refresh_el();
|
||||
var $s = $t.settings;
|
||||
if ($s.refreshMillis > 0) {
|
||||
setInterval(refresh_el, $s.refreshMillis);
|
||||
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
|
||||
}
|
||||
},
|
||||
update: function(time){
|
||||
$(this).data('timeago', { datetime: $t.parse(time) });
|
||||
var parsedTime = $t.parse(time);
|
||||
$(this).data('timeago', { datetime: parsedTime });
|
||||
if($t.settings.localeTitle) $(this).attr("title", parsedTime.toLocaleString());
|
||||
refresh.apply(this);
|
||||
},
|
||||
updateFromDOM: function(){
|
||||
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
|
||||
refresh.apply(this);
|
||||
},
|
||||
dispose: function () {
|
||||
if (this._timeagoInterval) {
|
||||
window.clearInterval(this._timeagoInterval);
|
||||
this._timeagoInterval = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -150,11 +175,18 @@
|
|||
};
|
||||
|
||||
function refresh() {
|
||||
//check if it's still visible
|
||||
if(!$.contains(document.documentElement,this)){
|
||||
//stop if it has been removed
|
||||
$(this).timeago("dispose");
|
||||
return this;
|
||||
}
|
||||
|
||||
var data = prepareData(this);
|
||||
var $s = $t.settings;
|
||||
|
||||
if (!isNaN(data.datetime)) {
|
||||
if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) {
|
||||
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
||||
$(this).text(inWords(data.datetime));
|
||||
}
|
||||
}
|
||||
|
|
24
locales/jquery.timeago.cs.js
Normal file
24
locales/jquery.timeago.cs.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Czech
|
||||
(function() {
|
||||
function f(n, d, a) {
|
||||
return a[d>=0 ? 0 : a.length==2 || n<5 ? 1 : 2];
|
||||
}
|
||||
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: 'před',
|
||||
prefixFromNow: 'za',
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
seconds: function(n, d) {return f(n, d, ['méně než minutou', 'méně než minutu'])},
|
||||
minute: function(n, d) {return f(n, d, ['minutou', 'minutu'])},
|
||||
minutes: function(n, d) {return f(n, d, ['%d minutami', '%d minuty', '%d minut'])},
|
||||
hour: function(n, d) {return f(n, d, ['hodinou', 'hodinu'])},
|
||||
hours: function(n, d) {return f(n, d, ['%d hodinami', '%d hodiny', '%d hodin'])},
|
||||
day: function(n, d) {return f(n, d, ['%d dnem', '%d den'])},
|
||||
days: function(n, d) {return f(n, d, ['%d dny', '%d dny', '%d dní'])},
|
||||
month: function(n, d) {return f(n, d, ['%d měsícem', '%d měsíc'])},
|
||||
months: function(n, d) {return f(n, d, ['%d měsící', '%d měsíce', '%d měsíců'])},
|
||||
year: function(n, d) {return f(n, d, ['%d rokem', '%d rok'])},
|
||||
years: function(n, d) {return f(n, d, ['%d lety', '%d roky', '%d let'])}
|
||||
};
|
||||
})();
|
|
@ -1,18 +0,0 @@
|
|||
// Czech
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "před",
|
||||
prefixFromNow: null,
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
seconds: "méně než minutou",
|
||||
minute: "minutou",
|
||||
minutes: "%d minutami",
|
||||
hour: "hodinou",
|
||||
hours: "%d hodinami",
|
||||
day: "1 dnem",
|
||||
days: "%d dny",
|
||||
month: "1 měsícem",
|
||||
months: "%d měsíci",
|
||||
year: "1 rokem",
|
||||
years: "%d roky"
|
||||
};
|
20
locales/jquery.timeago.es-short.js
Normal file
20
locales/jquery.timeago.es-short.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Spanish shortened
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "",
|
||||
suffixFromNow: "",
|
||||
seconds: "1m",
|
||||
minute: "1m",
|
||||
minutes: "%dm",
|
||||
hour: "1h",
|
||||
hours: "%dh",
|
||||
day: "1d",
|
||||
days: "%dd",
|
||||
month: "1me",
|
||||
months: "%dme",
|
||||
year: "1a",
|
||||
years: "%da",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
};
|
18
locales/jquery.timeago.et.js
Normal file
18
locales/jquery.timeago.et.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Estonian
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "tagasi",
|
||||
suffixFromNow: "pärast",
|
||||
seconds: function(n, d) { return d < 0 ? "vähem kui minuti aja" : "vähem kui minut aega" },
|
||||
minute: function(n, d) { return d < 0 ? "umbes minuti aja" : "umbes minut aega" },
|
||||
minutes: function(n, d) { return d < 0 ? "%d minuti" : "%d minutit" },
|
||||
hour: function(n, d) { return d < 0 ? "umbes tunni aja" : "umbes tund aega" },
|
||||
hours: function(n, d) { return d < 0 ? "%d tunni" : "%d tundi" },
|
||||
day: function(n, d) { return d < 0 ? "umbes päeva" : "umbes päev" },
|
||||
days: function(n, d) { return d < 0 ? "%d päeva" : "%d päeva" },
|
||||
month: function(n, d) { return d < 0 ? "umbes kuu aja" : "umbes kuu aega" },
|
||||
months: function(n, d) { return d < 0 ? "%d kuu" : "%d kuud" },
|
||||
year: function(n, d) { return d < 0 ? "umbes aasta aja" : "umbes aasta aega" },
|
||||
years: function(n, d) { return d < 0 ? "%d aasta" : "%d aastat" }
|
||||
};
|
18
locales/jquery.timeago.gl.js
Normal file
18
locales/jquery.timeago.gl.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Galician
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "hai",
|
||||
prefixFromNow: "dentro de",
|
||||
suffixAgo: "",
|
||||
suffixFromNow: "",
|
||||
seconds: "menos dun minuto",
|
||||
minute: "un minuto",
|
||||
minutes: "uns %d minutos",
|
||||
hour: "unha hora",
|
||||
hours: "%d horas",
|
||||
day: "un día",
|
||||
days: "%d días",
|
||||
month: "un mes",
|
||||
months: "%d meses",
|
||||
year: "un ano",
|
||||
years: "%d anos"
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
// Hebrew
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "לפני",
|
||||
prefixFromNow: "מעכשיו",
|
||||
prefixFromNow: "עוד",
|
||||
suffixAgo: "",
|
||||
suffixFromNow: "",
|
||||
seconds: "פחות מדקה",
|
||||
|
@ -15,4 +15,4 @@ jQuery.timeago.settings.strings = {
|
|||
months: "%d חודשים",
|
||||
year: "שנה",
|
||||
years: "%d שנים"
|
||||
};
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ jQuery.timeago.settings.strings = {
|
|||
day: "sehari",
|
||||
days: "%d hari",
|
||||
month: "sekitar sebulan",
|
||||
months: "%d tahun",
|
||||
months: "%d bulan",
|
||||
year: "sekitar setahun",
|
||||
years: "%d tahun"
|
||||
};
|
||||
};
|
||||
|
|
19
locales/jquery.timeago.is.js
Normal file
19
locales/jquery.timeago.is.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "fyrir",
|
||||
prefixFromNow: "eftir",
|
||||
suffixAgo: "síðan",
|
||||
suffixFromNow: null,
|
||||
seconds: "minna en mínútu",
|
||||
minute: "mínútu",
|
||||
minutes: "%d mínútum",
|
||||
hour: "klukkutíma",
|
||||
hours: "um %d klukkutímum",
|
||||
day: "degi",
|
||||
days: "%d dögum",
|
||||
month: "mánuði",
|
||||
months: "%d mánuðum",
|
||||
year: "ári",
|
||||
years: "%d árum",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
};
|
18
locales/jquery.timeago.jv.js
Normal file
18
locales/jquery.timeago.jv.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Javanesse (Boso Jowo)
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
suffixAgo: "kepungkur",
|
||||
suffixFromNow: "seko saiki",
|
||||
seconds: "kurang seko sakmenit",
|
||||
minute: "kurang luwih sakmenit",
|
||||
minutes: "%d menit",
|
||||
hour: "kurang luwih sakjam",
|
||||
hours: "kurang luwih %d jam",
|
||||
day: "sedina",
|
||||
days: "%d dina",
|
||||
month: "kurang luwih sewulan",
|
||||
months: "%d wulan",
|
||||
year: "kurang luwih setahun",
|
||||
years: "%d tahun"
|
||||
};
|
|
@ -1,16 +1,18 @@
|
|||
// Brazilian Portuguese
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: "atrás",
|
||||
suffixFromNow: "nesse momento",
|
||||
prefixAgo: "há",
|
||||
prefixFromNow: "em",
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
seconds: "alguns segundos",
|
||||
minute: "há um minuto",
|
||||
minutes: "há %d minutos",
|
||||
hour: "há uma hora",
|
||||
hours: "há %d horas",
|
||||
day: "há um dia",
|
||||
days: "há %d dias",
|
||||
month: "há um mês",
|
||||
months: "há %d meses",
|
||||
year: "há um ano",
|
||||
years: "há %d anos"
|
||||
minute: "um minuto",
|
||||
minutes: "%d minutos",
|
||||
hour: "uma hora",
|
||||
hours: "%d horas",
|
||||
day: "um dia",
|
||||
days: "%d dias",
|
||||
month: "um mês",
|
||||
months: "%d meses",
|
||||
year: "um ano",
|
||||
years: "%d anos"
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Romanian
|
||||
$.timeago.settings.strings = {
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: "acum",
|
||||
prefixFromNow: "in timp de",
|
||||
suffixAgo: "",
|
||||
|
@ -15,4 +15,4 @@ $.timeago.settings.strings = {
|
|||
months: "%d luni",
|
||||
year: "un an",
|
||||
years: "%d ani"
|
||||
};
|
||||
};
|
||||
|
|
49
locales/jquery.timeago.rs.js
Normal file
49
locales/jquery.timeago.rs.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Serbian
|
||||
(function () {
|
||||
var numpf;
|
||||
|
||||
numpf = function (n, f, s, t) {
|
||||
var n10;
|
||||
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: "pre",
|
||||
prefixFromNow: "za",
|
||||
suffixAgo: null,
|
||||
suffixFromNow: null,
|
||||
second: "sekund",
|
||||
seconds: function (value) {
|
||||
return numpf(value, "%d sekund", "%d sekunde", "%d sekundi");
|
||||
},
|
||||
minute: "oko minut",
|
||||
minutes: function (value) {
|
||||
return numpf(value, "%d minut", "%d minuta", "%d minuta");
|
||||
},
|
||||
hour: "oko jedan sat",
|
||||
hours: function (value) {
|
||||
return numpf(value, "%d sat", "%d sata", "%d sati");
|
||||
},
|
||||
day: "jedan dan",
|
||||
days: function (value) {
|
||||
return numpf(value, "%d dan", "%d dana", "%d dana");
|
||||
},
|
||||
month: "mesec dana",
|
||||
months: function (value) {
|
||||
return numpf(value, "%d mesec", "%d meseca", "%d meseci");
|
||||
},
|
||||
year: "godinu dana",
|
||||
years: function (value) {
|
||||
return numpf(value, "%d godinu", "%d godine", "%d godina");
|
||||
},
|
||||
wordSeparator: " "
|
||||
};
|
||||
|
||||
}).call(this);
|
|
@ -1,5 +1,5 @@
|
|||
// Turkish
|
||||
jQuery.extend($.timeago.settings.strings, {
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: 'önce',
|
||||
suffixFromNow: null,
|
||||
seconds: '1 dakikadan',
|
||||
|
@ -13,4 +13,4 @@ jQuery.extend($.timeago.settings.strings, {
|
|||
months: '%d ay',
|
||||
year: '1 yıl',
|
||||
years: '%d yıl'
|
||||
});
|
||||
};
|
||||
|
|
20
locales/jquery.timeago.vi.js
Normal file
20
locales/jquery.timeago.vi.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Vietnamese
|
||||
jQuery.timeago.settings.strings = {
|
||||
prefixAgo: 'cách đây',
|
||||
prefixFromNow: null,
|
||||
suffixAgo: null,
|
||||
suffixFromNow: "trước",
|
||||
seconds: "chưa đến một phút",
|
||||
minute: "khoảng một phút",
|
||||
minutes: "%d phút",
|
||||
hour: "khoảng một tiếng",
|
||||
hours: "khoảng %d tiếng",
|
||||
day: "một ngày",
|
||||
days: "%d ngày",
|
||||
month: "khoảng một tháng",
|
||||
months: "%d tháng",
|
||||
year: "khoảng một năm",
|
||||
years: "%d năm",
|
||||
wordSeparator: " ",
|
||||
numbers: []
|
||||
};
|
|
@ -4,17 +4,17 @@ jQuery.timeago.settings.strings = {
|
|||
prefixFromNow: "从现在开始",
|
||||
suffixAgo: "之前",
|
||||
suffixFromNow: null,
|
||||
seconds: "不到 1 分钟",
|
||||
minute: "大约 1 分钟",
|
||||
minutes: "%d 分钟",
|
||||
hour: "大约 1 小时",
|
||||
hours: "大约 %d 小时",
|
||||
day: "1 天",
|
||||
days: "%d 天",
|
||||
month: "大约 1 个月",
|
||||
months: "%d 月",
|
||||
year: "大约 1 年",
|
||||
years: "%d 年",
|
||||
seconds: "不到1分钟",
|
||||
minute: "大约1分钟",
|
||||
minutes: "%d分钟",
|
||||
hour: "大约1小时",
|
||||
hours: "大约%d小时",
|
||||
day: "1天",
|
||||
days: "%d天",
|
||||
month: "大约1个月",
|
||||
months: "%d月",
|
||||
year: "大约1年",
|
||||
years: "%d年",
|
||||
numbers: [],
|
||||
wordSeparator: ""
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,17 +4,17 @@ jQuery.timeago.settings.strings = {
|
|||
prefixFromNow: "從現在開始",
|
||||
suffixAgo: "之前",
|
||||
suffixFromNow: null,
|
||||
seconds: "不到 1 分鐘",
|
||||
minute: "大約 1 分鐘",
|
||||
minutes: "%d 分鐘",
|
||||
hour: "大約 1 小時",
|
||||
hours: "%d 小時",
|
||||
day: "大約 1 天",
|
||||
days: "%d 天",
|
||||
month: "大約 1 個月",
|
||||
months: "%d 個月",
|
||||
year: "大約 1 年",
|
||||
years: "%d 年",
|
||||
seconds: "不到1分鐘",
|
||||
minute: "大約1分鐘",
|
||||
minutes: "%d分鐘",
|
||||
hour: "大約1小時",
|
||||
hours: "%d小時",
|
||||
day: "大約1天",
|
||||
days: "%d天",
|
||||
month: "大約1個月",
|
||||
months: "%d個月",
|
||||
year: "大約1年",
|
||||
years: "%d年",
|
||||
numbers: [],
|
||||
wordSeparator: ""
|
||||
};
|
||||
|
|
179
test/index.html
179
test/index.html
|
@ -65,9 +65,13 @@
|
|||
|
||||
<h2>Cutoff</h2>
|
||||
|
||||
<p>Date that is older than cutoff: <abbr class="timeago cutoff doCutoff" title="1978-12-18">(this should be displayed)</abbr></p>
|
||||
<p>Date that is before a past cutoff: <abbr class="timeago cutoff doCutoffPast" title="1978-12-18">(this should be displayed)</abbr></p>
|
||||
|
||||
<p>Date that is newer than cutoff: <abbr class="timeago loaded cutoff dontCutoff">(you shouldn't see this)</abbr></p>
|
||||
<p>Date that is after a past cutoff: <abbr class="timeago loaded cutoff dontCutoffPast">(you shouldn't see this)</abbr></p>
|
||||
|
||||
<p>Date that is past a future cutoff: <abbr class="timeago cutoff doCutoffFuture" title="2999-12-18">(this should be displayed)</abbr></p>
|
||||
|
||||
<p>Date that is before a future cutoff: <abbr class="timeago loaded cutoff dontCutoffFuture">(you shouldn't see this)</abbr></p>
|
||||
|
||||
<h2>Errors</h2>
|
||||
|
||||
|
@ -90,6 +94,7 @@
|
|||
<li><abbr id="testParsing9" class="todate" title="1978-12-18 17:17:00.021432Z"></abbr> [from Z with microseconds]</li>
|
||||
<li><abbr id="testParsing10" class="todate" title="1978-12-18 17:17:00.0Z"></abbr> [from Z with tenths of a second]</li>
|
||||
<li><abbr id="testParsing11" class="todate" title="1978-12-18 17:17:00.02Z"></abbr> [from Z with hundreths of a second]</li>
|
||||
<li><abbr id="testParsing12" class="todate" title="1978-12-19T02:17:00+09"></abbr> [from +09]</li>
|
||||
</ul>
|
||||
|
||||
<h2>Wording</h2>
|
||||
|
@ -188,6 +193,23 @@
|
|||
<li><abbr id="testMillisSettings8" class="tomillis" title="90"></abbr> [90 sec]</li>
|
||||
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
|
||||
</ul>
|
||||
|
||||
<h2>Do Not Allow Future</h2>
|
||||
|
||||
<ul>
|
||||
<li><abbr id="testAllowFutureFalse1" class="doNotAllowFuture" title="2012-01-01T09:24:17Z">(you shouldn't see this)</abbr></li>
|
||||
</ul>
|
||||
|
||||
<h2>Do Not Allow Past</h2>
|
||||
|
||||
<ul>
|
||||
<li><abbr id="testAllowPastFalse1" class="doNotAllowPast" title="2008-01-01T09:24:17Z">(you shouldn't see this)</abbr></li>
|
||||
<li><abbr id="testAllowPastAndFutureFalse" title="2008-01-01T09:24:17Z"></abbr></li>
|
||||
</ul>
|
||||
|
||||
<h2>Disposal</h2>
|
||||
<p><abbr class="disposal disposed"></abbr></p>
|
||||
<p><abbr class="disposal notDisposed"></abbr></p>
|
||||
</div>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||
|
@ -238,6 +260,16 @@
|
|||
$("abbr.tonumbers").each(toWords);
|
||||
unloadNumbers();
|
||||
|
||||
loadDoNotAllowFuture();
|
||||
$("abbr.doNotAllowFuture").timeago();
|
||||
unloadDoNotAllowFuture();
|
||||
|
||||
loadDoNotAllowPast();
|
||||
$("abbr.doNotAllowPast").timeago();
|
||||
unloadDoNotAllowPast();
|
||||
|
||||
setupDisposal();
|
||||
|
||||
loadYoungOldYears();
|
||||
$("abbr.toyoungold").each(toWords);
|
||||
|
||||
|
@ -304,13 +336,25 @@
|
|||
module("Cutoff");
|
||||
|
||||
test("should not change dates older than cutoff setting", function () {
|
||||
ok(testElements("abbr.doCutoff", function (element) {
|
||||
ok(testElements("abbr.doCutoffPast", function (element) {
|
||||
return (element.html() === "(this should be displayed)");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should change dates newer than cutoff setting", function () {
|
||||
ok(testElements("abbr.dontCutoff", function (element) {
|
||||
ok(testElements("abbr.dontCutoffPast", function (element) {
|
||||
return (element.html() === "less than a minute ago");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should not change dates older than cutoff setting", function () {
|
||||
ok(testElements("abbr.doCutoffFuture", function (element) {
|
||||
return (element.html() === "(this should be displayed)");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
||||
test("should change dates newer than cutoff setting", function () {
|
||||
ok(testElements("abbr.dontCutoffFuture", function (element) {
|
||||
return (element.html() === "less than a minute ago");
|
||||
}), "Cutoff setting working fine");
|
||||
});
|
||||
|
@ -340,154 +384,159 @@
|
|||
|
||||
test("From Z", function () {
|
||||
var time = $("#testParsing1");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From -00:00", function () {
|
||||
var time = $("#testParsing2");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From -05:00", function () {
|
||||
var time = $("#testParsing3");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From -0500", function () {
|
||||
var time = $("#testParsing4");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From +09:00", function () {
|
||||
var time = $("#testParsing5");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From +0900", function () {
|
||||
var time = $("#testParsing6");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From blank TZ", function () {
|
||||
var time = $("#testParsing7");
|
||||
var correctMatch = /Mon, 18 Dec 1978 \d\d:17:00 (GMT|UTC)/;
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From Z with milliseconds", function () {
|
||||
var time = $("#testParsing8");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From Z with microseconds", function () {
|
||||
var time = $("#testParsing9");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From Z with tenths of a second", function () {
|
||||
var time = $("#testParsing10");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From Z with hundreths of a second", function () {
|
||||
var time = $("#testParsing11");
|
||||
ok((time.html().match(correctMatch)), "Correctly parsed " + time.attr("title"));
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
test("From +09", function () {
|
||||
var time = $("#testParsing12");
|
||||
ok((time.html().match(correctMatch)), "Incorrectly parsed " + time.attr("title"));
|
||||
});
|
||||
|
||||
module("Wording");
|
||||
|
||||
test("-120 min", function () {
|
||||
ok(($("#testWording1").html() === "about 2 hours from now"), "Correctly parsed");
|
||||
ok(($("#testWording1").html() === "about 2 hours from now"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("-60 sec", function () {
|
||||
ok(($("#testWording2").html() === "about a minute from now"), "Correctly parsed");
|
||||
ok(($("#testWording2").html() === "about a minute from now"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("-30 sec", function () {
|
||||
ok(($("#testWording3").html() === "less than a minute from now"), "Correctly parsed");
|
||||
ok(($("#testWording3").html() === "less than a minute from now"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("-1 sec", function () {
|
||||
ok(($("#testWording4").html() === "less than a minute from now"), "Correctly parsed");
|
||||
ok(($("#testWording4").html() === "less than a minute from now"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("0 sec", function () {
|
||||
ok(($("#testWording5").html() === "less than a minute ago"), "Correctly parsed");
|
||||
ok(($("#testWording5").html() === "less than a minute ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("30 sec", function () {
|
||||
ok(($("#testWording6").html() === "less than a minute ago"), "Correctly parsed");
|
||||
ok(($("#testWording6").html() === "less than a minute ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("45 sec", function () {
|
||||
ok(($("#testWording7").html() === "about a minute ago"), "Correctly parsed");
|
||||
ok(($("#testWording7").html() === "about a minute ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("90 sec", function () {
|
||||
ok(($("#testWording8").html() === "2 minutes ago"), "Correctly parsed");
|
||||
ok(($("#testWording8").html() === "2 minutes ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("120 sec", function () {
|
||||
ok(($("#testWording9").html() === "2 minutes ago"), "Correctly parsed");
|
||||
ok(($("#testWording9").html() === "2 minutes ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("45 min", function () {
|
||||
ok(($("#testWording10").html() === "about an hour ago"), "Correctly parsed");
|
||||
ok(($("#testWording10").html() === "about an hour ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("89 min", function () {
|
||||
ok(($("#testWording11").html() === "about an hour ago"), "Correctly parsed");
|
||||
ok(($("#testWording11").html() === "about an hour ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("90 min", function () {
|
||||
ok(($("#testWording12").html() === "about 2 hours ago"), "Correctly parsed");
|
||||
ok(($("#testWording12").html() === "about 2 hours ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("120 min", function () {
|
||||
ok(($("#testWording13").html() === "about 2 hours ago"), "Correctly parsed");
|
||||
ok(($("#testWording13").html() === "about 2 hours ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("1380 min", function () {
|
||||
ok(($("#testWording14").html() === "about 23 hours ago"), "Correctly parsed");
|
||||
ok(($("#testWording14").html() === "about 23 hours ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("25 hours", function () {
|
||||
ok(($("#testWording15").html() === "a day ago"), "Correctly parsed");
|
||||
ok(($("#testWording15").html() === "a day ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("41 hour", function () {
|
||||
ok(($("#testWording16a").html() === "a day ago"), "Correctly parsed");
|
||||
ok(($("#testWording16a").html() === "a day ago"), "Incorrectly parsed");
|
||||
});
|
||||
test("42 hours", function () {
|
||||
ok(($("#testWording16b").html() === "2 days ago"), "Correctly parsed");
|
||||
ok(($("#testWording16b").html() === "2 days ago"), "Incorrectly parsed");
|
||||
});
|
||||
test("48 hours", function () {
|
||||
ok(($("#testWording16c").html() === "2 days ago"), "Correctly parsed");
|
||||
ok(($("#testWording16c").html() === "2 days ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("696 hours", function () {
|
||||
ok(($("#testWording17").html() === "29 days ago"), "Correctly parsed");
|
||||
ok(($("#testWording17").html() === "29 days ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("30 days", function () {
|
||||
ok(($("#testWording18").html() === "about a month ago"), "Correctly parsed");
|
||||
ok(($("#testWording18").html() === "about a month ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("190 days", function () {
|
||||
ok(($("#testWording19").html() === "6 months ago"), "Correctly parsed");
|
||||
ok(($("#testWording19").html() === "6 months ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("366 days", function () {
|
||||
ok(($("#testWording20").html() === "about a year ago"), "Correctly parsed");
|
||||
ok(($("#testWording20").html() === "about a year ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("725 days", function () {
|
||||
ok(($("#testWording21").html() === "2 years ago"), "Correctly parsed");
|
||||
ok(($("#testWording21").html() === "2 years ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
test("1095 days", function () {
|
||||
ok(($("#testWording22").html() === "3 years ago"), "Correctly parsed");
|
||||
ok(($("#testWording22").html() === "3 years ago"), "Incorrectly parsed");
|
||||
});
|
||||
|
||||
module("Settings");
|
||||
|
@ -582,6 +631,58 @@
|
|||
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
||||
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
||||
});
|
||||
|
||||
module("Allow Future and Past");
|
||||
|
||||
// if allowFuture is false, then a minute into the future is actually reported as a minute in the past.
|
||||
// we did not want to alter the current behavior and break backwards compatability
|
||||
test("allow future false with a future date moves time backwards", function () {
|
||||
equal($("#testAllowFutureFalse1").html(), "2 years ago");
|
||||
});
|
||||
|
||||
test("allow future false with a future date moves time backwards", function () {
|
||||
equal($("#testAllowPastFalse1").html(), "in the past");
|
||||
});
|
||||
|
||||
test("throws if allowPast and allowFuture are both false", function () {
|
||||
// setup
|
||||
var origAllowFuture = $.timeago.settings.allowFuture;
|
||||
var origAllowPast = $.timeago.settings.allowPast;
|
||||
$.timeago.settings.allowFuture = false;
|
||||
$.timeago.settings.allowPast = false;
|
||||
|
||||
try {
|
||||
throws(function () {
|
||||
$("#testAllowPastAndFutureFalse").timeago();
|
||||
});
|
||||
} finally {
|
||||
// teardown
|
||||
$.timeago.settings.allowFuture = origAllowFuture;
|
||||
$.timeago.settings.allowPast = origAllowPast;
|
||||
}
|
||||
});
|
||||
|
||||
module("Disposal");
|
||||
|
||||
asyncTest("disposal", function() {
|
||||
$(".disposal.disposed").timeago('dispose');
|
||||
var initialTime_disposedTimeago = $(".disposal.disposed").html();
|
||||
var initialTime_activeTimeago = $(".disposal.notDisposed").html();
|
||||
|
||||
expect(2);
|
||||
setTimeout(function() {
|
||||
var updatedTime_disposedTimeago = $(".disposal.disposed").html();
|
||||
var updatedTime_activeTimeago = $(".disposal.notDisposed").html();
|
||||
|
||||
ok(initialTime_disposedTimeago === updatedTime_disposedTimeago, "A disposed timeago didn't get updated");
|
||||
ok(initialTime_activeTimeago !== updatedTime_activeTimeago, "A non-disposed timeago continued to be updated");
|
||||
|
||||
// Dispose still-active timeago
|
||||
$(".disposal.notDisposed").timeago('dispose');
|
||||
resetRefreshMillis();
|
||||
start();
|
||||
}, 50);
|
||||
});
|
||||
})(jQuery);
|
||||
//]]>
|
||||
</script>
|
||||
|
|
|
@ -30,6 +30,11 @@ function unloadCutoffSetting() {
|
|||
jQuery.timeago.settings.cutoff = 0;
|
||||
}
|
||||
|
||||
function setupDisposal() {
|
||||
jQuery.timeago.settings.refreshMillis = 50;
|
||||
$('abbr.disposal').attr("title", iso8601(new Date())).timeago();
|
||||
}
|
||||
|
||||
function loadPigLatin() {
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: "ago-hay",
|
||||
|
@ -84,6 +89,10 @@ function loadRussian() {
|
|||
})();
|
||||
}
|
||||
|
||||
function resetRefreshMillis() {
|
||||
jQuery.timeago.settings.refreshMillis = 60000;
|
||||
}
|
||||
|
||||
function loadMillis() {
|
||||
var millisSubstitution = function(number, millis) { return millis + " milliseconds"; };
|
||||
jQuery.timeago.settings.strings = {
|
||||
|
@ -122,3 +131,49 @@ function loadYoungOldYears() {
|
|||
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
|
||||
});
|
||||
}
|
||||
|
||||
function loadDoNotAllowFuture() {
|
||||
var mockDateToUse = "2010-01-01";
|
||||
$.timeago.settings.allowFuture = false;
|
||||
enableMockedDate(mockDateToUse);
|
||||
}
|
||||
|
||||
function unloadDoNotAllowFuture() {
|
||||
$.timeago.settings.allowFuture = true;
|
||||
disableMockedDate();
|
||||
}
|
||||
|
||||
function loadDoNotAllowPast() {
|
||||
var mockDateToUse = "2010-01-01";
|
||||
$.timeago.settings.allowFuture = true;
|
||||
$.timeago.settings.allowPast = false;
|
||||
$.timeago.settings.strings.inPast = "in the past";
|
||||
enableMockedDate(mockDateToUse);
|
||||
}
|
||||
|
||||
function unloadDoNotAllowPast() {
|
||||
$.timeago.settings.allowFuture = true;
|
||||
$.timeago.settings.allowPast = true;
|
||||
disableMockedDate();
|
||||
}
|
||||
|
||||
function enableMockedDate(dateToReturn) {
|
||||
var mockDate = dateToReturn;
|
||||
window.NativeDate = Date;
|
||||
window.Date = function () {
|
||||
if(arguments.length === 0) {
|
||||
return new window.NativeDate(mockDate);
|
||||
} else if(arguments.length === 1) {
|
||||
return new window.NativeDate(arguments[0]);
|
||||
} else if(arguments.length === 7) {
|
||||
return new window.NativeDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
|
||||
} else {
|
||||
throw "Mocking Date with this number of parameters is not implemented.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function disableMockedDate() {
|
||||
window.Date = window.NativeDate;
|
||||
delete window.NativeDate;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "timeago",
|
||||
"version": "1.2.0",
|
||||
"version": "1.4.1",
|
||||
"title": "jQuery Timeago",
|
||||
"author": {
|
||||
"name": "Ryan McGeary",
|
||||
|
|
Loading…
Add table
Reference in a new issue