You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery-ui.js 84KB

8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383
  1. /*! jQuery UI - v1.11.4 - 2015-04-20
  2. * http://jqueryui.com
  3. * Includes: core.js, datepicker.js
  4. * Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */
  5. (function( factory ) {
  6. if ( typeof define === "function" && define.amd ) {
  7. // AMD. Register as an anonymous module.
  8. define([ "jquery" ], factory );
  9. } else {
  10. // Browser globals
  11. factory( jQuery );
  12. }
  13. }(function( $ ) {
  14. /*!
  15. * jQuery UI Core 1.11.4
  16. * http://jqueryui.com
  17. *
  18. * Copyright jQuery Foundation and other contributors
  19. * Released under the MIT license.
  20. * http://jquery.org/license
  21. *
  22. * http://api.jqueryui.com/category/ui-core/
  23. */
  24. // $.ui might exist from components with no dependencies, e.g., $.ui.position
  25. $.ui = $.ui || {};
  26. $.extend( $.ui, {
  27. version: "1.11.4",
  28. keyCode: {
  29. BACKSPACE: 8,
  30. COMMA: 188,
  31. DELETE: 46,
  32. DOWN: 40,
  33. END: 35,
  34. ENTER: 13,
  35. ESCAPE: 27,
  36. HOME: 36,
  37. LEFT: 37,
  38. PAGE_DOWN: 34,
  39. PAGE_UP: 33,
  40. PERIOD: 190,
  41. RIGHT: 39,
  42. SPACE: 32,
  43. TAB: 9,
  44. UP: 38
  45. }
  46. });
  47. // plugins
  48. $.fn.extend({
  49. scrollParent: function( includeHidden ) {
  50. var position = this.css( "position" ),
  51. excludeStaticParent = position === "absolute",
  52. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  53. scrollParent = this.parents().filter( function() {
  54. var parent = $( this );
  55. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  56. return false;
  57. }
  58. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
  59. }).eq( 0 );
  60. return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
  61. },
  62. uniqueId: (function() {
  63. var uuid = 0;
  64. return function() {
  65. return this.each(function() {
  66. if ( !this.id ) {
  67. this.id = "ui-id-" + ( ++uuid );
  68. }
  69. });
  70. };
  71. })(),
  72. removeUniqueId: function() {
  73. return this.each(function() {
  74. if ( /^ui-id-\d+$/.test( this.id ) ) {
  75. $( this ).removeAttr( "id" );
  76. }
  77. });
  78. }
  79. });
  80. // selectors
  81. function focusable( element, isTabIndexNotNaN ) {
  82. var map, mapName, img,
  83. nodeName = element.nodeName.toLowerCase();
  84. if ( "area" === nodeName ) {
  85. map = element.parentNode;
  86. mapName = map.name;
  87. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  88. return false;
  89. }
  90. img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
  91. return !!img && visible( img );
  92. }
  93. return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
  94. !element.disabled :
  95. "a" === nodeName ?
  96. element.href || isTabIndexNotNaN :
  97. isTabIndexNotNaN) &&
  98. // the element and all of its ancestors must be visible
  99. visible( element );
  100. }
  101. function visible( element ) {
  102. return $.expr.filters.visible( element ) &&
  103. !$( element ).parents().addBack().filter(function() {
  104. return $.css( this, "visibility" ) === "hidden";
  105. }).length;
  106. }
  107. $.extend( $.expr[ ":" ], {
  108. data: $.expr.createPseudo ?
  109. $.expr.createPseudo(function( dataName ) {
  110. return function( elem ) {
  111. return !!$.data( elem, dataName );
  112. };
  113. }) :
  114. // support: jQuery <1.8
  115. function( elem, i, match ) {
  116. return !!$.data( elem, match[ 3 ] );
  117. },
  118. focusable: function( element ) {
  119. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  120. },
  121. tabbable: function( element ) {
  122. var tabIndex = $.attr( element, "tabindex" ),
  123. isTabIndexNaN = isNaN( tabIndex );
  124. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  125. }
  126. });
  127. // support: jQuery <1.8
  128. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  129. $.each( [ "Width", "Height" ], function( i, name ) {
  130. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  131. type = name.toLowerCase(),
  132. orig = {
  133. innerWidth: $.fn.innerWidth,
  134. innerHeight: $.fn.innerHeight,
  135. outerWidth: $.fn.outerWidth,
  136. outerHeight: $.fn.outerHeight
  137. };
  138. function reduce( elem, size, border, margin ) {
  139. $.each( side, function() {
  140. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  141. if ( border ) {
  142. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  143. }
  144. if ( margin ) {
  145. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  146. }
  147. });
  148. return size;
  149. }
  150. $.fn[ "inner" + name ] = function( size ) {
  151. if ( size === undefined ) {
  152. return orig[ "inner" + name ].call( this );
  153. }
  154. return this.each(function() {
  155. $( this ).css( type, reduce( this, size ) + "px" );
  156. });
  157. };
  158. $.fn[ "outer" + name] = function( size, margin ) {
  159. if ( typeof size !== "number" ) {
  160. return orig[ "outer" + name ].call( this, size );
  161. }
  162. return this.each(function() {
  163. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  164. });
  165. };
  166. });
  167. }
  168. // support: jQuery <1.8
  169. if ( !$.fn.addBack ) {
  170. $.fn.addBack = function( selector ) {
  171. return this.add( selector == null ?
  172. this.prevObject : this.prevObject.filter( selector )
  173. );
  174. };
  175. }
  176. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  177. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  178. $.fn.removeData = (function( removeData ) {
  179. return function( key ) {
  180. if ( arguments.length ) {
  181. return removeData.call( this, $.camelCase( key ) );
  182. } else {
  183. return removeData.call( this );
  184. }
  185. };
  186. })( $.fn.removeData );
  187. }
  188. // deprecated
  189. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  190. $.fn.extend({
  191. focus: (function( orig ) {
  192. return function( delay, fn ) {
  193. return typeof delay === "number" ?
  194. this.each(function() {
  195. var elem = this;
  196. setTimeout(function() {
  197. $( elem ).focus();
  198. if ( fn ) {
  199. fn.call( elem );
  200. }
  201. }, delay );
  202. }) :
  203. orig.apply( this, arguments );
  204. };
  205. })( $.fn.focus ),
  206. disableSelection: (function() {
  207. var eventType = "onselectstart" in document.createElement( "div" ) ?
  208. "selectstart" :
  209. "mousedown";
  210. return function() {
  211. return this.bind( eventType + ".ui-disableSelection", function( event ) {
  212. event.preventDefault();
  213. });
  214. };
  215. })(),
  216. enableSelection: function() {
  217. return this.unbind( ".ui-disableSelection" );
  218. },
  219. zIndex: function( zIndex ) {
  220. if ( zIndex !== undefined ) {
  221. return this.css( "zIndex", zIndex );
  222. }
  223. if ( this.length ) {
  224. var elem = $( this[ 0 ] ), position, value;
  225. while ( elem.length && elem[ 0 ] !== document ) {
  226. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  227. // This makes behavior of this function consistent across browsers
  228. // WebKit always returns auto if the element is positioned
  229. position = elem.css( "position" );
  230. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  231. // IE returns 0 when zIndex is not specified
  232. // other browsers return a string
  233. // we ignore the case of nested elements with an explicit value of 0
  234. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  235. value = parseInt( elem.css( "zIndex" ), 10 );
  236. if ( !isNaN( value ) && value !== 0 ) {
  237. return value;
  238. }
  239. }
  240. elem = elem.parent();
  241. }
  242. }
  243. return 0;
  244. }
  245. });
  246. // $.ui.plugin is deprecated. Use $.widget() extensions instead.
  247. $.ui.plugin = {
  248. add: function( module, option, set ) {
  249. var i,
  250. proto = $.ui[ module ].prototype;
  251. for ( i in set ) {
  252. proto.plugins[ i ] = proto.plugins[ i ] || [];
  253. proto.plugins[ i ].push( [ option, set[ i ] ] );
  254. }
  255. },
  256. call: function( instance, name, args, allowDisconnected ) {
  257. var i,
  258. set = instance.plugins[ name ];
  259. if ( !set ) {
  260. return;
  261. }
  262. if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
  263. return;
  264. }
  265. for ( i = 0; i < set.length; i++ ) {
  266. if ( instance.options[ set[ i ][ 0 ] ] ) {
  267. set[ i ][ 1 ].apply( instance.element, args );
  268. }
  269. }
  270. }
  271. };
  272. /*!
  273. * jQuery UI Datepicker 1.11.4
  274. * http://jqueryui.com
  275. *
  276. * Copyright jQuery Foundation and other contributors
  277. * Released under the MIT license.
  278. * http://jquery.org/license
  279. *
  280. * http://api.jqueryui.com/datepicker/
  281. */
  282. $.extend($.ui, { datepicker: { version: "1.11.4" } });
  283. var datepicker_instActive;
  284. function datepicker_getZindex( elem ) {
  285. var position, value;
  286. while ( elem.length && elem[ 0 ] !== document ) {
  287. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  288. // This makes behavior of this function consistent across browsers
  289. // WebKit always returns auto if the element is positioned
  290. position = elem.css( "position" );
  291. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  292. // IE returns 0 when zIndex is not specified
  293. // other browsers return a string
  294. // we ignore the case of nested elements with an explicit value of 0
  295. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  296. value = parseInt( elem.css( "zIndex" ), 10 );
  297. if ( !isNaN( value ) && value !== 0 ) {
  298. return value;
  299. }
  300. }
  301. elem = elem.parent();
  302. }
  303. return 0;
  304. }
  305. /* Date picker manager.
  306. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  307. Settings for (groups of) date pickers are maintained in an instance object,
  308. allowing multiple different settings on the same page. */
  309. function Datepicker() {
  310. this._curInst = null; // The current instance in use
  311. this._keyEvent = false; // If the last event was a key event
  312. this._disabledInputs = []; // List of date picker inputs that have been disabled
  313. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  314. this._inDialog = false; // True if showing within a "dialog", false if not
  315. this._mainDivId = "ui-datepicker-div"; // The ID of the main datepicker division
  316. this._inlineClass = "ui-datepicker-inline"; // The name of the inline marker class
  317. this._appendClass = "ui-datepicker-append"; // The name of the append marker class
  318. this._triggerClass = "ui-datepicker-trigger"; // The name of the trigger marker class
  319. this._dialogClass = "ui-datepicker-dialog"; // The name of the dialog marker class
  320. this._disableClass = "ui-datepicker-disabled"; // The name of the disabled covering marker class
  321. this._unselectableClass = "ui-datepicker-unselectable"; // The name of the unselectable cell marker class
  322. this._currentClass = "ui-datepicker-current-day"; // The name of the current day marker class
  323. this._dayOverClass = "ui-datepicker-days-cell-over"; // The name of the day hover marker class
  324. this.regional = []; // Available regional settings, indexed by language code
  325. this.regional[""] = { // Default regional settings
  326. closeText: "Done", // Display text for close link
  327. prevText: "Prev", // Display text for previous month link
  328. nextText: "Next", // Display text for next month link
  329. currentText: "Today", // Display text for current month link
  330. monthNames: ["January","February","March","April","May","June",
  331. "July","August","September","October","November","December"], // Names of months for drop-down and formatting
  332. monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], // For formatting
  333. dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], // For formatting
  334. dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], // For formatting
  335. dayNamesMin: ["Su","Mo","Tu","We","Th","Fr","Sa"], // Column headings for days starting at Sunday
  336. weekHeader: "Wk", // Column header for week of the year
  337. dateFormat: "mm/dd/yy", // See format options on parseDate
  338. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  339. isRTL: false, // True if right-to-left language, false if left-to-right
  340. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  341. yearSuffix: "" // Additional text to append to the year in the month headers
  342. };
  343. this._defaults = { // Global defaults for all the date picker instances
  344. showOn: "focus", // "focus" for popup on focus,
  345. // "button" for trigger button, or "both" for either
  346. showAnim: "fadeIn", // Name of jQuery animation for popup
  347. showOptions: {}, // Options for enhanced animations
  348. defaultDate: null, // Used when field is blank: actual date,
  349. // +/-number for offset from today, null for today
  350. appendText: "", // Display text following the input box, e.g. showing the format
  351. buttonText: "...", // Text for trigger button
  352. buttonImage: "", // URL for trigger button image
  353. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  354. hideIfNoPrevNext: false, // True to hide next/previous month links
  355. // if not applicable, false to just disable them
  356. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  357. gotoCurrent: false, // True if today link goes back to current selection instead
  358. changeMonth: false, // True if month can be selected directly, false if only prev/next
  359. changeYear: false, // True if year can be selected directly, false if only prev/next
  360. yearRange: "c-10:c+10", // Range of years to display in drop-down,
  361. // either relative to today's year (-nn:+nn), relative to currently displayed year
  362. // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
  363. showOtherMonths: false, // True to show dates in other months, false to leave blank
  364. selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
  365. showWeek: false, // True to show week of the year, false to not show it
  366. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  367. // takes a Date and returns the number of the week for it
  368. shortYearCutoff: "+10", // Short year values < this are in the current century,
  369. // > this are in the previous century,
  370. // string value starting with "+" for current year + value
  371. minDate: null, // The earliest selectable date, or null for no limit
  372. maxDate: null, // The latest selectable date, or null for no limit
  373. duration: "fast", // Duration of display/closure
  374. beforeShowDay: null, // Function that takes a date and returns an array with
  375. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or "",
  376. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  377. beforeShow: null, // Function that takes an input field and
  378. // returns a set of custom settings for the date picker
  379. onSelect: null, // Define a callback function when a date is selected
  380. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  381. onClose: null, // Define a callback function when the datepicker is closed
  382. numberOfMonths: 1, // Number of months to show at a time
  383. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  384. stepMonths: 1, // Number of months to step back/forward
  385. stepBigMonths: 12, // Number of months to step back/forward for the big links
  386. altField: "", // Selector for an alternate field to store selected dates into
  387. altFormat: "", // The date format to use for the alternate field
  388. constrainInput: true, // The input is constrained by the current date format
  389. showButtonPanel: false, // True to show button panel, false to not show it
  390. autoSize: false, // True to size the input for the date format, false to leave as is
  391. disabled: false // The initial disabled state
  392. };
  393. $.extend(this._defaults, this.regional[""]);
  394. this.regional.en = $.extend( true, {}, this.regional[ "" ]);
  395. this.regional[ "en-US" ] = $.extend( true, {}, this.regional.en );
  396. this.dpDiv = datepicker_bindHover($("<div id='" + this._mainDivId + "' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>"));
  397. }
  398. $.extend(Datepicker.prototype, {
  399. /* Class name added to elements to indicate already configured with a date picker. */
  400. markerClassName: "hasDatepicker",
  401. //Keep track of the maximum number of rows displayed (see #7043)
  402. maxRows: 4,
  403. // TODO rename to "widget" when switching to widget factory
  404. _widgetDatepicker: function() {
  405. return this.dpDiv;
  406. },
  407. /* Override the default settings for all instances of the date picker.
  408. * @param settings object - the new settings to use as defaults (anonymous object)
  409. * @return the manager object
  410. */
  411. setDefaults: function(settings) {
  412. datepicker_extendRemove(this._defaults, settings || {});
  413. return this;
  414. },
  415. /* Attach the date picker to a jQuery selection.
  416. * @param target element - the target input field or division or span
  417. * @param settings object - the new settings to use for this date picker instance (anonymous)
  418. */
  419. _attachDatepicker: function(target, settings) {
  420. var nodeName, inline, inst;
  421. nodeName = target.nodeName.toLowerCase();
  422. inline = (nodeName === "div" || nodeName === "span");
  423. if (!target.id) {
  424. this.uuid += 1;
  425. target.id = "dp" + this.uuid;
  426. }
  427. inst = this._newInst($(target), inline);
  428. inst.settings = $.extend({}, settings || {});
  429. if (nodeName === "input") {
  430. this._connectDatepicker(target, inst);
  431. } else if (inline) {
  432. this._inlineDatepicker(target, inst);
  433. }
  434. },
  435. /* Create a new instance object. */
  436. _newInst: function(target, inline) {
  437. var id = target[0].id.replace(/([^A-Za-z0-9_\-])/g, "\\\\$1"); // escape jQuery meta chars
  438. return {id: id, input: target, // associated target
  439. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  440. drawMonth: 0, drawYear: 0, // month being drawn
  441. inline: inline, // is datepicker inline or not
  442. dpDiv: (!inline ? this.dpDiv : // presentation div
  443. datepicker_bindHover($("<div class='" + this._inlineClass + " ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")))};
  444. },
  445. /* Attach the date picker to an input field. */
  446. _connectDatepicker: function(target, inst) {
  447. var input = $(target);
  448. inst.append = $([]);
  449. inst.trigger = $([]);
  450. if (input.hasClass(this.markerClassName)) {
  451. return;
  452. }
  453. this._attachments(input, inst);
  454. input.addClass(this.markerClassName).keydown(this._doKeyDown).
  455. keypress(this._doKeyPress).keyup(this._doKeyUp);
  456. this._autoSize(inst);
  457. $.data(target, "datepicker", inst);
  458. //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
  459. if( inst.settings.disabled ) {
  460. this._disableDatepicker( target );
  461. }
  462. },
  463. /* Make attachments based on settings. */
  464. _attachments: function(input, inst) {
  465. var showOn, buttonText, buttonImage,
  466. appendText = this._get(inst, "appendText"),
  467. isRTL = this._get(inst, "isRTL");
  468. if (inst.append) {
  469. inst.append.remove();
  470. }
  471. if (appendText) {
  472. inst.append = $("<span class='" + this._appendClass + "'>" + appendText + "</span>");
  473. input[isRTL ? "before" : "after"](inst.append);
  474. }
  475. input.unbind("focus", this._showDatepicker);
  476. if (inst.trigger) {
  477. inst.trigger.remove();
  478. }
  479. showOn = this._get(inst, "showOn");
  480. if (showOn === "focus" || showOn === "both") { // pop-up date picker when in the marked field
  481. input.focus(this._showDatepicker);
  482. }
  483. if (showOn === "button" || showOn === "both") { // pop-up date picker when button clicked
  484. buttonText = this._get(inst, "buttonText");
  485. buttonImage = this._get(inst, "buttonImage");
  486. inst.trigger = $(this._get(inst, "buttonImageOnly") ?
  487. $("<img/>").addClass(this._triggerClass).
  488. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  489. $("<button type='button'></button>").addClass(this._triggerClass).
  490. html(!buttonImage ? buttonText : $("<img/>").attr(
  491. { src:buttonImage, alt:buttonText, title:buttonText })));
  492. input[isRTL ? "before" : "after"](inst.trigger);
  493. inst.trigger.click(function() {
  494. if ($.datepicker._datepickerShowing && $.datepicker._lastInput === input[0]) {
  495. $.datepicker._hideDatepicker();
  496. } else if ($.datepicker._datepickerShowing && $.datepicker._lastInput !== input[0]) {
  497. $.datepicker._hideDatepicker();
  498. $.datepicker._showDatepicker(input[0]);
  499. } else {
  500. $.datepicker._showDatepicker(input[0]);
  501. }
  502. return false;
  503. });
  504. }
  505. },
  506. /* Apply the maximum length for the date format. */
  507. _autoSize: function(inst) {
  508. if (this._get(inst, "autoSize") && !inst.inline) {
  509. var findMax, max, maxI, i,
  510. date = new Date(2009, 12 - 1, 20), // Ensure double digits
  511. dateFormat = this._get(inst, "dateFormat");
  512. if (dateFormat.match(/[DM]/)) {
  513. findMax = function(names) {
  514. max = 0;
  515. maxI = 0;
  516. for (i = 0; i < names.length; i++) {
  517. if (names[i].length > max) {
  518. max = names[i].length;
  519. maxI = i;
  520. }
  521. }
  522. return maxI;
  523. };
  524. date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
  525. "monthNames" : "monthNamesShort"))));
  526. date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
  527. "dayNames" : "dayNamesShort"))) + 20 - date.getDay());
  528. }
  529. inst.input.attr("size", this._formatDate(inst, date).length);
  530. }
  531. },
  532. /* Attach an inline date picker to a div. */
  533. _inlineDatepicker: function(target, inst) {
  534. var divSpan = $(target);
  535. if (divSpan.hasClass(this.markerClassName)) {
  536. return;
  537. }
  538. divSpan.addClass(this.markerClassName).append(inst.dpDiv);
  539. $.data(target, "datepicker", inst);
  540. this._setDate(inst, this._getDefaultDate(inst), true);
  541. this._updateDatepicker(inst);
  542. this._updateAlternate(inst);
  543. //If disabled option is true, disable the datepicker before showing it (see ticket #5665)
  544. if( inst.settings.disabled ) {
  545. this._disableDatepicker( target );
  546. }
  547. // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements
  548. // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height
  549. inst.dpDiv.css( "display", "block" );
  550. },
  551. /* Pop-up the date picker in a "dialog" box.
  552. * @param input element - ignored
  553. * @param date string or Date - the initial date to display
  554. * @param onSelect function - the function to call when a date is selected
  555. * @param settings object - update the dialog date picker instance's settings (anonymous object)
  556. * @param pos int[2] - coordinates for the dialog's position within the screen or
  557. * event - with x/y coordinates or
  558. * leave empty for default (screen centre)
  559. * @return the manager object
  560. */
  561. _dialogDatepicker: function(input, date, onSelect, settings, pos) {
  562. var id, browserWidth, browserHeight, scrollX, scrollY,
  563. inst = this._dialogInst; // internal instance
  564. if (!inst) {
  565. this.uuid += 1;
  566. id = "dp" + this.uuid;
  567. this._dialogInput = $("<input type='text' id='" + id +
  568. "' style='position: absolute; top: -100px; width: 0px;'/>");
  569. this._dialogInput.keydown(this._doKeyDown);
  570. $("body").append(this._dialogInput);
  571. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  572. inst.settings = {};
  573. $.data(this._dialogInput[0], "datepicker", inst);
  574. }
  575. datepicker_extendRemove(inst.settings, settings || {});
  576. date = (date && date.constructor === Date ? this._formatDate(inst, date) : date);
  577. this._dialogInput.val(date);
  578. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  579. if (!this._pos) {
  580. browserWidth = document.documentElement.clientWidth;
  581. browserHeight = document.documentElement.clientHeight;
  582. scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  583. scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  584. this._pos = // should use actual width/height below
  585. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  586. }
  587. // move input on screen for focus, but hidden behind dialog
  588. this._dialogInput.css("left", (this._pos[0] + 20) + "px").css("top", this._pos[1] + "px");
  589. inst.settings.onSelect = onSelect;
  590. this._inDialog = true;
  591. this.dpDiv.addClass(this._dialogClass);
  592. this._showDatepicker(this._dialogInput[0]);
  593. if ($.blockUI) {
  594. $.blockUI(this.dpDiv);
  595. }
  596. $.data(this._dialogInput[0], "datepicker", inst);
  597. return this;
  598. },
  599. /* Detach a datepicker from its control.
  600. * @param target element - the target input field or division or span
  601. */
  602. _destroyDatepicker: function(target) {
  603. var nodeName,
  604. $target = $(target),
  605. inst = $.data(target, "datepicker");
  606. if (!$target.hasClass(this.markerClassName)) {
  607. return;
  608. }
  609. nodeName = target.nodeName.toLowerCase();
  610. $.removeData(target, "datepicker");
  611. if (nodeName === "input") {
  612. inst.append.remove();
  613. inst.trigger.remove();
  614. $target.removeClass(this.markerClassName).
  615. unbind("focus", this._showDatepicker).
  616. unbind("keydown", this._doKeyDown).
  617. unbind("keypress", this._doKeyPress).
  618. unbind("keyup", this._doKeyUp);
  619. } else if (nodeName === "div" || nodeName === "span") {
  620. $target.removeClass(this.markerClassName).empty();
  621. }
  622. if ( datepicker_instActive === inst ) {
  623. datepicker_instActive = null;
  624. }
  625. },
  626. /* Enable the date picker to a jQuery selection.
  627. * @param target element - the target input field or division or span
  628. */
  629. _enableDatepicker: function(target) {
  630. var nodeName, inline,
  631. $target = $(target),
  632. inst = $.data(target, "datepicker");
  633. if (!$target.hasClass(this.markerClassName)) {
  634. return;
  635. }
  636. nodeName = target.nodeName.toLowerCase();
  637. if (nodeName === "input") {
  638. target.disabled = false;
  639. inst.trigger.filter("button").
  640. each(function() { this.disabled = false; }).end().
  641. filter("img").css({opacity: "1.0", cursor: ""});
  642. } else if (nodeName === "div" || nodeName === "span") {
  643. inline = $target.children("." + this._inlineClass);
  644. inline.children().removeClass("ui-state-disabled");
  645. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  646. prop("disabled", false);
  647. }
  648. this._disabledInputs = $.map(this._disabledInputs,
  649. function(value) { return (value === target ? null : value); }); // delete entry
  650. },
  651. /* Disable the date picker to a jQuery selection.
  652. * @param target element - the target input field or division or span
  653. */
  654. _disableDatepicker: function(target) {
  655. var nodeName, inline,
  656. $target = $(target),
  657. inst = $.data(target, "datepicker");
  658. if (!$target.hasClass(this.markerClassName)) {
  659. return;
  660. }
  661. nodeName = target.nodeName.toLowerCase();
  662. if (nodeName === "input") {
  663. target.disabled = true;
  664. inst.trigger.filter("button").
  665. each(function() { this.disabled = true; }).end().
  666. filter("img").css({opacity: "0.5", cursor: "default"});
  667. } else if (nodeName === "div" || nodeName === "span") {
  668. inline = $target.children("." + this._inlineClass);
  669. inline.children().addClass("ui-state-disabled");
  670. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  671. prop("disabled", true);
  672. }
  673. this._disabledInputs = $.map(this._disabledInputs,
  674. function(value) { return (value === target ? null : value); }); // delete entry
  675. this._disabledInputs[this._disabledInputs.length] = target;
  676. },
  677. /* Is the first field in a jQuery collection disabled as a datepicker?
  678. * @param target element - the target input field or division or span
  679. * @return boolean - true if disabled, false if enabled
  680. */
  681. _isDisabledDatepicker: function(target) {
  682. if (!target) {
  683. return false;
  684. }
  685. for (var i = 0; i < this._disabledInputs.length; i++) {
  686. if (this._disabledInputs[i] === target) {
  687. return true;
  688. }
  689. }
  690. return false;
  691. },
  692. /* Retrieve the instance data for the target control.
  693. * @param target element - the target input field or division or span
  694. * @return object - the associated instance data
  695. * @throws error if a jQuery problem getting data
  696. */
  697. _getInst: function(target) {
  698. try {
  699. return $.data(target, "datepicker");
  700. }
  701. catch (err) {
  702. throw "Missing instance data for this datepicker";
  703. }
  704. },
  705. /* Update or retrieve the settings for a date picker attached to an input field or division.
  706. * @param target element - the target input field or division or span
  707. * @param name object - the new settings to update or
  708. * string - the name of the setting to change or retrieve,
  709. * when retrieving also "all" for all instance settings or
  710. * "defaults" for all global defaults
  711. * @param value any - the new value for the setting
  712. * (omit if above is an object or to retrieve a value)
  713. */
  714. _optionDatepicker: function(target, name, value) {
  715. var settings, date, minDate, maxDate,
  716. inst = this._getInst(target);
  717. if (arguments.length === 2 && typeof name === "string") {
  718. return (name === "defaults" ? $.extend({}, $.datepicker._defaults) :
  719. (inst ? (name === "all" ? $.extend({}, inst.settings) :
  720. this._get(inst, name)) : null));
  721. }
  722. settings = name || {};
  723. if (typeof name === "string") {
  724. settings = {};
  725. settings[name] = value;
  726. }
  727. if (inst) {
  728. if (this._curInst === inst) {
  729. this._hideDatepicker();
  730. }
  731. date = this._getDateDatepicker(target, true);
  732. minDate = this._getMinMaxDate(inst, "min");
  733. maxDate = this._getMinMaxDate(inst, "max");
  734. datepicker_extendRemove(inst.settings, settings);
  735. // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
  736. if (minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined) {
  737. inst.settings.minDate = this._formatDate(inst, minDate);
  738. }
  739. if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined) {
  740. inst.settings.maxDate = this._formatDate(inst, maxDate);
  741. }
  742. if ( "disabled" in settings ) {
  743. if ( settings.disabled ) {
  744. this._disableDatepicker(target);
  745. } else {
  746. this._enableDatepicker(target);
  747. }
  748. }
  749. this._attachments($(target), inst);
  750. this._autoSize(inst);
  751. this._setDate(inst, date);
  752. this._updateAlternate(inst);
  753. this._updateDatepicker(inst);
  754. }
  755. },
  756. // change method deprecated
  757. _changeDatepicker: function(target, name, value) {
  758. this._optionDatepicker(target, name, value);
  759. },
  760. /* Redraw the date picker attached to an input field or division.
  761. * @param target element - the target input field or division or span
  762. */
  763. _refreshDatepicker: function(target) {
  764. var inst = this._getInst(target);
  765. if (inst) {
  766. this._updateDatepicker(inst);
  767. }
  768. },
  769. /* Set the dates for a jQuery selection.
  770. * @param target element - the target input field or division or span
  771. * @param date Date - the new date
  772. */
  773. _setDateDatepicker: function(target, date) {
  774. var inst = this._getInst(target);
  775. if (inst) {
  776. this._setDate(inst, date);
  777. this._updateDatepicker(inst);
  778. this._updateAlternate(inst);
  779. }
  780. },
  781. /* Get the date(s) for the first entry in a jQuery selection.
  782. * @param target element - the target input field or division or span
  783. * @param noDefault boolean - true if no default date is to be used
  784. * @return Date - the current date
  785. */
  786. _getDateDatepicker: function(target, noDefault) {
  787. var inst = this._getInst(target);
  788. if (inst && !inst.inline) {
  789. this._setDateFromField(inst, noDefault);
  790. }
  791. return (inst ? this._getDate(inst) : null);
  792. },
  793. /* Handle keystrokes. */
  794. _doKeyDown: function(event) {
  795. var onSelect, dateStr, sel,
  796. inst = $.datepicker._getInst(event.target),
  797. handled = true,
  798. isRTL = inst.dpDiv.is(".ui-datepicker-rtl");
  799. inst._keyEvent = true;
  800. if ($.datepicker._datepickerShowing) {
  801. switch (event.keyCode) {
  802. case 9: $.datepicker._hideDatepicker();
  803. handled = false;
  804. break; // hide on tab out
  805. case 13: sel = $("td." + $.datepicker._dayOverClass + ":not(." +
  806. $.datepicker._currentClass + ")", inst.dpDiv);
  807. if (sel[0]) {
  808. $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
  809. }
  810. onSelect = $.datepicker._get(inst, "onSelect");
  811. if (onSelect) {
  812. dateStr = $.datepicker._formatDate(inst);
  813. // trigger custom callback
  814. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
  815. } else {
  816. $.datepicker._hideDatepicker();
  817. }
  818. return false; // don't submit the form
  819. case 27: $.datepicker._hideDatepicker();
  820. break; // hide on escape
  821. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  822. -$.datepicker._get(inst, "stepBigMonths") :
  823. -$.datepicker._get(inst, "stepMonths")), "M");
  824. break; // previous month/year on page up/+ ctrl
  825. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  826. +$.datepicker._get(inst, "stepBigMonths") :
  827. +$.datepicker._get(inst, "stepMonths")), "M");
  828. break; // next month/year on page down/+ ctrl
  829. case 35: if (event.ctrlKey || event.metaKey) {
  830. $.datepicker._clearDate(event.target);
  831. }
  832. handled = event.ctrlKey || event.metaKey;
  833. break; // clear on ctrl or command +end
  834. case 36: if (event.ctrlKey || event.metaKey) {
  835. $.datepicker._gotoToday(event.target);
  836. }
  837. handled = event.ctrlKey || event.metaKey;
  838. break; // current on ctrl or command +home
  839. case 37: if (event.ctrlKey || event.metaKey) {
  840. $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), "D");
  841. }
  842. handled = event.ctrlKey || event.metaKey;
  843. // -1 day on ctrl or command +left
  844. if (event.originalEvent.altKey) {
  845. $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  846. -$.datepicker._get(inst, "stepBigMonths") :
  847. -$.datepicker._get(inst, "stepMonths")), "M");
  848. }
  849. // next month/year on alt +left on Mac
  850. break;
  851. case 38: if (event.ctrlKey || event.metaKey) {
  852. $.datepicker._adjustDate(event.target, -7, "D");
  853. }
  854. handled = event.ctrlKey || event.metaKey;
  855. break; // -1 week on ctrl or command +up
  856. case 39: if (event.ctrlKey || event.metaKey) {
  857. $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), "D");
  858. }
  859. handled = event.ctrlKey || event.metaKey;
  860. // +1 day on ctrl or command +right
  861. if (event.originalEvent.altKey) {
  862. $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  863. +$.datepicker._get(inst, "stepBigMonths") :
  864. +$.datepicker._get(inst, "stepMonths")), "M");
  865. }
  866. // next month/year on alt +right
  867. break;
  868. case 40: if (event.ctrlKey || event.metaKey) {
  869. $.datepicker._adjustDate(event.target, +7, "D");
  870. }
  871. handled = event.ctrlKey || event.metaKey;
  872. break; // +1 week on ctrl or command +down
  873. default: handled = false;
  874. }
  875. } else if (event.keyCode === 36 && event.ctrlKey) { // display the date picker on ctrl+home
  876. $.datepicker._showDatepicker(this);
  877. } else {
  878. handled = false;
  879. }
  880. if (handled) {
  881. event.preventDefault();
  882. event.stopPropagation();
  883. }
  884. },
  885. /* Filter entered characters - based on date format. */
  886. _doKeyPress: function(event) {
  887. var chars, chr,
  888. inst = $.datepicker._getInst(event.target);
  889. if ($.datepicker._get(inst, "constrainInput")) {
  890. chars = $.datepicker._possibleChars($.datepicker._get(inst, "dateFormat"));
  891. chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
  892. return event.ctrlKey || event.metaKey || (chr < " " || !chars || chars.indexOf(chr) > -1);
  893. }
  894. },
  895. /* Synchronise manual entry and field/alternate field. */
  896. _doKeyUp: function(event) {
  897. var date,
  898. inst = $.datepicker._getInst(event.target);
  899. if (inst.input.val() !== inst.lastVal) {
  900. try {
  901. date = $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
  902. (inst.input ? inst.input.val() : null),
  903. $.datepicker._getFormatConfig(inst));
  904. if (date) { // only if valid
  905. $.datepicker._setDateFromField(inst);
  906. $.datepicker._updateAlternate(inst);
  907. $.datepicker._updateDatepicker(inst);
  908. }
  909. }
  910. catch (err) {
  911. }
  912. }
  913. return true;
  914. },
  915. /* Pop-up the date picker for a given input field.
  916. * If false returned from beforeShow event handler do not show.
  917. * @param input element - the input field attached to the date picker or
  918. * event - if triggered by focus
  919. */
  920. _showDatepicker: function(input) {
  921. input = input.target || input;
  922. if (input.nodeName.toLowerCase() !== "input") { // find from button/image trigger
  923. input = $("input", input.parentNode)[0];
  924. }
  925. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput === input) { // already here
  926. return;
  927. }
  928. var inst, beforeShow, beforeShowSettings, isFixed,
  929. offset, showAnim, duration;
  930. inst = $.datepicker._getInst(input);
  931. if ($.datepicker._curInst && $.datepicker._curInst !== inst) {
  932. $.datepicker._curInst.dpDiv.stop(true, true);
  933. if ( inst && $.datepicker._datepickerShowing ) {
  934. $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
  935. }
  936. }
  937. beforeShow = $.datepicker._get(inst, "beforeShow");
  938. beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
  939. if(beforeShowSettings === false){
  940. return;
  941. }
  942. datepicker_extendRemove(inst.settings, beforeShowSettings);
  943. inst.lastVal = null;
  944. $.datepicker._lastInput = input;
  945. $.datepicker._setDateFromField(inst);
  946. if ($.datepicker._inDialog) { // hide cursor
  947. input.value = "";
  948. }
  949. if (!$.datepicker._pos) { // position below input
  950. $.datepicker._pos = $.datepicker._findPos(input);
  951. $.datepicker._pos[1] += input.offsetHeight; // add the height
  952. }
  953. isFixed = false;
  954. $(input).parents().each(function() {
  955. isFixed |= $(this).css("position") === "fixed";
  956. return !isFixed;
  957. });
  958. offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  959. $.datepicker._pos = null;
  960. //to avoid flashes on Firefox
  961. inst.dpDiv.empty();
  962. // determine sizing offscreen
  963. inst.dpDiv.css({position: "absolute", display: "block", top: "-1000px"});
  964. $.datepicker._updateDatepicker(inst);
  965. // fix width for dynamic number of date pickers
  966. // and adjust position before showing
  967. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  968. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  969. "static" : (isFixed ? "fixed" : "absolute")), display: "none",
  970. left: offset.left + "px", top: offset.top + "px"});
  971. if (!inst.inline) {
  972. showAnim = $.datepicker._get(inst, "showAnim");
  973. duration = $.datepicker._get(inst, "duration");
  974. inst.dpDiv.css( "z-index", datepicker_getZindex( $( input ) ) + 1 );
  975. $.datepicker._datepickerShowing = true;
  976. if ( $.effects && $.effects.effect[ showAnim ] ) {
  977. inst.dpDiv.show(showAnim, $.datepicker._get(inst, "showOptions"), duration);
  978. } else {
  979. inst.dpDiv[showAnim || "show"](showAnim ? duration : null);
  980. }
  981. if ( $.datepicker._shouldFocusInput( inst ) ) {
  982. inst.input.focus();
  983. }
  984. $.datepicker._curInst = inst;
  985. }
  986. },
  987. /* Generate the date picker content. */
  988. _updateDatepicker: function(inst) {
  989. this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
  990. datepicker_instActive = inst; // for delegate hover events
  991. inst.dpDiv.empty().append(this._generateHTML(inst));
  992. this._attachHandlers(inst);
  993. var origyearshtml,
  994. numMonths = this._getNumberOfMonths(inst),
  995. cols = numMonths[1],
  996. width = 17,
  997. activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" );
  998. if ( activeCell.length > 0 ) {
  999. datepicker_handleMouseover.apply( activeCell.get( 0 ) );
  1000. }
  1001. inst.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");
  1002. if (cols > 1) {
  1003. inst.dpDiv.addClass("ui-datepicker-multi-" + cols).css("width", (width * cols) + "em");
  1004. }
  1005. inst.dpDiv[(numMonths[0] !== 1 || numMonths[1] !== 1 ? "add" : "remove") +
  1006. "Class"]("ui-datepicker-multi");
  1007. inst.dpDiv[(this._get(inst, "isRTL") ? "add" : "remove") +
  1008. "Class"]("ui-datepicker-rtl");
  1009. if (inst === $.datepicker._curInst && $.datepicker._datepickerShowing && $.datepicker._shouldFocusInput( inst ) ) {
  1010. inst.input.focus();
  1011. }
  1012. // deffered render of the years select (to avoid flashes on Firefox)
  1013. if( inst.yearshtml ){
  1014. origyearshtml = inst.yearshtml;
  1015. setTimeout(function(){
  1016. //assure that inst.yearshtml didn't change.
  1017. if( origyearshtml === inst.yearshtml && inst.yearshtml ){
  1018. inst.dpDiv.find("select.ui-datepicker-year:first").replaceWith(inst.yearshtml);
  1019. }
  1020. origyearshtml = inst.yearshtml = null;
  1021. }, 0);
  1022. }
  1023. },
  1024. // #6694 - don't focus the input if it's already focused
  1025. // this breaks the change event in IE
  1026. // Support: IE and jQuery <1.9
  1027. _shouldFocusInput: function( inst ) {
  1028. return inst.input && inst.input.is( ":visible" ) && !inst.input.is( ":disabled" ) && !inst.input.is( ":focus" );
  1029. },
  1030. /* Check positioning to remain on screen. */
  1031. _checkOffset: function(inst, offset, isFixed) {
  1032. var dpWidth = inst.dpDiv.outerWidth(),
  1033. dpHeight = inst.dpDiv.outerHeight(),
  1034. inputWidth = inst.input ? inst.input.outerWidth() : 0,
  1035. inputHeight = inst.input ? inst.input.outerHeight() : 0,
  1036. viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft()),
  1037. viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
  1038. offset.left -= (this._get(inst, "isRTL") ? (dpWidth - inputWidth) : 0);
  1039. offset.left -= (isFixed && offset.left === inst.input.offset().left) ? $(document).scrollLeft() : 0;
  1040. offset.top -= (isFixed && offset.top === (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  1041. // now check if datepicker is showing outside window viewport - move to a better place if so.
  1042. offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
  1043. Math.abs(offset.left + dpWidth - viewWidth) : 0);
  1044. offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
  1045. Math.abs(dpHeight + inputHeight) : 0);
  1046. return offset;
  1047. },
  1048. /* Find an object's position on the screen. */
  1049. _findPos: function(obj) {
  1050. var position,
  1051. inst = this._getInst(obj),
  1052. isRTL = this._get(inst, "isRTL");
  1053. while (obj && (obj.type === "hidden" || obj.nodeType !== 1 || $.expr.filters.hidden(obj))) {
  1054. obj = obj[isRTL ? "previousSibling" : "nextSibling"];
  1055. }
  1056. position = $(obj).offset();
  1057. return [position.left, position.top];
  1058. },
  1059. /* Hide the date picker from view.
  1060. * @param input element - the input field attached to the date picker
  1061. */
  1062. _hideDatepicker: function(input) {
  1063. var showAnim, duration, postProcess, onClose,
  1064. inst = this._curInst;
  1065. if (!inst || (input && inst !== $.data(input, "datepicker"))) {
  1066. return;
  1067. }
  1068. if (this._datepickerShowing) {
  1069. showAnim = this._get(inst, "showAnim");
  1070. duration = this._get(inst, "duration");
  1071. postProcess = function() {
  1072. $.datepicker._tidyDialog(inst);
  1073. };
  1074. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  1075. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) {
  1076. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, "showOptions"), duration, postProcess);
  1077. } else {
  1078. inst.dpDiv[(showAnim === "slideDown" ? "slideUp" :
  1079. (showAnim === "fadeIn" ? "fadeOut" : "hide"))]((showAnim ? duration : null), postProcess);
  1080. }
  1081. if (!showAnim) {
  1082. postProcess();
  1083. }
  1084. this._datepickerShowing = false;
  1085. onClose = this._get(inst, "onClose");
  1086. if (onClose) {
  1087. onClose.apply((inst.input ? inst.input[0] : null), [(inst.input ? inst.input.val() : ""), inst]);
  1088. }
  1089. this._lastInput = null;
  1090. if (this._inDialog) {
  1091. this._dialogInput.css({ position: "absolute", left: "0", top: "-100px" });
  1092. if ($.blockUI) {
  1093. $.unblockUI();
  1094. $("body").append(this.dpDiv);
  1095. }
  1096. }
  1097. this._inDialog = false;
  1098. }
  1099. },
  1100. /* Tidy up after a dialog display. */
  1101. _tidyDialog: function(inst) {
  1102. inst.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar");
  1103. },
  1104. /* Close date picker if clicked elsewhere. */
  1105. _checkExternalClick: function(event) {
  1106. if (!$.datepicker._curInst) {
  1107. return;
  1108. }
  1109. var $target = $(event.target),
  1110. inst = $.datepicker._getInst($target[0]);
  1111. if ( ( ( $target[0].id !== $.datepicker._mainDivId &&
  1112. $target.parents("#" + $.datepicker._mainDivId).length === 0 &&
  1113. !$target.hasClass($.datepicker.markerClassName) &&
  1114. !$target.closest("." + $.datepicker._triggerClass).length &&
  1115. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
  1116. ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst !== inst ) ) {
  1117. $.datepicker._hideDatepicker();
  1118. }
  1119. },
  1120. /* Adjust one of the date sub-fields. */
  1121. _adjustDate: function(id, offset, period) {
  1122. var target = $(id),
  1123. inst = this._getInst(target[0]);
  1124. if (this._isDisabledDatepicker(target[0])) {
  1125. return;
  1126. }
  1127. this._adjustInstDate(inst, offset +
  1128. (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
  1129. period);
  1130. this._updateDatepicker(inst);
  1131. },
  1132. /* Action for current link. */
  1133. _gotoToday: function(id) {
  1134. var date,
  1135. target = $(id),
  1136. inst = this._getInst(target[0]);
  1137. if (this._get(inst, "gotoCurrent") && inst.currentDay) {
  1138. inst.selectedDay = inst.currentDay;
  1139. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  1140. inst.drawYear = inst.selectedYear = inst.currentYear;
  1141. } else {
  1142. date = new Date();
  1143. inst.selectedDay = date.getDate();
  1144. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1145. inst.drawYear = inst.selectedYear = date.getFullYear();
  1146. }
  1147. this._notifyChange(inst);
  1148. this._adjustDate(target);
  1149. },
  1150. /* Action for selecting a new month/year. */
  1151. _selectMonthYear: function(id, select, period) {
  1152. var target = $(id),
  1153. inst = this._getInst(target[0]);
  1154. inst["selected" + (period === "M" ? "Month" : "Year")] =
  1155. inst["draw" + (period === "M" ? "Month" : "Year")] =
  1156. parseInt(select.options[select.selectedIndex].value,10);
  1157. this._notifyChange(inst);
  1158. this._adjustDate(target);
  1159. },
  1160. /* Action for selecting a day. */
  1161. _selectDay: function(id, month, year, td) {
  1162. var inst,
  1163. target = $(id);
  1164. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  1165. return;
  1166. }
  1167. inst = this._getInst(target[0]);
  1168. inst.selectedDay = inst.currentDay = $("a", td).html();
  1169. inst.selectedMonth = inst.currentMonth = month;
  1170. inst.selectedYear = inst.currentYear = year;
  1171. this._selectDate(id, this._formatDate(inst,
  1172. inst.currentDay, inst.currentMonth, inst.currentYear));
  1173. },
  1174. /* Erase the input field and hide the date picker. */
  1175. _clearDate: function(id) {
  1176. var target = $(id);
  1177. this._selectDate(target, "");
  1178. },
  1179. /* Update the input field with the selected date. */
  1180. _selectDate: function(id, dateStr) {
  1181. var onSelect,
  1182. target = $(id),
  1183. inst = this._getInst(target[0]);
  1184. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  1185. if (inst.input) {
  1186. inst.input.val(dateStr);
  1187. }
  1188. this._updateAlternate(inst);
  1189. onSelect = this._get(inst, "onSelect");
  1190. if (onSelect) {
  1191. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  1192. } else if (inst.input) {
  1193. inst.input.trigger("change"); // fire the change event
  1194. }
  1195. if (inst.inline){
  1196. this._updateDatepicker(inst);
  1197. } else {
  1198. this._hideDatepicker();
  1199. this._lastInput = inst.input[0];
  1200. if (typeof(inst.input[0]) !== "object") {
  1201. inst.input.focus(); // restore focus
  1202. }
  1203. this._lastInput = null;
  1204. }
  1205. },
  1206. /* Update any alternate field to synchronise with the main field. */
  1207. _updateAlternate: function(inst) {
  1208. var altFormat, date, dateStr,
  1209. altField = this._get(inst, "altField");
  1210. if (altField) { // update alternate field too
  1211. altFormat = this._get(inst, "altFormat") || this._get(inst, "dateFormat");
  1212. date = this._getDate(inst);
  1213. dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  1214. $(altField).each(function() { $(this).val(dateStr); });
  1215. }
  1216. },
  1217. /* Set as beforeShowDay function to prevent selection of weekends.
  1218. * @param date Date - the date to customise
  1219. * @return [boolean, string] - is this date selectable?, what is its CSS class?
  1220. */
  1221. noWeekends: function(date) {
  1222. var day = date.getDay();
  1223. return [(day > 0 && day < 6), ""];
  1224. },
  1225. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  1226. * @param date Date - the date to get the week for
  1227. * @return number - the number of the week within the year that contains this date
  1228. */
  1229. iso8601Week: function(date) {
  1230. var time,
  1231. checkDate = new Date(date.getTime());
  1232. // Find Thursday of this week starting on Monday
  1233. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  1234. time = checkDate.getTime();
  1235. checkDate.setMonth(0); // Compare with Jan 1
  1236. checkDate.setDate(1);
  1237. return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  1238. },
  1239. /* Parse a string value into a date object.
  1240. * See formatDate below for the possible formats.
  1241. *
  1242. * @param format string - the expected format of the date
  1243. * @param value string - the date in the above format
  1244. * @param settings Object - attributes include:
  1245. * shortYearCutoff number - the cutoff year for determining the century (optional)
  1246. * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  1247. * dayNames string[7] - names of the days from Sunday (optional)
  1248. * monthNamesShort string[12] - abbreviated names of the months (optional)
  1249. * monthNames string[12] - names of the months (optional)
  1250. * @return Date - the extracted date value or null if value is blank
  1251. */
  1252. parseDate: function (format, value, settings) {
  1253. if (format == null || value == null) {
  1254. throw "Invalid arguments";
  1255. }
  1256. value = (typeof value === "object" ? value.toString() : value + "");
  1257. if (value === "") {
  1258. return null;
  1259. }
  1260. var iFormat, dim, extra,
  1261. iValue = 0,
  1262. shortYearCutoffTemp = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff,
  1263. shortYearCutoff = (typeof shortYearCutoffTemp !== "string" ? shortYearCutoffTemp :
  1264. new Date().getFullYear() % 100 + parseInt(shortYearCutoffTemp, 10)),
  1265. dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
  1266. dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
  1267. monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
  1268. monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
  1269. year = -1,
  1270. month = -1,
  1271. day = -1,
  1272. doy = -1,
  1273. literal = false,
  1274. date,
  1275. // Check whether a format character is doubled
  1276. lookAhead = function(match) {
  1277. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  1278. if (matches) {
  1279. iFormat++;
  1280. }
  1281. return matches;
  1282. },
  1283. // Extract a number from the string value
  1284. getNumber = function(match) {
  1285. var isDoubled = lookAhead(match),
  1286. size = (match === "@" ? 14 : (match === "!" ? 20 :
  1287. (match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))),
  1288. minSize = (match === "y" ? size : 1),
  1289. digits = new RegExp("^\\d{" + minSize + "," + size + "}"),
  1290. num = value.substring(iValue).match(digits);
  1291. if (!num) {
  1292. throw "Missing number at position " + iValue;
  1293. }
  1294. iValue += num[0].length;
  1295. return parseInt(num[0], 10);
  1296. },
  1297. // Extract a name from the string value and convert to an index
  1298. getName = function(match, shortNames, longNames) {
  1299. var index = -1,
  1300. names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
  1301. return [ [k, v] ];
  1302. }).sort(function (a, b) {
  1303. return -(a[1].length - b[1].length);
  1304. });
  1305. $.each(names, function (i, pair) {
  1306. var name = pair[1];
  1307. if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
  1308. index = pair[0];
  1309. iValue += name.length;
  1310. return false;
  1311. }
  1312. });
  1313. if (index !== -1) {
  1314. return index + 1;
  1315. } else {
  1316. throw "Unknown name at position " + iValue;
  1317. }
  1318. },
  1319. // Confirm that a literal character matches the string value
  1320. checkLiteral = function() {
  1321. if (value.charAt(iValue) !== format.charAt(iFormat)) {
  1322. throw "Unexpected literal at position " + iValue;
  1323. }
  1324. iValue++;
  1325. };
  1326. for (iFormat = 0; iFormat < format.length; iFormat++) {
  1327. if (literal) {
  1328. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  1329. literal = false;
  1330. } else {
  1331. checkLiteral();
  1332. }
  1333. } else {
  1334. switch (format.charAt(iFormat)) {
  1335. case "d":
  1336. day = getNumber("d");
  1337. break;
  1338. case "D":
  1339. getName("D", dayNamesShort, dayNames);
  1340. break;
  1341. case "o":
  1342. doy = getNumber("o");
  1343. break;
  1344. case "m":
  1345. month = getNumber("m");
  1346. break;
  1347. case "M":
  1348. month = getName("M", monthNamesShort, monthNames);
  1349. break;
  1350. case "y":
  1351. year = getNumber("y");
  1352. break;
  1353. case "@":
  1354. date = new Date(getNumber("@"));
  1355. year = date.getFullYear();
  1356. month = date.getMonth() + 1;
  1357. day = date.getDate();
  1358. break;
  1359. case "!":
  1360. date = new Date((getNumber("!") - this._ticksTo1970) / 10000);
  1361. year = date.getFullYear();
  1362. month = date.getMonth() + 1;
  1363. day = date.getDate();
  1364. break;
  1365. case "'":
  1366. if (lookAhead("'")){
  1367. checkLiteral();
  1368. } else {
  1369. literal = true;
  1370. }
  1371. break;
  1372. default:
  1373. checkLiteral();
  1374. }
  1375. }
  1376. }
  1377. if (iValue < value.length){
  1378. extra = value.substr(iValue);
  1379. if (!/^\s+/.test(extra)) {
  1380. throw "Extra/unparsed characters found in date: " + extra;
  1381. }
  1382. }
  1383. if (year === -1) {
  1384. year = new Date().getFullYear();
  1385. } else if (year < 100) {
  1386. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  1387. (year <= shortYearCutoff ? 0 : -100);
  1388. }
  1389. if (doy > -1) {
  1390. month = 1;
  1391. day = doy;
  1392. do {
  1393. dim = this._getDaysInMonth(year, month - 1);
  1394. if (day <= dim) {
  1395. break;
  1396. }
  1397. month++;
  1398. day -= dim;
  1399. } while (true);
  1400. }
  1401. date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  1402. if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
  1403. throw "Invalid date"; // E.g. 31/02/00
  1404. }
  1405. return date;
  1406. },
  1407. /* Standard date formats. */
  1408. ATOM: "yy-mm-dd", // RFC 3339 (ISO 8601)
  1409. COOKIE: "D, dd M yy",
  1410. ISO_8601: "yy-mm-dd",
  1411. RFC_822: "D, d M y",
  1412. RFC_850: "DD, dd-M-y",
  1413. RFC_1036: "D, d M y",
  1414. RFC_1123: "D, d M yy",
  1415. RFC_2822: "D, d M yy",
  1416. RSS: "D, d M y", // RFC 822
  1417. TICKS: "!",
  1418. TIMESTAMP: "@",
  1419. W3C: "yy-mm-dd", // ISO 8601
  1420. _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
  1421. Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
  1422. /* Format a date object into a string value.
  1423. * The format can be combinations of the following:
  1424. * d - day of month (no leading zero)
  1425. * dd - day of month (two digit)
  1426. * o - day of year (no leading zeros)
  1427. * oo - day of year (three digit)
  1428. * D - day name short
  1429. * DD - day name long
  1430. * m - month of year (no leading zero)
  1431. * mm - month of year (two digit)
  1432. * M - month name short
  1433. * MM - month name long
  1434. * y - year (two digit)
  1435. * yy - year (four digit)
  1436. * @ - Unix timestamp (ms since 01/01/1970)
  1437. * ! - Windows ticks (100ns since 01/01/0001)
  1438. * "..." - literal text
  1439. * '' - single quote
  1440. *
  1441. * @param format string - the desired format of the date
  1442. * @param date Date - the date value to format
  1443. * @param settings Object - attributes include:
  1444. * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  1445. * dayNames string[7] - names of the days from Sunday (optional)
  1446. * monthNamesShort string[12] - abbreviated names of the months (optional)
  1447. * monthNames string[12] - names of the months (optional)
  1448. * @return string - the date in the above format
  1449. */
  1450. formatDate: function (format, date, settings) {
  1451. if (!date) {
  1452. return "";
  1453. }
  1454. var iFormat,
  1455. dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
  1456. dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
  1457. monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
  1458. monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
  1459. // Check whether a format character is doubled
  1460. lookAhead = function(match) {
  1461. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  1462. if (matches) {
  1463. iFormat++;
  1464. }
  1465. return matches;
  1466. },
  1467. // Format a number, with leading zero if necessary
  1468. formatNumber = function(match, value, len) {
  1469. var num = "" + value;
  1470. if (lookAhead(match)) {
  1471. while (num.length < len) {
  1472. num = "0" + num;
  1473. }
  1474. }
  1475. return num;
  1476. },
  1477. // Format a name, short or long as requested
  1478. formatName = function(match, value, shortNames, longNames) {
  1479. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  1480. },
  1481. output = "",
  1482. literal = false;
  1483. if (date) {
  1484. for (iFormat = 0; iFormat < format.length; iFormat++) {
  1485. if (literal) {
  1486. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  1487. literal = false;
  1488. } else {
  1489. output += format.charAt(iFormat);
  1490. }
  1491. } else {
  1492. switch (format.charAt(iFormat)) {
  1493. case "d":
  1494. output += formatNumber("d", date.getDate(), 2);
  1495. break;
  1496. case "D":
  1497. output += formatName("D", date.getDay(), dayNamesShort, dayNames);
  1498. break;
  1499. case "o":
  1500. output += formatNumber("o",
  1501. Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
  1502. break;
  1503. case "m":
  1504. output += formatNumber("m", date.getMonth() + 1, 2);
  1505. break;
  1506. case "M":
  1507. output += formatName("M", date.getMonth(), monthNamesShort, monthNames);
  1508. break;
  1509. case "y":
  1510. output += (lookAhead("y") ? date.getFullYear() :
  1511. (date.getYear() % 100 < 10 ? "0" : "") + date.getYear() % 100);
  1512. break;
  1513. case "@":
  1514. output += date.getTime();
  1515. break;
  1516. case "!":
  1517. output += date.getTime() * 10000 + this._ticksTo1970;
  1518. break;
  1519. case "'":
  1520. if (lookAhead("'")) {
  1521. output += "'";
  1522. } else {
  1523. literal = true;
  1524. }
  1525. break;
  1526. default:
  1527. output += format.charAt(iFormat);
  1528. }
  1529. }
  1530. }
  1531. }
  1532. return output;
  1533. },
  1534. /* Extract all possible characters from the date format. */
  1535. _possibleChars: function (format) {
  1536. var iFormat,
  1537. chars = "",
  1538. literal = false,
  1539. // Check whether a format character is doubled
  1540. lookAhead = function(match) {
  1541. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  1542. if (matches) {
  1543. iFormat++;
  1544. }
  1545. return matches;
  1546. };
  1547. for (iFormat = 0; iFormat < format.length; iFormat++) {
  1548. if (literal) {
  1549. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  1550. literal = false;
  1551. } else {
  1552. chars += format.charAt(iFormat);
  1553. }
  1554. } else {
  1555. switch (format.charAt(iFormat)) {
  1556. case "d": case "m": case "y": case "@":
  1557. chars += "0123456789";
  1558. break;
  1559. case "D": case "M":
  1560. return null; // Accept anything
  1561. case "'":
  1562. if (lookAhead("'")) {
  1563. chars += "'";
  1564. } else {
  1565. literal = true;
  1566. }
  1567. break;
  1568. default:
  1569. chars += format.charAt(iFormat);
  1570. }
  1571. }
  1572. }
  1573. return chars;
  1574. },
  1575. /* Get a setting value, defaulting if necessary. */
  1576. _get: function(inst, name) {
  1577. return inst.settings[name] !== undefined ?
  1578. inst.settings[name] : this._defaults[name];
  1579. },
  1580. /* Parse existing date and initialise date picker. */
  1581. _setDateFromField: function(inst, noDefault) {
  1582. if (inst.input.val() === inst.lastVal) {
  1583. return;
  1584. }
  1585. var dateFormat = this._get(inst, "dateFormat"),
  1586. dates = inst.lastVal = inst.input ? inst.input.val() : null,
  1587. defaultDate = this._getDefaultDate(inst),
  1588. date = defaultDate,
  1589. settings = this._getFormatConfig(inst);
  1590. try {
  1591. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  1592. } catch (event) {
  1593. dates = (noDefault ? "" : dates);
  1594. }
  1595. inst.selectedDay = date.getDate();
  1596. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1597. inst.drawYear = inst.selectedYear = date.getFullYear();
  1598. inst.currentDay = (dates ? date.getDate() : 0);
  1599. inst.currentMonth = (dates ? date.getMonth() : 0);
  1600. inst.currentYear = (dates ? date.getFullYear() : 0);
  1601. this._adjustInstDate(inst);
  1602. },
  1603. /* Retrieve the default date shown on opening. */
  1604. _getDefaultDate: function(inst) {
  1605. return this._restrictMinMax(inst,
  1606. this._determineDate(inst, this._get(inst, "defaultDate"), new Date()));
  1607. },
  1608. /* A date may be specified as an exact value or a relative one. */
  1609. _determineDate: function(inst, date, defaultDate) {
  1610. var offsetNumeric = function(offset) {
  1611. var date = new Date();
  1612. date.setDate(date.getDate() + offset);
  1613. return date;
  1614. },
  1615. offsetString = function(offset) {
  1616. try {
  1617. return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
  1618. offset, $.datepicker._getFormatConfig(inst));
  1619. }
  1620. catch (e) {
  1621. // Ignore
  1622. }
  1623. var date = (offset.toLowerCase().match(/^c/) ?
  1624. $.datepicker._getDate(inst) : null) || new Date(),
  1625. year = date.getFullYear(),
  1626. month = date.getMonth(),
  1627. day = date.getDate(),
  1628. pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,
  1629. matches = pattern.exec(offset);
  1630. while (matches) {
  1631. switch (matches[2] || "d") {
  1632. case "d" : case "D" :
  1633. day += parseInt(matches[1],10); break;
  1634. case "w" : case "W" :
  1635. day += parseInt(matches[1],10) * 7; break;
  1636. case "m" : case "M" :
  1637. month += parseInt(matches[1],10);
  1638. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  1639. break;
  1640. case "y": case "Y" :
  1641. year += parseInt(matches[1],10);
  1642. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  1643. break;
  1644. }
  1645. matches = pattern.exec(offset);
  1646. }
  1647. return new Date(year, month, day);
  1648. },
  1649. newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) :
  1650. (typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
  1651. newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate);
  1652. if (newDate) {
  1653. newDate.setHours(0);
  1654. newDate.setMinutes(0);
  1655. newDate.setSeconds(0);
  1656. newDate.setMilliseconds(0);
  1657. }
  1658. return this._daylightSavingAdjust(newDate);
  1659. },
  1660. /* Handle switch to/from daylight saving.
  1661. * Hours may be non-zero on daylight saving cut-over:
  1662. * > 12 when midnight changeover, but then cannot generate
  1663. * midnight datetime, so jump to 1AM, otherwise reset.
  1664. * @param date (Date) the date to check
  1665. * @return (Date) the corrected date
  1666. */
  1667. _daylightSavingAdjust: function(date) {
  1668. if (!date) {
  1669. return null;
  1670. }
  1671. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  1672. return date;
  1673. },
  1674. /* Set the date(s) directly. */
  1675. _setDate: function(inst, date, noChange) {
  1676. var clear = !date,
  1677. origMonth = inst.selectedMonth,
  1678. origYear = inst.selectedYear,
  1679. newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
  1680. inst.selectedDay = inst.currentDay = newDate.getDate();
  1681. inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
  1682. inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
  1683. if ((origMonth !== inst.selectedMonth || origYear !== inst.selectedYear) && !noChange) {
  1684. this._notifyChange(inst);
  1685. }
  1686. this._adjustInstDate(inst);
  1687. if (inst.input) {
  1688. inst.input.val(clear ? "" : this._formatDate(inst));
  1689. }
  1690. },
  1691. /* Retrieve the date(s) directly. */
  1692. _getDate: function(inst) {
  1693. var startDate = (!inst.currentYear || (inst.input && inst.input.val() === "") ? null :
  1694. this._daylightSavingAdjust(new Date(
  1695. inst.currentYear, inst.currentMonth, inst.currentDay)));
  1696. return startDate;
  1697. },
  1698. /* Attach the onxxx handlers. These are declared statically so
  1699. * they work with static code transformers like Caja.
  1700. */
  1701. _attachHandlers: function(inst) {
  1702. var stepMonths = this._get(inst, "stepMonths"),
  1703. id = "#" + inst.id.replace( /\\\\/g, "\\" );
  1704. inst.dpDiv.find("[data-handler]").map(function () {
  1705. var handler = {
  1706. prev: function () {
  1707. $.datepicker._adjustDate(id, -stepMonths, "M");
  1708. },
  1709. next: function () {
  1710. $.datepicker._adjustDate(id, +stepMonths, "M");
  1711. },
  1712. hide: function () {
  1713. $.datepicker._hideDatepicker();
  1714. },
  1715. today: function () {
  1716. $.datepicker._gotoToday(id);
  1717. },
  1718. selectDay: function () {
  1719. $.datepicker._selectDay(id, +this.getAttribute("data-month"), +this.getAttribute("data-year"), this);
  1720. return false;
  1721. },
  1722. selectMonth: function () {
  1723. $.datepicker._selectMonthYear(id, this, "M");
  1724. return false;
  1725. },
  1726. selectYear: function () {
  1727. $.datepicker._selectMonthYear(id, this, "Y");
  1728. return false;
  1729. }
  1730. };
  1731. $(this).bind(this.getAttribute("data-event"), handler[this.getAttribute("data-handler")]);
  1732. });
  1733. },
  1734. /* Generate the HTML for the current state of the date picker. */
  1735. _generateHTML: function(inst) {
  1736. var maxDraw, prevText, prev, nextText, next, currentText, gotoDate,
  1737. controls, buttonPanel, firstDay, showWeek, dayNames, dayNamesMin,
  1738. monthNames, monthNamesShort, beforeShowDay, showOtherMonths,
  1739. selectOtherMonths, defaultDate, html, dow, row, group, col, selectedDate,
  1740. cornerClass, calender, thead, day, daysInMonth, leadDays, curRows, numRows,
  1741. printDate, dRow, tbody, daySettings, otherMonth, unselectable,
  1742. tempDate = new Date(),
  1743. today = this._daylightSavingAdjust(
  1744. new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())), // clear time
  1745. isRTL = this._get(inst, "isRTL"),
  1746. showButtonPanel = this._get(inst, "showButtonPanel"),
  1747. hideIfNoPrevNext = this._get(inst, "hideIfNoPrevNext"),
  1748. navigationAsDateFormat = this._get(inst, "navigationAsDateFormat"),
  1749. numMonths = this._getNumberOfMonths(inst),
  1750. showCurrentAtPos = this._get(inst, "showCurrentAtPos"),
  1751. stepMonths = this._get(inst, "stepMonths"),
  1752. isMultiMonth = (numMonths[0] !== 1 || numMonths[1] !== 1),
  1753. currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  1754. new Date(inst.currentYear, inst.currentMonth, inst.currentDay))),
  1755. minDate = this._getMinMaxDate(inst, "min"),
  1756. maxDate = this._getMinMaxDate(inst, "max"),
  1757. drawMonth = inst.drawMonth - showCurrentAtPos,
  1758. drawYear = inst.drawYear;
  1759. if (drawMonth < 0) {
  1760. drawMonth += 12;
  1761. drawYear--;
  1762. }
  1763. if (maxDate) {
  1764. maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  1765. maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
  1766. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  1767. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  1768. drawMonth--;
  1769. if (drawMonth < 0) {
  1770. drawMonth = 11;
  1771. drawYear--;
  1772. }
  1773. }
  1774. }
  1775. inst.drawMonth = drawMonth;
  1776. inst.drawYear = drawYear;
  1777. prevText = this._get(inst, "prevText");
  1778. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  1779. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  1780. this._getFormatConfig(inst)));
  1781. prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  1782. "<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click'" +
  1783. " title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>" :
  1784. (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>"));
  1785. nextText = this._get(inst, "nextText");
  1786. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  1787. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  1788. this._getFormatConfig(inst)));
  1789. next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  1790. "<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click'" +
  1791. " title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>" :
  1792. (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>"));
  1793. currentText = this._get(inst, "currentText");
  1794. gotoDate = (this._get(inst, "gotoCurrent") && inst.currentDay ? currentDate : today);
  1795. currentText = (!navigationAsDateFormat ? currentText :
  1796. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  1797. controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
  1798. this._get(inst, "closeText") + "</button>" : "");
  1799. buttonPanel = (showButtonPanel) ? "<div class='ui-datepicker-buttonpane ui-widget-content'>" + (isRTL ? controls : "") +
  1800. (this._isInRange(inst, gotoDate) ? "<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'" +
  1801. ">" + currentText + "</button>" : "") + (isRTL ? "" : controls) + "</div>" : "";
  1802. firstDay = parseInt(this._get(inst, "firstDay"),10);
  1803. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  1804. showWeek = this._get(inst, "showWeek");
  1805. dayNames = this._get(inst, "dayNames");
  1806. dayNamesMin = this._get(inst, "dayNamesMin");
  1807. monthNames = this._get(inst, "monthNames");
  1808. monthNamesShort = this._get(inst, "monthNamesShort");
  1809. beforeShowDay = this._get(inst, "beforeShowDay");
  1810. showOtherMonths = this._get(inst, "showOtherMonths");
  1811. selectOtherMonths = this._get(inst, "selectOtherMonths");
  1812. defaultDate = this._getDefaultDate(inst);
  1813. html = "";
  1814. dow;
  1815. for (row = 0; row < numMonths[0]; row++) {
  1816. group = "";
  1817. this.maxRows = 4;
  1818. for (col = 0; col < numMonths[1]; col++) {
  1819. selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  1820. cornerClass = " ui-corner-all";
  1821. calender = "";
  1822. if (isMultiMonth) {
  1823. calender += "<div class='ui-datepicker-group";
  1824. if (numMonths[1] > 1) {
  1825. switch (col) {
  1826. case 0: calender += " ui-datepicker-group-first";
  1827. cornerClass = " ui-corner-" + (isRTL ? "right" : "left"); break;
  1828. case numMonths[1]-1: calender += " ui-datepicker-group-last";
  1829. cornerClass = " ui-corner-" + (isRTL ? "left" : "right"); break;
  1830. default: calender += " ui-datepicker-group-middle"; cornerClass = ""; break;
  1831. }
  1832. }
  1833. calender += "'>";
  1834. }
  1835. calender += "<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix" + cornerClass + "'>" +
  1836. (/all|left/.test(cornerClass) && row === 0 ? (isRTL ? next : prev) : "") +
  1837. (/all|right/.test(cornerClass) && row === 0 ? (isRTL ? prev : next) : "") +
  1838. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  1839. row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  1840. "</div><table class='ui-datepicker-calendar'><thead>" +
  1841. "<tr>";
  1842. thead = (showWeek ? "<th class='ui-datepicker-week-col'>" + this._get(inst, "weekHeader") + "</th>" : "");
  1843. for (dow = 0; dow < 7; dow++) { // days of the week
  1844. day = (dow + firstDay) % 7;
  1845. thead += "<th scope='col'" + ((dow + firstDay + 6) % 7 >= 5 ? " class='ui-datepicker-week-end'" : "") + ">" +
  1846. "<span title='" + dayNames[day] + "'>" + dayNamesMin[day] + "</span></th>";
  1847. }
  1848. calender += thead + "</tr></thead><tbody>";
  1849. daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  1850. if (drawYear === inst.selectedYear && drawMonth === inst.selectedMonth) {
  1851. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  1852. }
  1853. leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  1854. curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
  1855. numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
  1856. this.maxRows = numRows;
  1857. printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  1858. for (dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  1859. calender += "<tr>";
  1860. tbody = (!showWeek ? "" : "<td class='ui-datepicker-week-col'>" +
  1861. this._get(inst, "calculateWeek")(printDate) + "</td>");
  1862. for (dow = 0; dow < 7; dow++) { // create date picker days
  1863. daySettings = (beforeShowDay ?
  1864. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, ""]);
  1865. otherMonth = (printDate.getMonth() !== drawMonth);
  1866. unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
  1867. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  1868. tbody += "<td class='" +
  1869. ((dow + firstDay + 6) % 7 >= 5 ? " ui-datepicker-week-end" : "") + // highlight weekends
  1870. (otherMonth ? " ui-datepicker-other-month" : "") + // highlight days from other months
  1871. ((printDate.getTime() === selectedDate.getTime() && drawMonth === inst.selectedMonth && inst._keyEvent) || // user pressed key
  1872. (defaultDate.getTime() === printDate.getTime() && defaultDate.getTime() === selectedDate.getTime()) ?
  1873. // or defaultDate is current printedDate and defaultDate is selectedDate
  1874. " " + this._dayOverClass : "") + // highlight selected day
  1875. (unselectable ? " " + this._unselectableClass + " ui-state-disabled": "") + // highlight unselectable days
  1876. (otherMonth && !showOtherMonths ? "" : " " + daySettings[1] + // highlight custom dates
  1877. (printDate.getTime() === currentDate.getTime() ? " " + this._currentClass : "") + // highlight selected day
  1878. (printDate.getTime() === today.getTime() ? " ui-datepicker-today" : "")) + "'" + // highlight today (if different)
  1879. ((!otherMonth || showOtherMonths) && daySettings[2] ? " title='" + daySettings[2].replace(/'/g, "&#39;") + "'" : "") + // cell title
  1880. (unselectable ? "" : " data-handler='selectDay' data-event='click' data-month='" + printDate.getMonth() + "' data-year='" + printDate.getFullYear() + "'") + ">" + // actions
  1881. (otherMonth && !showOtherMonths ? "&#xa0;" : // display for other months
  1882. (unselectable ? "<span class='ui-state-default'>" + printDate.getDate() + "</span>" : "<a class='ui-state-default" +
  1883. (printDate.getTime() === today.getTime() ? " ui-state-highlight" : "") +
  1884. (printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "") + // highlight selected day
  1885. (otherMonth ? " ui-priority-secondary" : "") + // distinguish dates from other months
  1886. "' href='#'>" + printDate.getDate() + "</a>")) + "</td>"; // display selectable date
  1887. printDate.setDate(printDate.getDate() + 1);
  1888. printDate = this._daylightSavingAdjust(printDate);
  1889. }
  1890. calender += tbody + "</tr>";
  1891. }
  1892. drawMonth++;
  1893. if (drawMonth > 11) {
  1894. drawMonth = 0;
  1895. drawYear++;
  1896. }
  1897. calender += "</tbody></table>" + (isMultiMonth ? "</div>" +
  1898. ((numMonths[0] > 0 && col === numMonths[1]-1) ? "<div class='ui-datepicker-row-break'></div>" : "") : "");
  1899. group += calender;
  1900. }
  1901. html += group;
  1902. }
  1903. html += buttonPanel;
  1904. inst._keyEvent = false;
  1905. return html;
  1906. },
  1907. /* Generate the month and year header. */
  1908. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  1909. secondary, monthNames, monthNamesShort) {
  1910. var inMinYear, inMaxYear, month, years, thisYear, determineYear, year, endYear,
  1911. changeMonth = this._get(inst, "changeMonth"),
  1912. changeYear = this._get(inst, "changeYear"),
  1913. showMonthAfterYear = this._get(inst, "showMonthAfterYear"),
  1914. html = "<div class='ui-datepicker-title'>",
  1915. monthHtml = "";
  1916. // month selection
  1917. if (secondary || !changeMonth) {
  1918. monthHtml += "<span class='ui-datepicker-month'>" + monthNames[drawMonth] + "</span>";
  1919. } else {
  1920. inMinYear = (minDate && minDate.getFullYear() === drawYear);
  1921. inMaxYear = (maxDate && maxDate.getFullYear() === drawYear);
  1922. monthHtml += "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>";
  1923. for ( month = 0; month < 12; month++) {
  1924. if ((!inMinYear || month >= minDate.getMonth()) && (!inMaxYear || month <= maxDate.getMonth())) {
  1925. monthHtml += "<option value='" + month + "'" +
  1926. (month === drawMonth ? " selected='selected'" : "") +
  1927. ">" + monthNamesShort[month] + "</option>";
  1928. }
  1929. }
  1930. monthHtml += "</select>";
  1931. }
  1932. if (!showMonthAfterYear) {
  1933. html += monthHtml + (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "");
  1934. }
  1935. // year selection
  1936. if ( !inst.yearshtml ) {
  1937. inst.yearshtml = "";
  1938. if (secondary || !changeYear) {
  1939. html += "<span class='ui-datepicker-year'>" + drawYear + "</span>";
  1940. } else {
  1941. // determine range of years to display
  1942. years = this._get(inst, "yearRange").split(":");
  1943. thisYear = new Date().getFullYear();
  1944. determineYear = function(value) {
  1945. var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) :
  1946. (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) :
  1947. parseInt(value, 10)));
  1948. return (isNaN(year) ? thisYear : year);
  1949. };
  1950. year = determineYear(years[0]);
  1951. endYear = Math.max(year, determineYear(years[1] || ""));
  1952. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  1953. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  1954. inst.yearshtml += "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>";
  1955. for (; year <= endYear; year++) {
  1956. inst.yearshtml += "<option value='" + year + "'" +
  1957. (year === drawYear ? " selected='selected'" : "") +
  1958. ">" + year + "</option>";
  1959. }
  1960. inst.yearshtml += "</select>";
  1961. html += inst.yearshtml;
  1962. inst.yearshtml = null;
  1963. }
  1964. }
  1965. html += this._get(inst, "yearSuffix");
  1966. if (showMonthAfterYear) {
  1967. html += (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "") + monthHtml;
  1968. }
  1969. html += "</div>"; // Close datepicker_header
  1970. return html;
  1971. },
  1972. /* Adjust one of the date sub-fields. */
  1973. _adjustInstDate: function(inst, offset, period) {
  1974. var year = inst.drawYear + (period === "Y" ? offset : 0),
  1975. month = inst.drawMonth + (period === "M" ? offset : 0),
  1976. day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) + (period === "D" ? offset : 0),
  1977. date = this._restrictMinMax(inst, this._daylightSavingAdjust(new Date(year, month, day)));
  1978. inst.selectedDay = date.getDate();
  1979. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1980. inst.drawYear = inst.selectedYear = date.getFullYear();
  1981. if (period === "M" || period === "Y") {
  1982. this._notifyChange(inst);
  1983. }
  1984. },
  1985. /* Ensure a date is within any min/max bounds. */
  1986. _restrictMinMax: function(inst, date) {
  1987. var minDate = this._getMinMaxDate(inst, "min"),
  1988. maxDate = this._getMinMaxDate(inst, "max"),
  1989. newDate = (minDate && date < minDate ? minDate : date);
  1990. return (maxDate && newDate > maxDate ? maxDate : newDate);
  1991. },
  1992. /* Notify change of month/year. */
  1993. _notifyChange: function(inst) {
  1994. var onChange = this._get(inst, "onChangeMonthYear");
  1995. if (onChange) {
  1996. onChange.apply((inst.input ? inst.input[0] : null),
  1997. [inst.selectedYear, inst.selectedMonth + 1, inst]);
  1998. }
  1999. },
  2000. /* Determine the number of months to show. */
  2001. _getNumberOfMonths: function(inst) {
  2002. var numMonths = this._get(inst, "numberOfMonths");
  2003. return (numMonths == null ? [1, 1] : (typeof numMonths === "number" ? [1, numMonths] : numMonths));
  2004. },
  2005. /* Determine the current maximum date - ensure no time components are set. */
  2006. _getMinMaxDate: function(inst, minMax) {
  2007. return this._determineDate(inst, this._get(inst, minMax + "Date"), null);
  2008. },
  2009. /* Find the number of days in a given month. */
  2010. _getDaysInMonth: function(year, month) {
  2011. return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
  2012. },
  2013. /* Find the day of the week of the first of a month. */
  2014. _getFirstDayOfMonth: function(year, month) {
  2015. return new Date(year, month, 1).getDay();
  2016. },
  2017. /* Determines if we should allow a "next/prev" month display change. */
  2018. _canAdjustMonth: function(inst, offset, curYear, curMonth) {
  2019. var numMonths = this._getNumberOfMonths(inst),
  2020. date = this._daylightSavingAdjust(new Date(curYear,
  2021. curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
  2022. if (offset < 0) {
  2023. date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
  2024. }
  2025. return this._isInRange(inst, date);
  2026. },
  2027. /* Is the given date in the accepted range? */
  2028. _isInRange: function(inst, date) {
  2029. var yearSplit, currentYear,
  2030. minDate = this._getMinMaxDate(inst, "min"),
  2031. maxDate = this._getMinMaxDate(inst, "max"),
  2032. minYear = null,
  2033. maxYear = null,
  2034. years = this._get(inst, "yearRange");
  2035. if (years){
  2036. yearSplit = years.split(":");
  2037. currentYear = new Date().getFullYear();
  2038. minYear = parseInt(yearSplit[0], 10);
  2039. maxYear = parseInt(yearSplit[1], 10);
  2040. if ( yearSplit[0].match(/[+\-].*/) ) {
  2041. minYear += currentYear;
  2042. }
  2043. if ( yearSplit[1].match(/[+\-].*/) ) {
  2044. maxYear += currentYear;
  2045. }
  2046. }
  2047. return ((!minDate || date.getTime() >= minDate.getTime()) &&
  2048. (!maxDate || date.getTime() <= maxDate.getTime()) &&
  2049. (!minYear || date.getFullYear() >= minYear) &&
  2050. (!maxYear || date.getFullYear() <= maxYear));
  2051. },
  2052. /* Provide the configuration settings for formatting/parsing. */
  2053. _getFormatConfig: function(inst) {
  2054. var shortYearCutoff = this._get(inst, "shortYearCutoff");
  2055. shortYearCutoff = (typeof shortYearCutoff !== "string" ? shortYearCutoff :
  2056. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  2057. return {shortYearCutoff: shortYearCutoff,
  2058. dayNamesShort: this._get(inst, "dayNamesShort"), dayNames: this._get(inst, "dayNames"),
  2059. monthNamesShort: this._get(inst, "monthNamesShort"), monthNames: this._get(inst, "monthNames")};
  2060. },
  2061. /* Format the given date for display. */
  2062. _formatDate: function(inst, day, month, year) {
  2063. if (!day) {
  2064. inst.currentDay = inst.selectedDay;
  2065. inst.currentMonth = inst.selectedMonth;
  2066. inst.currentYear = inst.selectedYear;
  2067. }
  2068. var date = (day ? (typeof day === "object" ? day :
  2069. this._daylightSavingAdjust(new Date(year, month, day))) :
  2070. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  2071. return this.formatDate(this._get(inst, "dateFormat"), date, this._getFormatConfig(inst));
  2072. }
  2073. });
  2074. /*
  2075. * Bind hover events for datepicker elements.
  2076. * Done via delegate so the binding only occurs once in the lifetime of the parent div.
  2077. * Global datepicker_instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
  2078. */
  2079. function datepicker_bindHover(dpDiv) {
  2080. var selector = "button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a";
  2081. return dpDiv.delegate(selector, "mouseout", function() {
  2082. $(this).removeClass("ui-state-hover");
  2083. if (this.className.indexOf("ui-datepicker-prev") !== -1) {
  2084. $(this).removeClass("ui-datepicker-prev-hover");
  2085. }
  2086. if (this.className.indexOf("ui-datepicker-next") !== -1) {
  2087. $(this).removeClass("ui-datepicker-next-hover");
  2088. }
  2089. })
  2090. .delegate( selector, "mouseover", datepicker_handleMouseover );
  2091. }
  2092. function datepicker_handleMouseover() {
  2093. if (!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline? datepicker_instActive.dpDiv.parent()[0] : datepicker_instActive.input[0])) {
  2094. $(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
  2095. $(this).addClass("ui-state-hover");
  2096. if (this.className.indexOf("ui-datepicker-prev") !== -1) {
  2097. $(this).addClass("ui-datepicker-prev-hover");
  2098. }
  2099. if (this.className.indexOf("ui-datepicker-next") !== -1) {
  2100. $(this).addClass("ui-datepicker-next-hover");
  2101. }
  2102. }
  2103. }
  2104. /* jQuery extend now ignores nulls! */
  2105. function datepicker_extendRemove(target, props) {
  2106. $.extend(target, props);
  2107. for (var name in props) {
  2108. if (props[name] == null) {
  2109. target[name] = props[name];
  2110. }
  2111. }
  2112. return target;
  2113. }
  2114. /* Invoke the datepicker functionality.
  2115. @param options string - a command, optionally followed by additional parameters or
  2116. Object - settings for attaching new datepicker functionality
  2117. @return jQuery object */
  2118. $.fn.datepicker = function(options){
  2119. /* Verify an empty collection wasn't passed - Fixes #6976 */
  2120. if ( !this.length ) {
  2121. return this;
  2122. }
  2123. /* Initialise the date picker. */
  2124. if (!$.datepicker.initialized) {
  2125. $(document).mousedown($.datepicker._checkExternalClick);
  2126. $.datepicker.initialized = true;
  2127. }
  2128. /* Append datepicker main container to body if not exist. */
  2129. if ($("#"+$.datepicker._mainDivId).length === 0) {
  2130. $("body").append($.datepicker.dpDiv);
  2131. }
  2132. var otherArgs = Array.prototype.slice.call(arguments, 1);
  2133. if (typeof options === "string" && (options === "isDisabled" || options === "getDate" || options === "widget")) {
  2134. return $.datepicker["_" + options + "Datepicker"].
  2135. apply($.datepicker, [this[0]].concat(otherArgs));
  2136. }
  2137. if (options === "option" && arguments.length === 2 && typeof arguments[1] === "string") {
  2138. return $.datepicker["_" + options + "Datepicker"].
  2139. apply($.datepicker, [this[0]].concat(otherArgs));
  2140. }
  2141. return this.each(function() {
  2142. typeof options === "string" ?
  2143. $.datepicker["_" + options + "Datepicker"].
  2144. apply($.datepicker, [this].concat(otherArgs)) :
  2145. $.datepicker._attachDatepicker(this, options);
  2146. });
  2147. };
  2148. $.datepicker = new Datepicker(); // singleton instance
  2149. $.datepicker.initialized = false;
  2150. $.datepicker.uuid = new Date().getTime();
  2151. $.datepicker.version = "1.11.4";
  2152. var datepicker = $.datepicker;
  2153. }));