1(function ($, gform, gform_i18n) { 2 3 /** 4 * @function getDatepickerI18n 5 * @description Return month and day of week strings for use in the datepicker instances. 6 * @since 2.5 7 * 8 * @returns {{ 9 * dayNamesMin: *[], 10 * monthNamesShort: *[] 11 * }} 12 */ 13 14 function getDatepickerI18n() { 15 var i18n = gform_i18n.datepicker; 16 return { 17 dayNamesMin: [ 18 i18n.days.sunday, 19 i18n.days.monday, 20 i18n.days.tuesday, 21 i18n.days.wednesday, 22 i18n.days.thursday, 23 i18n.days.friday, 24 i18n.days.saturday, 25 ], 26 monthNamesShort: [ 27 i18n.months.january, 28 i18n.months.february, 29 i18n.months.march, 30 i18n.months.april, 31 i18n.months.may, 32 i18n.months.june, 33 i18n.months.july, 34 i18n.months.august, 35 i18n.months.september, 36 i18n.months.october, 37 i18n.months.november, 38 i18n.months.december, 39 ], 40 firstDay: i18n.firstDay, 41 iconText: i18n.iconText, 42 }; 43 } 44 45 /** 46 * @function getDatepickerBaseOptions 47 * @description Return base options object that configures the datepicker. 48 * @param $element The datepicker trigger. 49 * @since 2.5 50 * 51 * @returns {{ 52 * suppressDatePicker: boolean, 53 * changeMonth: boolean, 54 * changeYear: boolean, 55 * onClose: onClose, 56 * yearRange: string, 57 * dateFormat: string, 58 * showOn: string, 59 * dayNamesMin: *[], 60 * monthNamesShort: *[], 61 * beforeShow: (function(*, *): boolean), 62 * showOtherMonths: boolean 63 * }} 64 */ 65 66 function getDatepickerBaseOptions( $element ) { 67 var i18n = getDatepickerI18n(); 68 var isThemeDatepicker = $element.closest( '.gform_wrapper' ).length > 0; 69 var isPreview = $( '#preview_form_container' ).length > 0; 70 var isRTL = window.getComputedStyle($element[0], null).getPropertyValue('direction') === 'rtl'; 71 var formTheme = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).data( 'form-theme' ) : 'gravity-theme'; 72 var formId = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).attr( 'id' ).replace( 'gform_wrapper_', '' ) : ''; 73 var formPageInstance = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).attr( 'data-form-index' ) : ''; 74 75 return { 76 yearRange: '-100:+20', 77 showOn: 'focus', 78 dateFormat: 'mm/dd/yy', 79 dayNamesMin: i18n.dayNamesMin, 80 monthNamesShort: i18n.monthNamesShort, 81 firstDay: i18n.firstDay, 82 changeMonth: true, 83 changeYear: true, 84 isRTL: isRTL, 85 showOtherMonths: isThemeDatepicker, 86 suppressDatePicker: false, 87 onClose: function() { 88 var self = this; 89 $element.focus(); 90 this.suppressDatePicker = true; 91 setTimeout( function() { 92 self.suppressDatePicker = false; 93 }, 200 ); 94 }, 95 beforeShow: function( input, inst ) { 96 97 // Remove any classes that were added before as it could have been added to a different datepicker. 98 inst.dpDiv[0].classList.remove( 'gform-theme-datepicker' ); 99 inst.dpDiv[0].classList.remove( 'gravity-theme' ); 100 inst.dpDiv[0].classList.remove( 'gform-theme' ); 101 inst.dpDiv[0].classList.remove( 'gform-legacy-datepicker' ); 102 inst.dpDiv[0].classList.remove( 'gform-theme--framework' ); 103 inst.dpDiv[0].classList.remove( 'gform-theme--foundation' ); 104 inst.dpDiv[0].classList.remove( 'gform-theme--orbital' ); 105 106 // Add classes based on the form theme 107 if ( isThemeDatepicker ) { 108 inst.dpDiv[ 0 ].classList.add( 'gform-theme-datepicker' ); 109 $( inst.dpDiv[ 0 ] ).attr( 'data-parent-form', formId + '_' + formPageInstance ); 110 } 111 112 if ( formTheme === undefined || formTheme === 'gravity-theme' ) { 113 $( inst.dpDiv[0] ).addClass( 'gravity-theme' ); 114 } else if ( formTheme === 'legacy' ) { 115 $( inst.dpDiv[0] ).addClass( 'gform-legacy-datepicker' ); 116 } else { 117 $( inst.dpDiv[0] ).addClass( 'gform-theme--' + formTheme ); 118 if ( formTheme === 'orbital' ) { 119 $( inst.dpDiv[0] ).addClass( 'gform-theme--framework' ); 120 $( inst.dpDiv[0] ).addClass( 'gform-theme--foundation' ); 121 } 122 } 123 124 // If the form is in preview mode and the site is RTL, adjust the datepicker position. 125 if ( isRTL && isPreview ) { 126 var $inputContainer = $( input ).closest( '.gfield' ); 127 var rightOffset = $( document ).outerWidth() - ( $inputContainer.offset().left + $inputContainer.outerWidth() ); 128 inst.dpDiv[ 0 ].style.right = rightOffset + 'px'; 129 } 130 131 return ! this.suppressDatePicker; 132 }, 133 }; 134 } 135 136 /** 137 * @function initSingleDatepicker 138 * @description Initialize a datepicker assigning various additional options based on the trigger element. 139 * @param $element The datepicker trigger. 140 * @since 2.4 141 */ 142 143 function initSingleDatepicker( $element ) { 144 var i18n = getDatepickerI18n(); 145 var inputId = $element.attr( 'id' ) ? $element.attr( 'id' ) : ''; 146 var optionsObj = getDatepickerBaseOptions( $element ); 147 148 if ( $element.hasClass( 'dmy' ) ) { 149 optionsObj.dateFormat = 'dd/mm/yy'; 150 } else if ( $element.hasClass( 'dmy_dash' ) ) { 151 optionsObj.dateFormat = 'dd-mm-yy'; 152 } else if ( $element.hasClass( 'dmy_dot' ) ) { 153 optionsObj.dateFormat = 'dd.mm.yy'; 154 } else if ( $element.hasClass( 'ymd_slash' ) ) { 155 optionsObj.dateFormat = 'yy/mm/dd'; 156 } else if ( $element.hasClass( 'ymd_dash' ) ) { 157 optionsObj.dateFormat = 'yy-mm-dd'; 158 } else if ( $element.hasClass( 'ymd_dot' ) ) { 159 optionsObj.dateFormat = 'yy.mm.dd'; 160 } 161 162 if ( $element.hasClass( 'gdatepicker_with_icon' ) ) { 163 optionsObj.showOn = 'both'; 164 optionsObj.buttonImage = $element.parent().siblings( "[id^='gforms_calendar_icon_
164input']" ).val(); 165 optionsObj.buttonImageOnly = true; 166 optionsObj.buttonText = i18n.iconText; 167 } else { 168 optionsObj.showOn = 'focus'; 169 } 170 171 inputId = inputId.split( '_' ); 172 173 // allow the user to override the datepicker options object 174 optionsObj = gform.applyFilters( 'gform_datepicker_options_pre_init', optionsObj, inputId[ 1 ], inputId[ 2 ], $element ); 175 176 $element.datepicker( optionsObj ); 177 178 // We give the input focus after selecting a date which differs from default Datepicker behavior; this prevents 179 // users from clicking on the input again to open the datepicker. Let's add a manual click event to handle this. 180 if ( $element.is( ':input' ) ) { 181 $element.click( function() { 182 $element.datepicker( 'show' ); 183 } ); 184 } 185 } 186 187 /** 188 * @function initDatepickers 189 * @description Iterate over uninitialized datepickers and init. Exposed on window as gformInitDatepicker. 190 * Note: this function powers both admin and theme datepickers. 191 * @since 2.4 192 */ 193 194 function initDatepickers() { 195 $( '.gform-datepicker:not(.initialized)' ).each( function() { 196 var $element = $( this ); 197 initSingleDatepicker( $element ); 198 $element.addClass( 'initialized' ); 199 } ); 200 } 201 202 $( document ).ready( initDatepickers ); 203 204 // Make all and single init functions public for add-ons. 205 // Naming is done in the 2.4 backwards compatible way. 206 window.gformInitDatepicker = initDatepickers; 207 window.gformInitSingleDatepicker = initSingleDatepicker; 208 209})(jQuery, gform, gform_i18n);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.