app/jquery/jquery-ui.datetimepicker.js
changeset 1451 ef134d062b83
parent 843 a086ff3888d3
child 1452 2209a6e59870
equal deleted inserted replaced
1450:688648dfe42c 1451:ef134d062b83
     6    and GPL (GPL-LICENSE.txt) licenses.
     6    and GPL (GPL-LICENSE.txt) licenses.
     7    Date: 09-03-2007  */
     7    Date: 09-03-2007  */
     8 /*
     8 /*
     9  * Time functionality added by Stanislav Dobry (stanislav.dobry@datesoft.cz)
     9  * Time functionality added by Stanislav Dobry (stanislav.dobry@datesoft.cz)
    10  * Date: 2008-06-04
    10  * Date: 2008-06-04
       
    11  */
       
    12 /*
       
    13  * Patched by Haoyu Bai (baihaoyu@gmail.com) for date-picker only mode,
       
    14  * and better behavior. (Sync Year/Month select with input box)
    11  */
    15  */
    12 
    16 
    13 ;(function($) { // hide the namespace
    17 ;(function($) { // hide the namespace
    14 
    18 
    15 /* Date picker manager.
    19 /* Date picker manager.
    54 		firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
    58 		firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
    55 		initStatus: 'Select a date', // Initial Status text on opening
    59 		initStatus: 'Select a date', // Initial Status text on opening
    56 		isRTL: false // True if right-to-left language, false if left-to-right
    60 		isRTL: false // True if right-to-left language, false if left-to-right
    57 	};
    61 	};
    58 	this._defaults = { // Global defaults for all the date picker instances
    62 	this._defaults = { // Global defaults for all the date picker instances
       
    63         pickDateOnly: false, // If true, work as datepicker, no time-picker
    59 		showOn: 'focus', // 'focus' for popup on focus,
    64 		showOn: 'focus', // 'focus' for popup on focus,
    60 			// 'button' for trigger button, or 'both' for either
    65 			// 'button' for trigger button, or 'both' for either
    61 		showAnim: 'show', // Name of jQuery animation for popup
    66 		showAnim: 'show', // Name of jQuery animation for popup
    62 		defaultDate: null, // Used when field is blank: actual date,
    67 		defaultDate: null, // Used when field is blank: actual date,
    63 			// +/-number for offset from today, null for today
    68 			// +/-number for offset from today, null for today
   605 		var inst = this._getInst(id);
   610 		var inst = this._getInst(id);
   606 		inst._selectingMonthYear = false;
   611 		inst._selectingMonthYear = false;
   607 		inst[period == 'M' ? '_drawMonth' : '_drawYear'] =
   612 		inst[period == 'M' ? '_drawMonth' : '_drawYear'] =
   608 			select.options[select.selectedIndex].value - 0;
   613 			select.options[select.selectedIndex].value - 0;
   609 		this._adjustDate(inst);
   614 		this._adjustDate(inst);
       
   615 
       
   616 
       
   617         this._doNotHide = true;
       
   618 		$('td.datetimepicker_currentDay').each(function(){
       
   619 			$.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,$(this));
       
   620 		});
       
   621 		this._doNotHide = false;
   610 	},
   622 	},
   611 	_selectTime: function(id, select, period) {
   623 	_selectTime: function(id, select, period) {
   612 		var inst = this._getInst(id);
   624 		var inst = this._getInst(id);
   613 		inst._selectingMonthYear = false;
   625 		inst._selectingMonthYear = false;
   614 		inst[period == 'M' ? '_drawMinute' : '_drawHour'] =
   626 		inst[period == 'M' ? '_drawMinute' : '_drawHour'] =
   658 			this._stayOpen = !this._stayOpen;
   670 			this._stayOpen = !this._stayOpen;
   659 		}
   671 		}
   660 		inst._selectedDay = inst._currentDay = $('a', td).html();
   672 		inst._selectedDay = inst._currentDay = $('a', td).html();
   661 		inst._selectedMonth = inst._currentMonth = month;
   673 		inst._selectedMonth = inst._currentMonth = month;
   662 		inst._selectedYear = inst._currentYear = year;
   674 		inst._selectedYear = inst._currentYear = year;
   663 		inst._selectedHour = inst._currentHour = $('select.datetimepicker_newHour option:selected').val();
   675 
   664 		inst._selectedMinute = inst._currentMinute = $('select.datetimepicker_newMinute option:selected').val();
   676         inst._currentHour = $('select.datetimepicker_newHour option:selected').val();
       
   677         if (inst._currentHour==undefined)
       
   678             inst._currentHour = 0;
       
   679 		inst._selectedHour = inst._currentHour;
       
   680         inst._currentMinute = $('select.datetimepicker_newMinute option:selected').val();
       
   681         if (inst._currentMinute==undefined)
       
   682             inst._currentMinute = 0;
       
   683 		inst._selectedMinute = inst._currentMinute;
       
   684 
   665 		this._selectDate(id, inst._formatDateTime(
   685 		this._selectDate(id, inst._formatDateTime(
   666 			inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst._currentMinute));
   686 			inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst._currentMinute));
   667 		if (this._stayOpen) {
   687 		if (this._stayOpen) {
   668 			inst._endDay = inst._endMonth = inst._endYear = null;
   688 			inst._endDay = inst._endMonth = inst._endYear = null;
   669 			inst._rangeStart = new Date(inst._currentYear, inst._currentMonth, inst._currentDay);
   689 			inst._rangeStart = new Date(inst._currentYear, inst._currentMonth, inst._currentDay);
   791 		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
   811 		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
   792 		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
   812 		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
   793 		var year = -1;
   813 		var year = -1;
   794 		var month = -1;
   814 		var month = -1;
   795 		var day = -1;
   815 		var day = -1;
   796 		var hour = -1;
   816 		var hour = 0;
   797 		var minute = -1;
   817 		var minute = 0;
   798 		var literal = false;
   818 		var literal = false;
   799 		// Check whether a format character is doubled
   819 		// Check whether a format character is doubled
   800 		var lookAhead = function(match) {
   820 		var lookAhead = function(match) {
   801 			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
   821 			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
   802 			if (matches)
   822 			if (matches)
  1356 					(year == drawYear ? ' selected="selected"' : '') +
  1376 					(year == drawYear ? ' selected="selected"' : '') +
  1357 					'>' + year + '</option>';
  1377 					'>' + year + '</option>';
  1358 			}
  1378 			}
  1359 			html += '</select>';
  1379 			html += '</select>';
  1360 		}
  1380 		}
  1361 		// if (this._get('changeTime'))
  1381 		if (!this._get('pickDateOnly'))
  1362 		{
  1382 		{
  1363 			html += '<br />';
  1383 			html += '<br />';
  1364 			html += '<select class="datetimepicker_newHour" ' +
  1384 			html += '<select class="datetimepicker_newHour" ' +
  1365 				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'H\');" ' +
  1385 				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'H\');" ' +
  1366 				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
  1386 				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
  1406 		var minDate = this._getMinMaxDate('min', true);
  1426 		var minDate = this._getMinMaxDate('min', true);
  1407 		var maxDate = this._getMinMaxDate('max');
  1427 		var maxDate = this._getMinMaxDate('max');
  1408 		date = (minDate && date < minDate ? minDate : date);
  1428 		date = (minDate && date < minDate ? minDate : date);
  1409 		date = (maxDate && date > maxDate ? maxDate : date);
  1429 		date = (maxDate && date > maxDate ? maxDate : date);
  1410 		this._selectedDay = date.getDate();
  1430 		this._selectedDay = date.getDate();
  1411 		this._drawMonth = this._selectedMonth = date.getMonth();
  1431 		this._currentMonth = this._drawMonth = this._selectedMonth = date.getMonth();
  1412 		this._drawYear = this._selectedYear = date.getFullYear();
  1432 		this._currentYear = this._drawYear = this._selectedYear = date.getFullYear();
  1413 		this._drawHour = this._selectedHour = date.getHours();
  1433 		this._currentHour = this._drawHour = this._selectedHour = date.getHours();
  1414 		this._drawMinute = this._selectedMinute = date.getMinutes();
  1434 		this._currentMinute = this._drawMinute = this._selectedMinute = date.getMinutes();
  1415 	},
  1435 	},
  1416 
  1436 
  1417 	/* Determine the number of months to show. */
  1437 	/* Determine the number of months to show. */
  1418 	_getNumberOfMonths: function() {
  1438 	_getNumberOfMonths: function() {
  1419 		var numMonths = this._get('numberOfMonths');
  1439 		var numMonths = this._get('numberOfMonths');