jquery-ym-datePlugin-0.1.js 87 KB

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