Add typings for Pikaday

This commit is contained in:
Rudolph Gottesheim
2015-06-15 11:29:51 +02:00
parent 4502a738b2
commit ebe6f6affe
2 changed files with 146 additions and 0 deletions

57
pikaday/pikaday-tests.ts Normal file
View File

@@ -0,0 +1,57 @@
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../moment/moment.d.ts" />
/// <reference path="pikaday.d.ts" />
new Pikaday({field: document.getElementById('datepicker')});
new Pikaday({field: $('#datepicker')[0]});
(() => {
var field:HTMLInputElement = <HTMLInputElement>document.getElementById('datepicker');
var picker = new Pikaday({
onSelect: function (date:Date) {
field.value = picker.toString();
console.log(date.toISOString());
}
});
field.parentNode.insertBefore(picker.el, field.nextSibling);
})();
(() => {
var picker = new Pikaday({
field: document.getElementById('datepicker'),
format: 'D MMM YYYY',
onSelect: function () {
console.log(this.getMoment().format('Do MMMM YYYY'));
}
});
picker.toString();
picker.toString('YYYY-MM-DD');
picker.getDate();
picker.setDate('2015-01-01');
picker.getMoment();
picker.setMoment(moment('14th February 2014', 'DDo MMMM YYYY'));
picker.gotoDate(new Date(2014, 1));
picker.gotoToday();
picker.gotoMonth(2);
picker.nextMonth();
picker.prevMonth();
picker.gotoYear(2015);
picker.setMinDate(new Date);
picker.setMaxDate(new Date);
picker.isVisible();
picker.show();
picker.adjustPosition();
picker.hide();
picker.destroy();
})();
(() => {
var i18n:PikadayI18nConfig = {
previousMonth: 'Previous Month',
nextMonth: 'Next Month',
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
};
new Pikaday({i18n});
})();

89
pikaday/pikaday.d.ts vendored Normal file
View File

@@ -0,0 +1,89 @@
// Type definitions for pikaday
// Project: https://github.com/dbushell/Pikaday
// Definitions by: Rudolph Gottesheim <http://midnight-design.at/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../moment/moment.d.ts" />
interface PikadayI18nConfig {
previousMonth: string;
nextMonth: string;
months: string[];
weekdays: string[];
weekdaysShort: string[];
}
interface PikadayOptions {
field?: HTMLElement;
format?: string;
trigger?: HTMLElement;
bound?: boolean;
position?: string;
reposition?: boolean;
container?: HTMLElement;
defaultDate?: Date;
setDefaultDate?: boolean;
firstDay?: number;
minDate?: Date;
maxDate?: Date;
disableWeekends?: boolean;
disableDayFn?: (date:Date) => boolean;
yearRange?: number[];
showWeekNumber?: boolean;
isRTL?: boolean;
i18n?: PikadayI18nConfig;
yearSuffix?: string;
showMonthAfterYear?: boolean;
numberOfMonths?: number;
mainCalendar?: string;
theme?: string;
onSelect?: (date:Date) => void;
onOpen?: () => void;
onClose?: () => void;
onDraw?: () => void;
}
declare class Pikaday {
el:HTMLElement;
constructor(options:PikadayOptions);
toString():string;
toString(format:string):string;
getDate():Date|void;
setDate(date:string|Date, triggerOnSelect?:boolean):void;
getMoment():moment.Moment;
setMoment(moment:any):void;
gotoDate(date:Date):void;
gotoToday():void;
gotoMonth(monthIndex:number):void;
gotoYear(year:number):void;
nextMonth():void;
prevMonth():void;
gogoYear(year:number):void;
setMinDate(date:Date):void;
setMaxDate(date:Date):void;
isVisible():boolean;
show():void;
hide():void;
adjustPosition():void;
destroy():void;
}