Skip to content

Instantly share code, notes, and snippets.

@e7h4n
Created January 4, 2012 09:38
Show Gist options
  • Select an option

  • Save e7h4n/1559326 to your computer and use it in GitHub Desktop.

Select an option

Save e7h4n/1559326 to your computer and use it in GitHub Desktop.
/**
* @author zhangyc, yehao
* @version $Id: $
*/
/*jslint browser: true, vars: true, nomen: true, indent: 4, maxlen: 80, plusplus: true, sloppy: true*/
/*global define: true */
define(function (require, exports) {
var $ = require('../lib/jquery');
/**
* @class
* @name DatePicker
* @constructs
* @param {String} [options.eventName='click'] The desired event to trigger
* the date picker.
*
* @param {String|Date|Array} [options.date] The selected date(s) as string
* (will be converted to Date object based on teh format suplied) and Date
* object for single selection, as Array of strings or Date objects
*
* @param {Boolean} [options.flat=false] Whatever if the date picker is
* appended to the element or triggered by an event.
*
* @param {Integer} [options.start=1] The day week start.
*
* @param {String} [options.prev='<'] HTML inserted to previous links.
*
* @param {String} [options.next='>'] HTML inserted to next links.
*
* @param {String['single'|'multiple'|'range']} [options.mode='single']
* Date selection mode.
*
* @param {String['days'|'months'|'years']} [options.view='days'] Start
* view mode.
*
* @param {Integer} [options.calendars=1] Number of calendars to render
* inside the date picker.
*
* @param {String} [options.format='Y-m-d'] Date format.
*
* @param {String['top'|'left'|'right'|'bottom']}
* [options.position='bottom'] Date picker's position relative to the
* trigegr element (non flat mode only)
*
* @param {Hash} [options.locale='english'] Location: provide a hash with
* keys 'days', 'daysShort', 'daysMin', 'months', 'monthsShort', 'week'.
*
* @param {Function} [options.onShow] Callback function triggered when the
* date picker is shown
*
* @param {Function} [options.onBeforeShow] Callback function triggered
* before the date picker is shown
*
* @param {Function} [options.onHide] Callback function triggered when the
* date picker is hidden
*
* @param {Function} [options.onAfterHide] Callback function triggered when
* the date picker has been hidden
*
* @param {Function} [options.onChange] Callback function triggered when the
* date is changed
*
* @param {Function} [options.onRender] Callback function triggered when the
* date is rendered inside a calendar. It should return and hash with keys:
* 'selected' to select the date, 'disabled' to disable the date,
* 'className' for additional CSS class
*/
var DatePicker = function (elem, options) {
this.$el = $(elem)
.NeverUseThisMethodDirectlyAndTryUtilDatePickerInstead(options);
};
DatePicker.prototype = {
show: function () {
return this.$el.DatePickerShow();
},
hide: function () {
return this.$el.DatePickerHide();
},
/**
* set calendar date
* @param {String|Date|Array} [options.date] The selected date(s) as
* string
* @param {Boolean} shiftTo moves the curent month view to the date
* selection provided.
*/
setDate: function (date, shiftTo) {
return this.$el.DatePickerSetDate(date, shiftTo);
},
/**
* Get date selection.
* @param {Boolean} formated if you whant to get teh selection formated.
*/
getDate: function (formated) {
return this.$el.DatePickerGetDate(formated);
},
/**
* Clear selection in multiple and range mode
*/
clear: function () {
return this.$el.DatePickerClear();
},
/**
* Destroy date picker
*/
destroy: function () {
return this.$el.DatePickerDestroy();
}
};
return DatePicker;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment