mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-03-26 11:13:24 +08:00
flow ui
This commit is contained in:
6
OpenAuth.Mvc/Content/scripts/plugins/datetime/moment.min.js
vendored
Normal file
6
OpenAuth.Mvc/Content/scripts/plugins/datetime/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
26
OpenAuth.Mvc/Content/scripts/plugins/datetime/pikaday.css
Normal file
26
OpenAuth.Mvc/Content/scripts/plugins/datetime/pikaday.css
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
/*! * Pikaday * Copyright © 2012 David Bushell | BSD & MIT license | http://dbushell.com
|
||||
/*/.pika-single{z-index:9999;display:block;position:relative;width:210px;padding:8px;color:#333;background:#fff;border:1px solid #ccc;border-right-color:#bbb;border-bottom-color:#bbb;font-family:Arial,'Microsoft YaHei'}
|
||||
.pika-single.is-hidden{display:none}
|
||||
.pika-single.is-bound{position:absolute;box-shadow:0 5px 15px -5px rgba(0,0,0,.5)}
|
||||
.pika-title{height:30px;overflow:hidden}
|
||||
.pika-label{float:left;position:relative;z-index:9999;overflow:hidden;margin:0;padding:5px 0;font-size:14px;line-height:20px;font-weight:700;background-color:#fff}
|
||||
.pika-label-year{margin-left:50px;width:58px}
|
||||
.pika-label-month{width:54px}
|
||||
.pika-title select{cursor:pointer;position:absolute;z-index:9998;margin:0;left:0;top:5px;opacity:0;filter:alpha(opacity=0);font-size:12px}
|
||||
.pika-next,.pika-prev{display:block;cursor:pointer;outline:0;position:relative;text-indent:100%;overflow:hidden;width:0;height:0;padding:0;top:5px;border:8px solid #fff}
|
||||
.is-rtl .pika-next,.pika-prev{float:left;border-left-width:0;border-right-color:#aaa}
|
||||
.is-rtl .pika-prev,.pika-next{float:right;border-right-width:0;border-left-color:#aaa}
|
||||
.pika-title .pika-prev:hover{border-right-color:#666}
|
||||
.pika-title .pika-next:hover{border-left-color:#666}
|
||||
.pika-next.is-disabled,.pika-prev.is-disabled{cursor:default;filter:alpha(opacity=20);opacity:.2}
|
||||
.pika-table{width:100%;border-collapse:collapse;border-spacing:0;border:0}
|
||||
.pika-table td,.pika-table th{width:30px;height:25px;line-height:25px;}
|
||||
.pika-table th{color:#999;font-size:12px;line-height:25px;font-weight:700;text-align:center}
|
||||
.pika-table abbr{cursor:default;text-decoration:none;border:none}
|
||||
.pika-button{cursor:pointer;display:block;outline:0;border:0;margin:0;height:25px;padding:5px;color:#666;font-size:12px;line-height:17px;text-align:center;background:#f5f5f5;text-decoration:none;}
|
||||
.is-today .pika-button{color: #333;font-weight: 700;background: #ddd;box-shadow: 1px 1px 3px #ccc inset;border-radius: 3px;}
|
||||
.is-selected .pika-button{color:#fff;font-weight:700;background:#3af;box-shadow:1px 1px 3px #1775e5 inset;border-radius:3px}
|
||||
.is-disabled .pika-button{pointer-events:none;cursor:default;color:#999;filter:alpha(opacity=30);opacity:.3}
|
||||
a.pika-button{text-decoration:none;}
|
||||
a.pika-button:hover{color:#333;background:#ddd;border-radius:3px;box-shadow:1px 1px 3px #aaa inset}
|
||||
740
OpenAuth.Mvc/Content/scripts/plugins/datetime/pikaday.js
Normal file
740
OpenAuth.Mvc/Content/scripts/plugins/datetime/pikaday.js
Normal file
@@ -0,0 +1,740 @@
|
||||
/*!
|
||||
* Pikaday
|
||||
* Copyright © 2012 David Bushell | BSD & MIT license | http://dbushell.com/
|
||||
*/
|
||||
|
||||
(function (window, document, undefined) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* feature detection and helper functions
|
||||
*/
|
||||
var hasMoment = typeof window.moment === 'function',
|
||||
|
||||
hasEventListeners = !!window.addEventListener,
|
||||
|
||||
sto = window.setTimeout,
|
||||
|
||||
addEvent = function (el, e, callback, capture) {
|
||||
if (hasEventListeners) {
|
||||
el.addEventListener(e, callback, !!capture);
|
||||
} else {
|
||||
el.attachEvent('on' + e, callback);
|
||||
}
|
||||
},
|
||||
|
||||
removeEvent = function (el, e, callback, capture) {
|
||||
if (hasEventListeners) {
|
||||
el.removeEventListener(e, callback, !!capture);
|
||||
} else {
|
||||
el.detachEvent('on' + e, callback);
|
||||
}
|
||||
},
|
||||
|
||||
trim = function (str) {
|
||||
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
||||
},
|
||||
|
||||
hasClass = function (el, cn) {
|
||||
return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
|
||||
},
|
||||
|
||||
addClass = function (el, cn) {
|
||||
if (!hasClass(el, cn)) {
|
||||
el.className = (el.className === '') ? cn : el.className + ' ' + cn;
|
||||
}
|
||||
},
|
||||
|
||||
removeClass = function (el, cn) {
|
||||
el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
|
||||
},
|
||||
|
||||
isArray = function (obj) {
|
||||
return (/Array/).test(Object.prototype.toString.call(obj));
|
||||
},
|
||||
|
||||
isDate = function (obj) {
|
||||
return (/Date/).test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
|
||||
},
|
||||
|
||||
isLeapYear = function (year) {
|
||||
// solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
|
||||
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
||||
},
|
||||
|
||||
getDaysInMonth = function (year, month) {
|
||||
return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
||||
},
|
||||
|
||||
compareDates = function (a, b) {
|
||||
// weak date comparison (use date.setHours(0,0,0,0) to ensure correct result)
|
||||
return a.getTime() === b.getTime();
|
||||
},
|
||||
|
||||
extend = function (to, from, overwrite) {
|
||||
var prop, hasProp;
|
||||
for (prop in from) {
|
||||
hasProp = to[prop] !== undefined;
|
||||
if (hasProp && typeof from[prop] === 'object' && from[prop].nodeName === undefined) {
|
||||
if (isDate(from[prop])) {
|
||||
if (overwrite) {
|
||||
to[prop] = new Date(from[prop].getTime());
|
||||
}
|
||||
}
|
||||
else if (isArray(from[prop])) {
|
||||
if (overwrite) {
|
||||
to[prop] = from[prop].slice(0);
|
||||
}
|
||||
} else {
|
||||
to[prop] = extend({}, from[prop], overwrite);
|
||||
}
|
||||
} else if (overwrite || !hasProp) {
|
||||
to[prop] = from[prop];
|
||||
}
|
||||
}
|
||||
return to;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* defaults and localisation
|
||||
*/
|
||||
defaults = {
|
||||
|
||||
// bind the picker to a form field
|
||||
field: null,
|
||||
|
||||
// automatically show/hide the picker on `field` focus (default `true` if `field` is set)
|
||||
bound: undefined,
|
||||
|
||||
// the default output format for `.toString()` and `field` value
|
||||
format: 'YYYY-MM-DD',
|
||||
|
||||
// the initial date to view when first opened
|
||||
defaultDate: null,
|
||||
|
||||
// make the `defaultDate` the initial selected value
|
||||
setDefaultDate: false,
|
||||
|
||||
// first day of week (0: Sunday, 1: Monday etc)
|
||||
firstDay: 0,
|
||||
|
||||
// the minimum/earliest date that can be selected
|
||||
minDate: null,
|
||||
// the maximum/latest date that can be selected
|
||||
maxDate: null,
|
||||
|
||||
// number of years either side, or array of upper/lower range
|
||||
yearRange: 10,
|
||||
|
||||
// used internally (don't config outside)
|
||||
minYear: 1990,
|
||||
maxYear: 2099,
|
||||
minMonth: undefined,
|
||||
maxMonth: undefined,
|
||||
|
||||
isRTL: false,
|
||||
|
||||
// how many months are visible (not implemented yet)
|
||||
numberOfMonths: 1,
|
||||
|
||||
// internationalization
|
||||
/* i18n: {
|
||||
|
||||
months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
|
||||
//monthsShort : ['Jan_Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
|
||||
weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
|
||||
weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
|
||||
}, */
|
||||
|
||||
i18n: {
|
||||
|
||||
months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
|
||||
monthsShort: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
|
||||
weekdays: ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
|
||||
weekdaysShort: ['日', '一', '二', '三', '四', '五', '六']
|
||||
},
|
||||
|
||||
// callback function
|
||||
onSelect: null,
|
||||
onOpen: null,
|
||||
onClose: null
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* templating functions to abstract HTML rendering
|
||||
*/
|
||||
renderDayName = function (opts, day, abbr) {
|
||||
day += opts.firstDay;
|
||||
while (day >= 7) {
|
||||
day -= 7;
|
||||
}
|
||||
return abbr ? opts.i18n.weekdaysShort[day] : opts.i18n.weekdays[day];
|
||||
},
|
||||
|
||||
renderDay = function (i, isSelected, isToday, isDisabled, isEmpty) {
|
||||
if (isEmpty) {
|
||||
return '<td class="is-empty"></td>';
|
||||
}
|
||||
var arr = [];
|
||||
if (isDisabled) {
|
||||
arr.push('is-disabled');
|
||||
}
|
||||
if (isToday) {
|
||||
arr.push('is-today');
|
||||
}
|
||||
if (isSelected) {
|
||||
arr.push('is-selected');
|
||||
}
|
||||
return '<td data-day="' + i + '" class="' + arr.join(' ') + '"><a class="pika-button" href="javascript:void(0);">' + i + '</a>' + '</td>';
|
||||
},
|
||||
|
||||
renderRow = function (days, isRTL) {
|
||||
return '<tr>' + (isRTL ? days.reverse() : days).join('') + '</tr>';
|
||||
},
|
||||
|
||||
renderBody = function (rows) {
|
||||
return '<tbody>' + rows.join('') + '</tbody>';
|
||||
},
|
||||
|
||||
renderHead = function (opts) {
|
||||
var i, arr = [];
|
||||
for (i = 0; i < 7; i++) {
|
||||
arr.push('<th scope="col"><abbr title="' + renderDayName(opts, i) + '">' + renderDayName(opts, i, true) + '</abbr></th>');
|
||||
}
|
||||
return '<thead>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</thead>';
|
||||
},
|
||||
|
||||
renderTitle = function (instance) {
|
||||
var i, j, arr,
|
||||
opts = instance._o,
|
||||
month = instance._m,
|
||||
year = instance._y,
|
||||
isMinYear = year === opts.minYear,
|
||||
isMaxYear = year === opts.maxYear,
|
||||
html = '<div class="pika-title">',
|
||||
prev = true,
|
||||
next = true,
|
||||
months = opts.i18n.monthsShort ? opts.i18n.monthsShort : opts.i18n.months;
|
||||
|
||||
if (isMinYear && (month === 0 || opts.minMonth >= month)) {
|
||||
prev = false;
|
||||
}
|
||||
html += '<a class="pika-prev' + (prev ? '' : ' is-disabled') + '" href="javascript:void(0);"><</a>';
|
||||
|
||||
if (isArray(opts.yearRange)) {
|
||||
i = opts.yearRange[0];
|
||||
j = opts.yearRange[1] + 1;
|
||||
} else {
|
||||
i = year - opts.yearRange;
|
||||
j = 1 + year + opts.yearRange;
|
||||
}
|
||||
|
||||
for (arr = []; i < j && i <= opts.maxYear; i++) {
|
||||
if (i >= opts.minYear) {
|
||||
arr.push('<option value="' + i + '"' + (i === year ? ' selected' : '') + '>' + (i) + '</option>');
|
||||
}
|
||||
}
|
||||
html += '<div class="pika-label pika-label-year">' + year + '年 <select class="pika-select pika-select-year">' + arr.join('') + '</select></div>';
|
||||
|
||||
for (arr = [], i = 0; i < 12; i++) {
|
||||
arr.push('<option value="' + i + '"' +
|
||||
(i === month ? ' selected' : '') +
|
||||
((isMinYear && i < opts.minMonth) || (isMaxYear && i > opts.maxMonth) ? 'disabled' : '') + '>' +
|
||||
months[i] + '</option>');
|
||||
}
|
||||
html += '<div class="pika-label pika-label-month">' + months[month] + '月<select class="pika-select pika-select-month">' + arr.join('') + '</select></div>';
|
||||
|
||||
if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
|
||||
next = false;
|
||||
}
|
||||
html += '<a class="pika-next' + (next ? '' : ' is-disabled') + '" href="javascript:void(0);">></a>';
|
||||
|
||||
return html += '</div>';
|
||||
},
|
||||
|
||||
renderTable = function (opts, data) {
|
||||
return '<table cellpadding="0" cellspacing="0" class="pika-table">' + renderHead(opts) + renderBody(data) + '</table>';
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Pikaday constructor
|
||||
*/
|
||||
window.Pikaday = function (options) {
|
||||
var self = this,
|
||||
opts = self.config(options);
|
||||
self._hh = 0;
|
||||
self._mi = 0;
|
||||
|
||||
|
||||
self._onMouseDown = function (e) {
|
||||
if (!self._v) {
|
||||
return;
|
||||
}
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasClass(target, 'is-disabled')) {
|
||||
if (hasClass(target, 'pika-button') && !hasClass(target, 'is-empty')) {
|
||||
self.setDate(new Date(self._y, self._m, parseInt(target.innerHTML, 10)));
|
||||
if (opts.bound) {
|
||||
sto(function () {
|
||||
self.hide();
|
||||
}, 100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (hasClass(target, 'pika-prev')) {
|
||||
self.prevMonth();
|
||||
}
|
||||
else if (hasClass(target, 'pika-next')) {
|
||||
self.nextMonth();
|
||||
}
|
||||
}
|
||||
if (!hasClass(target, 'pika-select')) {
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
return e.returnValue = false;
|
||||
}
|
||||
} else {
|
||||
self._c = true;
|
||||
}
|
||||
};
|
||||
|
||||
self._onChange = function (e) {
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
if (hasClass(target, 'pika-select-month')) {
|
||||
self.gotoMonth(target.value);
|
||||
}
|
||||
else if (hasClass(target, 'pika-select-year')) {
|
||||
self.gotoYear(target.value);
|
||||
}
|
||||
};
|
||||
|
||||
self._onInputChange = function (e) {
|
||||
if (hasMoment) {
|
||||
self.setDate(window.moment(opts.field.value, opts.format).toDate());
|
||||
}
|
||||
else {
|
||||
var date = new Date(Date.parse(opts.field.value));
|
||||
self.setDate(isDate(date) ? date : null);
|
||||
}
|
||||
if (!self._v) {
|
||||
self.show();
|
||||
}
|
||||
};
|
||||
|
||||
self._onInputFocus = function (e) {
|
||||
self.show();
|
||||
};
|
||||
|
||||
self._onInputClick = function (e) {
|
||||
self.show();
|
||||
};
|
||||
|
||||
self._onInputBlur = function (e) {
|
||||
if (!self._c) {
|
||||
self._b = sto(function () {
|
||||
self.hide();
|
||||
}, 50);
|
||||
}
|
||||
self._c = false;
|
||||
};
|
||||
|
||||
self._onClick = function (e) {
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement,
|
||||
pEl = target;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
if (!hasEventListeners && hasClass(target, 'pika-select')) {
|
||||
if (!target.onchange) {
|
||||
target.setAttribute('onchange', 'return;');
|
||||
addEvent(target, 'change', self._onChange);
|
||||
}
|
||||
}
|
||||
do {
|
||||
if (hasClass(pEl, 'pika-single')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while ((pEl = pEl.parentNode));
|
||||
if (self._v && target !== opts.field) {
|
||||
self.hide();
|
||||
}
|
||||
};
|
||||
|
||||
self.el = document.createElement('div');
|
||||
self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '');
|
||||
|
||||
addEvent(self.el, 'mousedown', self._onMouseDown, true);
|
||||
addEvent(self.el, 'change', self._onChange);
|
||||
|
||||
if (opts.field) {
|
||||
if (opts.bound) {
|
||||
$('body').prepend(self.el);
|
||||
//document.body.appendChild(self.el);
|
||||
} else {
|
||||
opts.field.parentNode.insertBefore(self.el, opts.field.nextSibling);
|
||||
}
|
||||
addEvent(opts.field, 'change', self._onInputChange);
|
||||
|
||||
if (!opts.defaultDate) {
|
||||
if (hasMoment && opts.field.value) {
|
||||
opts.defaultDate = window.moment(opts.field.value, opts.format).toDate();
|
||||
} else {
|
||||
opts.defaultDate = new Date(Date.parse(opts.field.value));
|
||||
}
|
||||
opts.setDefaultDate = true;
|
||||
}
|
||||
}
|
||||
|
||||
var defDate = opts.defaultDate;
|
||||
|
||||
if (isDate(defDate)) {
|
||||
if (opts.setDefaultDate) {
|
||||
self.setDate(defDate);
|
||||
} else {
|
||||
self.gotoDate(defDate);
|
||||
}
|
||||
} else {
|
||||
self.gotoDate(new Date());
|
||||
}
|
||||
|
||||
if (opts.bound) {
|
||||
this.hide();
|
||||
self.el.className += ' is-bound';
|
||||
addEvent(opts.field, 'click', self._onInputClick);
|
||||
addEvent(opts.field, 'focus', self._onInputFocus);
|
||||
addEvent(opts.field, 'blur', self._onInputBlur);
|
||||
} else {
|
||||
this.show();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* public Pikaday API
|
||||
*/
|
||||
window.Pikaday.prototype = {
|
||||
|
||||
|
||||
/**
|
||||
* configure functionality
|
||||
*/
|
||||
config: function (options) {
|
||||
if (!this._o) {
|
||||
this._o = extend({}, defaults, true);
|
||||
}
|
||||
|
||||
var opts = extend(this._o, options, true);
|
||||
|
||||
opts.isRTL = !!opts.isRTL;
|
||||
|
||||
opts.field = (opts.field && opts.field.nodeName) ? opts.field : null;
|
||||
|
||||
opts.bound = !!(opts.bound !== undefined ? opts.field && opts.bound : opts.field);
|
||||
|
||||
var nom = parseInt(opts.numberOfMonths, 10) || 1;
|
||||
opts.numberOfMonths = nom > 4 ? 4 : nom;
|
||||
|
||||
if (!isDate(opts.minDate)) {
|
||||
opts.minDate = false;
|
||||
}
|
||||
if (!isDate(opts.maxDate)) {
|
||||
opts.maxDate = false;
|
||||
}
|
||||
if ((opts.minDate && opts.maxDate) && opts.maxDate < opts.minDate) {
|
||||
opts.maxDate = opts.minDate = false;
|
||||
}
|
||||
if (opts.minDate) {
|
||||
opts.minYear = opts.minDate.getFullYear();
|
||||
opts.minMonth = opts.minDate.getMonth();
|
||||
}
|
||||
if (opts.maxDate) {
|
||||
opts.maxYear = opts.maxDate.getFullYear();
|
||||
opts.maxMonth = opts.maxDate.getMonth();
|
||||
}
|
||||
|
||||
if (isArray(opts.yearRange)) {
|
||||
var fallback = new Date().getFullYear() - 10;
|
||||
opts.yearRange[0] = parseInt(opts.yearRange[0], 10) || fallback;
|
||||
opts.yearRange[1] = parseInt(opts.yearRange[1], 10) || fallback;
|
||||
} else {
|
||||
opts.yearRange = Math.abs(parseInt(opts.yearRange, 10)) || defaults.yearRange;
|
||||
if (opts.yearRange > 100) {
|
||||
opts.yearRange = 100;
|
||||
}
|
||||
}
|
||||
|
||||
return opts;
|
||||
},
|
||||
|
||||
/**
|
||||
* return a formatted string of the current selection (using Moment.js if available)
|
||||
*/
|
||||
toString: function (format) {
|
||||
if (!isDate(this._d)) return '';
|
||||
var y = this._d.getFullYear();
|
||||
var m = this._d.getMonth() + 1;
|
||||
var d = this._d.getDate();
|
||||
m = m < 10 ? '0' + m : m;
|
||||
d = d < 10 ? '0' + d : d;
|
||||
return hasMoment ? window.moment(this._d).format(format || this._o.format) : (y + '-' + m + '-' + d);
|
||||
},
|
||||
|
||||
/**
|
||||
* return a Moment.js object of the current selection (if available)
|
||||
*/
|
||||
getMoment: function () {
|
||||
return hasMoment ? window.moment(this._d) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* return a Date object of the current selection
|
||||
*/
|
||||
getDate: function () {
|
||||
return isDate(this._d) ? new Date(this._d.getTime()) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* set the current selection
|
||||
*/
|
||||
setDate: function (date) {
|
||||
if (!date) {
|
||||
this._d = null;
|
||||
return this.draw();
|
||||
}
|
||||
if (typeof date === 'string') {
|
||||
date = new Date(Date.parse(date));
|
||||
}
|
||||
if (!isDate(date)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var min = this._o.minDate,
|
||||
max = this._o.maxDate;
|
||||
|
||||
if (isDate(min) && date < min) {
|
||||
date = min;
|
||||
} else if (isDate(max) && date > max) {
|
||||
date = max;
|
||||
}
|
||||
|
||||
this._d = new Date(date.getTime());
|
||||
this._d.setHours(0, 0, 0, 0);
|
||||
this.gotoDate(this._d);
|
||||
|
||||
if (this._o.field) {
|
||||
this._o.field.value = this.toString();
|
||||
}
|
||||
if (typeof this._o.onSelect === 'function') {
|
||||
this._o.onSelect.call(this, this.getDate());
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* change view to a specific date
|
||||
*/
|
||||
gotoDate: function (date) {
|
||||
if (!isDate(date)) {
|
||||
return;
|
||||
}
|
||||
this._y = date.getFullYear();
|
||||
this._m = date.getMonth();
|
||||
this.draw();
|
||||
},
|
||||
|
||||
gotoToday: function () {
|
||||
this.gotoDate(new Date());
|
||||
},
|
||||
|
||||
/**
|
||||
* change view to a specific month (zero-index, e.g. 0: January)
|
||||
*/
|
||||
gotoMonth: function (month) {
|
||||
if (!isNaN((month = parseInt(month, 10)))) {
|
||||
this._m = month < 0 ? 0 : month > 11 ? 11 : month;
|
||||
this.draw();
|
||||
}
|
||||
},
|
||||
|
||||
nextMonth: function () {
|
||||
if (++this._m > 11) {
|
||||
this._m = 0;
|
||||
this._y++;
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
prevMonth: function () {
|
||||
if (--this._m < 0) {
|
||||
this._m = 11;
|
||||
this._y--;
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
/**
|
||||
* change view to a specific full year (e.g. "2012")
|
||||
*/
|
||||
gotoYear: function (year) {
|
||||
if (!isNaN(year)) {
|
||||
this._y = parseInt(year, 10);
|
||||
this.draw();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* refresh the HTML
|
||||
*/
|
||||
draw: function (force) {
|
||||
if (!this._v && !force) {
|
||||
return;
|
||||
}
|
||||
var opts = this._o,
|
||||
minYear = opts.minYear,
|
||||
maxYear = opts.maxYear,
|
||||
minMonth = opts.minMonth,
|
||||
maxMonth = opts.maxMonth;
|
||||
|
||||
if (this._y <= minYear) {
|
||||
this._y = minYear;
|
||||
if (!isNaN(minMonth) && this._m < minMonth) {
|
||||
this._m = minMonth;
|
||||
}
|
||||
}
|
||||
if (this._y >= maxYear) {
|
||||
this._y = maxYear;
|
||||
if (!isNaN(maxMonth) && this._m > maxMonth) {
|
||||
this._m = maxMonth;
|
||||
}
|
||||
}
|
||||
this.el.innerHTML = renderTitle(this) + this.render(this._y, this._m);
|
||||
if (opts.bound) {
|
||||
var pEl = opts.field,
|
||||
left = pEl.offsetLeft,
|
||||
top = pEl.offsetTop + pEl.offsetHeight;
|
||||
while ((pEl = pEl.offsetParent)) {
|
||||
left += pEl.offsetLeft;
|
||||
top += pEl.offsetTop;
|
||||
}
|
||||
//alert($(this.el).offset().top)
|
||||
this.el.style.cssText = 'position:absolute;left:' + (left) + 'px;top:' + top + 'px;';
|
||||
//this.el.style.cssText = 'position:absolute;left:' + (left + 1.5) + 'px;top:' + (top + 2) + 'px;';
|
||||
sto(function () {
|
||||
opts.field.focus();
|
||||
}, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* render HTML for a particular month
|
||||
*/
|
||||
render: function (year, month) {
|
||||
var opts = this._o,
|
||||
now = new Date(),
|
||||
days = getDaysInMonth(year, month),
|
||||
before = new Date(year, month, 1).getDay(),
|
||||
data = [],
|
||||
row = [];
|
||||
now.setHours(0, 0, 0, 0);
|
||||
if (opts.firstDay > 0) {
|
||||
before -= opts.firstDay;
|
||||
if (before < 0) {
|
||||
before += 7;
|
||||
}
|
||||
}
|
||||
var cells = days + before,
|
||||
after = cells;
|
||||
while (after > 7) {
|
||||
after -= 7;
|
||||
}
|
||||
cells += 7 - after;
|
||||
for (var i = 0, r = 0; i < cells; i++) {
|
||||
var day = new Date(year, month, 1 + (i - before)),
|
||||
isDisabled = (opts.minDate && day < opts.minDate) || (opts.maxDate && day > opts.maxDate),
|
||||
isSelected = isDate(this._d) ? compareDates(day, this._d) : false,
|
||||
isToday = compareDates(day, now),
|
||||
isEmpty = i < before || i >= (days + before);
|
||||
|
||||
row.push(renderDay(1 + (i - before), isSelected, isToday, isDisabled, isEmpty));
|
||||
|
||||
if (++r === 7) {
|
||||
data.push(renderRow(row, opts.isRTL));
|
||||
row = [];
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
return renderTable(opts, data);
|
||||
},
|
||||
|
||||
isVisible: function () {
|
||||
return this._v;
|
||||
},
|
||||
|
||||
show: function () {
|
||||
if (!this._v) {
|
||||
if (this._o.bound) {
|
||||
addEvent(document, 'click', this._onClick);
|
||||
}
|
||||
removeClass(this.el, 'is-hidden');
|
||||
this._v = true;
|
||||
this.draw();
|
||||
if (typeof this._o.onOpen === 'function') {
|
||||
this._o.onOpen.call(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
var v = this._v;
|
||||
if (v !== false) {
|
||||
if (this._o.bound) {
|
||||
removeEvent(document, 'click', this._onClick);
|
||||
}
|
||||
this.el.style.cssText = '';
|
||||
addClass(this.el, 'is-hidden');
|
||||
this._v = false;
|
||||
if (v !== undefined && typeof this._o.onClose === 'function') {
|
||||
this._o.onClose.call(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* GAME OVER
|
||||
*/
|
||||
destroy: function () {
|
||||
this.hide();
|
||||
removeEvent(this.el, 'mousedown', this._onMouseDown, true);
|
||||
removeEvent(this.el, 'change', this._onChange);
|
||||
if (this._o.field) {
|
||||
removeEvent(this._o.field, 'change', this._onInputChange);
|
||||
if (this._o.bound) {
|
||||
removeEvent(this._o.field, 'click', this._onInputClick);
|
||||
removeEvent(this._o.field, 'focus', this._onInputFocus);
|
||||
removeEvent(this._o.field, 'blur', this._onInputBlur);
|
||||
}
|
||||
}
|
||||
if (this.el.parentNode) {
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
})(window, window.document);
|
||||
Reference in New Issue
Block a user