From 3236bd800c71436f67fcfb48d6b60805bdc945ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Guillot?= Date: Fri, 1 Feb 2013 21:04:39 +0100 Subject: [PATCH] jQuery.timeago definitions file. --- jquery.timeago/jquery.timeago-tests.ts | 66 ++++++++++++++++++++++++++ jquery.timeago/jquery.timeago.d.ts | 62 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 jquery.timeago/jquery.timeago-tests.ts create mode 100644 jquery.timeago/jquery.timeago.d.ts diff --git a/jquery.timeago/jquery.timeago-tests.ts b/jquery.timeago/jquery.timeago-tests.ts new file mode 100644 index 00000000000000..55265827ebce1d --- /dev/null +++ b/jquery.timeago/jquery.timeago-tests.ts @@ -0,0 +1,66 @@ +/// +/// + +// Basic usage + +var jQueryElement: JQuery = jQuery("abbr.timeago").timeago(); + +// Programmatic use + +var result1: string = jQuery.timeago(new Date()); +var result2: string = jQuery.timeago("2008-07-17"); +var result3: string = jQuery.timeago(jQuery("abbr#some_id")); +var result4: string = jQuery.timeago(document.getElementById("some_id")); + +// Helpers + +var string1: string = jQuery.timeago.inWords(new Date()); +var string2: string = jQuery.timeago.inWords(123456); + +var date1: Date = jQuery.timeago.parse("2008-07-17T09:24:17Z"); + +var date2: Date = jQuery.timeago.datetime(jQuery("abbr#some_id")); +var date3: Date = jQuery.timeago.datetime(document.getElementById("some_id")); + +var isTime1: bool = jQuery.timeago.isTime(jQuery("abbr#some_id")); +var isTime2: bool = jQuery.timeago.isTime(document.getElementById("some_id")); + +// Settings + +jQuery.timeago.settings.refreshMillis = 6000; +jQuery.timeago.settings.allowFuture = true; +jQuery.timeago.settings.strings.wordSeparator = "#"; + +// Russian locale + +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 лет"); } +}; \ No newline at end of file diff --git a/jquery.timeago/jquery.timeago.d.ts b/jquery.timeago/jquery.timeago.d.ts new file mode 100644 index 00000000000000..ac6475023d4bfd --- /dev/null +++ b/jquery.timeago/jquery.timeago.d.ts @@ -0,0 +1,62 @@ +// Type definitions for jQuery.timeago.js 1.0.2 +// Project: http://timeago.yarp.com/ +// Definitions by: Franois Guillot +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +/// + +interface TimeagoSetings { + refreshMillis?: number; + allowFuture?: bool; + strings?: { + prefixAgo?: string; + prefixFromNow?: string; + suffixAgo?: string; + suffixFromNow?: string; + + // Those can be string or Function + seconds?: any; + minute?: any; + minutes?: any; + hour?: any; + hours?: any; + day?: any; + days?: any; + month?: any; + months?: any; + year?: any; + years?: any; + + wordSeparator?: string; + numbers?: any[]; + }; +} + +interface TimeagoStatic { + (timestamp: Date): string; + (timestamp: number): string; + (timestamp: string): string; + (timestamp: Element): string; + (timestamp: JQuery): string; + settings: TimeagoSetings; + inWords(distanceMillis: Date): string; + inWords(distanceMillis: number): string; + parse(iso8601: string): Date; + datetime(element: Element): Date; + datetime(element: JQuery): Date; + isTime(element: Element): bool; + isTime(element: JQuery): bool; +} + +interface Timeago { + (): JQuery; +} + +interface JQueryStatic { + timeago: TimeagoStatic; +} + +interface JQuery { + timeago: Timeago; +} \ No newline at end of file