1var wptDate = (function ($) { 2 var _tempConditions, 3 _tempField, 4 is_datepicker_style_loaded = false; 5 function init(parent, options) { 6 if ( typeof $.fn.datepicker === "function" ) { 7 $('input.js-wpt-date', $(parent)).each(function (index) { 8 if ( $( this ).hasClass( 'hasDatepicker' ) ) { 9 $( this ).parent().find( '.ui-datepicker-trigger' ).remove(); 10 $( this ).removeClass('hasDatepicker'); 11 } 12 wptDate.add($(this)); 13 }); 14 } 15 16 $(document).on('click', '.js-wpt-date-clear', function () { 17 var thiz = $(this), thiz_close, el, el_aux, el_select; 18 if (thiz.closest('.js-wpt-field-item').length > 0) { 19 thiz_close = thiz.closest('.js-wpt-field-item'); 20 el_aux = thiz_close.find('.js-wpt-date-auxiliar'); 21 el = thiz_close.find('.js-wpt-date'); 22 el_select = thiz_close.find('select'); 23 } else if (thiz.closest('.wpt-repctl').length > 0) { 24 thiz_close = thiz.closest('.wpt-repctl'); 25 el_aux = thiz_close.find('.js-wpt-date-auxiliar'); 26 el = thiz_close.find('.js-wpt-date'); 27 el_select = thiz_close.find('select'); 28 } else if (thiz.closest('.js-wpt-field-items').length > 0) { 29 thiz_close = thiz.closest('.js-wpt-field-items'); 30 el_aux = thiz_close.find('.js-wpt-date-auxiliar'); 31 el = thiz_close.find('.js-wpt-date'); 32 el_select = thiz_close.find('select'); 33 } else { 34 // This should be an empty object, but as we use the variable later we need to set it 35 el_aux = thiz.closest('.js-wpt-field-items'); 36 el = thiz.closest('.js-wpt-date'); 37 el_select = thiz.closest('select'); 38 } 39 //Added trigger('wptDateSelect'); fix trigger validation and condition on click of clear 40 el_aux.val('').trigger('change').trigger('wptDateSelect'); 41 el.val(''); 42 el_select.val('0'); 43 thiz.hide(); 44 45 }); 46 } 47 48 function add(el) 49 { 50 // Before anything, return if this is readonly 51 if (el.hasClass('js-wpv-date-readonly')) { 52 if (!el.hasClass('js-wpv-date-readonly-added')) { 53 el.addClass('js-wpv-date-readonly-added').after('<img src="' + wptDateData.readonly_image + '" alt="' + wptDateData.readonly + '" title="' + wptDateData.readonly + '" class="ui-datepicker-readonly" />'); 54 } 55 return; 56 } 57 // First, a hacky hack: make the id of each el unique, because the way they are produced on repetitive date fields does not ensure it 58 var rand_number = 1 + Math.floor(Math.random() * 150), 59 old_id = el.attr('id'); 60 el.attr('id', old_id + '-' + rand_number); 61 // Walk along, nothing to see here... 62 wptDate.maybeLoadDatepickerStyle(); 63 return el.datepicker({ 64 onSelect: function (dateText, inst) { 65 // The el_aux element depends on the scenario: backend or frontend 66 var el_close, el_aux, el_clear; 67 el.val(''); 68 if (el.closest('.js-wpt-field-item').length > 0) { 69 el_close = el.closest('.js-wpt-field-item'); 70 el_aux = el_close.find('.js-wpt-date-auxiliar'); 71 el_clear = el_close.find('.js-wpt-date-clear'); 72 } else if (el.closest('.wpt-repctl').length > 0) { 73 el_close = el.closest('.wpt-repctl'); 74 el_aux = el_close.find('.js-wpt-date-auxiliar'); 75 el_clear = el_close.find('.js-wpt-date-clear'); 76 } else if (el.closest('.js-wpt-field-items').length > 0) { 77 el_close = el.closest('.js-wpt-field-items'); 78 el_aux = el_close.find('.js-wpt-date-auxiliar'); 79 el_clear = el_close.find('.js-wpt-date-clear'); 80 } else { 81 // This should be an empty object, but as we use the variable later we need to set it 82 el_aux = el.closest('.js-wpt-field-items'); 83 el_clear = el.closest('.js-wpt-date-clear'); 84 } 85 var data = 'date=' + dateText; 86 data += '&date-format=' + wptDateData.dateFormatPhp; 87 data += '&action=wpt_localize_extended_date'; 88 89 $.post(wptDateData.ajaxurl, data, function (response) { 90 if (typeof ( response ) === 'string' || response instanceof String) { 91 response = window.JSON.parse( response ); 92 } 93 if (el_aux.length > 0) { 94 el_aux.val(response['timestamp']).trigger('wptDateSelect'); 95 } 96 el.val(response['display']); 97 el_clear.css('display', 'inline-block'); 98 99 //Fix adding remove label on date 100 el.prev('small.wpt-form-error').remove(); 101 }); 102 //el.trigger('wptDateSelect'); 103 }, 104 showOn: "both", 105 buttonImage: wptDateData.buttonImage, 106 buttonImageOnly: true, 107 buttonText: wptDateData.buttonText, 108 dateFormat: 'ddmmyy', 109 //dateFormat: wptDateData.dateFormat, 110 //altFormat: wptDateData.dateFormat, 111 changeMonth: true, 112 changeYear: true, 113 yearRange: wptDateData.yearMin + ':' + wptDateData.yearMax, 114 beforeShow: function(input) { } 115 }); 116 } 117 118 function ajaxConditional(formID, conditions, field) { 119 _tempConditions = conditions; 120 _tempField = field; 121 wptCallbacks.conditionalCheck.add(wptDate.ajaxCheck); 122 } 123 function ajaxCheck(formID) { 124 wptCallbacks.conditionalCheck.remove(wptDate.ajaxCheck); 125 wptCond.ajaxCheck(formID, _tempField, _tempConditions); 126 } 127 function ignoreConditional(val) { 128 if ('' == val) { 129 return '__ignore_negative'; 130 } 131 return val; 132 //return Date.parse(val); 133 } 134 function bindConditionalChange($trigger, func, formID) { 135 $trigger.on('wptDateSelect', func); 136 //var lazy = _.debounce(func, 1000); 137 //$trigger.on('keyup', lazy); 138 return false;
139 } 140 function triggerAjax(func) { 141 if ($(this).val().length >= wptDateData.dateFormatPhp.length) 142 func(); 143 } 144 function maybeLoadDatepickerStyle() { 145 // @note the handle for this used to be wptoolset-field-datepicker 146 if ( ! is_datepicker_style_loaded ) { 147 if ( document.getElementById( 'js-toolset-datepicker-style' ) ) { 148 149 is_datepicker_style_loaded = true; 150 151 } else { 152 153 var head = document.getElementsByTagName( 'head' )[0], 154 link = document.createElement( 'link' ); 155 156 link.id = 'js-toolset-datepicker-style'; 157 link.rel = 'stylesheet'; 158 link.type = 'text/css'; 159 link.href = wptDateData.datepicker_style_url; 160 link.media = 'all'; 161 head.appendChild( link ); 162 163 is_datepicker_style_loaded = true; 164 165 } 166 } 167 } 168 return { 169 init: init, 170 add: add, 171 ajaxConditional: ajaxConditional, 172 ajaxCheck: ajaxCheck, 173 ignoreConditional: ignoreConditional, 174 bindConditionalChange: bindConditionalChange, 175 triggerAjax: triggerAjax, 176 maybeLoadDatepickerStyle: maybeLoadDatepickerStyle 177 }; 178})(jQuery); 179 180jQuery(function () { 181 wptDate.init('body'); 182}); 183 184if ('undefined' != typeof (wptCallbacks)) { 185 wptCallbacks.reset.add(function (parent) { 186 wptDate.init(parent); 187 }); 188 wptCallbacks.addRepetitive.add(wptDate.init); 189} 190 191//add_action('conditional_check_date', wptDate.ajaxConditional, 10, 3); 192if ('function' == typeof (add_filter)) { 193 add_filter('conditional_value_date', wptDate.ignoreConditional, 10, 1); 194} 195if ('function' == typeof (add_action)) { 196 add_action('conditional_trigger_bind_date', wptDate.bindConditionalChange, 10, 3); 197}
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.