jQuery(document).ready(function(){function l(a){a=a||event;if(a.dataTransfer.types)for(var b=0;b<a.dataTransfer.types.length;b++)if("Files"==a.dataTransfer.types[b]){a.stopPropagation();a.preventDefault();a.dataTransfer.dropEffect="none";break}}function p(a){a=a||event;if(a.originalEvent.dataTransfer.types)for(var b=0;b<a.originalEvent.dataTransfer.types.length;b++)if("Files"==a.originalEvent.dataTransfer.types[b])return a.stopPropagation(),a.preventDefault(),a.originalEvent.dataTransfer.dropEffect=
"move",!1}function q(a){a=a||event;if(a.originalEvent.dataTransfer.types)for(var b=0;b<a.originalEvent.dataTransfer.types.length;b++)if("Files"==a.originalEvent.dataTransfer.types[b]){this.classList.add("dragover");c[jQuery(this).data("entry")]=c[jQuery(this).data("entry")].add(jQuery(a.target));break}}function r(a){a=a||event;if(a.originalEvent.dataTransfer.types)for(var b=0;b<a.originalEvent.dataTransfer.types.length;b++)if("Files"==a.originalEvent.dataTransfer.types[b]){c[jQuery(this).data("entry")]=
c[jQuery(this).data("entry")].not(a.target);0===c[jQuery(this).data("entry")].length&&this.classList.remove("dragover");break}}function t(a){a=a||event;if(a.originalEvent.dataTransfer.types)for(var b=0;b<a.originalEvent.dataTransfer.types.length;b++)if("Files"==a.originalEvent.dataTransfer.types[b]){a.stopPropagation();a.preventDefault();m(a.originalEvent.dataTransfer.files,jQuery(this).data("entry"));c[jQuery(this).data("entry")]=jQuery();this.classList.remove("dragover");break}}function u(a){a=
a||event;m(a.target.files,jQuery(this).closest("tr").data("entry"))}function m(a,b){for(var g=0,f;f=a[g];g++)if(0==f.type.indexOf("image/")&&"undefined"!=typeof dg_admin_vars.upload_limit&&f.size<=parseInt(dg_admin_vars.upload_limit)){var e,k=jQuery("[data-entry="+b+"]"),g=new FormData(k.closest("form")[0]);e=jQuery("#thumbnail-management-tab");e.length?e=e.attr("action"):(e=ajaxurl,g.append("action","dg_upload_thumb"));g.append("document_gallery[entry]",b);g.append("document_gallery[ajax]","true");
g.append("document_gallery[upload]","true");g.append("file",f);var d=new XMLHttpRequest;d.open("POST",e);var c=k.find(".column-icon img"),h=k.find(".progress > *:first");d.onreadystatechange=function(){if(4==d.readyState){if(200==d.status&&-1==d.responseText.indexOf("\n")){jQuery(h).parent().addClass("success");var a=jQuery.parseJSON(d.responseText);a.result&&(a.url===c.attr("src")?c.attr("src",c.attr("src")+"?"+(new Date).getTime()):c.attr("src",a.url))}else jQuery(h).parent().addClass("fail"),console.log("Invalid response from server:"),
console.log(d.responseText);setTimeout(function(){k.find(".column-thumbupload > *").toggleClass("invis");jQuery(h).parent().removeClass("success fail")},5E3)}};d.onload=function(){h.width("100%")};d.upload.onprogress=function(a){a.lengthComputable&&h.width((a.loaded/a.total*100|0)+"%")};h.width(0);k.find(".column-thumbupload > *").toggleClass("invis");d.send(g);break}else console.log("Attempt to upload improper file %c"+f.name+":","font-weight:bold;"),0!=f.type.indexOf("image/")&&console.log("\tIs not an image - "+
f.type),"undefined"!=typeof dg_admin_vars.upload_limit&&f.size>parseInt(dg_admin_vars.upload_limit)&&console.log("\tIs too big - "+f.size+"b; (Limit is "+dg_admin_vars.upload_limit+"b)")}function n(a){for(var b=4,g=0;6>g;g++)a.animate({"margin-left":"+="+(b=-b)+"px"},50)}jQuery(".cb-ids").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("tr").addClass("selected"):jQuery(this).closest("tr").removeClass("selected")});jQuery("th input:checkbox").change(function(){jQuery(this).is(":checked")?
jQuery("#ThumbsTable tbody tr").addClass("selected"):jQuery("#ThumbsTable tbody tr").removeClass("selected")});jQuery("input.current-page").bind("keypress",{},function(a){13==(a.keyCode?a.keyCode:a.which)&&(a.preventDefault(),jQuery(location).attr("href","?"+jQuery.param(jQuery.extend(URL_params,{sheet:this.value}))))});jQuery("select.limit_per_page").change(function(){jQuery(location).attr("href","?"+jQuery.param(jQuery.extend(URL_params,{limit:this.value})))});jQuery("#thumbnail-management-tab").submit(function(a){a.preventDefault();
if(0<jQuery(".cb-ids:checked").length){a=jQuery(this).attr("action");var b=jQuery(this).serialize()+"&document_gallery%5Bajax%5D=true&document_gallery%5Bcleanup%5D=true";jQuery(".deleteSelected").addClass("waiting").attr("disabled","disabled");jQuery.post(a,b,function(a){if(a.result){a=a.deleted;for(var b in a)jQuery("input[type=checkbox][value="+a[b]+"]").closest("tr").fadeOut("slow",0,function(){jQuery(this).slideUp("slow",function(){jQuery(this).remove()})})}jQuery(".deleteSelected").removeClass("waiting").removeAttr("disabled")}).fail(function(){console.log("Problem in reaching the server");
jQuery(".deleteSelected").removeClass("waiting").removeAttr("disabled")})}return!1});jQuery("#advanced-tab #options-dump").click(function(){jQuery(this).select()});jQuery(".expander").click(function(){getSelection().toString()||(jQuery(this).next().slideToggle("slow"),jQuery(this).find(".dashicons").toggleClass("dashicons-arrow-down-alt2 dashicons-arrow-up-alt2"),jQuery(this).toggleClass("expander collapser"),jQuery(this).attr("title",jQuery(this).hasClass("expander")?"Click to Expand":"Click to Collapse"))});
jQuery(".spoiler-body").length&&(jQuery(".expandAll, .collapseAll").addClass("button"),jQuery(".expandAll").click(function(a){a.preventDefault();jQuery(".expander").trigger("click")}),jQuery(".collapseAll").click(function(a){a.preventDefault();jQuery(".collapser").trigger("click")}));jQuery(".levelSelector input").change(function(){"all"==jQuery(this).val()?(jQuery(".levelSelector input").not("[value='all']").prop("checked",jQuery(this).is(":checked")),jQuery(this).is(":checked")?jQuery("#LogTable tbody tr").show():
jQuery("#LogTable tbody tr").hide()):(jQuery(this).is(":checked")?jQuery("#LogTable tbody tr:has(span."+jQuery(this).val()+")").show():jQuery("#LogTable tbody tr:has(span."+jQuery(this).val()+")").hide(),jQuery(".levelSelector input:checked").not("[value='all']").length+1==jQuery('.levelSelector input[type="checkbox"]').length?jQuery('.levelSelector input[value="all"]').prop("checked",!0):jQuery('.levelSelector input[value="all"]').prop("checked",!1))});jQuery("#LogTable .manage-column.column-date").click(function(){jQuery(this).toggleClass("asc desc");
var a=jQuery("#LogTable > tbody"),b=a.children("tr");a.append(b.get().reverse())});window.addEventListener("dragover",l,!1);window.addEventListener("drop",l,!1);var c={};jQuery("#ThumbsTable tbody tr").each(function(){jQuery(this).on("dragenter",q).on("dragover",p).on("dragleave",r).on("drop",t);c[jQuery(this).data("entry")]=jQuery();jQuery(this).find("input:button").on("click",function(){jQuery(this).prevAll("input:file").click()});jQuery(this).find("input:file").on("change",u)});"draggable"in document.createElement("span")||
jQuery(".html5dndmarker").hide();jQuery("td .dashicons-edit").click(function(){var a=jQuery(this).closest("td");if(a.hasClass("column-title")){if("none"==a.find("a").css("display"))return;a.find("a").hide().after('<input type="text" value="'+a.find(".editable-title").text()+'">');a.find("input").focus()}else if(a.hasClass("column-description")){if("none"==a.find(".editable-description").css("display"))return;a.find(".editable-description").hide().after("<textarea>"+a.find(".editable-description").html()+
"</textarea>");a.find("textarea").focus()}else return;jQuery(this).css("visibility","hidden");a.find(".edit-controls").show()});jQuery(".edit-controls .dashicons-no").click(function(){var a=jQuery(this).closest("td");if(a.hasClass("column-title")){if("none"!=a.find("a").css("display"))return;a.find("input").fadeOut("fast",function(){jQuery(this).remove();a.find("a").fadeIn("fast")})}else if(a.hasClass("column-description")){if("none"!=a.find(".editable-description").css("display"))return;a.find("textarea").fadeOut("fast",
function(){jQuery(this).remove();a.find(".editable-description").fadeIn("fast")})}else return;jQuery(this).closest(".edit-controls").hide();a.find(".dashicons-edit").css("visibility","visible")});jQuery(".edit-controls .dashicons-yes").click(function(){var a=jQuery(this).closest("td"),b=jQuery(this).closest("tr").data("entry"),g=jQuery("#thumbnail-management-tab").attr("action"),f=new FormData(jQuery("[data-entry="+b+"]").closest("form")[0]);f.append("document_gallery[entry]",b);f.append("document_gallery[ajax]",
"true");var e,c;if(a.hasClass("column-title"))e=a.find("input"),c=a.find(".editable-title"),f.append("document_gallery[title]",encodeURIComponent(e.val()));else if(a.hasClass("column-description"))e=a.find("textarea"),c=a.find(".editable-description"),f.append("document_gallery[description]",encodeURIComponent(e.val()));else return;if(e.val()==c.text()||a.hasClass("column-description")&&e.val()==c.html())jQuery(this).next(".dashicons-no").click();else{var d=new XMLHttpRequest;d.open("POST",g);d.onreadystatechange=
function(){4==d.readyState&&(a.addClass("trans"),a.find(".edit-controls").removeClass("waiting"),-1==d.responseText.indexOf("\n")?jQuery.parseJSON(d.responseText).result?(a.hasClass("column-description")?c.html(e.val()):c.text(e.val()),a.find(".dashicons-no").click(),a.addClass("responseSuccess").delay(2E3).queue(function(){jQuery(this).removeClass("responseSuccess").dequeue()}).delay(1100).queue(function(){jQuery(this).removeClass("trans").dequeue()})):(n(e),a.addClass("responseFail").delay(1100).queue(function(){jQuery(this).removeClass("responseFail").dequeue()}).delay(1100).queue(function(){jQuery(this).removeClass("trans").dequeue()})):
(n(e),a.addClass("responseFail").delay(1100).queue(function(){jQuery(this).removeClass("responseFail").dequeue()}).delay(1100).queue(function(){jQuery(this).removeClass("trans").dequeue()}),console.log("Invalid response from server:"),console.log(d.responseText)))};jQuery(this).closest(".edit-controls").addClass("waiting");d.send(f)}})});
