1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056 |
-
-
-
- (function($) {
-
-
- function Datepicker() {
- this._defaults = {
- pickerClass: '',
- showOnFocus: true,
- showTrigger: null,
- showAnim: 'show',
- showOptions: {},
- showSpeed: 'normal',
- popupContainer: null,
- alignment: 'bottom',
-
-
- fixedWeeks: false,
- firstDay: 0,
- calculateWeek: this.iso8601Week,
- monthsToShow: 1,
- monthsOffset: 0,
-
- monthsToStep: 1,
- monthsToJump: 12,
- useMouseWheel: true,
- changeMonth: true,
- yearRange: 'c-10:c+10',
-
-
-
- shortYearCutoff: '+10',
- showOtherMonths: false,
- selectOtherMonths: false,
- defaultDate: null,
- selectDefaultDate: false,
- minDate: null,
- maxDate: null,
- dateFormat: 'mm/dd/yyyy',
- autoSize: false,
- rangeSelect: false,
- rangeSeparator: ' - ',
- multiSelect: 0,
- multiSeparator: ',',
- onDate: null,
- onShow: null,
- onChangeMonthYear: null,
- onSelect: null,
- onClose: null,
- altField: null,
- altFormat: null,
- constrainInput: true,
- commandsAsDateFormat: false,
- commands: this.commands
- };
- this.regional = [];
- this.regional[''] = {
- monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
- 'July', 'August', 'September', 'October', 'November', 'December'],
- monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
- dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
- dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
- dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
- dateFormat: 'mm/dd/yyyy',
- firstDay: 0,
- renderer: this.defaultRenderer,
- prevText: '<Prev',
- prevStatus: 'Show the previous month',
- prevJumpText: '<<',
- prevJumpStatus: 'Show the previous year',
- nextText: 'Next>',
- nextStatus: 'Show the next month',
- nextJumpText: '>>',
- nextJumpStatus: 'Show the next year',
- currentText: 'Current',
- currentStatus: 'Show the current month',
- todayText: 'Today',
- todayStatus: 'Show today\'s month',
- clearText: 'Clear',
- clearStatus: 'Clear all the dates',
- closeText: 'Close',
- closeStatus: 'Close the datepicker',
- yearStatus: 'Change the year',
- monthStatus: 'Change the month',
- weekText: 'Wk',
- weekStatus: 'Week of the year',
- dayStatus: 'Select DD, M d, yyyy',
- defaultStatus: 'Select a date',
- isRTL: false
- };
- $.extend(this._defaults, this.regional['']);
- this._disabled = [];
- }
-
- $.extend(Datepicker.prototype, {
-
- markerClassName: 'hasDatepick',
-
- propertyName: 'datepick',
-
- _popupClass: 'datepick-popup',
- _triggerClass: 'datepick-trigger',
- _disableClass: 'datepick-disable',
- _monthYearClass: 'datepick-month-year',
- _curMonthClass: 'datepick-month-',
- _anyYearClass: 'datepick-any-year',
- _curDoWClass: 'datepick-dow-',
-
- commands: {
-
-
-
-
-
-
-
-
- prev: {text: 'prevText', status: 'prevStatus',
- keystroke: {keyCode: 33},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- return (!minDate || plugin.add(plugin.day(
- plugin._applyMonthsOffset(plugin.add(plugin.newDate(inst.drawDate),
- 1 - inst.options.monthsToStep, 'm'), inst), 1), -1, 'd').
- getTime() >= minDate.getTime()); },
- date: function(inst) {
- return plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), -inst.options.monthsToStep, 'm'), inst), 1); },
- action: function(inst) {
- plugin._changeMonthPlugin(this, -inst.options.monthsToStep); }
- },
- prevJump: {text: 'prevJumpText', status: 'prevJumpStatus',
- keystroke: {keyCode: 33, ctrlKey: true},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- return (!minDate || plugin.add(plugin.day(
- plugin._applyMonthsOffset(plugin.add(plugin.newDate(inst.drawDate),
- 1 - inst.options.monthsToJump, 'm'), inst), 1), -1, 'd').
- getTime() >= minDate.getTime()); },
- date: function(inst) {
- return plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), -inst.options.monthsToJump, 'm'), inst), 1); },
- action: function(inst) {
- plugin._changeMonthPlugin(this, -inst.options.monthsToJump); }
- },
- next: {text: 'nextText', status: 'nextStatus',
- keystroke: {keyCode: 34},
- enabled: function(inst) {
- var maxDate = inst.get('maxDate');
- return (!maxDate || plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), inst.options.monthsToStep, 'm'), inst), 1).
- getTime() <= maxDate.getTime()); },
- date: function(inst) {
- return plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), inst.options.monthsToStep, 'm'), inst), 1); },
- action: function(inst) {
- plugin._changeMonthPlugin(this, inst.options.monthsToStep); }
- },
- nextJump: {text: 'nextJumpText', status: 'nextJumpStatus',
- keystroke: {keyCode: 34, ctrlKey: true},
- enabled: function(inst) {
- var maxDate = inst.get('maxDate');
- return (!maxDate || plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), inst.options.monthsToJump, 'm'), inst), 1).
- getTime() <= maxDate.getTime()); },
- date: function(inst) {
- return plugin.day(plugin._applyMonthsOffset(plugin.add(
- plugin.newDate(inst.drawDate), inst.options.monthsToJump, 'm'), inst), 1); },
- action: function(inst) {
- plugin._changeMonthPlugin(this, inst.options.monthsToJump); }
- },
- current: {text: 'currentText', status: 'currentStatus',
- keystroke: {keyCode: 36, ctrlKey: true},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- var maxDate = inst.get('maxDate');
- var curDate = inst.selectedDates[0] || plugin.today();
- return (!minDate || curDate.getTime() >= minDate.getTime()) &&
- (!maxDate || curDate.getTime() <= maxDate.getTime()); },
- date: function(inst) {
- return inst.selectedDates[0] || plugin.today(); },
- action: function(inst) {
- var curDate = inst.selectedDates[0] || plugin.today();
- plugin._showMonthPlugin(this, curDate.getFullYear(), curDate.getMonth() + 1); }
- },
- today: {text: 'todayText', status: 'todayStatus',
- keystroke: {keyCode: 36, ctrlKey: true},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- var maxDate = inst.get('maxDate');
- return (!minDate || plugin.today().getTime() >= minDate.getTime()) &&
- (!maxDate || plugin.today().getTime() <= maxDate.getTime()); },
- date: function(inst) { return plugin.today(); },
- action: function(inst) { plugin._showMonthPlugin(this); }
- },
- clear: {text: 'clearText', status: 'clearStatus',
- keystroke: {keyCode: 35, ctrlKey: true},
- enabled: function(inst) { return true; },
- date: function(inst) { return null; },
- action: function(inst) { plugin._clearPlugin(this); }
- },
- close: {text: 'closeText', status: 'closeStatus',
- keystroke: {keyCode: 27},
- enabled: function(inst) { return true; },
- date: function(inst) { return null; },
- action: function(inst) { plugin._hidePlugin(this); }
- },
- prevWeek: {text: 'prevWeekText', status: 'prevWeekStatus',
- keystroke: {keyCode: 38, ctrlKey: true},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- return (!minDate || plugin.add(plugin.newDate(inst.drawDate), -7, 'd').
- getTime() >= minDate.getTime()); },
- date: function(inst) { return plugin.add(plugin.newDate(inst.drawDate), -7, 'd'); },
- action: function(inst) { plugin._changeDayPlugin(this, -7); }
- },
- prevDay: {text: 'prevDayText', status: 'prevDayStatus',
- keystroke: {keyCode: 37, ctrlKey: true},
- enabled: function(inst) {
- var minDate = inst.curMinDate();
- return (!minDate || plugin.add(plugin.newDate(inst.drawDate), -1, 'd').
- getTime() >= minDate.getTime()); },
- date: function(inst) { return plugin.add(plugin.newDate(inst.drawDate), -1, 'd'); },
- action: function(inst) { plugin._changeDayPlugin(this, -1); }
- },
- nextDay: {text: 'nextDayText', status: 'nextDayStatus',
- keystroke: {keyCode: 39, ctrlKey: true},
- enabled: function(inst) {
- var maxDate = inst.get('maxDate');
- return (!maxDate || plugin.add(plugin.newDate(inst.drawDate), 1, 'd').
- getTime() <= maxDate.getTime()); },
- date: function(inst) { return plugin.add(plugin.newDate(inst.drawDate), 1, 'd'); },
- action: function(inst) { plugin._changeDayPlugin(this, 1); }
- },
- nextWeek: {text: 'nextWeekText', status: 'nextWeekStatus',
- keystroke: {keyCode: 40, ctrlKey: true},
- enabled: function(inst) {
- var maxDate = inst.get('maxDate');
- return (!maxDate || plugin.add(plugin.newDate(inst.drawDate), 7, 'd').
- getTime() <= maxDate.getTime()); },
- date: function(inst) { return plugin.add(plugin.newDate(inst.drawDate), 7, 'd'); },
- action: function(inst) { plugin._changeDayPlugin(this, 7); }
- }
- },
-
-
- defaultRenderer: {
-
-
-
-
-
-
- picker: '<div class="datepick">' +
- '<div class="datepick-nav">{link:prev}{link:today}{link:next}</div>{months}' +
- '{popup:start}<div class="datepick-ctrl">{link:clear}{link:close}</div>{popup:end}' +
- '<div class="datepick-clear-fix"></div></div>',
-
- monthRow: '<div class="datepick-month-row">{months}</div>',
-
-
-
- month: '<div class="datepick-month"><div class="datepick-month-header">{monthHeader}</div>' +
- '<table><thead>{weekHeader}</thead><tbody>{weeks}</tbody></table></div>',
-
- weekHeader: '<tr>{days}</tr>',
-
- dayHeader: '<th>{day}</th>',
-
- week: '<tr>{days}</tr>',
-
- day: '<td>{day}</td>',
-
- monthSelector: '.datepick-month',
-
- daySelector: 'td',
-
- rtlClass: 'datepick-rtl',
-
- multiClass: 'datepick-multi',
-
- defaultClass: '',
-
- selectedClass: 'datepick-selected',
-
- highlightedClass: 'datepick-highlight',
-
- todayClass: 'datepick-today',
-
- otherMonthClass: 'datepick-other-month',
-
- weekendClass: 'datepick-weekend',
-
- commandClass: 'datepick-cmd',
-
- commandButtonClass: '',
-
- commandLinkClass: '',
-
- disabledClass: 'datepick-disabled'
- },
-
-
-
- setDefaults: function(options) {
- $.extend(this._defaults, options || {});
- return this;
- },
-
- _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
- Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
- _msPerDay: 24 * 60 * 60 * 1000,
-
- ATOM: 'yyyy-mm-dd',
- COOKIE: 'D, dd M yyyy',
- FULL: 'DD, MM d, yyyy',
- ISO_8601: 'yyyy-mm-dd',
- JULIAN: 'J',
- RFC_822: 'D, d M yy',
- RFC_850: 'DD, dd-M-yy',
- RFC_1036: 'D, d M yy',
- RFC_1123: 'D, d M yyyy',
- RFC_2822: 'D, d M yyyy',
- RSS: 'D, d M yy',
- TICKS: '!',
- TIMESTAMP: '@',
- W3C: 'yyyy-mm-dd',
-
-
-
- formatDate: function(format, date, settings) {
- if (typeof format != 'string') {
- settings = date;
- date = format;
- format = '';
- }
- if (!date) {
- return '';
- }
- format = format || this._defaults.dateFormat;
- settings = settings || {};
- var dayNamesShort = settings.dayNamesShort || this._defaults.dayNamesShort;
- var dayNames = settings.dayNames || this._defaults.dayNames;
- var monthNamesShort = settings.monthNamesShort || this._defaults.monthNamesShort;
- var monthNames = settings.monthNames || this._defaults.monthNames;
- var calculateWeek = settings.calculateWeek || this._defaults.calculateWeek;
-
- var doubled = function(match, step) {
- var matches = 1;
- while (iFormat + matches < format.length && format.charAt(iFormat + matches) == match) {
- matches++;
- }
- iFormat += matches - 1;
- return Math.floor(matches / (step || 1)) > 1;
- };
-
- var formatNumber = function(match, value, len, step) {
- var num = '' + value;
- if (doubled(match, step)) {
- while (num.length < len) {
- num = '0' + num;
- }
- }
- return num;
- };
-
- var formatName = function(match, value, shortNames, longNames) {
- return (doubled(match) ? longNames[value] : shortNames[value]);
- };
- var output = '';
- var literal = false;
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
- if (literal) {
- if (format.charAt(iFormat) == "'" && !doubled("'")) {
- literal = false;
- }
- else {
- output += format.charAt(iFormat);
- }
- }
- else {
- switch (format.charAt(iFormat)) {
- case 'd': output += formatNumber('d', date.getDate(), 2); break;
- case 'D': output += formatName('D', date.getDay(),
- dayNamesShort, dayNames); break;
- case 'o': output += formatNumber('o', this.dayOfYear(date), 3); break;
- case 'w': output += formatNumber('w', calculateWeek(date), 2); break;
- case 'm': output += formatNumber('m', date.getMonth() + 1, 2); break;
- case 'M': output += formatName('M', date.getMonth(),
- monthNamesShort, monthNames); break;
- case 'y':
- output += (doubled('y', 2) ? date.getFullYear() :
- (date.getFullYear() % 100 < 10 ? '0' : '') + date.getFullYear() % 100);
- break;
- case '@': output += Math.floor(date.getTime() / 1000); break;
- case '!': output += date.getTime() * 10000 + this._ticksTo1970; break;
- case "'":
- if (doubled("'")) {
- output += "'";
- }
- else {
- literal = true;
- }
- break;
- default:
- output += format.charAt(iFormat);
- }
- }
- }
- return output;
- },
-
-
-
- parseDate: function(format, value, settings) {
- if (value == null) {
- throw 'Invalid arguments';
- }
- value = (typeof value == 'object' ? value.toString() : value + '');
- if (value == '') {
- return null;
- }
- format = format || this._defaults.dateFormat;
- settings = settings || {};
- var shortYearCutoff = settings.shortYearCutoff || this._defaults.shortYearCutoff;
- shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
- this.today().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
- var dayNamesShort = settings.dayNamesShort || this._defaults.dayNamesShort;
- var dayNames = settings.dayNames || this._defaults.dayNames;
- var monthNamesShort = settings.monthNamesShort || this._defaults.monthNamesShort;
- var monthNames = settings.monthNames || this._defaults.monthNames;
- var year = -1;
- var month = -1;
- var day = -1;
- var doy = -1;
- var shortYear = false;
- var literal = false;
-
- var doubled = function(match, step) {
- var matches = 1;
- while (iFormat + matches < format.length && format.charAt(iFormat + matches) == match) {
- matches++;
- }
- iFormat += matches - 1;
- return Math.floor(matches / (step || 1)) > 1;
- };
-
- var getNumber = function(match, step) {
- var isDoubled = doubled(match, step);
- var size = [2, 3, isDoubled ? 4 : 2, 11, 20]['oy@!'.indexOf(match) + 1];
- var digits = new RegExp('^-?\\d{1,' + size + '}');
- var num = value.substring(iValue).match(digits);
- if (!num) {
- throw 'Missing number at position {0}'.replace(/\{0\}/, iValue);
- }
- iValue += num[0].length;
- return parseInt(num[0], 10);
- };
-
- var getName = function(match, shortNames, longNames, step) {
- var names = (doubled(match, step) ? longNames : shortNames);
- for (var i = 0; i < names.length; i++) {
- if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
- iValue += names[i].length;
- return i + 1;
- }
- }
- throw 'Unknown name at position {0}'.replace(/\{0\}/, iValue);
- };
-
- var checkLiteral = function() {
- if (value.charAt(iValue) != format.charAt(iFormat)) {
- throw 'Unexpected literal at position {0}'.replace(/\{0\}/, iValue);
- }
- iValue++;
- };
- var iValue = 0;
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
- if (literal) {
- if (format.charAt(iFormat) == "'" && !doubled("'")) {
- literal = false;
- }
- else {
- checkLiteral();
- }
- }
- else {
- switch (format.charAt(iFormat)) {
- case 'd': day = getNumber('d'); break;
- case 'D': getName('D', dayNamesShort, dayNames); break;
- case 'o': doy = getNumber('o'); break;
- case 'w': getNumber('w'); break;
- case 'm': month = getNumber('m'); break;
- case 'M': month = getName('M', monthNamesShort, monthNames); break;
- case 'y':
- var iSave = iFormat;
- shortYear = !doubled('y', 2);
- iFormat = iSave;
- year = getNumber('y', 2);
- break;
- case '@':
- var date = this._normaliseDate(new Date(getNumber('@') * 1000));
- year = date.getFullYear();
- month = date.getMonth() + 1;
- day = date.getDate();
- break;
- case '!':
- var date = this._normaliseDate(
- new Date((getNumber('!') - this._ticksTo1970) / 10000));
- year = date.getFullYear();
- month = date.getMonth() + 1;
- day = date.getDate();
- break;
- case '*': iValue = value.length; break;
- case "'":
- if (doubled("'")) {
- checkLiteral();
- }
- else {
- literal = true;
- }
- break;
- default: checkLiteral();
- }
- }
- }
- if (iValue < value.length) {
- throw 'Additional text found at end';
- }
- if (year == -1) {
- year = this.today().getFullYear();
- }
- else if (year < 100 && shortYear) {
- year += (shortYearCutoff == -1 ? 1900 : this.today().getFullYear() -
- this.today().getFullYear() % 100 - (year <= shortYearCutoff ? 0 : 100));
- }
- if (doy > -1) {
- month = 1;
- day = doy;
- for (var dim = this.daysInMonth(year, month); day > dim;
- dim = this.daysInMonth(year, month)) {
- month++;
- day -= dim;
- }
- }
- var date = this.newDate(year, month, day);
- if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) {
- throw 'Invalid date';
- }
- return date;
- },
-
-
-
- determineDate: function(dateSpec, defaultDate, currentDate, dateFormat, settings) {
- if (currentDate && typeof currentDate != 'object') {
- settings = dateFormat;
- dateFormat = currentDate;
- currentDate = null;
- }
- if (typeof dateFormat != 'string') {
- settings = dateFormat;
- dateFormat = '';
- }
- var offsetString = function(offset) {
- try {
- return plugin.parseDate(dateFormat, offset, settings);
- }
- catch (e) {
-
- }
- offset = offset.toLowerCase();
- var date = (offset.match(/^c/) && currentDate ? plugin.newDate(currentDate) : null) ||
- plugin.today();
- var pattern = /([+-]?[0-9]+)\s*(d|w|m|y)?/g;
- var matches = null;
- while (matches = pattern.exec(offset)) {
- date = plugin.add(date, parseInt(matches[1], 10), matches[2] || 'd');
- }
- return date;
- };
- defaultDate = (defaultDate ? plugin.newDate(defaultDate) : null);
- dateSpec = (dateSpec == null ? defaultDate :
- (typeof dateSpec == 'string' ? offsetString(dateSpec) : (typeof dateSpec == 'number' ?
- (isNaN(dateSpec) || dateSpec == Infinity || dateSpec == -Infinity ? defaultDate :
- plugin.add(plugin.today(), dateSpec, 'd')) : plugin.newDate(dateSpec))));
- return dateSpec;
- },
-
-
-
- daysInMonth: function(year, month) {
- month = (year.getFullYear ? year.getMonth() + 1 : month);
- year = (year.getFullYear ? year.getFullYear() : year);
- return this.newDate(year, month + 1, 0).getDate();
- },
-
-
-
- dayOfYear: function(year, month, day) {
- var date = (year.getFullYear ? year : this.newDate(year, month, day));
- var newYear = this.newDate(date.getFullYear(), 1, 1);
- return Math.floor((date.getTime() - newYear.getTime()) / this._msPerDay) + 1;
- },
-
-
-
- iso8601Week: function(year, month, day) {
- var checkDate = (year.getFullYear ?
- new Date(year.getTime()) : this.newDate(year, month, day));
-
- checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
- var time = checkDate.getTime();
- checkDate.setMonth(0, 1);
- return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
- },
-
-
-
- today: function() {
- return this._normaliseDate(new Date());
- },
-
-
-
- newDate: function(year, month, day) {
- return (!year ? null : (year.getFullYear ? this._normaliseDate(new Date(year.getTime())) :
- new Date(year, month - 1, day, 12)));
- },
-
-
-
- _normaliseDate: function(date) {
- if (date) {
- date.setHours(12, 0, 0, 0);
- }
- return date;
- },
-
-
-
- year: function(date, year) {
- date.setFullYear(year);
- return this._normaliseDate(date);
- },
-
-
-
- month: function(date, month) {
- date.setMonth(month - 1);
- return this._normaliseDate(date);
- },
-
-
-
- day: function(date, day) {
- date.setDate(day);
- return this._normaliseDate(date);
- },
-
-
-
- add: function(date, amount, period) {
- if (period == 'd' || period == 'w') {
- this._normaliseDate(date);
- date.setDate(date.getDate() + amount * (period == 'w' ? 7 : 1));
- }
- else {
- var year = date.getFullYear() + (period == 'y' ? amount : 0);
- var month = date.getMonth() + (period == 'm' ? amount : 0);
- date.setTime(plugin.newDate(year, month + 1,
- Math.min(date.getDate(), this.daysInMonth(year, month + 1))).getTime());
- }
- return date;
- },
-
-
-
- _applyMonthsOffset: function(date, inst) {
- var monthsOffset = inst.options.monthsOffset;
- if ($.isFunction(monthsOffset)) {
- monthsOffset = monthsOffset.apply(inst.target[0], [date]);
- }
- return plugin.add(date, -monthsOffset, 'm');
- },
-
-
-
- _attachPlugin: function(target, options) {
- target = $(target);
- if (target.hasClass(this.markerClassName)) {
- return;
- }
- var inlineSettings = ($.fn.metadata ? target.metadata() : {});
- var inst = {options: $.extend({}, this._defaults, inlineSettings, options),
- target: target, selectedDates: [], drawDate: null, pickingRange: false,
- inline: ($.inArray(target[0].nodeName.toLowerCase(), ['div', 'span']) > -1),
- get: function(name) {
- if ($.inArray(name, ['defaultDate', 'minDate', 'maxDate']) > -1) {
- return plugin.determineDate(this.options[name], null,
- this.selectedDates[0], this.options.dateFormat, inst.getConfig());
- }
- return this.options[name];
- },
- curMinDate: function() {
- return (this.pickingRange ? this.selectedDates[0] : this.get('minDate'));
- },
- getConfig: function() {
- return {dayNamesShort: this.options.dayNamesShort, dayNames: this.options.dayNames,
- monthNamesShort: this.options.monthNamesShort, monthNames: this.options.monthNames,
- calculateWeek: this.options.calculateWeek,
- shortYearCutoff: this.options.shortYearCutoff};
- }
- };
- target.addClass(this.markerClassName).data(this.propertyName, inst);
- if (inst.inline) {
- inst.drawDate = plugin._checkMinMax(plugin.newDate(inst.selectedDates[0] ||
- inst.get('defaultDate') || plugin.today()), inst);
- inst.prevDate = plugin.newDate(inst.drawDate);
- this._update(target[0]);
- if ($.fn.mousewheel) {
- target.mousewheel(this._doMouseWheel);
- }
- }
- else {
- this._attachments(target, inst);
- target.bind('keydown.' + this.propertyName, this._keyDown).
- bind('keypress.' + this.propertyName, this._keyPress).
- bind('keyup.' + this.propertyName, this._keyUp);
- if (target.attr('disabled')) {
- this._disablePlugin(target[0]);
- }
- }
- },
-
-
-
- _optionPlugin: function(target, options, value) {
- target = $(target);
- var inst = target.data(this.propertyName);
- if (!options || (typeof options == 'string' && value == null)) {
- var name = options;
- options = (inst || {}).options;
- return (options && name ? options[name] : options);
- }
-
- if (!target.hasClass(this.markerClassName)) {
- return;
- }
- options = options || {};
- if (typeof options == 'string') {
- var name = options;
- options = {};
- options[name] = value;
- }
- if (options.calendar && options.calendar != inst.options.calendar) {
- var discardDate = function(name) {
- return (typeof inst.options[name] == 'object' ? null : inst.options[name]);
- };
- options = $.extend({defaultDate: discardDate('defaultDate'),
- minDate: discardDate('minDate'), maxDate: discardDate('maxDate')}, options);
- inst.selectedDates = [];
- inst.drawDate = null;
- }
- var dates = inst.selectedDates;
- $.extend(inst.options, options);
- this._setDatePlugin(target[0], dates, null, false, true);
- inst.pickingRange = false;
- inst.drawDate = plugin.newDate(this._checkMinMax(
- (inst.options.defaultDate ? inst.get('defaultDate') : inst.drawDate) ||
- inst.get('defaultDate') || plugin.today(), inst));
- if (!inst.inline) {
- this._attachments(target, inst);
- }
- if (inst.inline || inst.div) {
- this._update(target[0]);
- }
- },
-
-
-
- _attachments: function(target, inst) {
- target.unbind('focus.' + this.propertyName);
- if (inst.options.showOnFocus) {
- target.bind('focus.' + this.propertyName, this._showPlugin);
- }
- if (inst.trigger) {
- inst.trigger.remove();
- }
- var trigger = inst.options.showTrigger;
- inst.trigger = (!trigger ? $([]) :
- $(trigger).clone().removeAttr('id').addClass(this._triggerClass)
- [inst.options.isRTL ? 'insertBefore' : 'insertAfter'](target).
- click(function() {
- if (!plugin._isDisabledPlugin(target[0])) {
- plugin[plugin.curInst == inst ? '_hidePlugin' : '_showPlugin'](target[0]);
- }
- }));
- this._autoSize(target, inst);
- var dates = this._extractDates(inst, target.val());
- if (dates) {
- this._setDatePlugin(target[0], dates, null, true);
- }
- var defaultDate = inst.get('defaultDate');
- if (inst.options.selectDefaultDate && defaultDate && inst.selectedDates.length == 0) {
- this._setDatePlugin(target[0], plugin.newDate(defaultDate || plugin.today()));
- }
- },
-
-
-
- _autoSize: function(target, inst) {
- if (inst.options.autoSize && !inst.inline) {
- var date = plugin.newDate(2009, 10, 20);
- var dateFormat = inst.options.dateFormat;
- if (dateFormat.match(/[DM]/)) {
- var findMax = function(names) {
- var max = 0;
- var maxI = 0;
- for (var i = 0; i < names.length; i++) {
- if (names[i].length > max) {
- max = names[i].length;
- maxI = i;
- }
- }
- return maxI;
- };
- date.setMonth(findMax(inst.options[dateFormat.match(/MM/) ?
- 'monthNames' : 'monthNamesShort']));
- date.setDate(findMax(inst.options[dateFormat.match(/DD/) ?
- 'dayNames' : 'dayNamesShort']) + 20 - date.getDay());
- }
- inst.target.attr('size', plugin.formatDate(dateFormat, date, inst.getConfig()).length);
- }
- },
-
-
-
- _destroyPlugin: function(target) {
- target = $(target);
- if (!target.hasClass(this.markerClassName)) {
- return;
- }
- var inst = target.data(this.propertyName);
- if (inst.trigger) {
- inst.trigger.remove();
- }
- target.removeClass(this.markerClassName).removeData(this.propertyName).
- empty().unbind('.' + this.propertyName);
- if (inst.inline && $.fn.mousewheel) {
- target.unmousewheel();
- }
- if (!inst.inline && inst.options.autoSize) {
- target.removeAttr('size');
- }
- },
-
-
-
- multipleEvents: function(fns) {
- var funcs = arguments;
- return function(args) {
- for (var i = 0; i < funcs.length; i++) {
- funcs[i].apply(this, arguments);
- }
- };
- },
-
-
-
- _enablePlugin: function(target) {
- target = $(target);
- if (!target.hasClass(this.markerClassName)) {
- return;
- }
- var inst = target.data(this.propertyName);
- if (inst.inline) {
- target.children('.' + this._disableClass).remove().end().
- find('button,select').removeAttr('disabled').end().
- find('a').attr('href', 'javascript:void(0)');
- }
- else {
- target.prop('disabled', false);
- inst.trigger.filter('button.' + this._triggerClass).
- removeAttr('disabled').end().
- filter('img.' + this._triggerClass).
- css({opacity: '1.0', cursor: ''});
- }
- this._disabled = $.map(this._disabled,
- function(value) { return (value == target[0] ? null : value); });
- },
-
-
-
- _disablePlugin: function(target) {
- target = $(target);
- if (!target.hasClass(this.markerClassName)) {
- return;
- }
- var inst = target.data(this.propertyName);
- if (inst.inline) {
- var inline = target.children(':last');
- var offset = inline.offset();
- var relOffset = {left: 0, top: 0};
- inline.parents().each(function() {
- if ($(this).css('position') == 'relative') {
- relOffset = $(this).offset();
- return false;
- }
- });
- var zIndex = target.css('zIndex');
- zIndex = (zIndex == 'auto' ? 0 : parseInt(zIndex, 10)) + 1;
- target.prepend('<div class="' + this._disableClass + '" style="' +
- 'width: ' + inline.outerWidth() + 'px; height: ' + inline.outerHeight() +
- 'px; left: ' + (offset.left - relOffset.left) + 'px; top: ' +
- (offset.top - relOffset.top) + 'px; z-index: ' + zIndex + '"></div>').
- find('button,select').attr('disabled', 'disabled').end().
- find('a').removeAttr('href');
- }
- else {
- target.prop('disabled', true);
- inst.trigger.filter('button.' + this._triggerClass).
- attr('disabled', 'disabled').end().
- filter('img.' + this._triggerClass).
- css({opacity: '0.5', cursor: 'default'});
- }
- this._disabled = $.map(this._disabled,
- function(value) { return (value == target[0] ? null : value); });
- this._disabled.push(target[0]);
- },
-
-
-
- _isDisabledPlugin: function(target) {
- return (target && $.inArray(target, this._disabled) > -1);
- },
-
-
-
- _showPlugin: function(target) {
- target = $(target.target || target);
- var inst = target.data(plugin.propertyName);
- if (plugin.curInst == inst) {
- return;
- }
- if (plugin.curInst) {
- plugin._hidePlugin(plugin.curInst, true);
- }
- if (inst) {
-
- inst.lastVal = null;
- inst.selectedDates = plugin._extractDates(inst, target.val());
- inst.pickingRange = false;
- inst.drawDate = plugin._checkMinMax(plugin.newDate(inst.selectedDates[0] ||
- inst.get('defaultDate') || plugin.today()), inst);
- inst.prevDate = plugin.newDate(inst.drawDate);
- plugin.curInst = inst;
-
- plugin._update(target[0], true);
-
- var offset = plugin._checkOffset(inst);
- inst.div.css({left: offset.left, top: offset.top});
-
- var showAnim = inst.options.showAnim;
- var showSpeed = inst.options.showSpeed;
- showSpeed = (showSpeed == 'normal' && $.ui && $.ui.version >= '1.8' ?
- '_default' : showSpeed);
- if ($.effects && $.effects[showAnim]) {
- var data = inst.div.data();
- for (var key in data) {
- if (key.match(/^ec\.storage\./)) {
- data[key] = inst._mainDiv.css(key.replace(/ec\.storage\./, ''));
- }
- }
- inst.div.data(data).show(showAnim, inst.options.showOptions, showSpeed);
- }
- else {
- inst.div[showAnim || 'show']((showAnim ? showSpeed : ''));
- }
- }
- },
-
-
-
- _extractDates: function(inst, datesText) {
- if (datesText == inst.lastVal) {
- return;
- }
- inst.lastVal = datesText;
- datesText = datesText.split(inst.options.multiSelect ? inst.options.multiSeparator :
- (inst.options.rangeSelect ? inst.options.rangeSeparator : '\x00'));
- var dates = [];
- for (var i = 0; i < datesText.length; i++) {
- try {
- var date = plugin.parseDate(inst.options.dateFormat, datesText[i], inst.getConfig());
- if (date) {
- var found = false;
- for (var j = 0; j < dates.length; j++) {
- if (dates[j].getTime() == date.getTime()) {
- found = true;
- break;
- }
- }
- if (!found) {
- dates.push(date);
- }
- }
- }
- catch (e) {
-
- }
- }
- dates.splice(inst.options.multiSelect || (inst.options.rangeSelect ? 2 : 1), dates.length);
- if (inst.options.rangeSelect && dates.length == 1) {
- dates[1] = dates[0];
- }
- return dates;
- },
-
-
-
- _update: function(target, hidden) {
- target = $(target.target || target);
- var inst = target.data(plugin.propertyName);
- if (inst) {
- if (inst.inline || plugin.curInst == inst) {
- if ($.isFunction(inst.options.onChangeMonthYear) && (!inst.prevDate ||
- inst.prevDate.getFullYear() != inst.drawDate.getFullYear() ||
- inst.prevDate.getMonth() != inst.drawDate.getMonth())) {
- inst.options.onChangeMonthYear.apply(target[0],
- [inst.drawDate.getFullYear(), inst.drawDate.getMonth() + 1]);
- }
- }
- if (inst.inline) {
- target.html(this._generateContent(target[0], inst));
- }
- else if (plugin.curInst == inst) {
- if (!inst.div) {
- inst.div = $('<div></div>').addClass(this._popupClass).
- css({display: (hidden ? 'none' : 'static'), position: 'absolute',
- left: target.offset().left,
- top: target.offset().top + target.outerHeight()}).
- appendTo($(inst.options.popupContainer || 'body'));
- if ($.fn.mousewheel) {
- inst.div.mousewheel(this._doMouseWheel);
- }
- }
- inst.div.html(this._generateContent(target[0], inst));
- target.focus();
- }
- }
- },
-
-
-
- _updateInput: function(target, keyUp) {
- var inst = $.data(target, this.propertyName);
- if (inst) {
- var value = '';
- var altValue = '';
- var sep = (inst.options.multiSelect ? inst.options.multiSeparator :
- inst.options.rangeSeparator);
- var altFormat = inst.options.altFormat || inst.options.dateFormat;
- for (var i = 0; i < inst.selectedDates.length; i++) {
- value += (keyUp ? '' : (i > 0 ? sep : '') + plugin.formatDate(
- inst.options.dateFormat, inst.selectedDates[i], inst.getConfig()));
- altValue += (i > 0 ? sep : '') + plugin.formatDate(
- altFormat, inst.selectedDates[i], inst.getConfig());
- }
- if (!inst.inline && !keyUp) {
- $(target).val(value);
- }
- $(inst.options.altField).val(altValue);
- if ($.isFunction(inst.options.onSelect) && !keyUp && !inst.inSelect) {
- inst.inSelect = true;
- inst.options.onSelect.apply(target, [inst.selectedDates]);
- inst.inSelect = false;
- }
- }
- },
-
-
-
- _getBorders: function(elem) {
- var convert = function(value) {
- return {thin: 1, medium: 3, thick: 5}[value] || value;
- };
- return [parseFloat(convert(elem.css('border-left-width'))),
- parseFloat(convert(elem.css('border-top-width')))];
- },
-
-
-
- _checkOffset: function(inst) {
- var base = (inst.target.is(':hidden') && inst.trigger ? inst.trigger : inst.target);
- var offset = base.offset();
- var browserWidth = $(window).width();
- var browserHeight = $(window).height();
- if (browserWidth == 0) {
- return offset;
- }
- var isFixed = false;
- $(inst.target).parents().each(function() {
- isFixed |= $(this).css('position') == 'fixed';
- return !isFixed;
- });
- var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
- var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
- var above = offset.top - (isFixed ? scrollY : 0) - inst.div.outerHeight();
- var below = offset.top - (isFixed ? scrollY : 0) + base.outerHeight();
- var alignL = offset.left - (isFixed ? scrollX : 0);
- var alignR = offset.left - (isFixed ? scrollX : 0) + base.outerWidth() - inst.div.outerWidth();
- var tooWide = (offset.left - scrollX + inst.div.outerWidth()) > browserWidth;
- var tooHigh = (offset.top - scrollY + inst.target.outerHeight() +
- inst.div.outerHeight()) > browserHeight;
- inst.div.css('position', isFixed ? 'fixed' : 'absolute');
- var alignment = inst.options.alignment;
- if (alignment == 'topLeft') {
- offset = {left: alignL, top: above};
- }
- else if (alignment == 'topRight') {
- offset = {left: alignR, top: above};
- }
- else if (alignment == 'bottomLeft') {
- offset = {left: alignL, top: below};
- }
- else if (alignment == 'bottomRight') {
- offset = {left: alignR, top: below};
- }
- else if (alignment == 'top') {
- offset = {left: (inst.options.isRTL || tooWide ? alignR : alignL), top: above};
- }
- else {
- offset = {left: (inst.options.isRTL || tooWide ? alignR : alignL),
- top: (tooHigh ? above : below)};
- }
- offset.left = Math.max((isFixed ? 0 : scrollX), offset.left);
- offset.top = Math.max((isFixed ? 0 : scrollY), offset.top);
- return offset;
- },
-
-
-
- _checkExternalClick: function(event) {
- if (!plugin.curInst) {
- return;
- }
- var target = $(event.target);
- if (!target.parents().andSelf().hasClass(plugin._popupClass) &&
- !target.hasClass(plugin.markerClassName) &&
- !target.parents().andSelf().hasClass(plugin._triggerClass)) {
- plugin._hidePlugin(plugin.curInst);
- }
- },
-
-
-
- _hidePlugin: function(target, immediate) {
- if (!target) {
- return;
- }
- var inst = $.data(target, this.propertyName) || target;
- if (inst && inst == plugin.curInst) {
- var showAnim = (immediate ? '' : inst.options.showAnim);
- var showSpeed = inst.options.showSpeed;
- showSpeed = (showSpeed == 'normal' && $.ui && $.ui.version >= '1.8' ?
- '_default' : showSpeed);
- var postProcess = function() {
- if (!inst.div) {
- return;
- }
- inst.div.remove();
- inst.div = null;
- plugin.curInst = null;
- if ($.isFunction(inst.options.onClose)) {
- inst.options.onClose.apply(target, [inst.selectedDates]);
- }
- };
- inst.div.stop();
- if ($.effects && $.effects[showAnim]) {
- inst.div.hide(showAnim, inst.options.showOptions, showSpeed, postProcess);
- }
- else {
- var hideAnim = (showAnim == 'slideDown' ? 'slideUp' :
- (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'));
- inst.div[hideAnim]((showAnim ? showSpeed : ''), postProcess);
- }
- if (!showAnim) {
- postProcess();
- }
- }
- },
-
-
-
- _keyDown: function(event) {
- var target = event.target;
- var inst = $.data(target, plugin.propertyName);
- var handled = false;
- if (inst.div) {
- if (event.keyCode == 9) {
- plugin._hidePlugin(target);
- }
- else if (event.keyCode == 13) {
- plugin._selectDatePlugin(target,
- $('a.' + inst.options.renderer.highlightedClass, inst.div)[0]);
- handled = true;
- }
- else {
- var commands = inst.options.commands;
- for (var name in commands) {
- var command = commands[name];
- if (command.keystroke.keyCode == event.keyCode &&
- !!command.keystroke.ctrlKey == !!(event.ctrlKey || event.metaKey) &&
- !!command.keystroke.altKey == event.altKey &&
- !!command.keystroke.shiftKey == event.shiftKey) {
- plugin._performActionPlugin(target, name);
- handled = true;
- break;
- }
- }
- }
- }
- else {
- var command = inst.options.commands.current;
- if (command.keystroke.keyCode == event.keyCode &&
- !!command.keystroke.ctrlKey == !!(event.ctrlKey || event.metaKey) &&
- !!command.keystroke.altKey == event.altKey &&
- !!command.keystroke.shiftKey == event.shiftKey) {
- plugin._showPlugin(target);
- handled = true;
- }
- }
- inst.ctrlKey = ((event.keyCode < 48 && event.keyCode != 32) ||
- event.ctrlKey || event.metaKey);
- if (handled) {
- event.preventDefault();
- event.stopPropagation();
- }
- return !handled;
- },
-
-
-
- _keyPress: function(event) {
- var inst = $.data(event.target, plugin.propertyName);
- if (inst && inst.options.constrainInput) {
- var ch = String.fromCharCode(event.keyCode || event.charCode);
- var allowedChars = plugin._allowedChars(inst);
- return (event.metaKey || inst.ctrlKey || ch < ' ' ||
- !allowedChars || allowedChars.indexOf(ch) > -1);
- }
- return true;
- },
-
-
-
- _allowedChars: function(inst) {
- var allowedChars = (inst.options.multiSelect ? inst.options.multiSeparator :
- (inst.options.rangeSelect ? inst.options.rangeSeparator : ''));
- var literal = false;
- var hasNum = false;
- var dateFormat = inst.options.dateFormat;
- for (var i = 0; i < dateFormat.length; i++) {
- var ch = dateFormat.charAt(i);
- if (literal) {
- if (ch == "'" && dateFormat.charAt(i + 1) != "'") {
- literal = false;
- }
- else {
- allowedChars += ch;
- }
- }
- else {
- switch (ch) {
- case 'd': case 'm': case 'o': case 'w':
- allowedChars += (hasNum ? '' : '0123456789'); hasNum = true; break;
- case 'y': case '@': case '!':
- allowedChars += (hasNum ? '' : '0123456789') + '-'; hasNum = true; break;
- case 'J':
- allowedChars += (hasNum ? '' : '0123456789') + '-.'; hasNum = true; break;
- case 'D': case 'M': case 'Y':
- return null;
- case "'":
- if (dateFormat.charAt(i + 1) == "'") {
- allowedChars += "'";
- }
- else {
- literal = true;
- }
- break;
- default:
- allowedChars += ch;
- }
- }
- }
- return allowedChars;
- },
-
-
-
- _keyUp: function(event) {
- var target = event.target;
- var inst = $.data(target, plugin.propertyName);
- if (inst && !inst.ctrlKey && inst.lastVal != inst.target.val()) {
- try {
- var dates = plugin._extractDates(inst, inst.target.val());
- if (dates.length > 0) {
- plugin._setDatePlugin(target, dates, null, true);
- }
- }
- catch (event) {
-
- }
- }
- return true;
- },
-
-
-
- _doMouseWheel: function(event, delta) {
- var target = (plugin.curInst && plugin.curInst.target[0]) ||
- $(event.target).closest('.' + plugin.markerClassName)[0];
- if (plugin._isDisabledPlugin(target)) {
- return;
- }
- var inst = $.data(target, plugin.propertyName);
- if (inst.options.useMouseWheel) {
- delta = (delta < 0 ? -1 : +1);
- plugin._changeMonthPlugin(target,
- -inst.options[event.ctrlKey ? 'monthsToJump' : 'monthsToStep'] * delta);
- }
- event.preventDefault();
- },
-
-
-
- _clearPlugin: function(target) {
- var inst = $.data(target, this.propertyName);
- if (inst) {
- inst.selectedDates = [];
- this._hidePlugin(target);
- var defaultDate = inst.get('defaultDate');
- if (inst.options.selectDefaultDate && defaultDate) {
- this._setDatePlugin(target, plugin.newDate(defaultDate || plugin.today()));
- }
- else {
- this._updateInput(target);
- }
- }
- },
-
-
-
- _getDatePlugin: function(target) {
- var inst = $.data(target, this.propertyName);
- return (inst ? inst.selectedDates : []);
- },
-
-
-
- _setDatePlugin: function(target, dates, endDate, keyUp, setOpt) {
- var inst = $.data(target, this.propertyName);
- if (inst) {
- if (!$.isArray(dates)) {
- dates = [dates];
- if (endDate) {
- dates.push(endDate);
- }
- }
- var minDate = inst.get('minDate');
- var maxDate = inst.get('maxDate');
- var curDate = inst.selectedDates[0];
- inst.selectedDates = [];
- for (var i = 0; i < dates.length; i++) {
- var date = plugin.determineDate(
- dates[i], null, curDate, inst.options.dateFormat, inst.getConfig());
- if (date) {
- if ((!minDate || date.getTime() >= minDate.getTime()) &&
- (!maxDate || date.getTime() <= maxDate.getTime())) {
- var found = false;
- for (var j = 0; j < inst.selectedDates.length; j++) {
- if (inst.selectedDates[j].getTime() == date.getTime()) {
- found = true;
- break;
- }
- }
- if (!found) {
- inst.selectedDates.push(date);
- }
- }
- }
- }
- inst.selectedDates.splice(inst.options.multiSelect ||
- (inst.options.rangeSelect ? 2 : 1), inst.selectedDates.length);
- if (inst.options.rangeSelect) {
- switch (inst.selectedDates.length) {
- case 1: inst.selectedDates[1] = inst.selectedDates[0]; break;
- case 2: inst.selectedDates[1] =
- (inst.selectedDates[0].getTime() > inst.selectedDates[1].getTime() ?
- inst.selectedDates[0] : inst.selectedDates[1]); break;
- }
- inst.pickingRange = false;
- }
- inst.prevDate = (inst.drawDate ? plugin.newDate(inst.drawDate) : null);
- inst.drawDate = this._checkMinMax(plugin.newDate(inst.selectedDates[0] ||
- inst.get('defaultDate') || plugin.today()), inst);
- if (!setOpt) {
- this._update(target);
- this._updateInput(target, keyUp);
- }
- }
- },
-
-
-
- _isSelectablePlugin: function(target, date) {
- var inst = $.data(target, this.propertyName);
- if (!inst) {
- return false;
- }
- date = plugin.determineDate(date, inst.selectedDates[0] || this.today(), null,
- inst.options.dateFormat, inst.getConfig());
- return this._isSelectable(target, date, inst.options.onDate,
- inst.get('minDate'), inst.get('maxDate'));
- },
-
-
-
- _isSelectable: function(target, date, onDate, minDate, maxDate) {
- var dateInfo = (typeof onDate == 'boolean' ? {selectable: onDate} :
- (!$.isFunction(onDate) ? {} : onDate.apply(target, [date, true])));
- return (dateInfo.selectable != false) &&
- (!minDate || date.getTime() >= minDate.getTime()) &&
- (!maxDate || date.getTime() <= maxDate.getTime());
- },
-
-
-
- _performActionPlugin: function(target, action) {
- var inst = $.data(target, this.propertyName);
- if (inst && !this._isDisabledPlugin(target)) {
- var commands = inst.options.commands;
- if (commands[action] && commands[action].enabled.apply(target, [inst])) {
- commands[action].action.apply(target, [inst]);
- }
- }
- },
-
-
-
- _showMonthPlugin: function(target, year, month, day) {
- var inst = $.data(target, this.propertyName);
- if (inst && (day != null ||
- (inst.drawDate.getFullYear() != year || inst.drawDate.getMonth() + 1 != month))) {
- inst.prevDate = plugin.newDate(inst.drawDate);
- var show = this._checkMinMax((year != null ?
- plugin.newDate(year, month, 1) : plugin.today()), inst);
- inst.drawDate = plugin.newDate(show.getFullYear(), show.getMonth() + 1,
- (day != null ? day : Math.min(inst.drawDate.getDate(),
- plugin.daysInMonth(show.getFullYear(), show.getMonth() + 1))));
- this._update(target);
- }
- },
-
-
-
- _changeMonthPlugin: function(target, offset) {
- var inst = $.data(target, this.propertyName);
- if (inst) {
- var date = plugin.add(plugin.newDate(inst.drawDate), offset, 'm');
- this._showMonthPlugin(target, date.getFullYear(), date.getMonth() + 1);
- }
- },
-
-
-
- _changeDayPlugin: function(target, offset) {
- var inst = $.data(target, this.propertyName);
- if (inst) {
- var date = plugin.add(plugin.newDate(inst.drawDate), offset, 'd');
- this._showMonthPlugin(target, date.getFullYear(), date.getMonth() + 1, date.getDate());
- }
- },
-
-
-
- _checkMinMax: function(date, inst) {
- var minDate = inst.get('minDate');
- var maxDate = inst.get('maxDate');
- date = (minDate && date.getTime() < minDate.getTime() ? plugin.newDate(minDate) : date);
- date = (maxDate && date.getTime() > maxDate.getTime() ? plugin.newDate(maxDate) : date);
- return date;
- },
-
-
-
- _retrieveDatePlugin: function(target, elem) {
- var inst = $.data(target, this.propertyName);
- return (!inst ? null : this._normaliseDate(
- new Date(parseInt(elem.className.replace(/^.*dp(-?\d+).*$/, '$1'), 10))));
- },
-
-
-
- _selectDatePlugin: function(target, elem) {
- var inst = $.data(target, this.propertyName);
- if (inst && !this._isDisabledPlugin(target)) {
- var date = this._retrieveDatePlugin(target, elem);
- if (inst.options.multiSelect) {
- var found = false;
- for (var i = 0; i < inst.selectedDates.length; i++) {
- if (date.getTime() == inst.selectedDates[i].getTime()) {
- inst.selectedDates.splice(i, 1);
- found = true;
- break;
- }
- }
- if (!found && inst.selectedDates.length < inst.options.multiSelect) {
- inst.selectedDates.push(date);
- }
- }
- else if (inst.options.rangeSelect) {
- if (inst.pickingRange) {
- inst.selectedDates[1] = date;
- }
- else {
- inst.selectedDates = [date, date];
- }
- inst.pickingRange = !inst.pickingRange;
- }
- else {
- inst.selectedDates = [date];
- }
- inst.prevDate = plugin.newDate(date);
- this._updateInput(target);
- if (inst.inline || inst.pickingRange || inst.selectedDates.length <
- (inst.options.multiSelect || (inst.options.rangeSelect ? 2 : 1))) {
- this._update(target);
- }
- else {
- this._hidePlugin(target);
- }
- }
- },
-
-
-
- _generateContent: function(target, inst) {
- var monthsToShow = inst.options.monthsToShow;
- monthsToShow = ($.isArray(monthsToShow) ? monthsToShow : [1, monthsToShow]);
- inst.drawDate = this._checkMinMax(
- inst.drawDate || inst.get('defaultDate') || plugin.today(), inst);
- var drawDate = plugin._applyMonthsOffset(plugin.newDate(inst.drawDate), inst);
-
- var monthRows = '';
- for (var row = 0; row < monthsToShow[0]; row++) {
- var months = '';
- for (var col = 0; col < monthsToShow[1]; col++) {
- months += this._generateMonth(target, inst, drawDate.getFullYear(),
- drawDate.getMonth() + 1, inst.options.renderer, (row == 0 && col == 0));
- plugin.add(drawDate, 1, 'm');
- }
- monthRows += this._prepare(inst.options.renderer.monthRow, inst).replace(/\{months\}/, months);
- }
- var picker = this._prepare(inst.options.renderer.picker, inst).replace(/\{months\}/, monthRows).
- replace(/\{weekHeader\}/g, this._generateDayHeaders(inst, inst.options.renderer));
-
- var addCommand = function(type, open, close, name, classes) {
- if (picker.indexOf('{' + type + ':' + name + '}') == -1) {
- return;
- }
- var command = inst.options.commands[name];
- var date = (inst.options.commandsAsDateFormat ? command.date.apply(target, [inst]) : null);
- picker = picker.replace(new RegExp('\\{' + type + ':' + name + '\\}', 'g'),
- '<' + open +
- (command.status ? ' title="' + inst.options[command.status] + '"' : '') +
- ' class="' + inst.options.renderer.commandClass + ' ' +
- inst.options.renderer.commandClass + '-' + name + ' ' + classes +
- (command.enabled(inst) ? '' : ' ' + inst.options.renderer.disabledClass) + '">' +
- (date ? plugin.formatDate(inst.options[command.text], date, inst.getConfig()) :
- inst.options[command.text]) + '</' + close + '>');
- };
- for (var name in inst.options.commands) {
- addCommand('button', 'button type="button"', 'button', name,
- inst.options.renderer.commandButtonClass);
- addCommand('link', 'a href="javascript:void(0)"', 'a', name,
- inst.options.renderer.commandLinkClass);
- }
- picker = $(picker);
- if (monthsToShow[1] > 1) {
- var count = 0;
- $(inst.options.renderer.monthSelector, picker).each(function() {
- var nth = ++count % monthsToShow[1];
- $(this).addClass(nth == 1 ? 'first' : (nth == 0 ? 'last' : ''));
- });
- }
-
- var self = this;
- picker.find(inst.options.renderer.daySelector + ' a').hover(
- function() { $(this).addClass(inst.options.renderer.highlightedClass); },
- function() {
- (inst.inline ? $(this).parents('.' + self.markerClassName) : inst.div).
- find(inst.options.renderer.daySelector + ' a').
- removeClass(inst.options.renderer.highlightedClass);
- }).
- click(function() {
- self._selectDatePlugin(target, this);
- }).end().
- find('select.' + this._monthYearClass + ':not(.' + this._anyYearClass + ')').
- change(function() {
- var monthYear = $(this).val().split('/');
- self._showMonthPlugin(target, parseInt(monthYear[1], 10), parseInt(monthYear[0], 10));
- }).end().
- find('select.' + this._anyYearClass).click(function() {
- $(this).css('visibility', 'hidden').
- next('input').css({left: this.offsetLeft, top: this.offsetTop,
- width: this.offsetWidth, height: this.offsetHeight}).show().focus();
- }).end().
- find('input.' + self._monthYearClass).change(function() {
- try {
- var year = parseInt($(this).val(), 10);
- year = (isNaN(year) ? inst.drawDate.getFullYear() : year);
- self._showMonthPlugin(target, year, inst.drawDate.getMonth() + 1, inst.drawDate.getDate());
- }
- catch (e) {
- alert(e);
- }
- }).keydown(function(event) {
- if (event.keyCode == 13) {
- $(event.target).change();
- }
- else if (event.keyCode == 27) {
- $(event.target).hide().prev('select').css('visibility', 'visible');
- inst.target.focus();
- }
- });
-
- picker.find('.' + inst.options.renderer.commandClass).click(function() {
- if (!$(this).hasClass(inst.options.renderer.disabledClass)) {
- var action = this.className.replace(
- new RegExp('^.*' + inst.options.renderer.commandClass + '-([^ ]+).*$'), '$1');
- plugin._performActionPlugin(target, action);
- }
- });
-
- if (inst.options.isRTL) {
- picker.addClass(inst.options.renderer.rtlClass);
- }
- if (monthsToShow[0] * monthsToShow[1] > 1) {
- picker.addClass(inst.options.renderer.multiClass);
- }
- if (inst.options.pickerClass) {
- picker.addClass(inst.options.pickerClass);
- }
-
- $('body').append(picker);
- var width = 0;
- picker.find(inst.options.renderer.monthSelector).each(function() {
- width += $(this).outerWidth();
- });
- picker.width(width / monthsToShow[0]);
-
- if ($.isFunction(inst.options.onShow)) {
- inst.options.onShow.apply(target, [picker, inst]);
- }
- return picker;
- },
-
-
-
- _generateMonth: function(target, inst, year, month, renderer, first) {
- var daysInMonth = plugin.daysInMonth(year, month);
- var monthsToShow = inst.options.monthsToShow;
- monthsToShow = ($.isArray(monthsToShow) ? monthsToShow : [1, monthsToShow]);
- var fixedWeeks = inst.options.fixedWeeks || (monthsToShow[0] * monthsToShow[1] > 1);
- var firstDay = inst.options.firstDay;
- var leadDays = (plugin.newDate(year, month, 1).getDay() - firstDay + 7) % 7;
- var numWeeks = (fixedWeeks ? 6 : Math.ceil((leadDays + daysInMonth) / 7));
- var selectOtherMonths = inst.options.selectOtherMonths && inst.options.showOtherMonths;
- var minDate = (inst.pickingRange ? inst.selectedDates[0] : inst.get('minDate'));
- var maxDate = inst.get('maxDate');
- var showWeeks = renderer.week.indexOf('{weekOfYear}') > -1;
- var today = plugin.today();
- var drawDate = plugin.newDate(year, month, 1);
- plugin.add(drawDate, -leadDays - (fixedWeeks && (drawDate.getDay() == firstDay) ? 7 : 0), 'd');
- var ts = drawDate.getTime();
-
- var weeks = '';
- for (var week = 0; week < numWeeks; week++) {
- var weekOfYear = (!showWeeks ? '' : '<span class="dp' + ts + '">' +
- ($.isFunction(inst.options.calculateWeek) ? inst.options.calculateWeek(drawDate) : 0) + '</span>');
- var days = '';
- for (var day = 0; day < 7; day++) {
- var selected = false;
- if (inst.options.rangeSelect && inst.selectedDates.length > 0) {
- selected = (drawDate.getTime() >= inst.selectedDates[0] &&
- drawDate.getTime() <= inst.selectedDates[1]);
- }
- else {
- for (var i = 0; i < inst.selectedDates.length; i++) {
- if (inst.selectedDates[i].getTime() == drawDate.getTime()) {
- selected = true;
- break;
- }
- }
- }
- var dateInfo = (!$.isFunction(inst.options.onDate) ? {} :
- inst.options.onDate.apply(target, [drawDate, drawDate.getMonth() + 1 == month]));
- var selectable = (selectOtherMonths || drawDate.getMonth() + 1 == month) &&
- this._isSelectable(target, drawDate, dateInfo.selectable, minDate, maxDate);
- days += this._prepare(renderer.day, inst).replace(/\{day\}/g,
- (selectable ? '<a href="javascript:void(0)"' : '<span') +
- ' class="dp' + ts + ' ' + (dateInfo.dateClass || '') +
- (selected && (selectOtherMonths || drawDate.getMonth() + 1 == month) ?
- ' ' + renderer.selectedClass : '') +
- (selectable ? ' ' + renderer.defaultClass : '') +
- ((drawDate.getDay() || 7) < 6 ? '' : ' ' + renderer.weekendClass) +
- (drawDate.getMonth() + 1 == month ? '' : ' ' + renderer.otherMonthClass) +
- (drawDate.getTime() == today.getTime() && (drawDate.getMonth() + 1) == month ?
- ' ' + renderer.todayClass : '') +
- (drawDate.getTime() == inst.drawDate.getTime() && (drawDate.getMonth() + 1) == month ?
- ' ' + renderer.highlightedClass : '') + '"' +
- (dateInfo.title || (inst.options.dayStatus && selectable) ? ' title="' +
- (dateInfo.title || plugin.formatDate(
- inst.options.dayStatus, drawDate, inst.getConfig())) + '"' : '') + '>' +
- (inst.options.showOtherMonths || (drawDate.getMonth() + 1) == month ?
- dateInfo.content || drawDate.getDate() : ' ') +
- (selectable ? '</a>' : '</span>'));
- plugin.add(drawDate, 1, 'd');
- ts = drawDate.getTime();
- }
- weeks += this._prepare(renderer.week, inst).replace(/\{days\}/g, days).
- replace(/\{weekOfYear\}/g, weekOfYear);
- }
- var monthHeader = this._prepare(renderer.month, inst).match(/\{monthHeader(:[^\}]+)?\}/);
- monthHeader = (monthHeader[0].length <= 13 ? 'MM yyyy' :
- monthHeader[0].substring(13, monthHeader[0].length - 1));
- monthHeader = (first ? this._generateMonthSelection(
- inst, year, month, minDate, maxDate, monthHeader, renderer) :
- plugin.formatDate(monthHeader, plugin.newDate(year, month, 1), inst.getConfig()));
- var weekHeader = this._prepare(renderer.weekHeader, inst).
- replace(/\{days\}/g, this._generateDayHeaders(inst, renderer));
- return this._prepare(renderer.month, inst).replace(/\{monthHeader(:[^\}]+)?\}/g, monthHeader).
- replace(/\{weekHeader\}/g, weekHeader).replace(/\{weeks\}/g, weeks);
- },
-
-
-
- _generateDayHeaders: function(inst, renderer) {
- var header = '';
- for (var day = 0; day < 7; day++) {
- var dow = (day + inst.options.firstDay) % 7;
- header += this._prepare(renderer.dayHeader, inst).replace(/\{day\}/g,
- '<span class="' + this._curDoWClass + dow + '" title="' +
- inst.options.dayNames[dow] + '">' + inst.options.dayNamesMin[dow] + '</span>');
- }
- return header;
- },
-
-
-
- _generateMonthSelection: function(inst, year, month, minDate, maxDate, monthHeader) {
- if (!inst.options.changeMonth) {
- return plugin.formatDate(
- monthHeader, plugin.newDate(year, month, 1), inst.getConfig());
- }
-
- var monthNames = inst.options['monthNames' + (monthHeader.match(/mm/i) ? '' : 'Short')];
- var html = monthHeader.replace(/m+/i, '\\x2E').replace(/y+/i, '\\x2F');
- var selector = '<select class="' + this._monthYearClass +
- '" title="' + inst.options.monthStatus + '">';
- for (var m = 1; m <= 12; m++) {
- if ((!minDate || plugin.newDate(year, m, plugin.daysInMonth(year, m)).
- getTime() >= minDate.getTime()) &&
- (!maxDate || plugin.newDate(year, m, 1).getTime() <= maxDate.getTime())) {
- selector += '<option value="' + m + '/' + year + '"' +
- (month == m ? ' selected="selected"' : '') + '>' +
- monthNames[m - 1] + '</option>';
- }
- }
- selector += '</select>';
- html = html.replace(/\\x2E/, selector);
-
- var yearRange = inst.options.yearRange;
- if (yearRange == 'any') {
- selector = '<select class="' + this._monthYearClass + ' ' + this._anyYearClass +
- '" title="' + inst.options.yearStatus + '">' +
- '<option>' + year + '</option></select>' +
- '<input class="' + this._monthYearClass + ' ' + this._curMonthClass +
- month + '" value="' + year + '">';
- }
- else {
- yearRange = yearRange.split(':');
- var todayYear = plugin.today().getFullYear();
- var start = (yearRange[0].match('c[+-].*') ? year + parseInt(yearRange[0].substring(1), 10) :
- ((yearRange[0].match('[+-].*') ? todayYear : 0) + parseInt(yearRange[0], 10)));
- var end = (yearRange[1].match('c[+-].*') ? year + parseInt(yearRange[1].substring(1), 10) :
- ((yearRange[1].match('[+-].*') ? todayYear : 0) + parseInt(yearRange[1], 10)));
- selector = '<select class="' + this._monthYearClass +
- '" title="' + inst.options.yearStatus + '">';
- start = plugin.add(plugin.newDate(start + 1, 1, 1), -1, 'd');
- end = plugin.newDate(end, 1, 1);
- var addYear = function(y) {
- if (y != 0) {
- selector += '<option value="' + month + '/' + y + '"' +
- (year == y ? ' selected="selected"' : '') + '>' + y + '</option>';
- }
- };
- if (start.getTime() < end.getTime()) {
- start = (minDate && minDate.getTime() > start.getTime() ? minDate : start).getFullYear();
- end = (maxDate && maxDate.getTime() < end.getTime() ? maxDate : end).getFullYear();
- for (var y = start; y <= end; y++) {
- addYear(y);
- }
- }
- else {
- start = (maxDate && maxDate.getTime() < start.getTime() ? maxDate : start).getFullYear();
- end = (minDate && minDate.getTime() > end.getTime() ? minDate : end).getFullYear();
- for (var y = start; y >= end; y--) {
- addYear(y);
- }
- }
- selector += '</select>';
- }
- html = html.replace(/\\x2F/, selector);
- return html;
- },
-
-
-
- _prepare: function(text, inst) {
- var replaceSection = function(type, retain) {
- while (true) {
- var start = text.indexOf('{' + type + ':start}');
- if (start == -1) {
- return;
- }
- var end = text.substring(start).indexOf('{' + type + ':end}');
- if (end > -1) {
- text = text.substring(0, start) +
- (retain ? text.substr(start + type.length + 8, end - type.length - 8) : '') +
- text.substring(start + end + type.length + 6);
- }
- }
- };
- replaceSection('inline', inst.inline);
- replaceSection('popup', !inst.inline);
- var pattern = /\{l10n:([^\}]+)\}/;
- var matches = null;
- while (matches = pattern.exec(text)) {
- text = text.replace(matches[0], inst.options[matches[1]]);
- }
- return text;
- }
- });
-
-
- var getters = ['getDate', 'isDisabled', 'isSelectable', 'retrieveDate'];
-
-
- function isNotChained(command, otherArgs) {
- if (command == 'option' && (otherArgs.length == 0 ||
- (otherArgs.length == 1 && typeof otherArgs[0] == 'string'))) {
- return true;
- }
- return $.inArray(command, getters) > -1;
- }
-
-
- $.fn.datepick = function(options) {
- var otherArgs = Array.prototype.slice.call(arguments, 1);
- if (isNotChained(options, otherArgs)) {
- return plugin['_' + options + 'Plugin'].apply(plugin, [this[0]].concat(otherArgs));
- }
- return this.each(function() {
- if (typeof options == 'string') {
- if (!plugin['_' + options + 'Plugin']) {
- throw 'Unknown command: ' + options;
- }
- plugin['_' + options + 'Plugin'].apply(plugin, [this].concat(otherArgs));
- }
- else {
- plugin._attachPlugin(this, options || {});
- }
- });
- };
-
-
- var plugin = $.datepick = new Datepicker();
-
- $(function() {
- $(document).mousedown(plugin._checkExternalClick).
- resize(function() { plugin._hidePlugin(plugin.curInst); });
- });
-
- })(jQuery);
|