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