mirror of
https://github.com/holo-gfx/mangadex.git
synced 2024-11-25 00:28:23 -05:00
1 line
4.6 KiB
JavaScript
1 line
4.6 KiB
JavaScript
!function(e){var t={};function i(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=t,i.d=function(e,t,a){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(i.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(a,n,function(t){return e[t]}.bind(null,n));return a},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";i.r(t);class a{constructor(e){e.dataset.initialized||(this.input=e,this.inputName=this.input.name,this.input.removeAttribute("name"),this.wrapper=document.createElement("div"),this.chipWrapper=document.createElement("div"),this.values=[],e.parentElement.replaceChild(this.wrapper,this.input),this.wrapper.appendChild(this.input),this.wrapper.appendChild(this.chipWrapper),this.wrapper.classList.add("chip-input-wrapper"),this.chipWrapper.classList.add("chip-array"),this.initialize(),this.input.dataset.initialized=!0,this.insertDefaults())}initialize(){this.input.value="",this.input.addEventListener("change",e=>{this.addValue(e.target.value),e.target.value=""})}getText(e){return e}addValue(e,t){return this.input.dataset.noTrim&&"0"!==this.input.dataset.noTrim||(e=e.trim()),this.values.find(t=>t.value==e)?null:(this.values.push(e),this.addChip(t||this.chipWrapper,e))}removeValue(e){const t=this.values.findIndex(t=>t==e);t>-1&&(this.removeChip(e),this.values.splice(t,1))}getChip(e){return this.chipWrapper.querySelector(`.chip[data-value="${e}"]`)}addChip(e,t){const i=e.appendChild(document.createElement("span"));i.classList.add("chip"),i.dataset.value=t;const a=i.appendChild(document.createElement("span"));a.textContent=this.getText(t),a.classList.add("badge","badge-pill");const n=a.appendChild(document.createElement("span"));n.classList.add("remove","fas","fa-times-circle","text-light");const s=i.appendChild(document.createElement("input"));return s.type="hidden",s.value=t,s.name=this.inputName,n.addEventListener("click",e=>{this.removeValue(e.target.closest(".chip").dataset.value)}),i}removeChip(e){const t=this.getChip(e);t?t.remove():console.error(`Chip ${e} not found`)}insertDefaults(){const e=this.input.dataset.separator?new RegExp(this.input.dataset.separator):",";for(let t of this.input.dataset.defaults.split(e))t&&this.addValue(t)}static initialize(e=".chip-input"){for(let t of document.querySelectorAll("select"+e))new s(t);for(let t of document.querySelectorAll('input[type="text"]'+e))new n(t)}}class n extends a{}class s extends a{initialize(){if(super.initialize(),this.input.dataset.grouped)for(let e of this.input.querySelectorAll("optgroup")){const t=document.createElement("div");t.classList.add("chip-group","d-none"),t.dataset.label=e.label,t.appendChild(document.createElement("label")).textContent=e.label,t.appendChild(document.createElement("div")).classList.add("chip-array"),this.chipWrapper.appendChild(t)}}getText(e){return this.getOption(e).textContent}getOption(e){return this.input.querySelector(`option[value="${e}"]`)}getOptgroup(e){return this.getOption(e).closest("optgroup")}getChipGroup(e){return this.chipWrapper.querySelector(`.chip-group[data-label="${e}"]`)}addValue(e){const t=this.input.dataset.grouped?this.getChipGroup(this.getOptgroup(e).label).querySelector(".chip-array"):this.chipWrapper,i=super.addValue(e,t);if(i){const t=this.getOption(e);t.disabled=!0,"check"===this.input.dataset.selectBehaviour?t.innerHTML="✓ "+t.innerHTML:"hide"===this.input.dataset.selectBehaviour&&t.classList.add("d-none"),t.dataset.chipClasses&&i.querySelector(".badge").classList.add(...t.dataset.chipClasses.split(" ")),this.input.dataset.grouped&&this.getChipGroup(this.getOptgroup(e).label).classList.remove("d-none")}}removeValue(e){super.removeValue(e);const t=this.getOption(e);if(t.disabled=!1,"check"===this.input.dataset.selectBehaviour?t.innerHTML=t.innerHTML.slice(2):"hide"===this.input.dataset.selectBehaviour&&t.classList.remove("d-none"),this.input.dataset.grouped){const t=this.getOptgroup(e),i=this.getChipGroup(t.label);i.classList.toggle("d-none",null==i.querySelector(".chip"))}}}a.initialize(".chip-input")}]); |