Permalink
Browse files

jQuery.timeago definitions file.

  • Loading branch information...
1 parent bc489ff commit 3236bd800c71436f67fcfb48d6b60805bdc945ce François Guillot committed Feb 1, 2013
Showing with 128 additions and 0 deletions.
  1. +66 −0 jquery.timeago/jquery.timeago-tests.ts
  2. +62 −0 jquery.timeago/jquery.timeago.d.ts
@@ -0,0 +1,66 @@
+/// <reference path="../jquery/jquery.d.ts"/>
+/// <reference path="jquery.timeago.d.ts"/>
+
+// 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 лет"); }
+};
@@ -0,0 +1,62 @@
+// Type definitions for jQuery.timeago.js 1.0.2
+// Project: http://timeago.yarp.com/
+// Definitions by: François Guillot <http://fguillot.developpez.com/>
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+
+/// <reference path="../jquery/jquery.d.ts"/>
+
+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;
+}

0 comments on commit 3236bd8

Please sign in to comment.