Jacks_Bastards_Website/static/wagtailadmin/js/date-time-chooser.js

1 line
5.7 KiB
JavaScript
Raw Normal View History

(()=>{"use strict";var e,t={1277:(e,t,n)=>{var i=n(1669),a=n.n(i);function r(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getYear()===t.getYear()}function o(e,t){r(new Date(t[0].value),e)||a()(this).find(".xdsoft_datepicker .xdsoft_current:not(.xdsoft_today)").removeClass("xdsoft_current")}var s=n(1002),l=n(6032);class u extends Error{constructor(e){super(`No input found with name "${e}"`),this.name="InputNotFoundError"}}class c{constructor(e,t,n){const i=`:is(input,select,textarea,button)[name="${t}"]`;if(this.input=((e,t)=>{const n=e.forEach?e:[e];for(let e=0;e<n.length;e+=1){const i=n[e];if(i.nodeType===Node.ELEMENT_NODE){if(i.matches(t))return i;const e=i.querySelector(t);if(e)return e}}return null})(e,i),!this.input)throw new u(t);this.idForLabel=this.input.id,this.parentCapabilities=n||new Map}getValue(){return this.input.value}getState(){return this.input.value}setState(e){this.input.value=e}setInvalid(e){e?this.input.setAttribute("aria-invalid","true"):this.input.removeAttribute("aria-invalid")}getValueForLabel(){return this.getValue()}getTextLabel(e){const t=this.getValueForLabel();if(!["string","number","boolean"].includes(typeof t))return null;const n=String(t).trim(),i=e&&e.maxLength;return i&&n.length>i?n.substring(0,i-1)+"…":n}focus(){this.input.focus()}setCapabilityOptions(e,t){Object.assign(this.parentCapabilities.get(e),t)}}class d{constructor(e){this.html=e}boundWidgetClass=c;render(e,t,n,i,a,r={}){const o=this.html.replace(/__NAME__/g,t).replace(/__ID__/g,n),u=document.createElement("div");u.innerHTML=o.trim();const c=Array.from(u.childNodes);e.replaceWith(...c);const d=c.filter(e=>e.nodeType===Node.ELEMENT_NODE);d.forEach(e=>{(0,l.v)(e)}),"object"==typeof r?.attributes&&(0,s.$)(d[0],r.attributes);const h=new this.boundWidgetClass(1===d.length?d[0]:c,t,a);return h.setState(i),h}getByName(e,t){return new this.boundWidgetClass(t,e)}}class h extends d{constructor(e){super(),this.options=e}render(e,t,n,i){const a=document.createElement("input");a.type="text",a.name=t,a.id=n,e.replaceWith(a),this.initChooserFn(n,this.options);const r={getValue:()=>a.value,getState:()=>a.value,setState(e){a.value=e},setInvalid(e){e?a.setAttribute("aria-invalid","true"):a.removeAttribute("aria-invalid")},focus(e){e&&e.soft||a.focus()},getTextLabel(){return this.getValue()||""},idForLabel:n};return r.setState(i),r}}a().fn.datetimepicker.defaults.i18n.wagtail_custom_locale={months:wagtailConfig.STRINGS.MONTHS,dayOfWeek:wagtailConfig.STRINGS.WEEKDAYS,dayOfWeekShort:wagtailConfig.STRINGS.WEEKDAYS_SHORT},a().datetimepicker.setLocale("wagtail_custom_locale"),window.dateEqual=r,window.hideCurrent=o,window.initDateChooser=function(e,t){window.dateTimePickerTranslations?a()("#"+e).datetimepicker(a().extend({closeOnDateSelect:!0,timepicker:!1,scrollInput:!1,format:"Y-m-d",onGenerate:o,onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{})):a()("#"+e).datetimepicker(a().extend({timepicker:!1,scrollInput:!1,format:"Y-m-d",onGenerate:o,onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{}))},window.initTimeChooser=function(e,t){window.dateTimePickerTranslations?a()("#"+e).datetimepicker(a().extend({closeOnDateSelect:!0,datepicker:!1,scrollInput:!1,format:"H:i",onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{})):a()("#"+e).datetimepicker(a().extend({datepicker:!1,format:"H:i",onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{}))},window.initDateTimeChooser=function(e,t){window.dateTimePickerTranslations?a()("#"+e).datetimepicker(a().extend({closeOnDateSelect:!0,format:"Y-m-d H:i",scrollInput:!1,onGenerate:o,onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{})):a()("#"+e).datetimepicker(a().extend({format:"Y-m-d H:i",onGenerate:o,onChangeDateTime(e,t){t.get(0).dispatchEvent(new Event("change",{bubbles:!0}))}},t||{}))},window.telepath&&(window.telepath.register("wagtail.widgets.AdminDateInput",class extends h{initChooserFn=window.initDateChoose