app/jquery/jquery-ui.datetimepicker.js
author James Levy <jamesalexanderlevy@gmail.com>
Sun, 28 Jun 2009 14:46:31 +0200
changeset 2435 dd16e9b3c2d0
parent 2022 3d84ec6dbd03
permissions -rwxr-xr-x
Added View for Surveys. Patch by: James Levy, Daniel Diniz Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     1
/* jQuery UI Date Picker v3.4.3 (previously jQuery Calendar)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     2
   Written by Marc Grabanski (m@marcgrabanski.com) and Keith Wood (kbwood@virginbroadband.com.au).
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     3
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     4
   Copyright (c) 2007 Marc Grabanski (http://marcgrabanski.com/code/ui-datetimepicker)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     5
   Dual licensed under the MIT (MIT-LICENSE.txt)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     6
   and GPL (GPL-LICENSE.txt) licenses.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     7
   Date: 09-03-2007  */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     8
/*
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     9
 * Time functionality added by Stanislav Dobry (stanislav.dobry@datesoft.cz)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    10
 * Date: 2008-06-04
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    11
 */
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
    12
/*
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
    13
 * Patched by Haoyu Bai (baihaoyu@gmail.com) for date-picker only mode,
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
    14
 * and better behavior. (Sync Year/Month select with input box)
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
    15
 */
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    16
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    17
;(function($) { // hide the namespace
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    18
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    19
/* Date picker manager.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    20
   Use the singleton instance of this class, $.datetimepicker, to interact with the date picker.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    21
   Settings for (groups of) date pickers are maintained in an instance object
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    22
   (DatepickerInstance), allowing multiple different settings on the same page. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    23
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    24
function DateTimepicker() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    25
	this.debug = false; // Change this to true to start debugging
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    26
	this._nextId = 0; // Next ID for a date picker instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    27
	this._inst = []; // List of instances indexed by ID
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    28
	this._curInst = null; // The current instance in use
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    29
	this._disabledInputs = []; // List of date picker inputs that have been disabled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    30
	this._datetimepickerShowing = false; // True if the popup picker is showing , false if not
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    31
	this._inDialog = false; // True if showing within a "dialog", false if not
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    32
	this.regional = []; // Available regional settings, indexed by language code
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    33
	this.regional[''] = { // Default regional settings
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    34
		clearText: 'Clear', // Display text for clear link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    35
		clearStatus: 'Erase the current date', // Status text for clear link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    36
		closeText: 'Close', // Display text for close link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    37
		closeStatus: 'Close without change', // Status text for close link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    38
		prevText: '&#x3c;Prev', // Display text for previous month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    39
		prevStatus: 'Show the previous month', // Status text for previous month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    40
		nextText: 'Next&#x3e;', // Display text for next month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    41
		nextStatus: 'Show the next month', // Status text for next month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    42
		currentText: 'Today', // Display text for current month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    43
		currentStatus: 'Show the current month', // Status text for current month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    44
		monthNames: ['January','February','March','April','May','June',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    45
			'July','August','September','October','November','December'], // Names of months for drop-down and formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    46
		monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    47
		monthStatus: 'Show a different month', // Status text for selecting a month
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    48
		yearStatus: 'Show a different year', // Status text for selecting a year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    49
		weekHeader: 'Wk', // Header for the week of the year column
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    50
		weekStatus: 'Week of the year', // Status text for the week of the year column
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    51
		dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    52
		dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    53
		dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    54
		dayStatus: 'Set DD as first week day', // Status text for the day of the week selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    55
		dateStatus: 'Select DD, M d', // Status text for the date selection
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
    56
		dateFormats: ['yy-mm-dd', 'mm/dd/yy'], // All date formats accepted by the input fields
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    57
		timeFormat: 'hh:ii',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    58
		firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    59
		initStatus: 'Select a date', // Initial Status text on opening
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    60
		isRTL: false // True if right-to-left language, false if left-to-right
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    61
	};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    62
	this._defaults = { // Global defaults for all the date picker instances
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
    63
        pickDateOnly: false, // If true, work as datepicker, no time-picker
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    64
		showOn: 'focus', // 'focus' for popup on focus,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    65
			// 'button' for trigger button, or 'both' for either
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    66
		showAnim: 'show', // Name of jQuery animation for popup
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    67
		defaultDate: null, // Used when field is blank: actual date,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    68
			// +/-number for offset from today, null for today
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    69
		appendText: '', // Display text following the input box, e.g. showing the format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    70
		buttonText: '...', // Text for trigger button
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    71
		buttonImage: '', // URL for trigger button image
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    72
		buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    73
		closeAtTop: true, // True to have the clear/close at the top,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    74
			// false to have them at the bottom
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    75
		mandatory: false, // True to hide the Clear link, false to include it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    76
		hideIfNoPrevNext: false, // True to hide next/previous month links
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    77
			// if not applicable, false to just disable them
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    78
		changeMonth: true, // True if month can be selected directly, false if only prev/next
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    79
		changeYear: true, // True if year can be selected directly, false if only prev/next
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    80
		yearRange: '-10:+10', // Range of years to display in drop-down,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    81
			// either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    82
		changeFirstDay: true, // True to click on day name to change, false to remain as set
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    83
		showOtherMonths: false, // True to show dates in other months, false to leave blank
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    84
		showWeeks: false, // True to show week of the year, false to omit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    85
		calculateWeek: this.iso8601Week, // How to calculate the week of the year,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    86
			// takes a Date and returns the number of the week for it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    87
		shortYearCutoff: '+10', // Short year values < this are in the current century,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    88
			// > this are in the previous century,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    89
			// string value starting with '+' for current year + value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    90
		showStatus: false, // True to show status bar at bottom, false to not show it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    91
		statusForDate: this.dateStatus, // Function to provide status text for a date -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    92
			// takes date and instance as parameters, returns display text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    93
		minDate: null, // The earliest selectable date, or null for no limit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    94
		maxDate: null, // The latest selectable date, or null for no limit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    95
		speed: 'normal', // Speed of display/closure
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    96
		beforeShowDay: null, // Function that takes a date and returns an array with
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    97
			// [0] = true if selectable, false if not,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    98
			// [1] = custom CSS class name(s) or '', e.g. $.datetimepicker.noWeekends
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    99
		beforeShow: null, // Function that takes an input field and
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   100
			// returns a set of custom settings for the date picker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   101
		onSelect: null, // Define a callback function when a date is selected
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   102
		onClose: null, // Define a callback function when the datetimepicker is closed
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   103
		numberOfMonths: 1, // Number of months to show at a time
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   104
		stepMonths: 1, // Number of months to step back/forward
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   105
		rangeSelect: false, // Allows for selecting a date range on one date picker
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   106
		rangeSeparator: ' - ', // Text between two dates in a range
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   107
		dateFormat: 'yy-mm-dd' // A default date format. See format options on parseDate
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   108
	};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   109
	$.extend(this._defaults, this.regional['']);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   110
	this._datetimepickerDiv = $('<div id="datetimepicker_div"></div>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   111
}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   112
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   113
$.extend(DateTimepicker.prototype, {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   114
	/* Class name added to elements to indicate already configured with a date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   115
	markerClassName: 'hasDatepicker',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   116
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   117
	/* Debug logging (if enabled). */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   118
	log: function () {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   119
		if (this.debug)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   120
			console.log.apply('', arguments);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   121
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   122
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   123
	/* Register a new date picker instance - with custom settings. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   124
	_register: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   125
		var id = this._nextId++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   126
		this._inst[id] = inst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   127
		return id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   128
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   129
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   130
	/* Retrieve a particular date picker instance based on its ID. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   131
	_getInst: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   132
		return this._inst[id] || id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   133
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   134
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   135
	/* Override the default settings for all instances of the date picker.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   136
	   @param  settings  object - the new settings to use as defaults (anonymous object)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   137
	   @return the manager object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   138
	setDefaults: function(settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   139
		extendRemove(this._defaults, settings || {});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   140
		return this;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   141
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   142
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   143
	/* Attach the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   144
	   @param  target    element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   145
	   @param  settings  object - the new settings to use for this date picker instance (anonymous) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   146
	_attachDatepicker: function(target, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   147
		// check for settings on the control itself - in namespace 'date:'
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   148
		var inlineSettings = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   149
		for (attrName in this._defaults) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   150
			var attrValue = target.getAttribute('date:' + attrName);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   151
			if (attrValue) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   152
				inlineSettings = inlineSettings || {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   153
				try {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   154
					inlineSettings[attrName] = eval(attrValue);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   155
				} catch (err) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   156
					inlineSettings[attrName] = attrValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   157
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   158
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   159
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   160
		var nodeName = target.nodeName.toLowerCase();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   161
		var instSettings = (inlineSettings ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   162
			$.extend(settings || {}, inlineSettings || {}) : settings);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   163
		if (nodeName == 'input') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   164
			var inst = (inst && !inlineSettings ? inst :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   165
				new DateTimepickerInstance(instSettings, false));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   166
			this._connectDatepicker(target, inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   167
		} else if (nodeName == 'div' || nodeName == 'span') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   168
			var inst = new DateTimepickerInstance(instSettings, true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   169
			this._inlineDatepicker(target, inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   170
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   171
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   172
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   173
	/* Detach a datetimepicker from its control.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   174
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   175
	_destroyDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   176
		var nodeName = target.nodeName.toLowerCase();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   177
		var calId = target._calId;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   178
		target._calId = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   179
		var $target = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   180
		if (nodeName == 'input') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   181
			$target.siblings('.datetimepicker_append').replaceWith('').end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   182
				.siblings('.datetimepicker_trigger').replaceWith('').end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   183
				.removeClass(this.markerClassName)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   184
				.unbind('focus', this._showDatepicker)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   185
				.unbind('keydown', this._doKeyDown)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   186
				.unbind('keypress', this._doKeyPress);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   187
			var wrapper = $target.parents('.datetimepicker_wrap');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   188
			if (wrapper)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   189
				wrapper.replaceWith(wrapper.html());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   190
		} else if (nodeName == 'div' || nodeName == 'span')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   191
			$target.removeClass(this.markerClassName).empty();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   192
		if ($('input[_calId=' + calId + ']').length == 0)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   193
			// clean up if last for this ID
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   194
			this._inst[calId] = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   195
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   196
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   197
	/* Enable the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   198
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   199
	_enableDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   200
		target.disabled = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   201
		$(target).siblings('button.datetimepicker_trigger').each(function() { this.disabled = false; }).end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   202
			.siblings('img.datetimepicker_trigger').css({opacity: '1.0', cursor: ''});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   203
		this._disabledInputs = $.map(this._disabledInputs,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   204
			function(value) { return (value == target ? null : value); }); // delete entry
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   205
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   206
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   207
	/* Disable the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   208
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   209
	_disableDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   210
		target.disabled = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   211
		$(target).siblings('button.datetimepicker_trigger').each(function() { this.disabled = true; }).end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   212
			.siblings('img.datetimepicker_trigger').css({opacity: '0.5', cursor: 'default'});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   213
		this._disabledInputs = $.map($.datetimepicker._disabledInputs,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   214
			function(value) { return (value == target ? null : value); }); // delete entry
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   215
		this._disabledInputs[$.datetimepicker._disabledInputs.length] = target;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   216
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   217
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   218
	/* Is the first field in a jQuery collection disabled as a datetimepicker?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   219
	   @param  target    element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   220
	   @return boolean - true if disabled, false if enabled */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   221
	_isDisabledDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   222
		if (!target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   223
			return false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   224
		for (var i = 0; i < this._disabledInputs.length; i++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   225
			if (this._disabledInputs[i] == target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   226
				return true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   227
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   228
		return false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   229
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   230
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   231
	/* Update the settings for a date picker attached to an input field or division.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   232
	   @param  target  element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   233
	   @param  name    string - the name of the setting to change or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   234
	                   object - the new settings to update
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   235
	   @param  value   any - the new value for the setting (omit if above is an object) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   236
	_changeDatepicker: function(target, name, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   237
		var settings = name || {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   238
		if (typeof name == 'string') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   239
			settings = {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   240
			settings[name] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   241
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   242
		if (inst = this._getInst(target._calId)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   243
			extendRemove(inst._settings, settings);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   244
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   245
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   246
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   247
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   248
	/* Set the dates for a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   249
	   @param  target   element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   250
	   @param  date     Date - the new date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   251
	   @param  endDate  Date - the new end date for a range (optional) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   252
	_setDateDatepicker: function(target, date, endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   253
		if (inst = this._getInst(target._calId)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   254
			inst._setDate(date, endDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   255
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   256
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   257
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   258
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   259
	/* Get the date(s) for the first entry in a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   260
	   @param  target  element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   261
	   @return Date - the current date or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   262
	           Date[2] - the current dates for a range */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   263
	_getDateDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   264
		var inst = this._getInst(target._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   265
		return (inst ? inst._getDate() : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   266
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   267
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   268
	/* Handle keystrokes. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   269
	_doKeyDown: function(e) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   270
		var inst = $.datetimepicker._getInst(this._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   271
		if ($.datetimepicker._datetimepickerShowing)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   272
			switch (e.keyCode) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   273
				case 9:  $.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   274
						break; // hide on tab out
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   275
				case 13: $.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   276
							$('td.datetimepicker_daysCellOver', inst._datetimepickerDiv)[0]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   277
						return false; // don't submit the form
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   278
						break; // select the value on enter
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   279
				case 27: $.datetimepicker._hideDatepicker(null, inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   280
						break; // hide on escape
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   281
				case 33: $.datetimepicker._adjustDate(inst,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   282
							(e.ctrlKey ? -1 : -inst._get('stepMonths')), (e.ctrlKey ? 'Y' : 'M'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   283
						break; // previous month/year on page up/+ ctrl
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   284
				case 34: $.datetimepicker._adjustDate(inst,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   285
							(e.ctrlKey ? +1 : +inst._get('stepMonths')), (e.ctrlKey ? 'Y' : 'M'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   286
						break; // next month/year on page down/+ ctrl
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   287
				case 35: if (e.ctrlKey) $.datetimepicker._clearDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   288
						break; // clear on ctrl+end
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   289
				case 36: if (e.ctrlKey) $.datetimepicker._gotoToday(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   290
						break; // current on ctrl+home
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   291
				case 37: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, -1, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   292
						break; // -1 day on ctrl+left
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   293
				case 38: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, -7, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   294
						break; // -1 week on ctrl+up
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   295
				case 39: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, +1, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   296
						break; // +1 day on ctrl+right
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   297
				case 40: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, +7, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   298
						break; // +1 week on ctrl+down
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   299
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   300
		else if (e.keyCode == 36 && e.ctrlKey) // display the date picker on ctrl+home
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   301
			$.datetimepicker._showDatepicker(this);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   302
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   303
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   304
	/* Filter entered characters - based on date format. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   305
	_doKeyPress: function(e) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   306
		var inst = $.datetimepicker._getInst(this._calId);
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   307
		var formats = ' '+ inst._get('timeFormat');
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   308
		var dateFormats = inst._get('dateFormats');
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   309
		for (var i = 0; i < dateFormats.length; i++)
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   310
			formats += dateFormats[i];
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   311
		var chars = $.datetimepicker._possibleChars(formats);
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   312
		var chr = String.fromCharCode(e.charCode == undefined ? e.keyCode : e.charCode);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   313
		return e.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   314
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   315
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   316
	/* Attach the date picker to an input field. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   317
	_connectDatepicker: function(target, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   318
		var input = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   319
		if (input.is('.' + this.markerClassName))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   320
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   321
		var appendText = inst._get('appendText');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   322
		var isRTL = inst._get('isRTL');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   323
		if (appendText) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   324
			if (isRTL)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   325
				input.before('<span class="datetimepicker_append">' + appendText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   326
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   327
				input.after('<span class="datetimepicker_append">' + appendText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   328
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   329
		var showOn = inst._get('showOn');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   330
		if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   331
			input.focus(this._showDatepicker);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   332
		if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   333
			input.wrap('<span class="datetimepicker_wrap">');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   334
			var buttonText = inst._get('buttonText');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   335
			var buttonImage = inst._get('buttonImage');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   336
			var trigger = $(inst._get('buttonImageOnly') ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   337
				$('<img>').addClass('datetimepicker_trigger').attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   338
				$('<button>').addClass('datetimepicker_trigger').attr({ type: 'button' }).html(buttonImage != '' ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   339
						$('<img>').attr({ src:buttonImage, alt:buttonText, title:buttonText }) : buttonText));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   340
			if (isRTL)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   341
				input.before(trigger);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   342
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   343
				input.after(trigger);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   344
			trigger.click(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   345
				if ($.datetimepicker._datetimepickerShowing && $.datetimepicker._lastInput == target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   346
					$.datetimepicker._hideDatepicker();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   347
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   348
					$.datetimepicker._showDatepicker(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   349
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   350
        }
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   351
		input.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   352
			.bind("setData.datetimepicker", function(event, key, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   353
				inst._settings[key] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   354
			}).bind("getData.datetimepicker", function(event, key) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   355
				return inst._get(key);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   356
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   357
		input[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   358
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   359
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   360
	/* Attach an inline date picker to a div. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   361
	_inlineDatepicker: function(target, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   362
		var input = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   363
		if (input.is('.' + this.markerClassName))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   364
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   365
		input.addClass(this.markerClassName).append(inst._datetimepickerDiv)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   366
			.bind("setData.datetimepicker", function(event, key, value){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   367
				inst._settings[key] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   368
			}).bind("getData.datetimepicker", function(event, key){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   369
				return inst._get(key);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   370
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   371
		input[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   372
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   373
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   374
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   375
	/* Tidy up after displaying the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   376
	_inlineShow: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   377
		var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   378
		inst._datetimepickerDiv.width(numMonths[1] * $('.datetimepicker', inst._datetimepickerDiv[0]).width());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   379
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   380
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   381
	/* Pop-up the date picker in a "dialog" box.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   382
	   @param  input     element - ignored
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   383
	   @param  dateText  string - the initial date to display (in the current format)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   384
	   @param  onSelect  function - the function(dateText) to call when a date is selected
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   385
	   @param  settings  object - update the dialog date picker instance's settings (anonymous object)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   386
	   @param  pos       int[2] - coordinates for the dialog's position within the screen or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   387
	                     event - with x/y coordinates or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   388
	                     leave empty for default (screen centre)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   389
	   @return the manager object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   390
	_dialogDatepicker: function(input, dateText, onSelect, settings, pos) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   391
		var inst = this._dialogInst; // internal instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   392
		if (!inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   393
			inst = this._dialogInst = new DateTimepickerInstance({}, false);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   394
			this._dialogInput = $('<input type="text" size="1" style="position: absolute; top: -100px;"/>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   395
			this._dialogInput.keydown(this._doKeyDown);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   396
			$('body').append(this._dialogInput);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   397
			this._dialogInput[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   398
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   399
		extendRemove(inst._settings, settings || {});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   400
		this._dialogInput.val(dateText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   401
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   402
		this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   403
		if (!this._pos) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   404
			var browserWidth = window.innerWidth || document.documentElement.clientWidth ||	document.body.clientWidth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   405
			var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   406
			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   407
			var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   408
			this._pos = // should use actual width/height below
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   409
				[(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   410
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   411
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   412
		// move input on screen for focus, but hidden behind dialog
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   413
		this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   414
		inst._settings.onSelect = onSelect;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   415
		this._inDialog = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   416
		this._datetimepickerDiv.addClass('datetimepicker_dialog');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   417
		this._showDatepicker(this._dialogInput[0]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   418
		if ($.blockUI)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   419
			$.blockUI(this._datetimepickerDiv);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   420
		return this;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   421
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   422
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   423
	/* Pop-up the date picker for a given input field.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   424
	   @param  input  element - the input field attached to the date picker or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   425
	                  event - if triggered by focus */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   426
	_showDatepicker: function(input) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   427
		input = input.target || input;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   428
		if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   429
			input = $('input', input.parentNode)[0];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   430
		if ($.datetimepicker._isDisabledDatepicker(input) || $.datetimepicker._lastInput == input) // already here
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   431
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   432
		var inst = $.datetimepicker._getInst(input._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   433
		var beforeShow = inst._get('beforeShow');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   434
		extendRemove(inst._settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   435
		$.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   436
		$.datetimepicker._lastInput = input;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   437
		inst._setDateFromField(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   438
		if ($.datetimepicker._inDialog) // hide cursor
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   439
			input.value = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   440
		if (!$.datetimepicker._pos) { // position below input
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   441
			$.datetimepicker._pos = $.datetimepicker._findPos(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   442
			$.datetimepicker._pos[1] += input.offsetHeight; // add the height
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   443
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   444
		var isFixed = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   445
		$(input).parents().each(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   446
			isFixed |= $(this).css('position') == 'fixed';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   447
		});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   448
		if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   449
			$.datetimepicker._pos[0] -= document.documentElement.scrollLeft;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   450
			$.datetimepicker._pos[1] -= document.documentElement.scrollTop;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   451
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   452
		inst._datetimepickerDiv.css('position', ($.datetimepicker._inDialog && $.blockUI ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   453
			'static' : (isFixed ? 'fixed' : 'absolute')))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   454
			.css({ left: $.datetimepicker._pos[0] + 'px', top: $.datetimepicker._pos[1] + 'px' });
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   455
		$.datetimepicker._pos = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   456
		inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   457
		$.datetimepicker._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   458
		if (!inst._inline) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   459
			var speed = inst._get('speed');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   460
			var postProcess = function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   461
				$.datetimepicker._datetimepickerShowing = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   462
				$.datetimepicker._afterShow(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   463
			};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   464
			var showAnim = inst._get('showAnim') || 'show';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   465
			inst._datetimepickerDiv[showAnim](speed, postProcess);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   466
			if (speed == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   467
				postProcess();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   468
			if (inst._input[0].type != 'hidden')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   469
				inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   470
			$.datetimepicker._curInst = inst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   471
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   472
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   473
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   474
	/* Generate the date picker content. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   475
	_updateDatepicker: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   476
		inst._datetimepickerDiv.empty().append(inst._generateDatepicker());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   477
		var numMonths = inst._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   478
		if (numMonths[0] != 1 || numMonths[1] != 1)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   479
			inst._datetimepickerDiv.addClass('datetimepicker_multi');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   480
		else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   481
			inst._datetimepickerDiv.removeClass('datetimepicker_multi');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   482
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   483
		if (inst._get('isRTL'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   484
			inst._datetimepickerDiv.addClass('datetimepicker_rtl');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   485
		else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   486
			inst._datetimepickerDiv.removeClass('datetimepicker_rtl');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   487
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   488
		if (inst._input && inst._input[0].type != 'hidden')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   489
			$(inst._input[0]).focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   490
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   491
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   492
	/* Tidy up after displaying the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   493
	_afterShow: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   494
		var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   495
		inst._datetimepickerDiv.width(numMonths[1] * $('.datetimepicker', inst._datetimepickerDiv[0])[0].offsetWidth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   496
		if ($.browser.msie && parseInt($.browser.version) < 7) { // fix IE < 7 select problems
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   497
			$('iframe.datetimepicker_cover').css({width: inst._datetimepickerDiv.width() + 4,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   498
				height: inst._datetimepickerDiv.height() + 4});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   499
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   500
		// re-position on screen if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   501
		var isFixed = inst._datetimepickerDiv.css('position') == 'fixed';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   502
		var pos = inst._input ? $.datetimepicker._findPos(inst._input[0]) : null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   503
		var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   504
		var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   505
		var scrollX = (isFixed ? 0 : document.documentElement.scrollLeft || document.body.scrollLeft);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   506
		var scrollY = (isFixed ? 0 : document.documentElement.scrollTop || document.body.scrollTop);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   507
		// reposition date picker horizontally if outside the browser window
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   508
		if ((inst._datetimepickerDiv.offset().left + inst._datetimepickerDiv.width() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   509
				(isFixed && $.browser.msie ? document.documentElement.scrollLeft : 0)) >
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   510
				(browserWidth + scrollX)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   511
			inst._datetimepickerDiv.css('left', Math.max(scrollX,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   512
				pos[0] + (inst._input ? $(inst._input[0]).width() : null) - inst._datetimepickerDiv.width() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   513
				(isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)) + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   514
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   515
		// reposition date picker vertically if outside the browser window
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   516
		if ((inst._datetimepickerDiv.offset().top + inst._datetimepickerDiv.height() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   517
				(isFixed && $.browser.msie ? document.documentElement.scrollTop : 0)) >
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   518
				(browserHeight + scrollY) ) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   519
			inst._datetimepickerDiv.css('top', Math.max(scrollY,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   520
				pos[1] - (this._inDialog ? 0 : inst._datetimepickerDiv.height()) -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   521
				(isFixed && $.browser.opera ? document.documentElement.scrollTop : 0)) + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   522
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   523
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   524
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   525
	/* Find an object's position on the screen. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   526
	_findPos: function(obj) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   527
        while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   528
            obj = obj.nextSibling;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   529
        }
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   530
        var position = $(obj).offset();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   531
	    return [position.left, position.top];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   532
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   533
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   534
	/* Hide the date picker from view.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   535
	   @param  input  element - the input field attached to the date picker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   536
	   @param  speed  string - the speed at which to close the date picker */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   537
	_hideDatepicker: function(input, speed) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   538
		var inst = this._curInst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   539
		if (!inst)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   540
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   541
		var rangeSelect = inst._get('rangeSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   542
		if (rangeSelect && this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   543
			this._selectDate(inst, inst._formatDateTime(
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   544
				inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst.currentMinute));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   545
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   546
		this._stayOpen = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   547
		if (this._datetimepickerShowing) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   548
			speed = (speed != null ? speed : inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   549
			var showAnim = inst._get('showAnim');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   550
			inst._datetimepickerDiv[(showAnim == 'slideDown' ? 'slideUp' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   551
				(showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))](speed, function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   552
				$.datetimepicker._tidyDialog(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   553
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   554
			if (speed == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   555
				this._tidyDialog(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   556
			var onClose = inst._get('onClose');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   557
			if (onClose) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   558
				onClose.apply((inst._input ? inst._input[0] : null),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   559
					[inst._getDate(), inst]);  // trigger custom callback
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   560
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   561
			this._datetimepickerShowing = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   562
			this._lastInput = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   563
			inst._settings.prompt = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   564
			if (this._inDialog) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   565
				this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   566
				if ($.blockUI) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   567
					$.unblockUI();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   568
					$('body').append(this._datetimepickerDiv);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   569
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   570
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   571
			this._inDialog = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   572
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   573
		this._curInst = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   574
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   575
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   576
	/* Tidy up after a dialog display. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   577
	_tidyDialog: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   578
		inst._datetimepickerDiv.removeClass('datetimepicker_dialog').unbind('.datetimepicker');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   579
		$('.datetimepicker_prompt', inst._datetimepickerDiv).remove();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   580
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   581
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   582
	/* Close date picker if clicked elsewhere. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   583
	_checkExternalClick: function(event) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   584
		if (!$.datetimepicker._curInst)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   585
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   586
		var $target = $(event.target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   587
		if (($target.parents("#datetimepicker_div").length == 0) &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   588
				($target.attr('class') != 'datetimepicker_trigger') &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   589
				$.datetimepicker._datetimepickerShowing && !($.datetimepicker._inDialog && $.blockUI)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   590
			$.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   591
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   592
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   593
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   594
	/* Adjust one of the date sub-fields. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   595
	_adjustDate: function(id, offset, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   596
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   597
		inst._adjustDate(offset, period);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   598
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   599
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   600
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   601
	/* Action for current link. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   602
	_gotoToday: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   603
		var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   604
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   605
		inst._selectedDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   606
		inst._drawMonth = inst._selectedMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   607
		inst._drawYear = inst._selectedYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   608
		inst._drawHour = inst._selectedHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   609
		inst._drawMinute = inst._selectedMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   610
		this._adjustDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   611
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   612
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   613
	/* Action for selecting a new month/year. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   614
	_selectMonthYear: function(id, select, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   615
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   616
		inst._selectingMonthYear = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   617
		inst[period == 'M' ? '_drawMonth' : '_drawYear'] =
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   618
			select.options[select.selectedIndex].value - 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   619
		this._adjustDate(inst);
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   620
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   621
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   622
        this._doNotHide = true;
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   623
		$('td.datetimepicker_currentDay').each(function(){
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   624
			$.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,$(this));
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   625
		});
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   626
		this._doNotHide = false;
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   627
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   628
	_selectTime: function(id, select, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   629
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   630
		inst._selectingMonthYear = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   631
		inst[period == 'M' ? '_drawMinute' : '_drawHour'] =
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   632
			select.options[select.selectedIndex].value - 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   633
		this._adjustDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   634
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   635
		this._doNotHide = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   636
		$('td.datetimepicker_currentDay').each(function(){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   637
			$.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,$(this));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   638
		});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   639
		this._doNotHide = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   640
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   641
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   642
	/* Restore input focus after not changing month/year. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   643
	_clickMonthYear: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   644
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   645
		if (inst._input && inst._selectingMonthYear && !$.browser.msie)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   646
			inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   647
		inst._selectingMonthYear = !inst._selectingMonthYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   648
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   649
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   650
	_clickTime: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   651
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   652
		if (inst._input && inst._selectingTime && !$.browser.msie)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   653
			inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   654
		inst._selectingTime = !inst._selectingTime;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   655
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   656
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   657
	/* Action for changing the first week day. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   658
	_changeFirstDay: function(id, day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   659
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   660
		inst._settings.firstDay = day;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   661
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   662
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   663
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   664
	/* Action for selecting a day. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   665
	_selectDay: function(id, month, year, td) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   666
		if ($(td).is('.datetimepicker_unselectable'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   667
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   668
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   669
		var rangeSelect = inst._get('rangeSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   670
		if (rangeSelect) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   671
			if (!this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   672
				$('.datetimepicker td').removeClass('datetimepicker_currentDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   673
				$(td).addClass('datetimepicker_currentDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   674
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   675
			this._stayOpen = !this._stayOpen;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   676
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   677
		inst._selectedDay = inst._currentDay = $('a', td).html();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   678
		inst._selectedMonth = inst._currentMonth = month;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   679
		inst._selectedYear = inst._currentYear = year;
1452
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   680
    inst._currentHour = $('select.datetimepicker_newHour option:selected').val();
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   681
    if (inst._currentHour == undefined)
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   682
      inst._currentHour = 0;
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   683
		inst._selectedHour = inst._currentHour;
1452
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   684
    inst._currentMinute = $('select.datetimepicker_newMinute option:selected').val();
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   685
    if (inst._currentMinute == undefined)
2209a6e59870 Style fixes in jquery-ui.datetimepicker.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1451
diff changeset
   686
      inst._currentMinute = 0;
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   687
		inst._selectedMinute = inst._currentMinute;
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   688
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   689
		this._selectDate(id, inst._formatDateTime(
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   690
			inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst._currentMinute));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   691
		if (this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   692
			inst._endDay = inst._endMonth = inst._endYear = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   693
			inst._rangeStart = new Date(inst._currentYear, inst._currentMonth, inst._currentDay);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   694
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   695
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   696
		else if (rangeSelect) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   697
			inst._endDay = inst._currentDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   698
			inst._endMonth = inst._currentMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   699
			inst._endYear = inst._currentYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   700
			inst._selectedDay = inst._currentDay = inst._rangeStart.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   701
			inst._selectedMonth = inst._currentMonth = inst._rangeStart.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   702
			inst._selectedYear = inst._currentYear = inst._rangeStart.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   703
			inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   704
			if (inst._inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   705
				this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   706
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   707
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   708
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   709
	/* Erase the input field and hide the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   710
	_clearDate: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   711
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   712
		if (inst._get('mandatory'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   713
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   714
		this._stayOpen = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   715
		inst._endDay = inst._endMonth = inst._endYear = inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   716
		this._selectDate(inst, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   717
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   718
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   719
	/* Update the input field with the selected date. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   720
	_selectDate: function(id, dateStr) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   721
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   722
		dateStr = (dateStr != null ? dateStr : inst._formatDateTime());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   723
		if (inst._rangeStart)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   724
			dateStr = inst._formatDateTime(inst._rangeStart) + inst._get('rangeSeparator') + dateStr;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   725
		if (inst._input)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   726
			inst._input.val(dateStr);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   727
		var onSelect = inst._get('onSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   728
		if (onSelect)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   729
			onSelect.apply((inst._input ? inst._input[0] : null), [dateStr, inst]);  // trigger custom callback
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   730
		else if (inst._input)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   731
			inst._input.trigger('change'); // fire the change event
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   732
		if (inst._inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   733
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   734
		else if (!this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   735
			if (! this._doNotHide) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   736
				this._hideDatepicker(null, inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   737
				this._lastInput = inst._input[0];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   738
				if (typeof(inst._input[0]) != 'object')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   739
					inst._input[0].focus(); // restore focus
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   740
				this._lastInput = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   741
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   742
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   743
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   744
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   745
	/* Set as beforeShowDay function to prevent selection of weekends.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   746
	   @param  date  Date - the date to customise
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   747
	   @return [boolean, string] - is this date selectable?, what is its CSS class? */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   748
	noWeekends: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   749
		var day = date.getDay();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   750
		return [(day > 0 && day < 6), ''];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   751
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   752
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   753
	/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   754
	   @param  date  Date - the date to get the week for
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   755
	   @return  number - the number of the week within the year that contains this date */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   756
	iso8601Week: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   757
		var checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), (date.getTimezoneOffset() / -60));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   758
		var firstMon = new Date(checkDate.getFullYear(), 1 - 1, 4); // First week always contains 4 Jan
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   759
		var firstDay = firstMon.getDay() || 7; // Day of week: Mon = 1, ..., Sun = 7
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   760
		firstMon.setDate(firstMon.getDate() + 1 - firstDay); // Preceding Monday
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   761
		if (firstDay < 4 && checkDate < firstMon) { // Adjust first three days in year if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   762
			checkDate.setDate(checkDate.getDate() - 3); // Generate for previous year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   763
			return $.datetimepicker.iso8601Week(checkDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   764
		} else if (checkDate > new Date(checkDate.getFullYear(), 12 - 1, 28)) { // Check last three days in year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   765
			firstDay = new Date(checkDate.getFullYear() + 1, 1 - 1, 4).getDay() || 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   766
			if (firstDay > 4 && (checkDate.getDay() || 7) < firstDay - 3) { // Adjust if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   767
				checkDate.setDate(checkDate.getDate() + 3); // Generate for next year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   768
				return $.datetimepicker.iso8601Week(checkDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   769
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   770
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   771
		return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   772
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   773
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   774
	/* Provide status text for a particular date.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   775
	   @param  date  the date to get the status for
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   776
	   @param  inst  the current datetimepicker instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   777
	   @return  the status display text for this date */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   778
	dateStatus: function(date, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   779
		return $.datetimepicker.formatDate(inst._get('dateStatus'), date, inst._getFormatConfig());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   780
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   781
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   782
	/* Parse a string value into a date object.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   783
	   The format can be combinations of the following:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   784
	   d  - day of month (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   785
	   dd - day of month (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   786
	   D  - day name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   787
	   DD - day name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   788
	   m  - month of year (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   789
	   mm - month of year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   790
	   M  - month name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   791
	   MM - month name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   792
	   y  - year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   793
	   yy - year (four digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   794
	   '...' - literal text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   795
	   '' - single quote
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   796
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   797
	   @param  format           String - the expected format of the date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   798
	   @param  value            String - the date in the above format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   799
	   @param  settings  Object - attributes include:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   800
	                     shortYearCutoff  Number - the cutoff year for determining the century (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   801
	                     dayNamesShort    String[7] - abbreviated names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   802
	                     dayNames         String[7] - names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   803
	                     monthNamesShort  String[12] - abbreviated names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   804
	                     monthNames       String[12] - names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   805
	   @return  Date - the extracted date value or null if value is blank */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   806
	parseDate: function (format, value, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   807
		if (format == null || value == null)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   808
			throw 'Invalid arguments';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   809
		value = (typeof value == 'object' ? value.toString() : value + '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   810
		if (value == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   811
			return null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   812
		var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   813
		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   814
		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   815
		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   816
		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   817
		var year = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   818
		var month = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   819
		var day = -1;
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   820
		var hour = 0;
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
   821
		var minute = 0;
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   822
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   823
		// Check whether a format character is doubled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   824
		var lookAhead = function(match) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   825
			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   826
			if (matches)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   827
				iFormat++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   828
			return matches;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   829
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   830
		// Extract a number from the string value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   831
		var getNumber = function(match) {
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   832
			matches = lookAhead(match);
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   833
			var size = ((match == 'y' && matches) ? 4 : 2);
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   834
			var num = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   835
			while (size > 0 && iValue < value.length &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   836
					value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') {
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   837
				num = num * 10 + (value.charAt(iValue++) - '0');
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   838
				size--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   839
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   840
			if (size == (match == 'y' ? 4 : 2))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   841
				throw 'Missing number at position ' + iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   842
			return num;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   843
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   844
		// Extract a name from the string value and convert to an index
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   845
		var getName = function(match, shortNames, longNames) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   846
			var names = (lookAhead(match) ? longNames : shortNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   847
			var size = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   848
			for (var j = 0; j < names.length; j++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   849
				size = Math.max(size, names[j].length);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   850
			var name = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   851
			var iInit = iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   852
			while (size > 0 && iValue < value.length) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   853
				name += value.charAt(iValue++);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   854
				for (var i = 0; i < names.length; i++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   855
					if (name == names[i])
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   856
						return i + 1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   857
				size--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   858
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   859
			throw 'Unknown name at position ' + iInit;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   860
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   861
		// Confirm that a literal character matches the string value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   862
		var checkLiteral = function() {
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
   863
			if (iValue < value.length && (value.charAt(iValue) != format.charAt(iFormat)))
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   864
				throw 'Unexpected literal at position ' + iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   865
			iValue++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   866
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   867
		var iValue = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   868
		for (var iFormat = 0; iFormat < format.length; iFormat++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   869
			if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   870
				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   871
					literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   872
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   873
					checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   874
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   875
				switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   876
					case 'h':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   877
						hour = getNumber('h');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   878
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   879
					case 'i':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   880
						minute = getNumber('i');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   881
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   882
					case 'd':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   883
						day = getNumber('d');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   884
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   885
					case 'D':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   886
						getName('D', dayNamesShort, dayNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   887
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   888
					case 'm':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   889
						month = getNumber('m');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   890
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   891
					case 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   892
						month = getName('M', monthNamesShort, monthNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   893
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   894
					case 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   895
						year = getNumber('y');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   896
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   897
					case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   898
						if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   899
							checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   900
						else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   901
							literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   902
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   903
					default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   904
						checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   905
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   906
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   907
		if (year < 100) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   908
			year += new Date().getFullYear() - new Date().getFullYear() % 100 +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   909
				(year <= shortYearCutoff ? 0 : -100);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   910
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   911
		var date = new Date(year, month - 1, day,hour,minute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   912
		if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   913
			throw 'Invalid date'; // E.g. 31/02/*
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   914
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   915
		return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   916
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   917
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   918
	/* Format a date object into a string value.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   919
	   The format can be combinations of the following:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   920
	   d  - day of month (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   921
	   dd - day of month (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   922
	   D  - day name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   923
	   DD - day name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   924
	   m  - month of year (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   925
	   mm - month of year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   926
	   M  - month name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   927
	   MM - month name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   928
	   y  - year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   929
	   yy - year (four digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   930
	   '...' - literal text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   931
	   '' - single quote
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   932
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   933
	   @param  format    String - the desired format of the date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   934
	   @param  date      Date - the date value to format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   935
	   @param  settings  Object - attributes include:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   936
	                     dayNamesShort    String[7] - abbreviated names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   937
	                     dayNames         String[7] - names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   938
	                     monthNamesShort  String[12] - abbreviated names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   939
	                     monthNames       String[12] - names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   940
	   @return  String - the date in the above format */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   941
	formatDate: function (format, date, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   942
		if (!date)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   943
			return '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   944
		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   945
		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   946
		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   947
		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   948
		// Check whether a format character is doubled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   949
		var lookAhead = function(match) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   950
			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   951
			if (matches)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   952
				iFormat++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   953
			return matches;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   954
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   955
		// Format a number, with leading zero if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   956
		var formatNumber = function(match, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   957
			return (lookAhead(match) && value < 10 ? '0' : '') + value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   958
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   959
		// Format a name, short or long as requested
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   960
		var formatName = function(match, value, shortNames, longNames) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   961
			return (lookAhead(match) ? longNames[value] : shortNames[value]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   962
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   963
		var output = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   964
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   965
		if (date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   966
			for (var iFormat = 0; iFormat < format.length; iFormat++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   967
				if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   968
					if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   969
						literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   970
					else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   971
						output += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   972
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   973
					switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   974
						case 'h':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   975
							output += formatNumber('h', date.getHours());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   976
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   977
						case 'i':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   978
							output += formatNumber('i', date.getMinutes());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   979
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   980
						case 'd':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   981
							output += formatNumber('d', date.getDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   982
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   983
						case 'D':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   984
							output += formatName('D', date.getDay(), dayNamesShort, dayNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   985
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   986
						case 'm':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   987
							output += formatNumber('m', date.getMonth() + 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   988
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   989
						case 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   990
							output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   991
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   992
						case 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   993
							output += (lookAhead('y') ? date.getFullYear() :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   994
								(date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   995
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   996
						case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   997
							if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   998
								output += "'";
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   999
							else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1000
								literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1001
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1002
						default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1003
							output += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1004
					}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1005
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1006
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1007
		return output;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1008
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1009
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1010
	/* Extract all possible characters from the date format. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1011
	_possibleChars: function (format) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1012
		var chars = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1013
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1014
		for (var iFormat = 0; iFormat < format.length; iFormat++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1015
			if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1016
				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1017
					literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1018
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1019
					chars += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1020
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1021
				switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1022
					case 'd' || 'm' || 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1023
						chars += '0123456789';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1024
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1025
					case 'D' || 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1026
						return null; // Accept anything
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1027
					case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1028
						if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1029
							chars += "'";
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1030
						else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1031
							literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1032
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1033
					default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1034
						chars += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1035
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1036
		return chars;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1037
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1038
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1039
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1040
/* Individualised settings for date picker functionality applied to one or more related inputs.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1041
   Instances are managed and manipulated through the Datepicker manager. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1042
function DateTimepickerInstance(settings, inline) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1043
	this._id = $.datetimepicker._register(this);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1044
	this._selectedDay = 0; // Current date for selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1045
	this._selectedMonth = 0; // 0-11
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1046
	this._selectedYear = 0; // 4-digit year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1047
	this._drawMonth = 0; // Current month at start of datetimepicker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1048
	this._drawYear = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1049
	this._drawHour = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1050
	this._drawMinute = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1051
	this._input = null; // The attached input field
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1052
	this._inline = inline; // True if showing inline, false if used in a popup
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1053
	this._datetimepickerDiv = (!inline ? $.datetimepicker._datetimepickerDiv :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1054
		$('<div id="datetimepicker_div_' + this._id + '" class="datetimepicker_inline">'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1055
	// customise the date picker object - uses manager defaults if not overridden
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1056
	this._settings = extendRemove(settings || {}); // clone
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1057
	if (inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1058
		this._setDate(this._getDefaultDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1059
}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1060
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1061
$.extend(DateTimepickerInstance.prototype, {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1062
	/* Get a setting value, defaulting if necessary. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1063
	_get: function(name) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1064
		return this._settings[name] !== undefined ? this._settings[name] : $.datetimepicker._defaults[name];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1065
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1066
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1067
	/* Parse existing date and initialise date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1068
	_setDateFromField: function(input) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1069
		this._input = $(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1070
		var dates = this._input ? this._input.val().split(this._get('rangeSeparator')) : null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1071
		this._endDay = this._endMonth = this._endYear = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1072
		var date = defaultDate = this._getDefaultDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1073
		if (dates.length > 0) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1074
			var settings = this._getFormatConfig();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1075
			if (dates.length > 1) {
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1076
				var dateFormat = this._get('dateFormat') +' '+this._get('timeFormat');
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1077
				date = $.datetimepicker.parseDate(dateFormat, dates[1], settings) || defaultDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1078
				this._endDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1079
				this._endMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1080
				this._endYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1081
			}
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1082
			date = null;
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1083
			var dateFormats = this._get('dateFormats');
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1084
			for (var i = 0; i < dateFormats.length; i++) {
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1085
				var dateFormat = dateFormats[i] +' '+this._get('timeFormat');
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1086
				try {
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1087
				date = $.datetimepicker.parseDate(dateFormat, dates[0], settings) || defaultDate;
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1088
				} catch (e) {}
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1089
				if (date != null) {
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1090
					$.datetimepicker._defaults['dateFormat'] = dateFormats[i];
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1091
					break;
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1092
				}
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1093
			}
2022
3d84ec6dbd03 Fix Issue 381(Date fields should be displayed in ISO standard formatting) and Issue 207 (Date selector Javascript control always starts out with year 1900 selected).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1462
diff changeset
  1094
			if (date == null) date = defaultDate;
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1095
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1096
		this._selectedDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1097
		this._drawMonth = this._selectedMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1098
		this._drawYear = this._selectedYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1099
		this._drawHour = this._selectedHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1100
		this._drawMinute = this._selectedMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1101
		this._currentDay = (dates[0] ? date.getDate() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1102
		this._currentMonth = (dates[0] ? date.getMonth() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1103
		this._currentYear = (dates[0] ? date.getFullYear() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1104
		this._adjustDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1105
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1106
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1107
	/* Retrieve the default date shown on opening. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1108
	_getDefaultDate: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1109
		var date = this._determineDate('defaultDate', new Date());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1110
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1111
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1112
		date = (minDate && date < minDate ? minDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1113
		date = (maxDate && date > maxDate ? maxDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1114
		return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1115
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1116
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1117
	/* A date may be specified as an exact value or a relative one. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1118
	_determineDate: function(name, defaultDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1119
		var offsetNumeric = function(offset) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1120
			var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1121
			date.setDate(date.getDate() + offset);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1122
			return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1123
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1124
		var offsetString = function(offset, getDaysInMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1125
			var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1126
			var matches = /^([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?$/.exec(offset);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1127
			if (matches) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1128
				var year = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1129
				var month = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1130
				var day = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1131
				switch (matches[2] || 'd') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1132
					case 'd' : case 'D' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1133
						day += (matches[1] - 0); break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1134
					case 'w' : case 'W' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1135
						day += (matches[1] * 7); break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1136
					case 'm' : case 'M' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1137
						month += (matches[1] - 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1138
						day = Math.min(day, getDaysInMonth(year, month));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1139
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1140
					case 'y': case 'Y' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1141
						year += (matches[1] - 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1142
						day = Math.min(day, getDaysInMonth(year, month));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1143
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1144
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1145
				date = new Date(year, month, day);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1146
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1147
			return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1148
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1149
		var date = this._get(name);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1150
		return (date == null ? defaultDate :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1151
			(typeof date == 'string' ? offsetString(date, this._getDaysInMonth) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1152
			(typeof date == 'number' ? offsetNumeric(date) : date)));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1153
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1154
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1155
	/* Set the date(s) directly. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1156
	_setDate: function(date, endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1157
		this._selectedDay = this._currentDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1158
		this._drawMonth = this._selectedMonth = this._currentMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1159
		this._drawYear = this._selectedYear = this._currentYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1160
		this._drawHour = this._selectedHour = this._currentHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1161
		this._drawMinute = this._selectedMinute = this._currentMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1162
		if (this._get('rangeSelect')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1163
			if (endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1164
				this._endDay = endDate.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1165
				this._endMonth = endDate.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1166
				this._endYear = endDate.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1167
			} else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1168
				this._endDay = this._currentDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1169
				this._endMonth = this._currentMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1170
				this._endYear = this._currentYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1171
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1172
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1173
		this._adjustDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1174
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1175
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1176
	/* Retrieve the date(s) directly. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1177
	_getDate: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1178
		var startDate = (!this._currentYear || (this._input && this._input.val() == '') ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1179
			new Date(this._currentYear, this._currentMonth, this._currentDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1180
		if (this._get('rangeSelect')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1181
			return [startDate, (!this._endYear ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1182
				new Date(this._endYear, this._endMonth, this._endDay))];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1183
		} else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1184
			return startDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1185
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1186
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1187
	/* Generate the HTML for the current state of the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1188
	_generateDatepicker: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1189
		var today = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1190
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1191
		var showStatus = this._get('showStatus');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1192
		var isRTL = this._get('isRTL');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1193
		// build the date picker HTML
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1194
		var clear = (this._get('mandatory') ? '' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1195
			'<div class="datetimepicker_clear"><a onclick="jQuery.datetimepicker._clearDate(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1196
			(showStatus ? this._addStatus(this._get('clearStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1197
			this._get('clearText') + '</a></div>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1198
		var controls = '<div class="datetimepicker_control">' + (isRTL ? '' : clear) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1199
			'<div class="datetimepicker_close"><a onclick="jQuery.datetimepicker._hideDatepicker();"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1200
			(showStatus ? this._addStatus(this._get('closeStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1201
			this._get('closeText') + '</a></div>' + (isRTL ? clear : '')  + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1202
		var prompt = this._get('prompt');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1203
		var closeAtTop = this._get('closeAtTop');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1204
		var hideIfNoPrevNext = this._get('hideIfNoPrevNext');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1205
		var numMonths = this._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1206
		var stepMonths = this._get('stepMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1207
		var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1208
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1209
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1210
		var drawMonth = this._drawMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1211
		var drawYear = this._drawYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1212
		var drawHour = this._drawHour;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1213
		var drawMinute = this._drawMinute;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1214
		if (maxDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1215
			var maxDraw = new Date(maxDate.getFullYear(),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1216
				maxDate.getMonth() - numMonths[1] + 1, maxDate.getDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1217
			maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1218
			while (new Date(drawYear, drawMonth, 1) > maxDraw) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1219
				drawMonth--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1220
				if (drawMonth < 0) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1221
					drawMonth = 11;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1222
					drawYear--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1223
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1224
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1225
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1226
		// controls and links
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1227
		var prev = '<div class="datetimepicker_prev">' + (this._canAdjustMonth(-1, drawYear, drawMonth) ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1228
			'<a onclick="jQuery.datetimepicker._adjustDate(' + this._id + ', -' + stepMonths + ', \'M\');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1229
			(showStatus ? this._addStatus(this._get('prevStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1230
			this._get('prevText') + '</a>' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1231
			(hideIfNoPrevNext ? '' : '<label>' + this._get('prevText') + '</label>')) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1232
		var next = '<div class="datetimepicker_next">' + (this._canAdjustMonth(+1, drawYear, drawMonth) ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1233
			'<a onclick="jQuery.datetimepicker._adjustDate(' + this._id + ', +' + stepMonths + ', \'M\');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1234
			(showStatus ? this._addStatus(this._get('nextStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1235
			this._get('nextText') + '</a>' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1236
			(hideIfNoPrevNext ? '>' : '<label>' + this._get('nextText') + '</label>')) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1237
		var html = (prompt ? '<div class="datetimepicker_prompt">' + prompt + '</div>' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1238
			(closeAtTop && !this._inline ? controls : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1239
			'<div class="datetimepicker_links">' + (isRTL ? next : prev) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1240
			(this._isInRange(today) ? '<div class="datetimepicker_current">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1241
			'<a onclick="jQuery.datetimepicker._gotoToday(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1242
			(showStatus ? this._addStatus(this._get('currentStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1243
			this._get('currentText') + '</a></div>' : '') + (isRTL ? prev : next) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1244
		var showWeeks = this._get('showWeeks');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1245
		for (var row = 0; row < numMonths[0]; row++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1246
			for (var col = 0; col < numMonths[1]; col++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1247
				var selectedDate = new Date(drawYear, drawMonth, this._selectedDay, drawHour, drawMinute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1248
				html += '<div class="datetimepicker_oneMonth' + (col == 0 ? ' datetimepicker_newRow' : '') + '">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1249
					this._generateMonthYearHeader(drawMinute,drawHour,drawMonth, drawYear, minDate, maxDate,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1250
					selectedDate, row > 0 || col > 0) + // draw month headers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1251
					'<table class="datetimepicker" cellpadding="0" cellspacing="0"><thead>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1252
					'<tr class="datetimepicker_titleRow">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1253
					(showWeeks ? '<td>' + this._get('weekHeader') + '</td>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1254
				var firstDay = this._get('firstDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1255
				var changeFirstDay = this._get('changeFirstDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1256
				var dayNames = this._get('dayNames');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1257
				var dayNamesShort = this._get('dayNamesShort');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1258
				var dayNamesMin = this._get('dayNamesMin');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1259
				for (var dow = 0; dow < 7; dow++) { // days of the week
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1260
					var day = (dow + firstDay) % 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1261
					var status = this._get('dayStatus') || '&#xa0;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1262
					status = (status.indexOf('DD') > -1 ? status.replace(/DD/, dayNames[day]) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1263
						status.replace(/D/, dayNamesShort[day]));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1264
					html += '<td' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="datetimepicker_weekEndCell"' : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1265
						(!changeFirstDay ? '<span' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1266
						'<a onclick="jQuery.datetimepicker._changeFirstDay(' + this._id + ', ' + day + ');"') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1267
						(showStatus ? this._addStatus(status) : '') + ' title="' + dayNames[day] + '">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1268
						dayNamesMin[day] + (changeFirstDay ? '</a>' : '</span>') + '</td>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1269
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1270
				html += '</tr></thead><tbody>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1271
				var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1272
				if (drawYear == this._selectedYear && drawMonth == this._selectedMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1273
					this._selectedDay = Math.min(this._selectedDay, daysInMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1274
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1275
				var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1276
				var currentDate = (!this._currentDay ? new Date(9999, 9, 9) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1277
					new Date(this._currentYear, this._currentMonth, this._currentDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1278
				var endDate = this._endDay ? new Date(this._endYear, this._endMonth, this._endDay) : currentDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1279
				var printDate = new Date(drawYear, drawMonth, 1 - leadDays);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1280
				var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1281
				var beforeShowDay = this._get('beforeShowDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1282
				var showOtherMonths = this._get('showOtherMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1283
				var calculateWeek = this._get('calculateWeek') || $.datetimepicker.iso8601Week;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1284
				var dateStatus = this._get('statusForDate') || $.datetimepicker.dateStatus;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1285
				for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1286
					html += '<tr class="datetimepicker_daysRow">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1287
						(showWeeks ? '<td class="datetimepicker_weekCol">' + calculateWeek(printDate) + '</td>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1288
					for (var dow = 0; dow < 7; dow++) { // create date picker days
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1289
						var daySettings = (beforeShowDay ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1290
							beforeShowDay.apply((this._input ? this._input[0] : null), [printDate]) : [true, '']);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1291
						var otherMonth = (printDate.getMonth() != drawMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1292
						var unselectable = otherMonth || !daySettings[0] ||
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1293
							(minDate && printDate < minDate) || (maxDate && printDate > maxDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1294
						html += '<td class="datetimepicker_daysCell' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1295
							((dow + firstDay + 6) % 7 >= 5 ? ' datetimepicker_weekEndCell' : '') + // highlight weekends
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1296
							(otherMonth ? ' datetimepicker_otherMonth' : '') + // highlight days from other months
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1297
							(printDate.getTime() == selectedDate.getTime() && drawMonth == this._selectedMonth ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1298
							' datetimepicker_daysCellOver' : '') + // highlight selected day
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1299
							(unselectable ? ' datetimepicker_unselectable' : '') +  // highlight unselectable days
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1300
							(otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1301
							(printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ?  // in current range
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1302
							' datetimepicker_currentDay' : '') + // highlight selected day
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1303
							(printDate.getTime() == today.getTime() ? ' datetimepicker_today' : '')) + '"' + // highlight today (if different)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1304
							(unselectable ? '' : ' onmouseover="jQuery(this).addClass(\'datetimepicker_daysCellOver\');' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1305
							(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#datetimepicker_status_' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1306
							this._id + '\').html(\'' + (dateStatus.apply((this._input ? this._input[0] : null),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1307
							[printDate, this]) || '&#xa0;') +'\');') + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1308
							' onmouseout="jQuery(this).removeClass(\'datetimepicker_daysCellOver\');' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1309
							(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#datetimepicker_status_' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1310
							this._id + '\').html(\'&#xa0;\');') + '" onclick="jQuery.datetimepicker._selectDay(' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1311
							this._id + ',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1312
							(otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1313
							(unselectable ? printDate.getDate() : '<a>' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1314
						printDate.setDate(printDate.getDate() + 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1315
					}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1316
					html += '</tr>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1317
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1318
				drawMonth++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1319
				if (drawMonth > 11) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1320
					drawMonth = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1321
					drawYear++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1322
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1323
				html += '</tbody></table></div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1324
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1325
		html += (showStatus ? '<div style="clear: both;"></div><div id="datetimepicker_status_' + this._id +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1326
			'" class="datetimepicker_status">' + (this._get('initStatus') || '&#xa0;') + '</div>' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1327
			(!closeAtTop && !this._inline ? controls : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1328
			'<div style="clear: both;"></div>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1329
			($.browser.msie && parseInt($.browser.version) < 7 && !this._inline ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1330
			'<iframe src="javascript:false;" class="datetimepicker_cover"></iframe>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1331
		return html;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1332
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1333
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1334
	/* Generate the month and year header. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1335
	_generateMonthYearHeader: function(drawMinute,drawHour,drawMonth, drawYear, minDate, maxDate, selectedDate, secondary) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1336
		minDate = (this._rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1337
		var showStatus = this._get('showStatus');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1338
		var html = '<div class="datetimepicker_header">';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1339
		// month selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1340
		var monthNames = this._get('monthNames');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1341
		if (secondary || !this._get('changeMonth'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1342
			html += monthNames[drawMonth] + '&#xa0;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1343
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1344
		else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1345
			var inMinYear = (minDate && minDate.getFullYear() == drawYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1346
			var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1347
			html += '<select class="datetimepicker_newMonth" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1348
				'onchange="jQuery.datetimepicker._selectMonthYear(' + this._id + ', this, \'M\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1349
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1350
				(showStatus ? this._addStatus(this._get('monthStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1351
			for (var month = 0; month < 12; month++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1352
				if ((!inMinYear || month >= minDate.getMonth()) &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1353
						(!inMaxYear || month <= maxDate.getMonth())) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1354
					html += '<option value="' + month + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1355
						(month == drawMonth ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1356
						'>' + monthNames[month] + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1357
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1358
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1359
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1360
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1361
		// year selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1362
		if (secondary || !this._get('changeYear'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1363
			html += drawYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1364
		else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1365
			// determine range of years to display
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1366
			var years = this._get('yearRange').split(':');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1367
			var year = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1368
			var endYear = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1369
			if (years.length != 2) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1370
				year = drawYear - 10;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1371
				endYear = drawYear + 10;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1372
			} else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1373
				year = drawYear + parseInt(years[0], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1374
				endYear = drawYear + parseInt(years[1], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1375
			} else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1376
				year = parseInt(years[0], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1377
				endYear = parseInt(years[1], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1378
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1379
			year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1380
			endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1381
			html += '<select class="datetimepicker_newYear" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1382
				'onchange="jQuery.datetimepicker._selectMonthYear(' + this._id + ', this, \'Y\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1383
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1384
				(showStatus ? this._addStatus(this._get('yearStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1385
			for (; year <= endYear; year++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1386
				html += '<option value="' + year + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1387
					(year == drawYear ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1388
					'>' + year + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1389
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1390
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1391
		}
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1392
		if (!this._get('pickDateOnly'))
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1393
		{
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1394
			html += '<br />';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1395
			html += '<select class="datetimepicker_newHour" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1396
				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'H\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1397
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1398
				(showStatus ? this._addStatus(this._get('hourStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1399
			for (hour=0; hour < 24; hour++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1400
				html += '<option value="' + hour + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1401
					(hour == drawHour ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1402
					'>' + ((hour<10)?'0'+hour:hour) + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1403
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1404
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1405
			html += '&nbsp;:&nbsp;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1406
			html += '<select class="datetimepicker_newMinute" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1407
				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'M\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1408
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1409
				(showStatus ? this._addStatus(this._get('minuteStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1410
			for (minute=0; minute < 60; minute++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1411
				html += '<option value="' + minute + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1412
					(minute == drawMinute ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1413
					'>' + ((minute<10)?'0'+minute:minute) + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1414
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1415
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1416
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1417
		html += '</div>'; // Close datetimepicker_header
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1418
		return html;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1419
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1420
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1421
	/* Provide code to set and clear the status panel. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1422
	_addStatus: function(text) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1423
		return ' onmouseover="jQuery(\'#datetimepicker_status_' + this._id + '\').html(\'' + text + '\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1424
			'onmouseout="jQuery(\'#datetimepicker_status_' + this._id + '\').html(\'&#xa0;\');"';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1425
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1426
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1427
	/* Adjust one of the date sub-fields. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1428
	_adjustDate: function(offset, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1429
		var year = this._drawYear + (period == 'Y' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1430
		var month = this._drawMonth + (period == 'M' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1431
		var day = Math.min(this._selectedDay, this._getDaysInMonth(year, month)) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1432
			(period == 'D' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1433
		var hour = this._drawHour + (period == 'H' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1434
		var minute = this._drawMinute + (period == 'I' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1435
		var date = new Date(year, month, day, hour, minute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1436
		// ensure it is within the bounds set
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1437
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1438
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1439
		date = (minDate && date < minDate ? minDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1440
		date = (maxDate && date > maxDate ? maxDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1441
		this._selectedDay = date.getDate();
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1442
		this._currentMonth = this._drawMonth = this._selectedMonth = date.getMonth();
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1443
		this._currentYear = this._drawYear = this._selectedYear = date.getFullYear();
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1444
		this._currentHour = this._drawHour = this._selectedHour = date.getHours();
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1445
		this._currentMinute = this._drawMinute = this._selectedMinute = date.getMinutes();
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1446
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1447
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1448
	/* Determine the number of months to show. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1449
	_getNumberOfMonths: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1450
		var numMonths = this._get('numberOfMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1451
		return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1452
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1453
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1454
	/* Determine the current maximum date - ensure no time components are set - may be overridden for a range. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1455
	_getMinMaxDate: function(minMax, checkRange) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1456
		var date = this._determineDate(minMax + 'Date', null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1457
		if (date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1458
			date.setHours(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1459
			date.setMinutes(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1460
			date.setSeconds(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1461
			date.setMilliseconds(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1462
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1463
		return date || (checkRange ? this._rangeStart : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1464
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1465
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1466
	/* Find the number of days in a given month. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1467
	_getDaysInMonth: function(year, month) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1468
		return 32 - new Date(year, month, 32).getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1469
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1470
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1471
	/* Find the day of the week of the first of a month. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1472
	_getFirstDayOfMonth: function(year, month) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1473
		return new Date(year, month, 1).getDay();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1474
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1475
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1476
	/* Determines if we should allow a "next/prev" month display change. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1477
	_canAdjustMonth: function(offset, curYear, curMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1478
		var numMonths = this._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1479
		var date = new Date(curYear, curMonth + (offset < 0 ? offset : numMonths[1]), 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1480
		if (offset < 0)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1481
			date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1482
		return this._isInRange(date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1483
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1484
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1485
	/* Is the given date in the accepted range? */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1486
	_isInRange: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1487
		// during range selection, use minimum of selected date and range start
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1488
		var newMinDate = (!this._rangeStart ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1489
			new Date(this._selectedYear, this._selectedMonth, this._selectedDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1490
		newMinDate = (newMinDate && this._rangeStart < newMinDate ? this._rangeStart : newMinDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1491
		var minDate = newMinDate || this._getMinMaxDate('min');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1492
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1493
		return ((!minDate || date >= minDate) && (!maxDate || date <= maxDate));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1494
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1495
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1496
	/* Provide the configuration settings for formatting/parsing. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1497
	_getFormatConfig: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1498
		var shortYearCutoff = this._get('shortYearCutoff');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1499
		shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1500
			new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1501
		return {shortYearCutoff: shortYearCutoff,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1502
			dayNamesShort: this._get('dayNamesShort'), dayNames: this._get('dayNames'),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1503
			monthNamesShort: this._get('monthNamesShort'), monthNames: this._get('monthNames')};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1504
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1505
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1506
	/* Format the given date for display. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1507
	_formatDateTime: function(day, month, year, hour, minute) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1508
		if (!day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1509
			this._currentDay = this._selectedDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1510
			this._currentMonth = this._selectedMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1511
			this._currentYear = this._selectedYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1512
			this._currentHour = this._selectedHour;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1513
			this._currentMinute = this._selectedMinute;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1514
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1515
		var date = (day ? (typeof day == 'object' ? day : new Date(year, month, day, hour, minute)) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1516
			new Date(this._currentYear, this._currentMonth, this._currentDay, this._currentHour, this._currentMinute));
1462
8686c7223028 Fix datetimepicker so that it doesn't add trailing whitespaces.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1452
diff changeset
  1517
		
8686c7223028 Fix datetimepicker so that it doesn't add trailing whitespaces.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1452
diff changeset
  1518
		if (this._get('pickDateOnly'))
8686c7223028 Fix datetimepicker so that it doesn't add trailing whitespaces.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1452
diff changeset
  1519
			return $.datetimepicker.formatDate(this._get('dateFormat'), date, this._getFormatConfig());
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1520
		return $.datetimepicker.formatDate(this._get('dateFormat')+' '+this._get('timeFormat'), date, this._getFormatConfig());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1521
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1522
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1523
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1524
/* jQuery extend now ignores nulls! */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1525
function extendRemove(target, props) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1526
	$.extend(target, props);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1527
	for (var name in props)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1528
		if (props[name] == null)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1529
			target[name] = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1530
	return target;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1531
};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1532
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1533
/* Invoke the datetimepicker functionality.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1534
   @param  options  String - a command, optionally followed by additional parameters or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1535
                    Object - settings for attaching new datetimepicker functionality
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1536
   @return  jQuery object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1537
$.fn.datetimepicker = function(options){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1538
	var otherArgs = Array.prototype.slice.call(arguments, 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1539
	if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1540
		return $.datetimepicker['_' + options + 'Datepicker'].apply($.datetimepicker, [this[0]].concat(otherArgs));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1541
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1542
	return this.each(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1543
		typeof options == 'string' ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1544
			$.datetimepicker['_' + options + 'Datepicker'].apply($.datetimepicker, [this].concat(otherArgs)) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1545
			$.datetimepicker._attachDatepicker(this, options);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1546
	});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1547
};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1548
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1549
$.datetimepicker = new DateTimepicker(); // singleton instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1550
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1551
/* Initialise the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1552
$(document).ready(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1553
	$(document.body).append($.datetimepicker._datetimepickerDiv)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1554
		.mousedown($.datetimepicker._checkExternalClick);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1555
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1556
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 843
diff changeset
  1557
})(jQuery);