hydra-file-access 5.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +5 -0
  3. data/app/assets/images/hydra/powered_by_hydra.png +0 -0
  4. data/app/assets/images/hydra/search-button.png +0 -0
  5. data/app/assets/javascripts/date-picker/booking/index.html +368 -0
  6. data/app/assets/javascripts/date-picker/calendarHTML.txt +84 -0
  7. data/app/assets/javascripts/date-picker/css/datepicker.css +511 -0
  8. data/app/assets/javascripts/date-picker/css/demo.css +229 -0
  9. data/app/assets/javascripts/date-picker/index.html +798 -0
  10. data/app/assets/javascripts/date-picker/js/datepicker.js +2898 -0
  11. data/app/assets/javascripts/date-picker/js/datepicker.packed.js +1 -0
  12. data/app/assets/javascripts/date-picker/js/lang/ar.js +9 -0
  13. data/app/assets/javascripts/date-picker/js/lang/cs.js +9 -0
  14. data/app/assets/javascripts/date-picker/js/lang/da.js +10 -0
  15. data/app/assets/javascripts/date-picker/js/lang/de.js +10 -0
  16. data/app/assets/javascripts/date-picker/js/lang/en.js +9 -0
  17. data/app/assets/javascripts/date-picker/js/lang/eo.js +13 -0
  18. data/app/assets/javascripts/date-picker/js/lang/es.js +9 -0
  19. data/app/assets/javascripts/date-picker/js/lang/et.js +23 -0
  20. data/app/assets/javascripts/date-picker/js/lang/fi.js +7 -0
  21. data/app/assets/javascripts/date-picker/js/lang/fr.js +69 -0
  22. data/app/assets/javascripts/date-picker/js/lang/he.js +9 -0
  23. data/app/assets/javascripts/date-picker/js/lang/hu.js +9 -0
  24. data/app/assets/javascripts/date-picker/js/lang/id.js +9 -0
  25. data/app/assets/javascripts/date-picker/js/lang/it.js +11 -0
  26. data/app/assets/javascripts/date-picker/js/lang/kr.js +9 -0
  27. data/app/assets/javascripts/date-picker/js/lang/lt.js +8 -0
  28. data/app/assets/javascripts/date-picker/js/lang/lv.js +9 -0
  29. data/app/assets/javascripts/date-picker/js/lang/nl.js +9 -0
  30. data/app/assets/javascripts/date-picker/js/lang/no.js +9 -0
  31. data/app/assets/javascripts/date-picker/js/lang/pl.js +10 -0
  32. data/app/assets/javascripts/date-picker/js/lang/pt-br.js +11 -0
  33. data/app/assets/javascripts/date-picker/js/lang/pt.js +9 -0
  34. data/app/assets/javascripts/date-picker/js/lang/ru.js +11 -0
  35. data/app/assets/javascripts/date-picker/js/lang/se.js +9 -0
  36. data/app/assets/javascripts/date-picker/js/lang/si.js +9 -0
  37. data/app/assets/javascripts/date-picker/js/lang/tr.js +9 -0
  38. data/app/assets/javascripts/date-picker/language/index.html +240 -0
  39. data/app/assets/javascripts/date-picker/media/Thumbs.db +0 -0
  40. data/app/assets/javascripts/date-picker/media/backstripes.gif +0 -0
  41. data/app/assets/javascripts/date-picker/media/bg_header.jpg +0 -0
  42. data/app/assets/javascripts/date-picker/media/bullet1.gif +0 -0
  43. data/app/assets/javascripts/date-picker/media/bullet2.gif +0 -0
  44. data/app/assets/javascripts/date-picker/media/cal-grey.gif +0 -0
  45. data/app/assets/javascripts/date-picker/media/cal.gif +0 -0
  46. data/app/assets/javascripts/date-picker/media/gradient-e5e5e5-ffffff.gif +0 -0
  47. data/app/assets/javascripts/hydra/hydra-head.js +195 -0
  48. data/app/assets/javascripts/hydra/mediashelf.datepicker.js +39 -0
  49. data/app/assets/javascripts/hydra/mediashelf.placeholder.js +67 -0
  50. data/app/assets/javascripts/jquery.form.js +1076 -0
  51. data/app/assets/javascripts/jquery.ui.datepicker.js +1793 -0
  52. data/app/assets/javascripts/spin.min.js +2 -0
  53. data/app/assets/stylesheets/hydra/html_refactor.css +79 -0
  54. data/app/assets/stylesheets/hydra/hydrangea-split-button.css +18 -0
  55. data/app/assets/stylesheets/hydra/hydrangea.css +288 -0
  56. data/app/assets/stylesheets/hydra/ie-styles.css +149 -0
  57. data/app/assets/stylesheets/hydra/styles.css +946 -0
  58. data/app/assets/stylesheets/redmond/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  59. data/app/assets/stylesheets/redmond/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
  60. data/app/assets/stylesheets/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  61. data/app/assets/stylesheets/redmond/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  62. data/app/assets/stylesheets/redmond/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  63. data/app/assets/stylesheets/redmond/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  64. data/app/assets/stylesheets/redmond/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  65. data/app/assets/stylesheets/redmond/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  66. data/app/assets/stylesheets/redmond/images/ui-icons_217bc0_256x240.png +0 -0
  67. data/app/assets/stylesheets/redmond/images/ui-icons_2e83ff_256x240.png +0 -0
  68. data/app/assets/stylesheets/redmond/images/ui-icons_469bdd_256x240.png +0 -0
  69. data/app/assets/stylesheets/redmond/images/ui-icons_6da8d5_256x240.png +0 -0
  70. data/app/assets/stylesheets/redmond/images/ui-icons_cd0a0a_256x240.png +0 -0
  71. data/app/assets/stylesheets/redmond/images/ui-icons_d8e7f3_256x240.png +0 -0
  72. data/app/assets/stylesheets/redmond/images/ui-icons_f9bd01_256x240.png +0 -0
  73. data/app/assets/stylesheets/redmond/jquery-ui-1.8.5.custom.css +572 -0
  74. data/app/controllers/hydra/application_controller.rb +5 -0
  75. data/app/controllers/hydra/file_assets_controller.rb +3 -0
  76. data/app/helpers/application_helper.rb +3 -0
  77. data/app/helpers/hydra/application_helper_behavior.rb +8 -0
  78. data/app/helpers/hydra/hydra_helper_behavior.rb +70 -0
  79. data/app/helpers/hydra_helper.rb +4 -0
  80. data/app/models/file_asset.rb +5 -0
  81. data/app/models/uses_default_partials.rb +23 -0
  82. data/app/views/_add_assets_links.html.erb +14 -0
  83. data/app/views/_user_util_links.html.erb +24 -0
  84. data/app/views/generic_content_objects/_contributor_form.html.erb +11 -0
  85. data/app/views/generic_content_objects/_description_form.html.erb +7 -0
  86. data/app/views/generic_content_objects/_edit_description.html.erb +23 -0
  87. data/app/views/generic_content_objects/_new.html.erb +0 -0
  88. data/app/views/generic_content_objects/_show_description.html.erb +41 -0
  89. data/app/views/generic_contents/_edit.html.erb +10 -0
  90. data/app/views/generic_contents/_index.html.erb +21 -0
  91. data/app/views/generic_contents/_show.html.erb +6 -0
  92. data/app/views/generic_contents/_show_content.html.erb +7 -0
  93. data/app/views/generic_images/_edit.html.erb +36 -0
  94. data/app/views/generic_images/_index.html.erb +24 -0
  95. data/app/views/generic_images/_show.html.erb +13 -0
  96. data/app/views/generic_images/_show_all.html.erb +14 -0
  97. data/app/views/generic_images/_show_content.html.erb +7 -0
  98. data/app/views/hydra/file_assets/_asset_saved_flash.html.erb +2 -0
  99. data/app/views/hydra/file_assets/_deletable_result.html.erb +5 -0
  100. data/app/views/hydra/file_assets/_file_assets_form.html.erb +11 -0
  101. data/app/views/hydra/file_assets/_index.html.erb +29 -0
  102. data/app/views/hydra/file_assets/_new.html.erb +6 -0
  103. data/app/views/hydra/file_assets/_result.html.erb +11 -0
  104. data/app/views/hydra/file_assets/index.html.erb +5 -0
  105. data/app/views/hydra/permissions/_edit_person_permissions.html.erb +30 -0
  106. data/app/views/hydra/permissions/_index.html.erb +46 -0
  107. data/app/views/hydra/permissions/_new.html.erb +14 -0
  108. data/app/views/hydra/permissions/_permissions_form.html.erb +23 -0
  109. data/app/views/hydra/permissions/index.html.erb +1 -0
  110. data/app/views/hydra/permissions/new.html.erb +1 -0
  111. data/app/views/mods_assets/_additional_info_form.html.erb +44 -0
  112. data/app/views/mods_assets/_contributor_form.html.erb +14 -0
  113. data/app/views/mods_assets/_edit.html.erb +10 -0
  114. data/app/views/mods_assets/_edit_description.html.erb +73 -0
  115. data/app/views/mods_assets/_edit_journal.html.erb +57 -0
  116. data/app/views/mods_assets/_index.html.erb +1 -0
  117. data/app/views/mods_assets/_index_list.html.erb +37 -0
  118. data/app/views/mods_assets/_index_table.html.erb +7 -0
  119. data/app/views/mods_assets/_progress_box.html.erb +82 -0
  120. data/app/views/mods_assets/_publication_form.html.erb +13 -0
  121. data/app/views/mods_assets/_show.html.erb +39 -0
  122. data/app/views/mods_assets/_show_additional_info.html.erb +17 -0
  123. data/app/views/mods_assets/_show_contributors.html.erb +7 -0
  124. data/app/views/mods_assets/_show_description.html.erb +35 -0
  125. data/app/views/mods_assets/_show_file_assets.html.erb +22 -0
  126. data/app/views/mods_assets/_show_journal.html.erb +42 -0
  127. data/app/views/mods_assets/_show_permissions.html.erb +15 -0
  128. data/app/views/mods_assets/_show_publication.html.erb +8 -0
  129. data/app/views/shared/_delete_asset_confirmation.html.erb +17 -0
  130. data/config/jetty.yml +7 -0
  131. data/hydra-file-access.gemspec +39 -0
  132. data/lib/hydra-file-access.rb +15 -0
  133. data/lib/hydra/assets.rb +5 -0
  134. data/lib/hydra/assets_controller_helper.rb +122 -0
  135. data/lib/hydra/controller/assets_controller_behavior.rb +153 -0
  136. data/lib/hydra/controller/file_assets_behavior.rb +140 -0
  137. data/lib/hydra/file_access/engine.rb +12 -0
  138. data/lib/hydra/file_assets.rb +11 -0
  139. data/lib/hydra/submission_workflow.rb +139 -0
  140. data/lib/hydra/ui.rb +6 -0
  141. data/spec/.gitignore +1 -0
  142. data/spec/controllers/file_assets_controller_spec.rb +180 -0
  143. data/spec/fixtures/small_file.txt +1 -0
  144. data/spec/helpers/access_controls_evaluation_spec.rb +19 -0
  145. data/spec/helpers/assets_controller_helper_spec.rb +63 -0
  146. data/spec/helpers/file_assets_helper_spec.rb +116 -0
  147. data/spec/helpers/hydra_helper_spec.rb +21 -0
  148. data/spec/helpers/hydra_model_methods_spec.rb +88 -0
  149. data/spec/integration/file_asset_spec.rb +68 -0
  150. data/spec/lib/hydra_submission_workflow_spec.rb +141 -0
  151. data/spec/models/file_asset_spec.rb +25 -0
  152. data/spec/spec_helper.rb +27 -0
  153. data/spec/support/Gemfile +12 -0
  154. data/spec/support/app/models/generic_content.rb +26 -0
  155. data/spec/support/app/models/sample.rb +33 -0
  156. data/spec/support/app/models/solr_document.rb +5 -0
  157. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  158. data/spec/support/lib/generators/test_app_generator.rb +39 -0
  159. data/spec/support/matchers/helper_matcher.rb +14 -0
  160. data/spec/support/matchers/solr_matchers.rb +60 -0
  161. data/spec/support/spec/factories/users.rb +11 -0
  162. data/spec/support/spec/fixtures/hydra_test_generic_content.foxml.xml +138 -0
  163. data/spec/support/spec/fixtures/hydrangea_fixture_file_asset1.foxml.xml +4946 -0
  164. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +234 -0
  165. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article2.foxml.xml +177 -0
  166. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article3.foxml.xml +170 -0
  167. data/spec/support/spec/fixtures/hydrangea_fixture_uploaded_svg1.foxml.xml +676 -0
  168. data/tasks/rspec.rake +55 -0
  169. metadata +516 -0
@@ -0,0 +1,1793 @@
1
+ /*
2
+ * jQuery UI Datepicker @VERSION
3
+ *
4
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ * http://jquery.org/license
7
+ *
8
+ * http://docs.jquery.com/UI/Datepicker
9
+ *
10
+ * Depends:
11
+ * jquery.ui.core.js
12
+ */
13
+ (function( $, undefined ) {
14
+
15
+ $.extend($.ui, { datepicker: { version: "@VERSION" } });
16
+
17
+ var PROP_NAME = 'datepicker';
18
+ var dpuuid = new Date().getTime();
19
+
20
+ /* Date picker manager.
21
+ Use the singleton instance of this class, $.datepicker, to interact with the date picker.
22
+ Settings for (groups of) date pickers are maintained in an instance object,
23
+ allowing multiple different settings on the same page. */
24
+
25
+ function Datepicker() {
26
+ this.debug = false; // Change this to true to start debugging
27
+ this._curInst = null; // The current instance in use
28
+ this._keyEvent = false; // If the last event was a key event
29
+ this._disabledInputs = []; // List of date picker inputs that have been disabled
30
+ this._datepickerShowing = false; // True if the popup picker is showing , false if not
31
+ this._inDialog = false; // True if showing within a "dialog", false if not
32
+ this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
33
+ this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
34
+ this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
35
+ this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
36
+ this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
37
+ this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
38
+ this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
39
+ this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
40
+ this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
41
+ this.regional = []; // Available regional settings, indexed by language code
42
+ this.regional[''] = { // Default regional settings
43
+ closeText: 'Done', // Display text for close link
44
+ prevText: 'Prev', // Display text for previous month link
45
+ nextText: 'Next', // Display text for next month link
46
+ currentText: 'Today', // Display text for current month link
47
+ monthNames: ['January','February','March','April','May','June',
48
+ 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
49
+ monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
50
+ dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
51
+ dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
52
+ dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
53
+ weekHeader: 'Wk', // Column header for week of the year
54
+ dateFormat: 'mm/dd/yy', // See format options on parseDate
55
+ partialDateFormats: [], // An array of additional formats for partial dates (e.g. "yy-mm") which the picker will recognize when typed in the text field
56
+ firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
57
+ isRTL: false, // True if right-to-left language, false if left-to-right
58
+ showMonthAfterYear: false, // True if the year select precedes month, false for month then year
59
+ yearSuffix: '' // Additional text to append to the year in the month headers
60
+ };
61
+ this._defaults = { // Global defaults for all the date picker instances
62
+ showOn: 'focus', // 'focus' for popup on focus,
63
+ // 'button' for trigger button, or 'both' for either
64
+ showAnim: 'fadeIn', // Name of jQuery animation for popup
65
+ showOptions: {}, // Options for enhanced animations
66
+ defaultDate: null, // Used when field is blank: actual date,
67
+ // +/-number for offset from today, null for today
68
+ appendText: '', // Display text following the input box, e.g. showing the format
69
+ buttonText: '...', // Text for trigger button
70
+ buttonImage: '', // URL for trigger button image
71
+ buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
72
+ hideIfNoPrevNext: false, // True to hide next/previous month links
73
+ // if not applicable, false to just disable them
74
+ navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
75
+ gotoCurrent: false, // True if today link goes back to current selection instead
76
+ changeMonth: false, // True if month can be selected directly, false if only prev/next
77
+ changeYear: false, // True if year can be selected directly, false if only prev/next
78
+ yearRange: 'c-10:c+10', // Range of years to display in drop-down,
79
+ // either relative to today's year (-nn:+nn), relative to currently displayed year
80
+ // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
81
+ showOtherMonths: false, // True to show dates in other months, false to leave blank
82
+ selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
83
+ showWeek: false, // True to show week of the year, false to not show it
84
+ calculateWeek: this.iso8601Week, // How to calculate the week of the year,
85
+ // takes a Date and returns the number of the week for it
86
+ allowShortYear: true, // Set to false to require user to type 4-digit year for datepicker to recognize it.
87
+ shortYearCutoff: '+10', // Short year values < this are in the current century,
88
+ // > this are in the previous century,
89
+ // string value starting with '+' for current year + value
90
+ ignoreTrailingCharacters: true, // Set to false to reject user-entered dates with extra characters after the format.
91
+ minDate: null, // The earliest selectable date, or null for no limit
92
+ maxDate: null, // The latest selectable date, or null for no limit
93
+ duration: 'fast', // Duration of display/closure
94
+ beforeShowDay: null, // Function that takes a date and returns an array with
95
+ // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
96
+ // [2] = cell title (optional), e.g. $.datepicker.noWeekends
97
+ beforeShow: null, // Function that takes an input field and
98
+ // returns a set of custom settings for the date picker
99
+ onSelect: null, // Define a callback function when a date is selected
100
+ onChangeMonthYear: null, // Define a callback function when the month or year is changed
101
+ onClose: null, // Define a callback function when the datepicker is closed
102
+ numberOfMonths: 1, // Number of months to show at a time
103
+ showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
104
+ stepMonths: 1, // Number of months to step back/forward
105
+ stepBigMonths: 12, // Number of months to step back/forward for the big links
106
+ altField: '', // Selector for an alternate field to store selected dates into
107
+ altFormat: '', // The date format to use for the alternate field
108
+ constrainInput: true, // The input is constrained by the current date format
109
+ showButtonPanel: false, // True to show button panel, false to not show it
110
+ autoSize: false // True to size the input for the date format, false to leave as is
111
+ };
112
+ $.extend(this._defaults, this.regional['']);
113
+ this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>');
114
+ }
115
+
116
+ $.extend(Datepicker.prototype, {
117
+ /* Class name added to elements to indicate already configured with a date picker. */
118
+ markerClassName: 'hasDatepicker',
119
+
120
+ /* Debug logging (if enabled). */
121
+ log: function () {
122
+ if (this.debug)
123
+ console.log.apply('', arguments);
124
+ },
125
+
126
+ // TODO rename to "widget" when switching to widget factory
127
+ _widgetDatepicker: function() {
128
+ return this.dpDiv;
129
+ },
130
+
131
+ /* Override the default settings for all instances of the date picker.
132
+ @param settings object - the new settings to use as defaults (anonymous object)
133
+ @return the manager object */
134
+ setDefaults: function(settings) {
135
+ extendRemove(this._defaults, settings || {});
136
+ return this;
137
+ },
138
+
139
+ /* Attach the date picker to a jQuery selection.
140
+ @param target element - the target input field or division or span
141
+ @param settings object - the new settings to use for this date picker instance (anonymous) */
142
+ _attachDatepicker: function(target, settings) {
143
+ // check for settings on the control itself - in namespace 'date:'
144
+ var inlineSettings = null;
145
+ for (var attrName in this._defaults) {
146
+ var attrValue = target.getAttribute('date:' + attrName);
147
+ if (attrValue) {
148
+ inlineSettings = inlineSettings || {};
149
+ try {
150
+ inlineSettings[attrName] = eval(attrValue);
151
+ } catch (err) {
152
+ inlineSettings[attrName] = attrValue;
153
+ }
154
+ }
155
+ }
156
+ var nodeName = target.nodeName.toLowerCase();
157
+ var inline = (nodeName == 'div' || nodeName == 'span');
158
+ if (!target.id) {
159
+ this.uuid += 1;
160
+ target.id = 'dp' + this.uuid;
161
+ }
162
+ var inst = this._newInst($(target), inline);
163
+ inst.settings = $.extend({}, settings || {}, inlineSettings || {});
164
+ if (nodeName == 'input') {
165
+ this._connectDatepicker(target, inst);
166
+ } else if (inline) {
167
+ this._inlineDatepicker(target, inst);
168
+ }
169
+ },
170
+
171
+ /* Create a new instance object. */
172
+ _newInst: function(target, inline) {
173
+ var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
174
+ return {id: id, input: target, // associated target
175
+ selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
176
+ drawMonth: 0, drawYear: 0, // month being drawn
177
+ inline: inline, // is datepicker inline or not
178
+ dpDiv: (!inline ? this.dpDiv : // presentation div
179
+ $('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))};
180
+ },
181
+
182
+ /* Attach the date picker to an input field. */
183
+ _connectDatepicker: function(target, inst) {
184
+ var input = $(target);
185
+ inst.append = $([]);
186
+ inst.trigger = $([]);
187
+ if (input.hasClass(this.markerClassName))
188
+ return;
189
+ this._attachments(input, inst);
190
+ input.addClass(this.markerClassName).keydown(this._doKeyDown).
191
+ keypress(this._doKeyPress).keyup(this._doKeyUp).
192
+ bind("setData.datepicker", function(event, key, value) {
193
+ inst.settings[key] = value;
194
+ }).bind("getData.datepicker", function(event, key) {
195
+ return this._get(inst, key);
196
+ });
197
+ this._autoSize(inst);
198
+ $.data(target, PROP_NAME, inst);
199
+ },
200
+
201
+ /* Make attachments based on settings. */
202
+ _attachments: function(input, inst) {
203
+ var appendText = this._get(inst, 'appendText');
204
+ var isRTL = this._get(inst, 'isRTL');
205
+ if (inst.append)
206
+ inst.append.remove();
207
+ if (appendText) {
208
+ inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
209
+ input[isRTL ? 'before' : 'after'](inst.append);
210
+ }
211
+ input.unbind('focus', this._showDatepicker);
212
+ if (inst.trigger)
213
+ inst.trigger.remove();
214
+ var showOn = this._get(inst, 'showOn');
215
+ if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
216
+ input.focus(this._showDatepicker);
217
+ if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
218
+ var buttonText = this._get(inst, 'buttonText');
219
+ var buttonImage = this._get(inst, 'buttonImage');
220
+ inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
221
+ $('<img/>').addClass(this._triggerClass).
222
+ attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
223
+ $('<button type="button"></button>').addClass(this._triggerClass).
224
+ html(buttonImage == '' ? buttonText : $('<img/>').attr(
225
+ { src:buttonImage, alt:buttonText, title:buttonText })));
226
+ input[isRTL ? 'before' : 'after'](inst.trigger);
227
+ inst.trigger.click(function() {
228
+ if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
229
+ $.datepicker._hideDatepicker();
230
+ else
231
+ $.datepicker._showDatepicker(input[0]);
232
+ return false;
233
+ });
234
+ }
235
+ },
236
+
237
+ /* Apply the maximum length for the date format. */
238
+ _autoSize: function(inst) {
239
+ if (this._get(inst, 'autoSize') && !inst.inline) {
240
+ var date = new Date(2009, 12 - 1, 20); // Ensure double digits
241
+ var dateFormat = this._get(inst, 'dateFormat');
242
+ if (dateFormat.match(/[DM]/)) {
243
+ var findMax = function(names) {
244
+ var max = 0;
245
+ var maxI = 0;
246
+ for (var i = 0; i < names.length; i++) {
247
+ if (names[i].length > max) {
248
+ max = names[i].length;
249
+ maxI = i;
250
+ }
251
+ }
252
+ return maxI;
253
+ };
254
+ date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
255
+ 'monthNames' : 'monthNamesShort'))));
256
+ date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
257
+ 'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
258
+ }
259
+ inst.input.attr('size', this._formatDate(inst, date).length);
260
+ }
261
+ },
262
+
263
+ /* Attach an inline date picker to a div. */
264
+ _inlineDatepicker: function(target, inst) {
265
+ var divSpan = $(target);
266
+ if (divSpan.hasClass(this.markerClassName))
267
+ return;
268
+ divSpan.addClass(this.markerClassName).append(inst.dpDiv).
269
+ bind("setData.datepicker", function(event, key, value){
270
+ inst.settings[key] = value;
271
+ }).bind("getData.datepicker", function(event, key){
272
+ return this._get(inst, key);
273
+ });
274
+ $.data(target, PROP_NAME, inst);
275
+ this._setDate(inst, this._getDefaultDate(inst), true);
276
+ this._updateDatepicker(inst);
277
+ this._updateAlternate(inst);
278
+ },
279
+
280
+ /* Pop-up the date picker in a "dialog" box.
281
+ @param input element - ignored
282
+ @param date string or Date - the initial date to display
283
+ @param onSelect function - the function to call when a date is selected
284
+ @param settings object - update the dialog date picker instance's settings (anonymous object)
285
+ @param pos int[2] - coordinates for the dialog's position within the screen or
286
+ event - with x/y coordinates or
287
+ leave empty for default (screen centre)
288
+ @return the manager object */
289
+ _dialogDatepicker: function(input, date, onSelect, settings, pos) {
290
+ var inst = this._dialogInst; // internal instance
291
+ if (!inst) {
292
+ this.uuid += 1;
293
+ var id = 'dp' + this.uuid;
294
+ this._dialogInput = $('<input type="text" id="' + id +
295
+ '" style="position: absolute; top: -100px; width: 0px; z-index: -10;"/>');
296
+ this._dialogInput.keydown(this._doKeyDown);
297
+ $('body').append(this._dialogInput);
298
+ inst = this._dialogInst = this._newInst(this._dialogInput, false);
299
+ inst.settings = {};
300
+ $.data(this._dialogInput[0], PROP_NAME, inst);
301
+ }
302
+ extendRemove(inst.settings, settings || {});
303
+ date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
304
+ this._dialogInput.val(date);
305
+
306
+ this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
307
+ if (!this._pos) {
308
+ var browserWidth = document.documentElement.clientWidth;
309
+ var browserHeight = document.documentElement.clientHeight;
310
+ var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
311
+ var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
312
+ this._pos = // should use actual width/height below
313
+ [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
314
+ }
315
+
316
+ // move input on screen for focus, but hidden behind dialog
317
+ this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
318
+ inst.settings.onSelect = onSelect;
319
+ this._inDialog = true;
320
+ this.dpDiv.addClass(this._dialogClass);
321
+ this._showDatepicker(this._dialogInput[0]);
322
+ if ($.blockUI)
323
+ $.blockUI(this.dpDiv);
324
+ $.data(this._dialogInput[0], PROP_NAME, inst);
325
+ return this;
326
+ },
327
+
328
+ /* Detach a datepicker from its control.
329
+ @param target element - the target input field or division or span */
330
+ _destroyDatepicker: function(target) {
331
+ var $target = $(target);
332
+ var inst = $.data(target, PROP_NAME);
333
+ if (!$target.hasClass(this.markerClassName)) {
334
+ return;
335
+ }
336
+ var nodeName = target.nodeName.toLowerCase();
337
+ $.removeData(target, PROP_NAME);
338
+ if (nodeName == 'input') {
339
+ inst.append.remove();
340
+ inst.trigger.remove();
341
+ $target.removeClass(this.markerClassName).
342
+ unbind('focus', this._showDatepicker).
343
+ unbind('keydown', this._doKeyDown).
344
+ unbind('keypress', this._doKeyPress).
345
+ unbind('keyup', this._doKeyUp);
346
+ } else if (nodeName == 'div' || nodeName == 'span')
347
+ $target.removeClass(this.markerClassName).empty();
348
+ },
349
+
350
+ /* Enable the date picker to a jQuery selection.
351
+ @param target element - the target input field or division or span */
352
+ _enableDatepicker: function(target) {
353
+ var $target = $(target);
354
+ var inst = $.data(target, PROP_NAME);
355
+ if (!$target.hasClass(this.markerClassName)) {
356
+ return;
357
+ }
358
+ var nodeName = target.nodeName.toLowerCase();
359
+ if (nodeName == 'input') {
360
+ target.disabled = false;
361
+ inst.trigger.filter('button').
362
+ each(function() { this.disabled = false; }).end().
363
+ filter('img').css({opacity: '1.0', cursor: ''});
364
+ }
365
+ else if (nodeName == 'div' || nodeName == 'span') {
366
+ var inline = $target.children('.' + this._inlineClass);
367
+ inline.children().removeClass('ui-state-disabled');
368
+ }
369
+ this._disabledInputs = $.map(this._disabledInputs,
370
+ function(value) { return (value == target ? null : value); }); // delete entry
371
+ },
372
+
373
+ /* Disable the date picker to a jQuery selection.
374
+ @param target element - the target input field or division or span */
375
+ _disableDatepicker: function(target) {
376
+ var $target = $(target);
377
+ var inst = $.data(target, PROP_NAME);
378
+ if (!$target.hasClass(this.markerClassName)) {
379
+ return;
380
+ }
381
+ var nodeName = target.nodeName.toLowerCase();
382
+ if (nodeName == 'input') {
383
+ target.disabled = true;
384
+ inst.trigger.filter('button').
385
+ each(function() { this.disabled = true; }).end().
386
+ filter('img').css({opacity: '0.5', cursor: 'default'});
387
+ }
388
+ else if (nodeName == 'div' || nodeName == 'span') {
389
+ var inline = $target.children('.' + this._inlineClass);
390
+ inline.children().addClass('ui-state-disabled');
391
+ }
392
+ this._disabledInputs = $.map(this._disabledInputs,
393
+ function(value) { return (value == target ? null : value); }); // delete entry
394
+ this._disabledInputs[this._disabledInputs.length] = target;
395
+ },
396
+
397
+ /* Is the first field in a jQuery collection disabled as a datepicker?
398
+ @param target element - the target input field or division or span
399
+ @return boolean - true if disabled, false if enabled */
400
+ _isDisabledDatepicker: function(target) {
401
+ if (!target) {
402
+ return false;
403
+ }
404
+ for (var i = 0; i < this._disabledInputs.length; i++) {
405
+ if (this._disabledInputs[i] == target)
406
+ return true;
407
+ }
408
+ return false;
409
+ },
410
+
411
+ /* Retrieve the instance data for the target control.
412
+ @param target element - the target input field or division or span
413
+ @return object - the associated instance data
414
+ @throws error if a jQuery problem getting data */
415
+ _getInst: function(target) {
416
+ try {
417
+ return $.data(target, PROP_NAME);
418
+ }
419
+ catch (err) {
420
+ throw 'Missing instance data for this datepicker';
421
+ }
422
+ },
423
+
424
+ /* Update or retrieve the settings for a date picker attached to an input field or division.
425
+ @param target element - the target input field or division or span
426
+ @param name object - the new settings to update or
427
+ string - the name of the setting to change or retrieve,
428
+ when retrieving also 'all' for all instance settings or
429
+ 'defaults' for all global defaults
430
+ @param value any - the new value for the setting
431
+ (omit if above is an object or to retrieve a value) */
432
+ _optionDatepicker: function(target, name, value) {
433
+ var inst = this._getInst(target);
434
+ if (arguments.length == 2 && typeof name == 'string') {
435
+ return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
436
+ (inst ? (name == 'all' ? $.extend({}, inst.settings) :
437
+ this._get(inst, name)) : null));
438
+ }
439
+ var settings = name || {};
440
+ if (typeof name == 'string') {
441
+ settings = {};
442
+ settings[name] = value;
443
+ }
444
+ if (inst) {
445
+ if (this._curInst == inst) {
446
+ this._hideDatepicker();
447
+ }
448
+ var date = this._getDateDatepicker(target, true);
449
+ extendRemove(inst.settings, settings);
450
+ this._attachments($(target), inst);
451
+ this._autoSize(inst);
452
+ this._setDateDatepicker(target, date);
453
+ this._updateDatepicker(inst);
454
+ }
455
+ },
456
+
457
+ // change method deprecated
458
+ _changeDatepicker: function(target, name, value) {
459
+ this._optionDatepicker(target, name, value);
460
+ },
461
+
462
+ /* Redraw the date picker attached to an input field or division.
463
+ @param target element - the target input field or division or span */
464
+ _refreshDatepicker: function(target) {
465
+ var inst = this._getInst(target);
466
+ if (inst) {
467
+ this._updateDatepicker(inst);
468
+ }
469
+ },
470
+
471
+ /* Set the dates for a jQuery selection.
472
+ @param target element - the target input field or division or span
473
+ @param date Date - the new date */
474
+ _setDateDatepicker: function(target, date) {
475
+ var inst = this._getInst(target);
476
+ if (inst) {
477
+ this._setDate(inst, date);
478
+ this._updateDatepicker(inst);
479
+ this._updateAlternate(inst);
480
+ }
481
+ },
482
+
483
+ /* Get the date(s) for the first entry in a jQuery selection.
484
+ @param target element - the target input field or division or span
485
+ @param noDefault boolean - true if no default date is to be used
486
+ @return Date - the current date */
487
+ _getDateDatepicker: function(target, noDefault) {
488
+ var inst = this._getInst(target);
489
+ if (inst && !inst.inline)
490
+ this._setDateFromField(inst, noDefault);
491
+ return (inst ? this._getDate(inst) : null);
492
+ },
493
+
494
+ /* Handle keystrokes. */
495
+ _doKeyDown: function(event) {
496
+ var inst = $.datepicker._getInst(event.target);
497
+ var handled = true;
498
+ var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
499
+ inst._keyEvent = true;
500
+ if ($.datepicker._datepickerShowing)
501
+ switch (event.keyCode) {
502
+ case 9: $.datepicker._hideDatepicker();
503
+ handled = false;
504
+ break; // hide on tab out
505
+ case 13: var sel = $('td.' + $.datepicker._dayOverClass, inst.dpDiv).
506
+ add($('td.' + $.datepicker._currentClass, inst.dpDiv));
507
+ if (sel[0])
508
+ $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
509
+ else
510
+ $.datepicker._hideDatepicker();
511
+ return false; // don't submit the form
512
+ break; // select the value on enter
513
+ case 27: $.datepicker._hideDatepicker();
514
+ break; // hide on escape
515
+ case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
516
+ -$.datepicker._get(inst, 'stepBigMonths') :
517
+ -$.datepicker._get(inst, 'stepMonths')), 'M');
518
+ break; // previous month/year on page up/+ ctrl
519
+ case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
520
+ +$.datepicker._get(inst, 'stepBigMonths') :
521
+ +$.datepicker._get(inst, 'stepMonths')), 'M');
522
+ break; // next month/year on page down/+ ctrl
523
+ case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
524
+ handled = event.ctrlKey || event.metaKey;
525
+ break; // clear on ctrl or command +end
526
+ case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
527
+ handled = event.ctrlKey || event.metaKey;
528
+ break; // current on ctrl or command +home
529
+ case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
530
+ handled = event.ctrlKey || event.metaKey;
531
+ // -1 day on ctrl or command +left
532
+ if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
533
+ -$.datepicker._get(inst, 'stepBigMonths') :
534
+ -$.datepicker._get(inst, 'stepMonths')), 'M');
535
+ // next month/year on alt +left on Mac
536
+ break;
537
+ case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
538
+ handled = event.ctrlKey || event.metaKey;
539
+ break; // -1 week on ctrl or command +up
540
+ case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
541
+ handled = event.ctrlKey || event.metaKey;
542
+ // +1 day on ctrl or command +right
543
+ if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
544
+ +$.datepicker._get(inst, 'stepBigMonths') :
545
+ +$.datepicker._get(inst, 'stepMonths')), 'M');
546
+ // next month/year on alt +right
547
+ break;
548
+ case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
549
+ handled = event.ctrlKey || event.metaKey;
550
+ break; // +1 week on ctrl or command +down
551
+ default: handled = false;
552
+ }
553
+ else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
554
+ $.datepicker._showDatepicker(this);
555
+ else {
556
+ handled = false;
557
+ }
558
+ if (handled) {
559
+ event.preventDefault();
560
+ event.stopPropagation();
561
+ }
562
+ },
563
+
564
+ /* Filter entered characters - based on date format. */
565
+ _doKeyPress: function(event) {
566
+ var inst = $.datepicker._getInst(event.target);
567
+ if ($.datepicker._get(inst, 'constrainInput')) {
568
+ var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
569
+ var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
570
+ return event.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
571
+ }
572
+ },
573
+
574
+ /* Synchronise manual entry and field/alternate field. */
575
+ _doKeyUp: function(event) {
576
+ var inst = $.datepicker._getInst(event.target);
577
+ if (inst.input.val() != inst.lastVal) {
578
+ try {
579
+ var date = $.datepicker.parseDate(inst, (inst.input ? inst.input.val() : null));
580
+ if (date) { // only if valid
581
+ $.datepicker._setDateFromField(inst);
582
+ $.datepicker._updateAlternate(inst);
583
+ $.datepicker._updateDatepicker(inst);
584
+ }
585
+ }
586
+ catch (event) {
587
+ $.datepicker.log(event);
588
+ }
589
+ }
590
+ return true;
591
+ },
592
+
593
+ /* Pop-up the date picker for a given input field.
594
+ @param input element - the input field attached to the date picker or
595
+ event - if triggered by focus */
596
+ _showDatepicker: function(input) {
597
+ input = input.target || input;
598
+ if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
599
+ input = $('input', input.parentNode)[0];
600
+ if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
601
+ return;
602
+ var inst = $.datepicker._getInst(input);
603
+ if ($.datepicker._curInst && $.datepicker._curInst != inst) {
604
+ $.datepicker._curInst.dpDiv.stop(true, true);
605
+ }
606
+ var beforeShow = $.datepicker._get(inst, 'beforeShow');
607
+ extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
608
+ inst.lastVal = null;
609
+ $.datepicker._lastInput = input;
610
+ $.datepicker._setDateFromField(inst);
611
+ if ($.datepicker._inDialog) // hide cursor
612
+ input.value = '';
613
+ if (!$.datepicker._pos) { // position below input
614
+ $.datepicker._pos = $.datepicker._findPos(input);
615
+ $.datepicker._pos[1] += input.offsetHeight; // add the height
616
+ }
617
+ var isFixed = false;
618
+ $(input).parents().each(function() {
619
+ isFixed |= $(this).css('position') == 'fixed';
620
+ return !isFixed;
621
+ });
622
+ if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
623
+ $.datepicker._pos[0] -= document.documentElement.scrollLeft;
624
+ $.datepicker._pos[1] -= document.documentElement.scrollTop;
625
+ }
626
+ var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
627
+ $.datepicker._pos = null;
628
+ //to avoid flashes on Firefox
629
+ inst.dpDiv.empty();
630
+ // determine sizing offscreen
631
+ inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
632
+ $.datepicker._updateDatepicker(inst);
633
+ // fix width for dynamic number of date pickers
634
+ // and adjust position before showing
635
+ offset = $.datepicker._checkOffset(inst, offset, isFixed);
636
+ inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
637
+ 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
638
+ left: offset.left + 'px', top: offset.top + 'px'});
639
+ if (!inst.inline) {
640
+ var showAnim = $.datepicker._get(inst, 'showAnim');
641
+ var duration = $.datepicker._get(inst, 'duration');
642
+ var postProcess = function() {
643
+ $.datepicker._datepickerShowing = true;
644
+ var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
645
+ if( !! cover.length ){
646
+ var borders = $.datepicker._getBorders(inst.dpDiv);
647
+ cover.css({left: -borders[0], top: -borders[1],
648
+ width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
649
+ }
650
+ };
651
+ inst.dpDiv.zIndex($(input).zIndex()+1);
652
+ if ($.effects && $.effects[showAnim])
653
+ inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
654
+ else
655
+ inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
656
+ if (!showAnim || !duration)
657
+ postProcess();
658
+ if (inst.input.is(':visible') && !inst.input.is(':disabled'))
659
+ inst.input.focus();
660
+ $.datepicker._curInst = inst;
661
+ }
662
+ },
663
+
664
+ /* Generate the date picker content. */
665
+ _updateDatepicker: function(inst) {
666
+ var self = this;
667
+ var borders = $.datepicker._getBorders(inst.dpDiv);
668
+ inst.dpDiv.empty().append(this._generateHTML(inst));
669
+ var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
670
+ if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
671
+ cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
672
+ }
673
+ inst.dpDiv.find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a')
674
+ .bind('mouseout', function(){
675
+ $(this).removeClass('ui-state-hover');
676
+ if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
677
+ if(this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
678
+ })
679
+ .bind('mouseover', function(){
680
+ if (!self._isDisabledDatepicker( inst.inline ? inst.dpDiv.parent()[0] : inst.input[0])) {
681
+ $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
682
+ $(this).addClass('ui-state-hover');
683
+ if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
684
+ if(this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
685
+ }
686
+ })
687
+ .end()
688
+ .find('.' + this._dayOverClass + ' a')
689
+ .trigger('mouseover')
690
+ .end();
691
+ var numMonths = this._getNumberOfMonths(inst);
692
+ var cols = numMonths[1];
693
+ var width = 17;
694
+ if (cols > 1)
695
+ inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
696
+ else
697
+ inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
698
+ inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
699
+ 'Class']('ui-datepicker-multi');
700
+ inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
701
+ 'Class']('ui-datepicker-rtl');
702
+ if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
703
+ inst.input.is(':visible') && !inst.input.is(':disabled'))
704
+ inst.input.focus();
705
+ // deffered render of the years select (to avoid flashes on Firefox)
706
+ if( inst.yearshtml ){
707
+ var origyearshtml = inst.yearshtml;
708
+ setTimeout(function(){
709
+ //assure that inst.yearshtml didn't change.
710
+ if( origyearshtml === inst.yearshtml ){
711
+ inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml);
712
+ }
713
+ origyearshtml = inst.yearshtml = null;
714
+ }, 0);
715
+ }
716
+ },
717
+
718
+ /* Retrieve the size of left and top borders for an element.
719
+ @param elem (jQuery object) the element of interest
720
+ @return (number[2]) the left and top borders */
721
+ _getBorders: function(elem) {
722
+ var convert = function(value) {
723
+ return {thin: 1, medium: 2, thick: 3}[value] || value;
724
+ };
725
+ return [parseFloat(convert(elem.css('border-left-width'))),
726
+ parseFloat(convert(elem.css('border-top-width')))];
727
+ },
728
+
729
+ /* Check positioning to remain on screen. */
730
+ _checkOffset: function(inst, offset, isFixed) {
731
+ var dpWidth = inst.dpDiv.outerWidth();
732
+ var dpHeight = inst.dpDiv.outerHeight();
733
+ var inputWidth = inst.input ? inst.input.outerWidth() : 0;
734
+ var inputHeight = inst.input ? inst.input.outerHeight() : 0;
735
+ var viewWidth = document.documentElement.clientWidth + $(document).scrollLeft();
736
+ var viewHeight = document.documentElement.clientHeight + $(document).scrollTop();
737
+
738
+ offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
739
+ offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
740
+ offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
741
+
742
+ // now check if datepicker is showing outside window viewport - move to a better place if so.
743
+ offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
744
+ Math.abs(offset.left + dpWidth - viewWidth) : 0);
745
+ offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
746
+ Math.abs(dpHeight + inputHeight) : 0);
747
+
748
+ return offset;
749
+ },
750
+
751
+ /* Find an object's position on the screen. */
752
+ _findPos: function(obj) {
753
+ var inst = this._getInst(obj);
754
+ var isRTL = this._get(inst, 'isRTL');
755
+ while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
756
+ obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
757
+ }
758
+ var position = $(obj).offset();
759
+ return [position.left, position.top];
760
+ },
761
+
762
+ /* Hide the date picker from view.
763
+ @param input element - the input field attached to the date picker */
764
+ _hideDatepicker: function(input) {
765
+ var inst = this._curInst;
766
+ if (!inst || (input && inst != $.data(input, PROP_NAME)))
767
+ return;
768
+ if (this._datepickerShowing) {
769
+ var showAnim = this._get(inst, 'showAnim');
770
+ var duration = this._get(inst, 'duration');
771
+ var postProcess = function() {
772
+ $.datepicker._tidyDialog(inst);
773
+ this._curInst = null;
774
+ };
775
+ if ($.effects && $.effects[showAnim])
776
+ inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
777
+ else
778
+ inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
779
+ (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
780
+ if (!showAnim)
781
+ postProcess();
782
+ var onClose = this._get(inst, 'onClose');
783
+ if (onClose)
784
+ onClose.apply((inst.input ? inst.input[0] : null),
785
+ [(inst.input ? inst.input.val() : ''), inst]); // trigger custom callback
786
+ this._datepickerShowing = false;
787
+ this._lastInput = null;
788
+ if (this._inDialog) {
789
+ this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
790
+ if ($.blockUI) {
791
+ $.unblockUI();
792
+ $('body').append(this.dpDiv);
793
+ }
794
+ }
795
+ this._inDialog = false;
796
+ }
797
+ },
798
+
799
+ /* Tidy up after a dialog display. */
800
+ _tidyDialog: function(inst) {
801
+ inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
802
+ },
803
+
804
+ /* Close date picker if clicked elsewhere. */
805
+ _checkExternalClick: function(event) {
806
+ if (!$.datepicker._curInst)
807
+ return;
808
+ var $target = $(event.target);
809
+ if ($target[0].id != $.datepicker._mainDivId &&
810
+ $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
811
+ !$target.hasClass($.datepicker.markerClassName) &&
812
+ !$target.hasClass($.datepicker._triggerClass) &&
813
+ $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI))
814
+ $.datepicker._hideDatepicker();
815
+ },
816
+
817
+ /* Adjust one of the date sub-fields. */
818
+ _adjustDate: function(id, offset, period) {
819
+ var target = $(id);
820
+ var inst = this._getInst(target[0]);
821
+ if (this._isDisabledDatepicker(target[0])) {
822
+ return;
823
+ }
824
+ this._adjustInstDate(inst, offset +
825
+ (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
826
+ period);
827
+ this._updateDatepicker(inst);
828
+ },
829
+
830
+ /* Action for current link. */
831
+ _gotoToday: function(id) {
832
+ var target = $(id);
833
+ var inst = this._getInst(target[0]);
834
+ if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
835
+ inst.selectedDay = inst.currentDay;
836
+ inst.drawMonth = inst.selectedMonth = inst.currentMonth;
837
+ inst.drawYear = inst.selectedYear = inst.currentYear;
838
+ }
839
+ else {
840
+ var date = new Date();
841
+ inst.selectedDay = date.getDate();
842
+ inst.drawMonth = inst.selectedMonth = date.getMonth();
843
+ inst.drawYear = inst.selectedYear = date.getFullYear();
844
+ }
845
+ this._notifyChange(inst);
846
+ this._adjustDate(target);
847
+ },
848
+
849
+ /* Action for selecting a new month/year. */
850
+ _selectMonthYear: function(id, select, period) {
851
+ var target = $(id);
852
+ var inst = this._getInst(target[0]);
853
+ inst._selectingMonthYear = false;
854
+ inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
855
+ inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
856
+ parseInt(select.options[select.selectedIndex].value,10);
857
+ this._notifyChange(inst);
858
+ this._adjustDate(target);
859
+ },
860
+
861
+ /* Restore input focus after not changing month/year. */
862
+ _clickMonthYear: function(id) {
863
+ var target = $(id);
864
+ var inst = this._getInst(target[0]);
865
+ if (inst.input && inst._selectingMonthYear) {
866
+ setTimeout(function() {
867
+ inst.input.focus();
868
+ }, 0);
869
+ }
870
+ inst._selectingMonthYear = !inst._selectingMonthYear;
871
+ },
872
+
873
+ /* Action for selecting a day. */
874
+ _selectDay: function(id, month, year, td) {
875
+ var target = $(id);
876
+ if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
877
+ return;
878
+ }
879
+ var inst = this._getInst(target[0]);
880
+ inst.selectedDay = inst.currentDay = $('a', td).html();
881
+ inst.selectedMonth = inst.currentMonth = month;
882
+ inst.selectedYear = inst.currentYear = year;
883
+ this._selectDate(id, this._formatDate(inst,
884
+ inst.currentDay, inst.currentMonth, inst.currentYear));
885
+ },
886
+
887
+ /* Erase the input field and hide the date picker. */
888
+ _clearDate: function(id) {
889
+ var target = $(id);
890
+ var inst = this._getInst(target[0]);
891
+ this._selectDate(target, '');
892
+ },
893
+
894
+ /* Update the input field with the selected date. */
895
+ _selectDate: function(id, dateStr) {
896
+ var target = $(id);
897
+ var inst = this._getInst(target[0]);
898
+ dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
899
+ if (inst.input)
900
+ inst.input.val(dateStr);
901
+ this._updateAlternate(inst);
902
+ var onSelect = this._get(inst, 'onSelect');
903
+ if (onSelect)
904
+ onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
905
+ else if (inst.input)
906
+ inst.input.trigger('change'); // fire the change event
907
+ if (inst.inline)
908
+ this._updateDatepicker(inst);
909
+ else {
910
+ this._hideDatepicker();
911
+ this._lastInput = inst.input[0];
912
+ if (typeof(inst.input[0]) != 'object')
913
+ inst.input.focus(); // restore focus
914
+ this._lastInput = null;
915
+ }
916
+ },
917
+
918
+ /* Update any alternate field to synchronise with the main field. */
919
+ _updateAlternate: function(inst) {
920
+ var altField = this._get(inst, 'altField');
921
+ if (altField) { // update alternate field too
922
+ var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
923
+ var date = this._getDate(inst);
924
+ var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
925
+ $(altField).each(function() { $(this).val(dateStr); });
926
+ }
927
+ },
928
+
929
+ /* Set as beforeShowDay function to prevent selection of weekends.
930
+ @param date Date - the date to customise
931
+ @return [boolean, string] - is this date selectable?, what is its CSS class? */
932
+ noWeekends: function(date) {
933
+ var day = date.getDay();
934
+ return [(day > 0 && day < 6), ''];
935
+ },
936
+
937
+ /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
938
+ @param date Date - the date to get the week for
939
+ @return number - the number of the week within the year that contains this date */
940
+ iso8601Week: function(date) {
941
+ var checkDate = new Date(date.getTime());
942
+ // Find Thursday of this week starting on Monday
943
+ checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
944
+ var time = checkDate.getTime();
945
+ checkDate.setMonth(0); // Compare with Jan 1
946
+ checkDate.setDate(1);
947
+ return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
948
+ },
949
+
950
+ /* Parse a string value into a date object.
951
+ See formatDate below for the possible formats.
952
+
953
+ @param format string - the expected format of the date
954
+ @param partialFormats string - a list of fallback formats which allow partial dates
955
+ @param value string - the date in the above format
956
+ @param settings Object - attributes include:
957
+ shortYearCutoff number - the cutoff year for determining the century (optional)
958
+ dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
959
+ dayNames string[7] - names of the days from Sunday (optional)
960
+ monthNamesShort string[12] - abbreviated names of the months (optional)
961
+ monthNames string[12] - names of the months (optional)
962
+ @return Date - the extracted date value or null if value is blank */
963
+ parseDate: function (inst, value) {
964
+ var format = this._get(inst, 'dateFormat');
965
+ var partialFormats = this._get(inst, 'partialDateFormats');
966
+ var settings = this._getFormatConfig(inst);
967
+
968
+ if (format == null || value == null)
969
+ throw 'Invalid arguments';
970
+ value = (typeof value == 'object' ? value.toString() : value + '');
971
+ if (value == '')
972
+ return null;
973
+
974
+ var date = null, err = null;
975
+ try {
976
+ date = this._tryParsingDate(format, false, value, settings);
977
+ } catch(e) {
978
+ err = e;
979
+ for(var i = 0; i < partialFormats.length; i++) {
980
+ try {
981
+ date = this._tryParsingDate(partialFormats[i], true, value, settings);
982
+ break;
983
+ } catch(e) {
984
+ // ignore and try next
985
+ }
986
+ }
987
+ }
988
+ if(!date && err)
989
+ throw err;
990
+ return date;
991
+ },
992
+
993
+ _tryParsingDate: function(format, allowPartial, value, settings) {
994
+ var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
995
+ var allowShortYear = (settings && ('allowShortYear' in settings) ? settings.allowShortYear : this._defaults.allowShortYear);
996
+ var ignoreTrailingCharacters = (settings && ('ignoreTrailingCharacters' in settings) ? settings.ignoreTrailingCharacters : this._defaults.allowShortYear);
997
+ var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
998
+ var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
999
+ var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
1000
+ var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
1001
+ var year = -1;
1002
+ var month = -1;
1003
+ var day = -1;
1004
+ var doy = -1;
1005
+ var literal = false;
1006
+ // Check whether a format character is doubled
1007
+ var lookAhead = function(match) {
1008
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1009
+ if (matches)
1010
+ iFormat++;
1011
+ return matches;
1012
+ };
1013
+ // Extract a number from the string value
1014
+ var getNumber = function(match) {
1015
+ lookAhead(match);
1016
+ var size = (match == '@' ? 14 : (match == '!' ? 20 :
1017
+ (match == 'y' ? 4 : (match == 'o' ? 3 : 2))));
1018
+ var digits = new RegExp('^\\d{1,' + size + '}');
1019
+ var num = value.substring(iValue).match(digits);
1020
+ if (!num)
1021
+ throw 'Missing number at position ' + iValue;
1022
+ iValue += num[0].length;
1023
+ return parseInt(num[0], 10);
1024
+ };
1025
+ // Extract a name from the string value and convert to an index
1026
+ var getName = function(match, shortNames, longNames) {
1027
+ var names = (lookAhead(match) ? longNames : shortNames);
1028
+ for (var i = 0; i < names.length; i++) {
1029
+ if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
1030
+ iValue += names[i].length;
1031
+ return i + 1;
1032
+ }
1033
+ }
1034
+ throw 'Unknown name at position ' + iValue;
1035
+ };
1036
+ // Confirm that a literal character matches the string value
1037
+ var checkLiteral = function() {
1038
+ if (value.charAt(iValue) != format.charAt(iFormat))
1039
+ throw 'Unexpected literal at position ' + iValue;
1040
+ iValue++;
1041
+ };
1042
+ var iValue = 0;
1043
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
1044
+ if (literal)
1045
+ if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1046
+ literal = false;
1047
+ else
1048
+ checkLiteral();
1049
+ else
1050
+ switch (format.charAt(iFormat)) {
1051
+ case 'd':
1052
+ day = getNumber('d');
1053
+ break;
1054
+ case 'D':
1055
+ getName('D', dayNamesShort, dayNames);
1056
+ break;
1057
+ case 'o':
1058
+ doy = getNumber('o');
1059
+ break;
1060
+ case 'm':
1061
+ month = getNumber('m');
1062
+ break;
1063
+ case 'M':
1064
+ month = getName('M', monthNamesShort, monthNames);
1065
+ break;
1066
+ case 'y':
1067
+ year = getNumber('y');
1068
+ break;
1069
+ case '@':
1070
+ var date = new Date(getNumber('@'));
1071
+ year = date.getFullYear();
1072
+ month = date.getMonth() + 1;
1073
+ day = date.getDate();
1074
+ break;
1075
+ case '!':
1076
+ var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
1077
+ year = date.getFullYear();
1078
+ month = date.getMonth() + 1;
1079
+ day = date.getDate();
1080
+ break;
1081
+ case "'":
1082
+ if (lookAhead("'"))
1083
+ checkLiteral();
1084
+ else
1085
+ literal = true;
1086
+ break;
1087
+ default:
1088
+ checkLiteral();
1089
+ }
1090
+ }
1091
+ if (year == -1)
1092
+ year = new Date().getFullYear();
1093
+ else if (!allowShortYear && year < 1000)
1094
+ throw 'Short year not allowed';
1095
+ else if (year < 100)
1096
+ year += new Date().getFullYear() - new Date().getFullYear() % 100 +
1097
+ (year <= shortYearCutoff ? 0 : -100);
1098
+ if (doy > -1) {
1099
+ month = 1;
1100
+ day = doy;
1101
+ do {
1102
+ var dim = this._getDaysInMonth(year, month - 1);
1103
+ if (day <= dim)
1104
+ break;
1105
+ month++;
1106
+ day -= dim;
1107
+ } while (true);
1108
+ }
1109
+ if (allowPartial) {
1110
+ if(month == -1)
1111
+ month = 1;
1112
+ if(day == -1)
1113
+ day = 1;
1114
+ }
1115
+ if (!ignoreTrailingCharacters && iValue < value.length)
1116
+ throw 'Extra characters after date';
1117
+ var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
1118
+ if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
1119
+ throw 'Invalid date'; // E.g. 31/02/*
1120
+ return date;
1121
+ },
1122
+
1123
+ /* Standard date formats. */
1124
+ ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
1125
+ COOKIE: 'D, dd M yy',
1126
+ ISO_8601: 'yy-mm-dd',
1127
+ RFC_822: 'D, d M y',
1128
+ RFC_850: 'DD, dd-M-y',
1129
+ RFC_1036: 'D, d M y',
1130
+ RFC_1123: 'D, d M yy',
1131
+ RFC_2822: 'D, d M yy',
1132
+ RSS: 'D, d M y', // RFC 822
1133
+ TICKS: '!',
1134
+ TIMESTAMP: '@',
1135
+ W3C: 'yy-mm-dd', // ISO 8601
1136
+
1137
+ _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
1138
+ Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
1139
+
1140
+ /* Format a date object into a string value.
1141
+ The format can be combinations of the following:
1142
+ d - day of month (no leading zero)
1143
+ dd - day of month (two digit)
1144
+ o - day of year (no leading zeros)
1145
+ oo - day of year (three digit)
1146
+ D - day name short
1147
+ DD - day name long
1148
+ m - month of year (no leading zero)
1149
+ mm - month of year (two digit)
1150
+ M - month name short
1151
+ MM - month name long
1152
+ y - year (two digit)
1153
+ yy - year (four digit)
1154
+ @ - Unix timestamp (ms since 01/01/1970)
1155
+ ! - Windows ticks (100ns since 01/01/0001)
1156
+ '...' - literal text
1157
+ '' - single quote
1158
+
1159
+ @param format string - the desired format of the date
1160
+ @param date Date - the date value to format
1161
+ @param settings Object - attributes include:
1162
+ dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
1163
+ dayNames string[7] - names of the days from Sunday (optional)
1164
+ monthNamesShort string[12] - abbreviated names of the months (optional)
1165
+ monthNames string[12] - names of the months (optional)
1166
+ @return string - the date in the above format */
1167
+ formatDate: function (format, date, settings) {
1168
+ if (!date)
1169
+ return '';
1170
+ var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
1171
+ var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
1172
+ var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
1173
+ var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
1174
+ // Check whether a format character is doubled
1175
+ var lookAhead = function(match) {
1176
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1177
+ if (matches)
1178
+ iFormat++;
1179
+ return matches;
1180
+ };
1181
+ // Format a number, with leading zero if necessary
1182
+ var formatNumber = function(match, value, len) {
1183
+ var num = '' + value;
1184
+ if (lookAhead(match))
1185
+ while (num.length < len)
1186
+ num = '0' + num;
1187
+ return num;
1188
+ };
1189
+ // Format a name, short or long as requested
1190
+ var formatName = function(match, value, shortNames, longNames) {
1191
+ return (lookAhead(match) ? longNames[value] : shortNames[value]);
1192
+ };
1193
+ var output = '';
1194
+ var literal = false;
1195
+ if (date)
1196
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
1197
+ if (literal)
1198
+ if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1199
+ literal = false;
1200
+ else
1201
+ output += format.charAt(iFormat);
1202
+ else
1203
+ switch (format.charAt(iFormat)) {
1204
+ case 'd':
1205
+ output += formatNumber('d', date.getDate(), 2);
1206
+ break;
1207
+ case 'D':
1208
+ output += formatName('D', date.getDay(), dayNamesShort, dayNames);
1209
+ break;
1210
+ case 'o':
1211
+ output += formatNumber('o',
1212
+ (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000, 3);
1213
+ break;
1214
+ case 'm':
1215
+ output += formatNumber('m', date.getMonth() + 1, 2);
1216
+ break;
1217
+ case 'M':
1218
+ output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
1219
+ break;
1220
+ case 'y':
1221
+ output += (lookAhead('y') ? date.getFullYear() :
1222
+ (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
1223
+ break;
1224
+ case '@':
1225
+ output += date.getTime();
1226
+ break;
1227
+ case '!':
1228
+ output += date.getTime() * 10000 + this._ticksTo1970;
1229
+ break;
1230
+ case "'":
1231
+ if (lookAhead("'"))
1232
+ output += "'";
1233
+ else
1234
+ literal = true;
1235
+ break;
1236
+ default:
1237
+ output += format.charAt(iFormat);
1238
+ }
1239
+ }
1240
+ return output;
1241
+ },
1242
+
1243
+ /* Extract all possible characters from the date format. */
1244
+ _possibleChars: function (format) {
1245
+ var chars = '';
1246
+ var literal = false;
1247
+ // Check whether a format character is doubled
1248
+ var lookAhead = function(match) {
1249
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1250
+ if (matches)
1251
+ iFormat++;
1252
+ return matches;
1253
+ };
1254
+ for (var iFormat = 0; iFormat < format.length; iFormat++)
1255
+ if (literal)
1256
+ if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1257
+ literal = false;
1258
+ else
1259
+ chars += format.charAt(iFormat);
1260
+ else
1261
+ switch (format.charAt(iFormat)) {
1262
+ case 'd': case 'm': case 'y': case '@':
1263
+ chars += '0123456789';
1264
+ break;
1265
+ case 'D': case 'M':
1266
+ return null; // Accept anything
1267
+ case "'":
1268
+ if (lookAhead("'"))
1269
+ chars += "'";
1270
+ else
1271
+ literal = true;
1272
+ break;
1273
+ default:
1274
+ chars += format.charAt(iFormat);
1275
+ }
1276
+ return chars;
1277
+ },
1278
+
1279
+ /* Get a setting value, defaulting if necessary. */
1280
+ _get: function(inst, name) {
1281
+ return inst.settings[name] !== undefined ?
1282
+ inst.settings[name] : this._defaults[name];
1283
+ },
1284
+
1285
+ /* Parse existing date and initialise date picker. */
1286
+ _setDateFromField: function(inst, noDefault) {
1287
+ if (inst.input.val() == inst.lastVal) {
1288
+ return;
1289
+ }
1290
+ var dates = inst.lastVal = inst.input ? inst.input.val() : null;
1291
+ var date, defaultDate;
1292
+ date = defaultDate = this._getDefaultDate(inst);
1293
+ try {
1294
+ date = this.parseDate(inst, dates) || defaultDate;
1295
+ } catch (event) {
1296
+ this.log(event);
1297
+ dates = (noDefault ? '' : dates);
1298
+ }
1299
+ inst.selectedDay = date.getDate();
1300
+ inst.drawMonth = inst.selectedMonth = date.getMonth();
1301
+ inst.drawYear = inst.selectedYear = date.getFullYear();
1302
+ inst.currentDay = (dates ? date.getDate() : 0);
1303
+ inst.currentMonth = (dates ? date.getMonth() : 0);
1304
+ inst.currentYear = (dates ? date.getFullYear() : 0);
1305
+ this._adjustInstDate(inst);
1306
+ },
1307
+
1308
+ /* Retrieve the default date shown on opening. */
1309
+ _getDefaultDate: function(inst) {
1310
+ return this._restrictMinMax(inst,
1311
+ this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
1312
+ },
1313
+
1314
+ /* A date may be specified as an exact value or a relative one. */
1315
+ _determineDate: function(inst, date, defaultDate) {
1316
+ var offsetNumeric = function(offset) {
1317
+ var date = new Date();
1318
+ date.setDate(date.getDate() + offset);
1319
+ return date;
1320
+ };
1321
+ var offsetString = function(offset) {
1322
+ try {
1323
+ return $.datepicker.parseDate(inst, offset);
1324
+ }
1325
+ catch (e) {
1326
+ // Ignore
1327
+ }
1328
+ var date = (offset.toLowerCase().match(/^c/) ?
1329
+ $.datepicker._getDate(inst) : null) || new Date();
1330
+ var year = date.getFullYear();
1331
+ var month = date.getMonth();
1332
+ var day = date.getDate();
1333
+ var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
1334
+ var matches = pattern.exec(offset);
1335
+ while (matches) {
1336
+ switch (matches[2] || 'd') {
1337
+ case 'd' : case 'D' :
1338
+ day += parseInt(matches[1],10); break;
1339
+ case 'w' : case 'W' :
1340
+ day += parseInt(matches[1],10) * 7; break;
1341
+ case 'm' : case 'M' :
1342
+ month += parseInt(matches[1],10);
1343
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
1344
+ break;
1345
+ case 'y': case 'Y' :
1346
+ year += parseInt(matches[1],10);
1347
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
1348
+ break;
1349
+ }
1350
+ matches = pattern.exec(offset);
1351
+ }
1352
+ return new Date(year, month, day);
1353
+ };
1354
+ date = (date == null ? defaultDate : (typeof date == 'string' ? offsetString(date) :
1355
+ (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : date)));
1356
+ date = (date && date.toString() == 'Invalid Date' ? defaultDate : date);
1357
+ if (date) {
1358
+ date.setHours(0);
1359
+ date.setMinutes(0);
1360
+ date.setSeconds(0);
1361
+ date.setMilliseconds(0);
1362
+ }
1363
+ return this._daylightSavingAdjust(date);
1364
+ },
1365
+
1366
+ /* Handle switch to/from daylight saving.
1367
+ Hours may be non-zero on daylight saving cut-over:
1368
+ > 12 when midnight changeover, but then cannot generate
1369
+ midnight datetime, so jump to 1AM, otherwise reset.
1370
+ @param date (Date) the date to check
1371
+ @return (Date) the corrected date */
1372
+ _daylightSavingAdjust: function(date) {
1373
+ if (!date) return null;
1374
+ date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
1375
+ return date;
1376
+ },
1377
+
1378
+ /* Set the date(s) directly. */
1379
+ _setDate: function(inst, date, noChange) {
1380
+ var clear = !(date);
1381
+ var origMonth = inst.selectedMonth;
1382
+ var origYear = inst.selectedYear;
1383
+ date = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
1384
+ inst.selectedDay = inst.currentDay = date.getDate();
1385
+ inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth();
1386
+ inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear();
1387
+ if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
1388
+ this._notifyChange(inst);
1389
+ this._adjustInstDate(inst);
1390
+ if (inst.input) {
1391
+ inst.input.val(clear ? '' : this._formatDate(inst));
1392
+ }
1393
+ },
1394
+
1395
+ /* Retrieve the date(s) directly. */
1396
+ _getDate: function(inst) {
1397
+ var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
1398
+ this._daylightSavingAdjust(new Date(
1399
+ inst.currentYear, inst.currentMonth, inst.currentDay)));
1400
+ return startDate;
1401
+ },
1402
+
1403
+ /* Generate the HTML for the current state of the date picker. */
1404
+ _generateHTML: function(inst) {
1405
+ var today = new Date();
1406
+ today = this._daylightSavingAdjust(
1407
+ new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
1408
+ var isRTL = this._get(inst, 'isRTL');
1409
+ var showButtonPanel = this._get(inst, 'showButtonPanel');
1410
+ var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
1411
+ var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
1412
+ var numMonths = this._getNumberOfMonths(inst);
1413
+ var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
1414
+ var stepMonths = this._get(inst, 'stepMonths');
1415
+ var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
1416
+ var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
1417
+ new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
1418
+ var minDate = this._getMinMaxDate(inst, 'min');
1419
+ var maxDate = this._getMinMaxDate(inst, 'max');
1420
+ var drawMonth = inst.drawMonth - showCurrentAtPos;
1421
+ var drawYear = inst.drawYear;
1422
+ if (drawMonth < 0) {
1423
+ drawMonth += 12;
1424
+ drawYear--;
1425
+ }
1426
+ if (maxDate) {
1427
+ var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
1428
+ maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
1429
+ maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
1430
+ while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
1431
+ drawMonth--;
1432
+ if (drawMonth < 0) {
1433
+ drawMonth = 11;
1434
+ drawYear--;
1435
+ }
1436
+ }
1437
+ }
1438
+ inst.drawMonth = drawMonth;
1439
+ inst.drawYear = drawYear;
1440
+ var prevText = this._get(inst, 'prevText');
1441
+ prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
1442
+ this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
1443
+ this._getFormatConfig(inst)));
1444
+ var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
1445
+ '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1446
+ '.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
1447
+ ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
1448
+ (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
1449
+ var nextText = this._get(inst, 'nextText');
1450
+ nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
1451
+ this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
1452
+ this._getFormatConfig(inst)));
1453
+ var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
1454
+ '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1455
+ '.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
1456
+ ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
1457
+ (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
1458
+ var currentText = this._get(inst, 'currentText');
1459
+ var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
1460
+ currentText = (!navigationAsDateFormat ? currentText :
1461
+ this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
1462
+ var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1463
+ '.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
1464
+ var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
1465
+ (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1466
+ '.datepicker._gotoToday(\'#' + inst.id + '\');"' +
1467
+ '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
1468
+ var firstDay = parseInt(this._get(inst, 'firstDay'),10);
1469
+ firstDay = (isNaN(firstDay) ? 0 : firstDay);
1470
+ var showWeek = this._get(inst, 'showWeek');
1471
+ var dayNames = this._get(inst, 'dayNames');
1472
+ var dayNamesShort = this._get(inst, 'dayNamesShort');
1473
+ var dayNamesMin = this._get(inst, 'dayNamesMin');
1474
+ var monthNames = this._get(inst, 'monthNames');
1475
+ var monthNamesShort = this._get(inst, 'monthNamesShort');
1476
+ var beforeShowDay = this._get(inst, 'beforeShowDay');
1477
+ var showOtherMonths = this._get(inst, 'showOtherMonths');
1478
+ var selectOtherMonths = this._get(inst, 'selectOtherMonths');
1479
+ var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
1480
+ var defaultDate = this._getDefaultDate(inst);
1481
+ var html = '';
1482
+ for (var row = 0; row < numMonths[0]; row++) {
1483
+ var group = '';
1484
+ for (var col = 0; col < numMonths[1]; col++) {
1485
+ var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
1486
+ var cornerClass = ' ui-corner-all';
1487
+ var calender = '';
1488
+ if (isMultiMonth) {
1489
+ calender += '<div class="ui-datepicker-group';
1490
+ if (numMonths[1] > 1)
1491
+ switch (col) {
1492
+ case 0: calender += ' ui-datepicker-group-first';
1493
+ cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
1494
+ case numMonths[1]-1: calender += ' ui-datepicker-group-last';
1495
+ cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
1496
+ default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
1497
+ }
1498
+ calender += '">';
1499
+ }
1500
+ calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
1501
+ (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
1502
+ (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
1503
+ this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
1504
+ row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
1505
+ '</div><table class="ui-datepicker-calendar"><thead>' +
1506
+ '<tr>';
1507
+ var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
1508
+ for (var dow = 0; dow < 7; dow++) { // days of the week
1509
+ var day = (dow + firstDay) % 7;
1510
+ thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
1511
+ '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
1512
+ }
1513
+ calender += thead + '</tr></thead><tbody>';
1514
+ var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
1515
+ if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
1516
+ inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
1517
+ var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
1518
+ var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
1519
+ var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
1520
+ for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
1521
+ calender += '<tr>';
1522
+ var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
1523
+ this._get(inst, 'calculateWeek')(printDate) + '</td>');
1524
+ for (var dow = 0; dow < 7; dow++) { // create date picker days
1525
+ var daySettings = (beforeShowDay ?
1526
+ beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
1527
+ var otherMonth = (printDate.getMonth() != drawMonth);
1528
+ var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
1529
+ (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
1530
+ tbody += '<td class="' +
1531
+ ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
1532
+ (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
1533
+ ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
1534
+ (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
1535
+ // or defaultDate is current printedDate and defaultDate is selectedDate
1536
+ ' ' + this._dayOverClass : '') + // highlight selected day
1537
+ (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
1538
+ (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
1539
+ (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
1540
+ (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
1541
+ ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
1542
+ (unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
1543
+ inst.id + '\',' + printDate.getMonth() + ',' + printDate.getFullYear() + ', this);return false;"') + '>' + // actions
1544
+ (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
1545
+ (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
1546
+ (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
1547
+ (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
1548
+ (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
1549
+ '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
1550
+ printDate.setDate(printDate.getDate() + 1);
1551
+ printDate = this._daylightSavingAdjust(printDate);
1552
+ }
1553
+ calender += tbody + '</tr>';
1554
+ }
1555
+ drawMonth++;
1556
+ if (drawMonth > 11) {
1557
+ drawMonth = 0;
1558
+ drawYear++;
1559
+ }
1560
+ calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
1561
+ ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
1562
+ group += calender;
1563
+ }
1564
+ html += group;
1565
+ }
1566
+ html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
1567
+ '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
1568
+ inst._keyEvent = false;
1569
+ return html;
1570
+ },
1571
+
1572
+ /* Generate the month and year header. */
1573
+ _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
1574
+ secondary, monthNames, monthNamesShort) {
1575
+ var changeMonth = this._get(inst, 'changeMonth');
1576
+ var changeYear = this._get(inst, 'changeYear');
1577
+ var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
1578
+ var html = '<div class="ui-datepicker-title">';
1579
+ var monthHtml = '';
1580
+ // month selection
1581
+ if (secondary || !changeMonth)
1582
+ monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
1583
+ else {
1584
+ var inMinYear = (minDate && minDate.getFullYear() == drawYear);
1585
+ var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
1586
+ monthHtml += '<select class="ui-datepicker-month" ' +
1587
+ 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
1588
+ 'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
1589
+ '>';
1590
+ for (var month = 0; month < 12; month++) {
1591
+ if ((!inMinYear || month >= minDate.getMonth()) &&
1592
+ (!inMaxYear || month <= maxDate.getMonth()))
1593
+ monthHtml += '<option value="' + month + '"' +
1594
+ (month == drawMonth ? ' selected="selected"' : '') +
1595
+ '>' + monthNamesShort[month] + '</option>';
1596
+ }
1597
+ monthHtml += '</select>';
1598
+ }
1599
+ if (!showMonthAfterYear)
1600
+ html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
1601
+ // year selection
1602
+ inst.yearshtml = '';
1603
+ if (secondary || !changeYear)
1604
+ html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
1605
+ else {
1606
+ // determine range of years to display
1607
+ var years = this._get(inst, 'yearRange').split(':');
1608
+ var thisYear = new Date().getFullYear();
1609
+ var determineYear = function(value) {
1610
+ var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
1611
+ (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
1612
+ parseInt(value, 10)));
1613
+ return (isNaN(year) ? thisYear : year);
1614
+ };
1615
+ var year = determineYear(years[0]);
1616
+ var endYear = Math.max(year, determineYear(years[1] || ''));
1617
+ year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
1618
+ endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
1619
+ inst.yearshtml += '<select class="ui-datepicker-year" ' +
1620
+ 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
1621
+ 'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
1622
+ '>';
1623
+ for (; year <= endYear; year++) {
1624
+ inst.yearshtml += '<option value="' + year + '"' +
1625
+ (year == drawYear ? ' selected="selected"' : '') +
1626
+ '>' + year + '</option>';
1627
+ }
1628
+ inst.yearshtml += '</select>';
1629
+ //when showing there is no need for later update
1630
+ if( ! $.browser.mozilla ){
1631
+ html += inst.yearshtml;
1632
+ inst.yearshtml = null;
1633
+ } else {
1634
+ // will be replaced later with inst.yearshtml
1635
+ html += '<select class="ui-datepicker-year"><option value="' + drawYear + '" selected="selected">' + drawYear + '</option></select>';
1636
+ }
1637
+ }
1638
+ html += this._get(inst, 'yearSuffix');
1639
+ if (showMonthAfterYear)
1640
+ html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
1641
+ html += '</div>'; // Close datepicker_header
1642
+ return html;
1643
+ },
1644
+
1645
+ /* Adjust one of the date sub-fields. */
1646
+ _adjustInstDate: function(inst, offset, period) {
1647
+ var year = inst.drawYear + (period == 'Y' ? offset : 0);
1648
+ var month = inst.drawMonth + (period == 'M' ? offset : 0);
1649
+ var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
1650
+ (period == 'D' ? offset : 0);
1651
+ var date = this._restrictMinMax(inst,
1652
+ this._daylightSavingAdjust(new Date(year, month, day)));
1653
+ inst.selectedDay = date.getDate();
1654
+ inst.drawMonth = inst.selectedMonth = date.getMonth();
1655
+ inst.drawYear = inst.selectedYear = date.getFullYear();
1656
+ if (period == 'M' || period == 'Y')
1657
+ this._notifyChange(inst);
1658
+ },
1659
+
1660
+ /* Ensure a date is within any min/max bounds. */
1661
+ _restrictMinMax: function(inst, date) {
1662
+ var minDate = this._getMinMaxDate(inst, 'min');
1663
+ var maxDate = this._getMinMaxDate(inst, 'max');
1664
+ date = (minDate && date < minDate ? minDate : date);
1665
+ date = (maxDate && date > maxDate ? maxDate : date);
1666
+ return date;
1667
+ },
1668
+
1669
+ /* Notify change of month/year. */
1670
+ _notifyChange: function(inst) {
1671
+ var onChange = this._get(inst, 'onChangeMonthYear');
1672
+ if (onChange)
1673
+ onChange.apply((inst.input ? inst.input[0] : null),
1674
+ [inst.selectedYear, inst.selectedMonth + 1, inst]);
1675
+ },
1676
+
1677
+ /* Determine the number of months to show. */
1678
+ _getNumberOfMonths: function(inst) {
1679
+ var numMonths = this._get(inst, 'numberOfMonths');
1680
+ return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
1681
+ },
1682
+
1683
+ /* Determine the current maximum date - ensure no time components are set. */
1684
+ _getMinMaxDate: function(inst, minMax) {
1685
+ return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
1686
+ },
1687
+
1688
+ /* Find the number of days in a given month. */
1689
+ _getDaysInMonth: function(year, month) {
1690
+ return 32 - new Date(year, month, 32).getDate();
1691
+ },
1692
+
1693
+ /* Find the day of the week of the first of a month. */
1694
+ _getFirstDayOfMonth: function(year, month) {
1695
+ return new Date(year, month, 1).getDay();
1696
+ },
1697
+
1698
+ /* Determines if we should allow a "next/prev" month display change. */
1699
+ _canAdjustMonth: function(inst, offset, curYear, curMonth) {
1700
+ var numMonths = this._getNumberOfMonths(inst);
1701
+ var date = this._daylightSavingAdjust(new Date(curYear,
1702
+ curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
1703
+ if (offset < 0)
1704
+ date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
1705
+ return this._isInRange(inst, date);
1706
+ },
1707
+
1708
+ /* Is the given date in the accepted range? */
1709
+ _isInRange: function(inst, date) {
1710
+ var minDate = this._getMinMaxDate(inst, 'min');
1711
+ var maxDate = this._getMinMaxDate(inst, 'max');
1712
+ return ((!minDate || date.getTime() >= minDate.getTime()) &&
1713
+ (!maxDate || date.getTime() <= maxDate.getTime()));
1714
+ },
1715
+
1716
+ /* Provide the configuration settings for formatting/parsing. */
1717
+ _getFormatConfig: function(inst) {
1718
+ var shortYearCutoff = this._get(inst, 'shortYearCutoff');
1719
+ shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
1720
+ new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
1721
+ return {shortYearCutoff: shortYearCutoff, allowShortYear: this._get(inst, 'allowShortYear'),
1722
+ dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
1723
+ monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames'),
1724
+ ignoreTrailingCharacters: this._get(inst, 'ignoreTrailingCharacters')};
1725
+ },
1726
+
1727
+ /* Format the given date for display. */
1728
+ _formatDate: function(inst, day, month, year) {
1729
+ if (!day) {
1730
+ inst.currentDay = inst.selectedDay;
1731
+ inst.currentMonth = inst.selectedMonth;
1732
+ inst.currentYear = inst.selectedYear;
1733
+ }
1734
+ var date = (day ? (typeof day == 'object' ? day :
1735
+ this._daylightSavingAdjust(new Date(year, month, day))) :
1736
+ this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
1737
+ return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
1738
+ }
1739
+ });
1740
+
1741
+ /* jQuery extend now ignores nulls! */
1742
+ function extendRemove(target, props) {
1743
+ $.extend(target, props);
1744
+ for (var name in props)
1745
+ if (props[name] == null || props[name] == undefined)
1746
+ target[name] = props[name];
1747
+ return target;
1748
+ };
1749
+
1750
+ /* Determine whether an object is an array. */
1751
+ function isArray(a) {
1752
+ return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
1753
+ (a.constructor && a.constructor.toString().match(/\Array\(\)/))));
1754
+ };
1755
+
1756
+ /* Invoke the datepicker functionality.
1757
+ @param options string - a command, optionally followed by additional parameters or
1758
+ Object - settings for attaching new datepicker functionality
1759
+ @return jQuery object */
1760
+ $.fn.datepicker = function(options){
1761
+
1762
+ /* Initialise the date picker. */
1763
+ if (!$.datepicker.initialized) {
1764
+ $(document).mousedown($.datepicker._checkExternalClick).
1765
+ find('body').append($.datepicker.dpDiv);
1766
+ $.datepicker.initialized = true;
1767
+ }
1768
+
1769
+ var otherArgs = Array.prototype.slice.call(arguments, 1);
1770
+ if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
1771
+ return $.datepicker['_' + options + 'Datepicker'].
1772
+ apply($.datepicker, [this[0]].concat(otherArgs));
1773
+ if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
1774
+ return $.datepicker['_' + options + 'Datepicker'].
1775
+ apply($.datepicker, [this[0]].concat(otherArgs));
1776
+ return this.each(function() {
1777
+ typeof options == 'string' ?
1778
+ $.datepicker['_' + options + 'Datepicker'].
1779
+ apply($.datepicker, [this].concat(otherArgs)) :
1780
+ $.datepicker._attachDatepicker(this, options);
1781
+ });
1782
+ };
1783
+
1784
+ $.datepicker = new Datepicker(); // singleton instance
1785
+ $.datepicker.initialized = false;
1786
+ $.datepicker.uuid = new Date().getTime();
1787
+ $.datepicker.version = "@VERSION";
1788
+
1789
+ // Workaround for #4055
1790
+ // Add another global to avoid noConflict issues with inline event handlers
1791
+ window['DP_jQuery_' + dpuuid] = $;
1792
+
1793
+ })(jQuery);