|
| 1 | +/*! |
| 2 | + * jQuery Mobile Datepicker |
| 3 | + * http://uglymongrel.com.com |
| 4 | + * |
| 5 | + * Copyright 2014 Alexander Schmitz and other contributors |
| 6 | + * Released under the MIT license. |
| 7 | + * http://jquery.org/license |
| 8 | + * |
| 9 | + * http://api.uglymongrel.com.com/jquery-mobile-datepicker-wrapper/ |
| 10 | + */ |
| 11 | +//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); |
| 12 | +//>>description: Consistent styling for native dates. Tapping opens a calender to select date. |
| 13 | +//>>label: Datepicker |
| 14 | +//>>group: Forms |
| 15 | +//>>css.structure: ../external/uglymongrel/arschmitz/jquery.mobile.datepicker.wrapper.css |
| 16 | +//>>css.theme: ../css/themes/default/jquery.mobile.theme.css |
| 17 | +//>>excludeEnd("jqmBuildExclude"); |
| 18 | +(function( factory ) { |
| 19 | + if ( typeof define === "function" && define.amd ) { |
| 20 | + |
| 21 | + // AMD. Register as an anonymous module. |
| 22 | + define([ |
| 23 | + "jquery", |
| 24 | + "jquery-ui/datepicker" |
| 25 | + ], factory ); |
| 26 | + } else { |
| 27 | + |
| 28 | + // Browser globals |
| 29 | + factory( jQuery ); |
| 30 | + } |
| 31 | +}(function( $ ) { |
| 32 | +$.widget("mobile.date",{ |
| 33 | + options:{ |
| 34 | + defaultDate: null, // Used when field is blank: actual date, |
| 35 | + // +/-number for offset from today, null for today |
| 36 | + appendText: "", // Display text following the input box, e.g. showing the format |
| 37 | + buttonText: "...", // Text for trigger button |
| 38 | + buttonImage: "", // URL for trigger button image |
| 39 | + buttonImageOnly: false, // True if the image appears alone, false if it appears on a button |
| 40 | + hideIfNoPrevNext: false, // True to hide next/previous month links |
| 41 | + // if not applicable, false to just disable them |
| 42 | + navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links |
| 43 | + gotoCurrent: false, // True if today link goes back to current selection instead |
| 44 | + changeMonth: false, // True if month can be selected directly, false if only prev/next |
| 45 | + changeYear: false, // True if year can be selected directly, false if only prev/next |
| 46 | + yearRange: "c-10:c+10", // Range of years to display in drop-down, |
| 47 | + // either relative to today's year (-nn:+nn), relative to currently displayed year |
| 48 | + // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n) |
| 49 | + showOtherMonths: false, // True to show dates in other months, false to leave blank |
| 50 | + selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable |
| 51 | + showWeek: false, // True to show week of the year, false to not show it |
| 52 | + calculateWeek: this.iso8601Week, // How to calculate the week of the year, |
| 53 | + // takes a Date and returns the number of the week for it |
| 54 | + shortYearCutoff: "+10", // Short year values < this are in the current century, |
| 55 | + // > this are in the previous century, |
| 56 | + // string value starting with "+" for current year + value |
| 57 | + minDate: null, // The earliest selectable date, or null for no limit |
| 58 | + maxDate: null, // The latest selectable date, or null for no limit |
| 59 | + beforeShowDay: null, // Function that takes a date and returns an array with |
| 60 | + // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or "", |
| 61 | + // [2] = cell title (optional), e.g. $.datepicker.noWeekends |
| 62 | + onSelect: null, // Define a callback function when a date is selected |
| 63 | + onChangeMonthYear: null, // Define a callback function when the month or year is changed |
| 64 | + beforeShow: null, // Define a callback function when the calendar is shown |
| 65 | + numberOfMonths: 1, // Number of months to show at a time |
| 66 | + showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0) |
| 67 | + stepMonths: 1, // Number of months to step back/forward |
| 68 | + stepBigMonths: 12, // Number of months to step back/forward for the big links |
| 69 | + altField: "", // Selector for an alternate field to store selected dates into |
| 70 | + altFormat: "", // The date format to use for the alternate field |
| 71 | + constrainInput: true, // The input is constrained by the current date format |
| 72 | + showButtonPanel: false, // True to show button panel, false to not show it |
| 73 | + autoSize: false, // True to size the input for the date format, false to leave as is |
| 74 | + disabled: false, // The initial disabled state |
| 75 | + inline: false, // True to set the calendar always visible |
| 76 | + theme: "a", |
| 77 | + dateFormat: "mm/dd/yy" |
| 78 | + }, |
| 79 | + _getCreateOptions: function(){ |
| 80 | + $.extend( this.options, $.datepicker._defaults ); |
| 81 | + return this._super(); |
| 82 | + }, |
| 83 | + _create:function(){ |
| 84 | + var calendar; |
| 85 | + |
| 86 | + if( this.options.inline ){ |
| 87 | + this.options.altField = this.element; |
| 88 | + calendar = $("<div>").datepicker(this.options); |
| 89 | + this.element.parent().after(calendar); |
| 90 | + } else { |
| 91 | + this.element.datepicker( this.options ); |
| 92 | + calendar = this.element.datepicker( "widget" ); |
| 93 | + } |
| 94 | + |
| 95 | + this.baseWidget = ( !this.options.inline )? this.element: this.calendar; |
| 96 | + |
| 97 | + if ( this.options.inline ) { |
| 98 | + this._on({ |
| 99 | + "change": function() { |
| 100 | + calendar.datepicker( "setDate", this.element.val() ); |
| 101 | + } |
| 102 | + }); |
| 103 | + } |
| 104 | + }, |
| 105 | + setOption:function( key, value ){ |
| 106 | + this.baseWidget.datepicker( "option", key, value ); |
| 107 | + }, |
| 108 | + getDate: function(){ |
| 109 | + return this.baseWidget.datepicker( "getDate" ); |
| 110 | + }, |
| 111 | + _destroy: function(){ |
| 112 | + return this.baseWidget.datepicker( "destroy" ); |
| 113 | + }, |
| 114 | + isDisabled: function(){ |
| 115 | + return this.baseWidget.datepicker( "isDisabled" ); |
| 116 | + }, |
| 117 | + refresh: function(){ |
| 118 | + return this.baseWidget.datepicker( "refresh" ); |
| 119 | + }, |
| 120 | + setDate: function( date ){ |
| 121 | + return this.baseWidget.datepicker( "setDate", date ); |
| 122 | + }, |
| 123 | + widget:function(){ |
| 124 | + return this.element; |
| 125 | + } |
| 126 | +}); |
| 127 | + |
| 128 | +return $.mobile.date; |
| 129 | + |
| 130 | +})); |
0 commit comments