window.XFMG=window.XFMG||{};
((h,g)=>{XF.Inserter=XF.extend(XF.Inserter,{__backup:{_applyAppend:"__applyAppend"},_applyAppend(a,b,c){if(0>[".js-yourMediaList",".js-yourAlbumsList",".js-browseMediaList",".js-browseAlbumsList"].indexOf(a))this.__applyAppend(a,b,c);else{var e=Array.from(b.querySelectorAll(".itemList-item--placeholder")),d=Array.from(c.children);e.length?(d.forEach(f=>f.classList.add("itemList-item--placeholder--temp")),this.__applyAppend(a,b,c),setTimeout(()=>{d.forEach(f=>f.classList.remove("itemList-item--placeholder--temp"));e.forEach(f=>
f.remove());XF.layoutChange()},10)):this.__applyAppend(a,b,c)}}});XFMG.editorButton={container:null,init(){XFMG.editorButton.initializeDialog();XF.EditorHelpers.dialogs.gallery=new XFMG.EditorDialogGallery("gallery");FroalaEditor.COMMANDS.xfCustom_gallery&&(FroalaEditor.COMMANDS.xfCustom_gallery.callback=XFMG.editorButton.callback)},initializeDialog(){XFMG.EditorDialogGallery=XF.extend(XF.EditorDialog,{cache:!1,container:null,_init(a){a=a.container;XF.onDelegated(a,"change",".js-mediaPicker",XF.proxy(this,
"pick"));this.container=a;XF.on(g.querySelector("#xfmg_editor_dialog_form"),"submit",XF.proxy(this,"submit"))},_afterShow(a){this.tabCounts={yourMedia:0,yourAlbums:0,browseMedia:0,browseAlbums:0}},pick(a){a=a.target;const b=a.parentNode;a.checked?this.checked(b):this.unchecked(b)},checked(a,b){a.classList.add("is-selected");b=a.closest("ul > li.is-active");const c=this.container.querySelector(b.dataset.tab);b=c.getAttribute("id");c.classList.contains("has-selected")||c.classList.add("has-selected");
const e=this.container.querySelector(".js-embedValue"),d=JSON.parse(e.value);a=a.dataset.type+"-"+a.dataset.id;XF.hasOwn(d,a)||(d[a]=1,a=c.querySelector(".js-tabCounter"),this.tabCounts[b]+=1,a.textContent=this.tabCounts[b],e.value=JSON.stringify(d))},unchecked(a,b){a.classList.remove("is-selected");b=a.closest("ul > li.is-active");b=this.container.querySelector(b.dataset.tab);const c=b.getAttribute("id"),e=this.container.querySelector(".js-embedValue"),d=JSON.parse(e.value);a=a.dataset.type+"-"+
a.dataset.id;XF.hasOwn(d,a)&&(delete d[a],a=b.querySelector(".js-tabCounter"),--this.tabCounts[c],this.tabCounts[c]?a.textContent=this.tabCounts[c]:(a.textContent="0",b.classList.remove("has-selected")),e.value=JSON.stringify(d))},submit(a){a.preventDefault();a=this.ed;const b=this.overlay;var c=this.container.querySelector(".js-embedValue");c=JSON.parse(c.value);let e="";for(const d in c){if(!XF.hasOwn(c,d))continue;const f=d.split("-");e+=XF.htmlspecialchars("[GALLERY="+f[0]+", "+parseInt(f[1])+
"][/GALLERY]");e+="<p><br></p>"}a.selection.restore();a.html.insert(e);"function"===typeof XF.EditorHelpers.normalizeAfterInsert&&XF.EditorHelpers.normalizeAfterInsert(a);b.hide()}})},callback(){XF.EditorHelpers.loadDialog(this,"gallery")}};XF.on(g,"editor:first-start",XFMG.editorButton.init)})(window,document);
