').css({width:"100%",height:"100%",position:"fixed",zIndex:1e3,left:0,top:0}))}}),$(document).on({dragover:function(t){if(t.preventDefault(),!e(t))return!1;$(CHV.fn.uploader.selectors.root).data("shown")||CHV.fn.uploader.toggle({reset:!1})},dragleave:function(e){$(CHV.fn.uploader.selectors.dropzone).remove(),$.isEmptyObject(CHV.fn.uploader.files)&&CHV.fn.uploader.toggle()},drop:function(e){e.preventDefault(),CHV.fn.uploader.add(e),$(CHV.fn.uploader.selectors.dropzone).remove()}},CHV.fn.uploader.selectors.dropzone)),$(document).on("keyup change","[data-action=resize-combo-input]",function(e){var t=$(this).closest("[data-action=resize-combo-input]"),a=$("[name=form-width]",t),o=$("[name=form-height]",t),i=a.data("initial")/o.data("initial"),r={width:Math.round(a.prop("value")/i),height:Math.round(o.prop("value")*i)};$(e.target).is(a)?o.prop("value",Math.round(r.width)):a.prop("value",Math.round(r.height))}),$(document).on("click",l+" [data-action=edit]",function(){for(var e=$(this).closest("li"),t=(e.closest("ul"),e.data("id")),a=CHV.fn.uploader.files[t],o=PF.obj.modal.selectors.root,i=$.extend({},a.formValues||a.parsedMeta),r=["album_id","category_id","nsfw"],n=0;ne.height&&(r.height=e.height,r.width=Math.round(r.height*n)),r.width>e.width&&(r.width=e.width,r.height=Math.round(r.width/n)),$.each(i,function(e,t){var i="[name=form-"+e.replace(/_/g,"-")+"]",n=$(i,o);if(!n.exists())return!0;if(n.is(":checkbox"))n.prop("checked",n.attr("value")==t);else if(n.is("select")){var s=n.find("[value="+t+"]");s.exists()||(s=n.find("option:first")),s.prop("selected",!0)}else n.prop("value",t);if("width"==e||"height"==e){var l=r[e],d=a.parsedMeta[e]>l?l:a.parsedMeta[e];n.prop("max",d).data("initial",a.parsedMeta[e]).prop("value",d)}}),"image/gif"!==a.parsedMeta.mimetype&&$("[ data-content=animated-gif-warning]",o).remove(),$(".image-preview",o).append($("",{class:"canvas"}));var s=$(".queue-item[data-id="+t+"] .preview .canvas")[0],l=$(".image-preview .canvas",o)[0];l.width=s.width,l.height=s.height;var d=l.getContext("2d");d.drawImage(s,0,0)},confirm:function(){if(PF.fn.form_modal_has_changed()){var e=!1;return $.each(["width","height"],function(t,a){var i=$("[name=form-"+a+"]",o),r=parseInt(i.val()),n=parseInt(i.attr("min")),s=parseInt(i.attr("max"));if(r>s||r-1&&CHV.fn.uploader.clipboardImages.splice(n,1)}delete CHV.fn.uploader.files[a],CHV.fn.uploader.queueSize(),0==Object.size(CHV.fn.uploader.files)?"success"in CHV.fn.uploader&&"results"in CHV.fn.uploader&&(0!=Object.size(CHV.fn.uploader.results.success)||0!=Object.size(CHV.fn.uploader.results.error))||CHV.fn.uploader.reset():i&&0!==$("li.waiting",t).first().length&&CHV.fn.uploader.upload($("li.waiting",t).first())}}),$(document).on("click","[data-action=upload]",function(){$("[data-group=upload], [data-group=upload-queue-ready]",d).hide(),d.removeClass("queueReady").addClass("queueUploading").find("[data-group=uploading]").show(),CHV.fn.uploader.queueSize(),CHV.fn.uploader.canAdd=!1,$queue_items=$("li",c),$queue_items.addClass("uploading waiting"),CHV.fn.uploader.timestamp=(new Date).getTime(),CHV.fn.uploader.upload($queue_items.first("li"))}),$("body#user").exists()&&PF.obj.listing.query_string.page>1){var m=History.getState();if(m.data&&void 0!==m.data.scrollTop)$(window).scrollTop()!==m.data.scrollTop&&$(window).scrollTop(m.data.scrollTop);else{var f=$("#background-cover").height()-160;$("html, body").animate({scrollTop:f},0)}}$("#top-bar-shade").exists()&&$("#top-bar-shade").css("opacity")&&$("#top-bar-shade").data("initial-opacity",Number($("#top-bar-shade").css("opacity"))),PF.fn.isDevice("phone"),$(window).on("scroll resize",function(){var e=$(window).scrollTop();if(!(e<0)){var t=$("#top-bar"),a=Number(e/($("#background-cover, [data-content=follow-scroll-opacity]").height()-t.height()));a>1&&(a=1),$("#top-bar-shade").data("initial-opacity")&&(a+=$("#top-bar-shade").data("initial-opacity")),$("#top-bar-shade").css({opacity:a}),$("#background-cover-src").css({transform:"translate(0, "+.8*e+"px)"})}}),CHV.fn.bindSelectableItems(),$("body#image").exists()&&($(CHV.obj.image_viewer.selector+" [data-load=full]").length>0?($(document).on("click",CHV.obj.image_viewer.loader,function(e){CHV.fn.viewerLoadImage()}),$(CHV.obj.image_viewer.loader).data("size")>CHV.obj.config.image.load_max_filesize.getBytes()?$(CHV.obj.image_viewer.loader).css("display","block"):CHV.fn.viewerLoadImage(),$(document).bind("DOMSubtreeModified",function(){$("html").height()>$(window).innerHeight()&&!$("html").hasClass("scrollbar-y")&&($("html").addClass("scrollbar-y"),$(document).data({width:$(this).width(),height:$(this).height()}),CHV.fn.image_viewer_full_fix())}),$(window).on("resize",function(){CHV.fn.image_viewer_full_fix()}),$(document).on("keyup",function(e){var t=$(e.target),a=e.charCode||e.keyCode;if(!t.is(":input")&&CHV.obj.image_viewer.$navigation.exists()&&(37==a||39==a)){var o=$("[data-action="+(37==a?"prev":"next")+"]",CHV.obj.image_viewer.$navigation).attr("href");void 0!==o&&""!==o&&(window.location=$("[data-action="+(37==a?"prev":"next")+"]",CHV.obj.image_viewer.$navigation).attr("href"))}})):CHV.fn.viewerImageZoomClass()),$(document).on("click",CHV.obj.image_viewer.container,function(e){if($(this).hasClass("cursor-zoom-in")||$(this).hasClass("cursor-zoom-out")){var t=$(this).hasClass("cursor-zoom-in");if($(this).removeClass("cursor-zoom-in cursor-zoom-out"),t){var a,o=$(this)[0].getBoundingClientRect().width,i=$(this)[0].getBoundingClientRect().height,r=$("img",this).attr("width")/$("img",this).attr("height");void 0===$(this).data("dimentions")&&$(this).data({dimentions:{width:o,height:i},ratio:r}),$("img",this).attr("width")>$(window).width()?($(this).css({width:"100%"}),a=$(this).width(),$(this).css({width:o})):a=$("img",this).attr("width"),$(this).addClass("cursor-zoom-out").css({width:a,height:a/r+"px"})}else $(this).addClass("cursor-zoom-in").css($(this).data("dimentions"));e.preventDefault()}}).on("contextmenu",CHV.obj.image_viewer.container,function(e){if(!CHV.obj.config.image.right_click)return e.preventDefault(),!1}),$(document).on("contextmenu","html.device-mobile a.image-container",function(e){return e.preventDefault(),!1}),$(document).on("keyup","input[data-dashboard-tool]",function(e){if(13==e.keyCode){var t=$("[data-action="+$(this).data("dashboard-tool")+"]");t.click()}}),$(document).on("click","[data-action=dashboardTool]",function(e){e.preventDefault();var t=$(this).data("tool"),a=$(this).data("data"),o=$.extend({},a),i={};for(var r in o){var n=$(o[r]).val();if($(o[r]).prop("disabled")||!n)return;i[r]=$(o[r]),o[r]=n}o.action=t;var s={type:"GET",cache:!1};s.data=o;var l,d=$(this).closest(".input-label"),c=!0;if(0!=c){for(var r in i);PF.fn.loading.inline($(".loading",d),{size:"small",valign:"middle"}),d.find(".btn .text").hide(),$.ajax(s).complete(function(e){var t=e.responseJSON;$(".loading",d).empty(),d.find(".btn .text").show(),200!=t.status_code||void 0===t.success.redirURL?PF.fn.growl.call(t[200==t.status_code?"success":"error"].message):window.location.href=t.success.redirURL})}else PF.fn.growl.expirable(l)}),$(document).on("click","[data-action=openerPostMessage]",function(e){if(window.opener){e.preventDefault();var t="data-action-target",a=$($(this).is("["+t+"]")?$(this).attr(t):this),o=a[a.is(":input")?"val":"html"]();window.opener.postMessage({id:window.name,message:o},"*")}}),$(document).on("click","[data-action=list-tools] [data-action]",function(e){var t=$(e.target),a=t.closest("[data-id]");a&&a.find("[data-action=select]").exists()&&(e.ctrlKey||e.metaKey)&&e.altKey&&(CHV.fn.list_editor.toggleSelectItem(a,!a.hasClass("selected")),e.preventDefault(),e.stopPropagation())}),PF.fn.listing.ajax.callback=function(e){200===e.status&&CHV.fn.list_editor.listMassActionSet("select")},$(document).on("click","[data-action=list-select-all]",function(){CHV.fn.list_editor.selectItem($(".list-item:visible:not(.selected)")),CHV.fn.list_editor.listMassActionSet("clear")}),$(document).on("click","[data-action=list-clear-all]",function(){PF.fn.close_pops(),CHV.fn.list_editor.clearSelection()}),$(document).on("click","[data-action=list-tools] [data-action]",function(e){if(e.isPropagationStopped())return!1;var t=$(this).closest(PF.obj.listing.selectors.list_item+", .viewer"),a=t.data("id");if(void 0!==t.data("type")){o=t.data("type");var o,i=$("[data-type="+o+"][data-id="+a+"]");switch($(this).data("action")){case"select":CHV.fn.list_editor.toggleSelectItem(t,!t.hasClass("selected"));break;case"edit":var r="[data-modal=form-edit-single]";switch(o){case"image":$("[name=form-image-title]",r).attr("value",t.attr("data-title")),$("[name=form-image-description]",r).html(PF.fn.htmlEncode(t.data("description"))),$("[name=form-album-id]",r).find("option").removeAttr("selected"),$("[name=form-album-id]",r).find("[value="+t.data("image"==o?"album-id":"id")+"]").attr("selected",!0),$("[name=form-category-id]",r).find("option").removeAttr("selected"),$("[name=form-category-id]",r).find("[value="+t.data("category-id")+"]").attr("selected",!0),$("[name=form-nsfw]",r).attr("checked","unsafe"==t.data("flag")),$("[name=form-album-name]",r).attr("value",""),$("[name=form-album-description]",r).html(""),$("[name=form-privacy]",r).find("option").removeAttr("selected");break;case"album":$("[data-action=album-switch]",r).remove(),$("[name=form-album-name]",r).attr("value",t.data("name")),$("[name=form-album-description]",r).html(PF.fn.htmlEncode(t.data("description"))),$("[name=form-privacy]",r).find("option").removeAttr("selected"),$("[name=form-privacy]",r).find("[value="+t.data("privacy")+"]").attr("selected",!0),"password"==t.data("privacy")?($("[data-combo-value=password]").show(),$("[name=form-album-password]",r).attr("value",t.data("password"))):($("[data-combo-value=password]").hide(),$("[name=form-album-password]",r).attr("value",""))}PF.fn.modal.call({type:"html",template:$(r).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateItem("[data-type="+o+"][data-id="+a+"]",e.responseJSON[o],"edit")}}},confirm:function(){var e=$(PF.obj.modal.selectors.root);if(("image"==o||"album"==o)&&$("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val())return PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1;if(PF.fn.form_modal_has_changed()){switch(PF.obj.modal.form_data={action:"edit",edit:t.data("type"),single:!0,owner:CHV.obj.resource.user.id,editing:{id:a,description:$("[name=form-"+o+"-description]",e).val()}},o){case"image":PF.obj.modal.form_data.editing.title=$("[name=form-image-title]",e).val(),PF.obj.modal.form_data.editing.category_id=$("[name=form-category-id]",e).val()||null,PF.obj.modal.form_data.editing.nsfw=$("[name=form-nsfw]",e).prop("checked")?1:0;break;case"album":PF.obj.modal.form_data.editing.name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.privacy&&(PF.obj.modal.form_data.editing.password=$("[name=form-album-password]",e).val())}return PF.obj.modal.form_data.editing.new_album=$("[data-content=form-new-album]",e).is(":visible"),PF.obj.modal.form_data.editing.new_album?(PF.obj.modal.form_data.editing.album_name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.album_privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.album_privacy&&(PF.obj.modal.form_data.editing.album_password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.editing.album_description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.editing.album_id=$("[name=form-album-id]",e).val(),!0}PF.fn.modal.close()}});break;case"move":r="[data-modal=form-move-single]";$("[name=form-album-id]",r).find("option").removeAttr("selected"),$("[name=form-album-id]",r).find("[value="+t.data("image"==o?"album-id":"id")+"]").attr("selected",!0),$("[name=form-album-name]",r).attr("value",""),$("[name=form-album-description]",r).html(""),$("[name=form-privacy]",r).find("option").removeAttr("selected"),PF.fn.modal.call({type:"html",template:$(r).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateMoveItemLists(e.responseJSON,o,i)}}},load:function(){},confirm:function(){var e=$(PF.obj.modal.selectors.root);return $("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val()?(PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1):PF.fn.form_modal_has_changed()?(PF.obj.modal.form_data={action:"edit",edit:t.data("type"),single:!0,owner:CHV.obj.resource.user.id,editing:{id:a}},PF.obj.modal.form_data.editing.new_album=$("[data-content=form-new-album]",e).is(":visible"),PF.obj.modal.form_data.editing.new_album?(PF.obj.modal.form_data.editing.album_name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.album_privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.album_privacy&&(PF.obj.modal.form_data.editing.album_password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.editing.album_description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.editing.album_id=$("[name=form-album-id]",e).val(),!0):void PF.fn.modal.close()}});break;case"delete":PF.fn.modal.call({type:"html",template:$("[data-modal=form-delete-single]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){"album"==o&&($("[name=form-album-id]","[data-modal]").find("[value="+a+"]").remove(),CHV.fn.list_editor.updateUserCounters("image",e.responseJSON.success.affected,"-")),CHV.fn.list_editor.deleteFromList(t),CHV.fn.queuePixel()}}},confirm:function(){return PF.obj.modal.form_data={action:"delete",single:!0,delete:t.data("type"),deleting:{id:a}},!0}});break;case"flag":$.ajax({type:"POST",data:{action:"edit",edit:"image",single:!0,editing:{id:a,nsfw:"unsafe"==t.data("flag")?0:1}}}).complete(function(e){var t=e.responseJSON,a=1==t.image.nsfw?"unsafe":"safe";i.attr("data-flag",a).data("flag",a),CHV.fn.list_editor.selectionCount()})}}else console.log("Error: data-type not defined")}),$(".pop-box-menu a","[data-content=list-selection]").click(function(e){var t=$(PF.obj.listing.selectors.content_listing_visible);if(void 0!==t.data("list")){dealing_with=t.data("list");var a=$(PF.obj.listing.selectors.list_item+".selected",t),o=$.map(a,function(e,t){return $(e).data("id")});switch($(this).closest(".pop-btn").click(),$(this).data("action")){case"get-embed-codes":var i="[data-modal=form-embed-codes]",r=[];$("textarea",i).html(""),a.each(function(){var e={image:$.parseJSON(decodeURIComponent($(this).data("object")))};"url"in e.image&&r.push(e)}),CHV.fn.fillEmbedCodes(r,i,"html"),PF.fn.modal.call({type:"html",template:$(i).html(),buttons:!1});break;case"clear":CHV.fn.list_editor.clearSelection(),e.stopPropagation();break;case"move":case"create-album":i="move"==$(this).data("action")?"form-move-multiple":"form-create-album";var n="[data-modal="+i+"]",s=/image/.test(dealing_with)?"album-id":"id";$("[name=form-album-id]",n).find("[value=null]").remove(),$("[name=form-album-id]",n).find("option").removeAttr("selected"),$("[name=form-album-name]",n).attr("value",""),$("[name=form-album-description]",n).html(""),$("[name=form-privacy]",n).find("option").removeAttr("selected");var l=a.first().data(s),d=!0;a.each(function(){if($(this).data(s)!==l)return d=!1,!1}),d||$("[name=form-album-id]",n).prepend('"),$("[name=form-album-id]",n).find("[value="+(d?a.first().data(s):"null")+"]").attr("selected",!0),PF.fn.modal.call({type:"html",template:$(n).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateMoveItemLists(e.responseJSON,dealing_with,a)}}},load:function(){},confirm:function(){var e=$(PF.obj.modal.selectors.root),t=!1;if($("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val())return PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1;if($("[data-content=form-new-album]",e).is(":visible")&&(t=!0),PF.fn.form_modal_has_changed()){return PF.obj.modal.form_data={action:t?"create-album":"move",type:dealing_with,owner:CHV.obj.resource.user.id,multiple:!0,album:{ids:o,new:t}},t?(PF.obj.modal.form_data.album.name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.album.privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.album.privacy&&(PF.obj.modal.form_data.album.password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.album.description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.album.id=$("[name=form-album-id]",e).val(),!0}PF.fn.modal.close()}});break;case"delete":PF.fn.modal.call({template:$("[data-modal=form-delete-multiple]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){"albums"==dealing_with&&(a.each(function(){$("[name=form-album-id]","[data-modal]").find("[value="+$(this).data("id")+"]").remove()}),CHV.fn.list_editor.updateUserCounters("image",e.responseJSON.success.affected,"-")),CHV.fn.list_editor.deleteFromList(a),CHV.fn.queuePixel()}}},confirm:function(){return PF.obj.modal.form_data={action:"delete",from:"list",delete:dealing_with,multiple:!0,deleting:{ids:o}},!0}});break;case"assign-category":var c=a.first().data("category-id"),u=!0;a.each(function(){if($(this).data("category-id")!==c)return u=!1,!1}),PF.fn.modal.call({type:"html",template:$("[data-modal=form-assign-category]").html(),forced:!0,ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){a.each(function(){var t=e.responseJSON;$(this).data("category-id",t.category_id)}),CHV.fn.list_editor.clearSelection()}}},confirm:function(){var e=$(PF.obj.modal.selectors.root),t=$("[name=form-category-id]",e).val()||null;return u&&c==t?(PF.fn.modal.close(function(){CHV.fn.list_editor.clearSelection()}),!1):(PF.obj.modal.form_data={action:"edit-category",from:"list",multiple:!0,editing:{ids:o,category_id:t}},!0)}});break;case"flag-safe":case"flag-unsafe":var m=$(this).data("action"),f="flag-safe"==m?"safe":"unsafe";PF.fn.modal.call({template:$("[data-modal=form-"+m+"]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){a.each(function(){$(this).removeClass("safe unsafe").addClass(f).removeAttr("data-flag").attr("data-flag",f).data("flag",f)}),CHV.fn.list_editor.clearSelection()}}},confirm:function(){return PF.obj.modal.form_data={action:m,from:"list",multiple:!0,editing:{ids:o,nsfw:"flag-safe"==m?0:1}},!0}})}return!PF.fn.isDevice(["phone","phablet"])&&void 0}console.log("Error: data-list not defined")}),$("body#image").exists()&&$(window).scroll(function(){CHV.obj.topBar.transparencyScrollToggle()}),$(document).on("click","[data-action=disconnect]",function(){var e=$(this),t=e.data("connection");PF.fn.modal.confirm({message:e.data("confirm-message"),ajax:{data:{action:"disconnect",disconnect:t,user_id:CHV.obj.resource.user.id},deferred:{success:function(e){var a=e.responseJSON;$("[data-connection="+t+"]").fadeOut(function(){$($("[data-connect="+t+"]")).fadeIn(),$(this).remove(),0==$("[data-connection]").length&&$("[data-content=empty-message]").show(),PF.fn.growl.expirable(a.success.message)})},error:function(e){var t=e.responseJSON;PF.fn.growl.call(t.error.message)}}}})}),$(document).on("click","[data-action=delete-avatar]",function(){var e=$(".user-settings-avatar"),t=$(".loading-placeholder",e),a=$("#top-bar");t.removeClass("hidden"),PF.fn.loading.inline(t,{center:!0}),$.ajax({type:"POST",data:{action:"delete",delete:"avatar",owner:CHV.obj.resource.user.id}}).complete(function(o){t.addClass("hidden").empty(),200==o.status?(CHV.obj.logged_user.id==CHV.obj.resource.user.id&&($("img.user-image",a).hide(),$(".default-user-image",a).removeClass("hidden")),$(".default-user-image",e).removeClass("hidden").css({opacity:0}),$(".btn-alt",e).closest("div").hide(),$("img.user-image",e).fadeOut(function(){$(".default-user-image",e).animate({opacity:1})})):PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later."))})}),$(document).on("change","[data-content=user-avatar-upload-input]",function(e){e.preventDefault(),e.stopPropagation();var t=$(this),a=$(".user-settings-avatar"),o=$(".loading-placeholder",".user-settings-avatar"),i=$("#top-bar"),r=$(this)[0].files[0];if(!t.data("uploading"))if(0!=/^image\/.*$/.test(r.type))if(r.size>CHV.obj.config.user.avatar_max_filesize.getBytes())PF.fn.growl.call(PF.fn._s("Please select a picture of at most %s size.",CHV.obj.config.user.avatar_max_filesize));else{o.removeClass("hidden"),PF.fn.loading.inline(o,{center:!0}),t.data("uploading",!0);var n=new FormData;n.append("source",r),n.append("action","upload"),n.append("type","file"),n.append("what","avatar"),n.append("owner",CHV.obj.resource.user.id),n.append("auth_token",PF.obj.config.auth_token),avatarXHR=new XMLHttpRequest,avatarXHR.open("POST",PF.obj.config.json_api,!0),avatarXHR.send(n),avatarXHR.onreadystatechange=function(){if(4==this.readyState){var e="json"!==this.responseType?JSON.parse(this.response):this.response,r=e.success.image;o.addClass("hidden").empty(),200==this.status?(change_avatar=function(e){$("img.user-image",e).attr("src",r.url).removeClass("hidden").show()},hide_default=function(e){$(".default-user-image",e).addClass("hidden")},hide_default(a),$(".btn-alt",a).closest("div").show(),change_avatar(a),CHV.obj.logged_user.id==CHV.obj.resource.user.id&&(change_avatar(i),hide_default(i)),PF.fn.growl.expirable(PF.fn._s("Profile image updated."))):PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later.")),t.data("uploading",!1)}}}else PF.fn.growl.call(PF.fn._s("Please select a valid image file type."))}),$(document).on("change","[data-content=user-background-upload-input]",function(e){e.preventDefault(),e.stopPropagation();var t=$(this),a=$("[data-content=user-background-cover]"),o=$("[data-content=user-background-cover-src]"),i=$(".loading-placeholder",a),r=($("#top-bar"),$(this)[0].files[0]);if(!t.data("uploading"))if(0!=/^image\/.*$/.test(r.type))if(r.size>CHV.obj.config.user.background_max_filesize.getBytes())PF.fn.growl.call(PF.fn._s("Please select a picture of at most %s size.",CHV.obj.config.user.background_max_filesize));else{i.removeClass("hidden"),PF.fn.loading.inline(i,{center:!0,size:"big",color:"#FFF"}),t.data("uploading",!0);var n=new FormData;n.append("source",r),n.append("action","upload"),n.append("type","file"),n.append("what","background"),n.append("owner",CHV.obj.resource.user.id),n.append("auth_token",PF.obj.config.auth_token),avatarXHR=new XMLHttpRequest,avatarXHR.open("POST",PF.obj.config.json_api,!0),avatarXHR.send(n),avatarXHR.onreadystatechange=function(){if(4==this.readyState){var e="json"!==this.responseType?JSON.parse(this.response):this.response,r=e.success.image;if(200==this.status){var n=$("");n.attr("src",r.url).imagesLoaded(function(){i.addClass("hidden").empty(),o.css("background-image","url("+r.url+")").hide().fadeIn(),$("[data-content=user-change-background]",a).removeClass("hidden"),a.removeClass("no-background"),$("[data-content=user-upload-background]").hide(),$("[data-content=user-change-background]").show(),PF.fn.growl.expirable(PF.fn._s("Profile background image updated.")),n.remove(),"function"==typeof user_background_full_fix&&user_background_full_fix()})}else i.addClass("hidden").empty(),PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later."));t.data("uploading",!1)}}}else PF.fn.growl.call(PF.fn._s("Please select a valid image file type."))}),CHV.fn.user_background={delete:{submit:function(){return PF.obj.modal.form_data={action:"delete",delete:"background",owner:CHV.obj.resource.user.id},!0},deferred:{success:{before:function(e){$("[data-content=user-background-cover-src]").css("background-image","none"),$("[data-content=user-background-cover]").addClass("no-background").height(""),$("[data-content=user-upload-background]").removeClass("hidden").show(),$("[data-content=user-change-background]").hide(),$("#top-bar-shade").remove()},
-done:function(e){PF.fn.modal.close(function(){PF.fn.growl.expirable(PF.fn._s("Profile background image deleted."))})}},error:function(e){PF.fn.growl.expirable(PF.fn._s("Error deleting profile background image."))}}}},CHV.str.mainform="[data-content=main-form]",CHV.obj.timezone={selector:"[data-content=timezone]",input:"#timezone-region"},$(document).on("keyup change",CHV.str.mainform+" :input",function(){$(this).is("[name=username]")&&$("[data-text=username]").text($(this).val())}),$(document).on("change",CHV.obj.timezone.input,function(){var e=$(this).val(),t=$("#timezone-combo-"+e);t.find("option:first").prop("selected",!0),$(CHV.obj.timezone.selector).val(t.val()).change()}),$(document).on("change","[id^=timezone-combo-]",function(){var e=$(this).val();$(CHV.obj.timezone.selector).val(e).change()}),$(document).on("keyup change blur","[name^=new-password]",function(){var e=$("[name=new-password]"),t=$("[name=new-password-confirm]"),a=e.val()==t.val(),o=t.closest(".input-password").find(".input-warning");0==o.exists()&&(o=$("[data-message=new-password-confirm]")),$(this).is(t)&&t.data("touched",!0),t.data("touched")&&o.text(a?"":o.data("text"))[a?"addClass":"removeClass"]("hidden-visibility")}),$(document).on("submit",CHV.obj.mainform,function(){switch($(this).data("type")){case"password":var e=$("[name=new-password]",this),t=$("[name=new-password-confirm]",this);if((""!==e.val()||""!==t.val())&&e.val()!==t.val())return e.highlight(),t.highlight(),PF.fn.growl.expirable(PF.fn._s("Passwords don't match")),!1}}),$(document).on("click","[data-action=check-for-updates]",function(){PF.fn.loading.fullscreen(),CHV.fn.system.checkUpdates(function(e){if(PF.fn.loading.destroy("fullscreen"),200===e.status){var t=e.responseJSON.software;-1==PF.fn.versionCompare(CHV.obj.system_info.version,t.current_version)?PF.fn.modal.simple({title:PF.fn._s("Update available v%s",t.current_version),message:"
"+PF.fn._s("There is an update available for your system. You can automatic download and install this update or go to %s to proceed to download the file.",''+CHEVERETO.source.label+"")+"
"+PF.fn._s("The release notes for this update are:")+'
"})}else CHV.fn.uploader.focus();CHV.fn.uploader.boxSizer()}},$.extend({},h,{orientation:o.exif?o.exif.get("Orientation"):1})),setTimeout(function(){a(e+1)},25)})}else PF.fn.loading.destroy("fullscreen")}var o;if(!this.canAdd){e=e.originalEvent;return e.preventDefault(),e.stopPropagation(),!1}$fileinput=$(this.selectors.file),$fileinput.replaceWith($fileinput=$fileinput.clone(!0));var i=$(this.selectors.upload_item_template).html(),r=[];if(void 0===t){e=e.originalEvent;if(e.preventDefault(),e.stopPropagation(),r=e.dataTransfer||e.target,r=$.makeArray(r.files),e.clipboard){if(o=PF.fn.md5(e.dataURL),-1!=$.inArray(o,this.clipboardImages))return null;this.clipboardImages.push(o)}for(var n=[],s=0;sCHV.obj.config.image.max_filesize.getBytes()?n.push({uid:s,name:d.name.truncate_middle()+" - "+PF.fn._s("File too big.")}):-1!=CHV.obj.config.upload.image_types.indexOf(l)||0!=/android/i.test(navigator.userAgent)?(o&&(d.md5=o),d.fromClipboard=1==e.clipboard,d.uid=s):n.push({uid:s,name:d.name.truncate_middle()+" - "+PF.fn._s("Invalid or unsupported file format.")})}for(s=0;s0&&0==r.length){var u="";for(s=0;s"+PF.fn.htmlEncode(n[s].name)+"";return void PF.fn.modal.simple({title:PF.fn._s("Some files couldn't be added"),message:"
"+u+"
"})}if(0==r.length)return}else{if(t=t.replace(/(<([^>]+)>)/g,"").replace(/(\[([^\]]+)\])/g,""),r=t.match_urls(),!r)return;r=r.array_unique(),r=$.map(r,function(e,t){return{uid:t,name:e,url:e}})}if($.isEmptyObject(this.files))for(s=0;s0){var i=[];for(var o in this.results.error)"object"==typeof this.results.error[o]&&(i[o]=this.results.error[o].error.message);i.length>0&&$(this.selectors.failed_result).html("
"+i.join("
")+"
")}else $(a.error,this.selectors.root).hide();if(!window.opener&&CHV.obj.config.upload.redirect_single_upload&&1==Object.size(this.results.success)&&0==Object.size(this.results.error))return window.location.href=this.results.success[0].image.url_viewer,!1;if($("[data-text=queue-progress]",this.selectors.root).text(100),$("[data-group=uploading]",this.selectors.root).hide(),$(this.selectors.root).removeClass("queueUploading queueHasResults").addClass("queueCompleted"),$(this.selectors.queue).addClass(this.selectors.queue_complete.substring(1)),Object.size(this.results.success)>0&&$("[data-group=upload-result] textarea",this.selectors.root).exists()&&CHV.fn.fillEmbedCodes(this.results.success,CHV.fn.uploader.selectors.root,"val"),Object.size(this.results.success)>0&&Object.size(this.results.error)>0?$(a.mixed+", "+a.success,this.selectors.root).show():Object.size(this.results.success)>0?$(a.success,this.selectors.root).show():Object.size(this.results.error)>0&&$(a.error,this.selectors.root).show(),$(a.success,this.selectors.root).is(":visible")){$(a.success,this.selectors.root).find("[data-group^=user], [data-group=guest]").hide(),$(a.success,this.selectors.root).find("[data-group="+(PF.fn.is_user_logged()?"user":"guest")+"]").show();var r=Object.keys(this.results.success)[0];if(void 0!==this.results.success[r].image.album){var n=[];for(var s in this.results.success){var l=this.results.success[s].image;l.album&&l.album.id_encoded&&-1==n.indexOf(l.album.id_encoded)&&n.push(l.album.id_encoded)}var d={link:null,text:null};if(n.length<=1?(d.link=this.results.success[r].image.album.url,d.text=this.results.success[r].image.album.name):(d.link=this.results.success[r].image.user.url_albums,d.text=PF.fn._s("%s's Albums",this.results.success[r].image.user.name_short_html)),$("[data-text=upload-target]",this.selectors.root).text(d.text),$("[data-link=upload-target]",this.selectors.root).attr("href",d.link),PF.fn.is_user_logged()){var c=n.length>0?"album":"stream";$("[data-group=user-"+c+"]",this.selectors.root).show()}}}if(this.boxSizer(),this.queueStatus="done",window.opener&&void 0!==CHV.obj.opener.uploadPlugin[window.name]){if($('[data-action="copy"]',this.selectors.root).remove(),CHV.obj.opener.uploadPlugin[window.name].hasOwnProperty("autoInsert")&&CHV.obj.opener.uploadPlugin[window.name].autoInsert){var u=$(':input[name="'+CHV.obj.opener.uploadPlugin[window.name].autoInsert+'"]',CHV.fn.uploader.selectors.root),m=u.val();if(m)return window.opener.postMessage({id:window.name,message:m},"*"),void window.close()}}else $('[data-action="openerPostMessage"]',this.selectors.root).remove()}},$.extend(CHV.fn.uploader,$.extend(!0,{},CHV.obj.uploaderReset)),CHV.fn.fillEmbedCodes=function(e,t,a){void 0===a&&(a="val"),$.each(e,function(e,o){if(void 0!==o){var i="id_encoded"in o?o:o.image;if(!i.medium){i.medium={};for(var r=["filename","name","width","height","extension","size","size_formatted","url"],n=0;n0&&$.each(CHV.obj.categories,function(o,i){return void 0!==e&&i.id==e||(i.url_key==$("[name=form-category-url_key]",t).val()?(a=!0,!1):void 0)}),!a||(PF.fn.growl.call(PF.fn._s("Category URL key already being used.")),$("[name=form-category-url_key]",t).highlight(),!1)))},edit:{before:function(e){var t=$(e.target),a=t.data("category-id"),o=CHV.obj.categories[a],i="[data-modal="+t.data("target")+"]";$.each(CHV.fn.category.formFields,function(e,t){e="form-category-"+t,t=o[t];var a=$("[name="+e+"]",i);a.is("textarea")?a.html(PF.fn.htmlEncode(t)):a.attr("value",t)})},submit:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-category-id]",e).val();return!!CHV.fn.category.validateForm(t)&&(PF.obj.modal.form_data={action:"edit",edit:"category",editing:{}},$.each(CHV.fn.category.formFields,function(t,a){PF.obj.modal.form_data.editing[a]=$("[name=form-category-"+a+"]",e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.category,a="[data-content=category][data-category-id="+t.id+"]";$.each(t,function(e,t){$("[data-content=category-"+e+"]",a).html(PF.fn.htmlEncode(t))}),$("[data-link=category-url]").attr("href",t.url),CHV.obj.categories[t.id]=t}}},delete:{before:function(e){var t=$(e.target),a=t.data("category-id"),o=CHV.obj.categories[a];t.attr("data-confirm",t.attr("data-confirm").replace("%s",'"'+o.name+'"'))},submit:function(e){return PF.obj.modal.form_data={action:"delete",delete:"category",deleting:{id:e}},!0},complete:{success:function(e){PF.fn.growl.expirable(PF.fn._s("Category successfully deleted."));var t=e.responseJSON.request.deleting.id;$("[data-content=category][data-category-id="+t+"]").remove(),delete CHV.obj.categories[t]}}},add:{submit:function(){var e=PF.obj.modal.selectors.root;return!!CHV.fn.category.validateForm()&&(PF.obj.modal.form_data={action:"add-category",category:{}},$.each(CHV.fn.category.formFields,function(t,a){"id"!=a&&(PF.obj.modal.form_data.category[a]=$("[name=form-category-"+a+"]",e).val())}),!0)},complete:{success:function(e){var t=e.responseJSON.category,a="[data-content=dashboard-categories-list]",o=$("[data-content=category-dashboard-template]").html();$.each(t,function(e,t){o=o.replace(new RegExp("%"+e.toUpperCase()+"%","g"),t||"")}),$(a).append(o),0==Object.size(CHV.obj.categories)&&(CHV.obj.categories={}),CHV.obj.categories[t.id]=t,PF.fn.growl.call(PF.fn._s("Category %s added.",'"'+t.name+'"'))}}}},CHV.fn.ip_ban={formFields:["id","ip","expires","message"],validateForm:function(e){var t=PF.obj.modal.selectors.root,a=!1,o=$("[name=form-ip_ban-ip]",t).val();return!!CHV.fn.common.validateForm(t)&&(""!==$("[name=form-ip_ban-expires]",t).val()&&0==/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test($("[name=form-ip_ban-expires]",t).val())?(PF.fn.growl.call(PF.fn._s("Invalid expiration date.")),$("[name=form-ip_ban-expires]",t).highlight(),!1):(Object.size(CHV.obj.ip_bans)>0&&$.each(CHV.obj.ip_bans,function(t,i){return void 0!==e&&i.id==e||(i.ip==o?(a=!0,!1):void 0)}),!a||(PF.fn.growl.call(PF.fn._s("IP %s already banned.",o)),$("[name=form-ip_ban-ip]",t).highlight(),!1)))},add:{submit:function(){var e=PF.obj.modal.selectors.root;return!!CHV.fn.ip_ban.validateForm()&&(PF.obj.modal.form_data={action:"add-ip_ban",ip_ban:{}},$.each(CHV.fn.ip_ban.formFields,function(t,a){"id"!=a&&(PF.obj.modal.form_data.ip_ban[a]=$("[name=form-ip_ban-"+a+"]",e).val())}),!0)},complete:{success:function(e){var t=e.responseJSON.ip_ban,a="[data-content=dashboard-ip_bans-list]",o=$("[data-content=ip_ban-dashboard-template]").html();void 0!==o&&($.each(t,function(e,t){o=o.replace(new RegExp("%"+e.toUpperCase()+"%","g"),t||"")}),$(a).append(o)),0==Object.size(CHV.obj.ip_bans)&&(CHV.obj.ip_bans={}),CHV.obj.ip_bans[t.id]=t,$("[data-content=ban_ip]").hide(),$("[data-content=banned_ip]").show(),PF.fn.growl.call(PF.fn._s("IP %s banned.",t.ip))},error:function(e){var t=e.responseJSON.error;PF.fn.growl.call(PF.fn._s(t.message))}}},edit:{before:function(e){var t=$(e.target),a=t.data("ip_ban-id"),o=CHV.obj.ip_bans[a],i="[data-modal="+t.data("target")+"]";$.each(CHV.fn.ip_ban.formFields,function(e,t){e="form-ip_ban-"+t,t=o[t];var a=$("[name="+e+"]",i);a.is("textarea")?a.html(PF.fn.htmlEncode(t)):a.attr("value",t)})},submit:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-ip_ban-id]",e).val();return!!CHV.fn.ip_ban.validateForm(t)&&(PF.obj.modal.form_data={action:"edit",edit:"ip_ban",editing:{}},$.each(CHV.fn.ip_ban.formFields,function(t,a){PF.obj.modal.form_data.editing[a]=$("[name=form-ip_ban-"+a+"]",e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.ip_ban,a="[data-content=ip_ban][data-ip_ban-id="+t.id+"]";$.each(t,function(e,t){$("[data-content=ip_ban-"+e+"]",a).html(PF.fn.htmlEncode(t))}),CHV.obj.ip_bans[t.id]=t},error:function(e){var t=e.responseJSON.error;PF.fn.growl.call(PF.fn._s(t.message))}}},delete:{before:function(e){var t=$(e.target),a=t.data("ip_ban-id"),o=CHV.obj.ip_bans[a];t.attr("data-confirm",t.attr("data-confirm").replace("%s",o.ip))},submit:function(e){return PF.obj.modal.form_data={action:"delete",delete:"ip_ban",deleting:{id:e}},!0},complete:{success:function(e){PF.fn.growl.expirable(PF.fn._s("IP ban successfully deleted."));var t=e.responseJSON.request.deleting.id;$("[data-content=ip_ban][data-ip_ban-id="+t+"]").remove(),delete CHV.obj.ip_bans[t]}}}},CHV.fn.storage={formFields:["id","name","api_id","bucket","server","service","capacity","region","key","secret","url","account_id","account_name"],calling:!1,validateForm:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-storage-id]",e).val(),a=!0;if($.each($(":input",e),function(e,t){$(this).is(":hidden")?$(this).attr("required")&&$(this).removeAttr("required").attr("data-required",1):1==$(this).attr("data-required")&&$(this).attr("required","required"),$(this).is(":visible")&&""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),a=!1)}),!a)return PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1;var o,i=$("[name=form-storage-capacity]",e),r=i.val();return""!==r&&(0==/^[\d\.]+\s*[A-Za-z]{2}$/.test(r)||void 0===r.getBytes()?o=PF.fn._s("Invalid storage capacity value. Make sure to use a valid format."):void 0!==CHV.obj.storages[t]&&r.getBytes()0&&(t=t.formatBytes(2)),s.attr("value",t))}),$("[data-combo-value]").addClass("soft-hidden"),$(r).removeClass("soft-hidden")},submit:function(){var e=PF.obj.modal.selectors.root;$("[name=form-storage-id]",e).val();return!!CHV.fn.storage.validateForm()&&(PF.obj.modal.form_data={action:"edit",edit:"storage",editing:{}},$.each(CHV.fn.storage.formFields,function(t,a){var o;o="[name=form-storage-"+a+"]","hidden"!==$(o,e).attr("type")&&(o+=":visible"),PF.obj.modal.form_data.editing[a]=$(o,e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.storage,a="[data-content=storage][data-storage-id="+t.id+"]",o=$("[data-action=toggle-storage-https]",a);$.each(t,function(e,t){$("[data-content=storage-"+e+"]",a).html(PF.fn.htmlEncode(t))}),CHV.obj.storages[t.id]=t,CHV.fn.storage.toggleBoolDisplay(o,1==t.is_https),CHV.fn.queuePixel()},error:function(e){var t=e.responseJSON,a=t.error.message;PF.fn.growl.call(a)}}},add:{submit:function(){if(!CHV.fn.storage.validateForm())return!1;var e=PF.obj.modal.selectors.root;return PF.obj.modal.form_data={action:"add-storage",storage:{}},$.each(CHV.fn.storage.formFields,function(t,a){var o;"id"!=a&&(o="[name=form-storage-"+a+"]","hidden"!==$(o,e).attr("type")&&(o+=":visible"),PF.obj.modal.form_data.storage[a]=$(o,e).val())}),!0},complete:{success:function(e){var t=e.responseJSON.storage,a="[data-content=dashboard-storages-list]",o=$("[data-content=storage-dashboard-template]").html();$.each(t,function(e,t){var a=e.toUpperCase();if("is_https"==e||"is_active"==e)t=CHV.obj.storageTemplate.icon.replace("%TITLE%",CHV.obj.storageTemplate.messages[e]).replace("%ICON%",CHV.obj.storageTemplate.checkboxes[t]).replace("%PROP%",e.replace("is_",""));o=o.replace(new RegExp("%"+a+"%","g"),t||"")}),$(a).append(o),PF.fn.bindtipTip($("[data-storage-id="+t.id+"]")),0==CHV.obj.storages.length&&(CHV.obj.storages={}),CHV.obj.storages[t.id]=t,CHV.fn.queuePixel()},error:function(e){var t=e.responseJSON,a=t.error.message;PF.fn.growl.call(a)}}},toggleBoolDisplay:function(e,t){var a={0:e.data("unchecked-icon"),1:e.data("checked-icon")};e.removeClass(a[0]+" "+a[1]).addClass(a[t?1:0])}},CHV.fn.common={validateForm:function(e){if(void 0===e)e=PF.obj.modal.selectors.root;var t=!0;return $.each($(":input:visible",e),function(e,a){""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),t=!1)}),!!t||(PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1)},updateDoctitle:function(e){void 0!==CHV.obj.page_info&&(CHV.obj.page_info.pre_doctitle=e,CHV.obj.page_info.doctitle=CHV.obj.page_info.pre_doctitle+CHV.obj.page_info.pos_doctitle,document.title=CHV.obj.page_info.doctitle)}},CHV.fn.user={add:{submit:function(){var e=$(PF.obj.modal.selectors.root),t=!0;return $.each($(":input",e),function(e,a){""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),t=!1)}),t?(PF.obj.modal.form_data={action:"add-user",user:{username:$("[name=form-username]",e).val(),email:$("[name=form-email]",e).val(),password:$("[name=form-password]",e).val(),role:$("[name=form-role]",e).val()}},!0):(PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1)},complete:{success:function(e){e.responseJSON;PF.fn.growl.expirable(PF.fn._s("User added successfully."))},error:function(e){var t=e.responseJSON;PF.fn.growl.call(PF.fn._s(t.error.message))}}},delete:{submit:function(){return PF.obj.modal.form_data={action:"delete",delete:"user",owner:CHV.obj.resource.user.id,deleting:CHV.obj.resource.user},!0}}},CHV.fn.submit_resource_delete=function(){return PF.obj.modal.form_data={action:"delete",delete:CHV.obj.resource.type,from:"resource",owner:void 0!==CHV.obj.resource.user?CHV.obj.resource.user.id:null,deleting:CHV.obj.resource},!0},CHV.fn.complete_resource_delete={success:function(e){e.responseJSON;$("body").fadeOut("normal",function(){var e;e="album"==CHV.obj.resource.type||"image"==CHV.obj.resource.type?CHV.obj.resource.parent_url:CHV.obj.resource.user?CHV.obj.resource.user.url:CHV.obj.resource.url,void 0!==e&&(window.location=e+"?deleted")})}},CHV.fn.list_editor={selectionCount:function(){var e=$(PF.obj.listing.selectors.content_listing);e.each(function(){var t=$("[data-content=pop-selection]","[data-content=list-selection][data-tab="+$(this).attr("id")+"]"),a=$(PF.obj.listing.selectors.list_item+".selected",this).length;if(all_count=$(PF.obj.listing.selectors.list_item,this).length,t[a>0?"removeClass":"addClass"]("disabled"),$("[data-text=selection-count]",t).text(a>0?a:""),"images"==e.data("list")&&a>0){var o=$(PF.obj.listing.selectors.list_item+".selected[data-flag=safe]",this).length>0,i=$(PF.obj.listing.selectors.list_item+".selected[data-flag=unsafe]",this).length>0;$("[data-action=flag-safe]",t)[(i?"remove":"add")+"Class"]("hidden"),$("[data-action=flag-unsafe]",t)[(o?"remove":"add")+"Class"]("hidden")}$(this).is(":visible")&&CHV.fn.list_editor.listMassActionSet(all_count==a?"clear":"select")})},removeFromList:function(e,t){if(void 0!==e){e=e instanceof jQuery==0?$(e):e;var a=$(PF.obj.listing.selectors.content_listing_visible),o=e.length;e.fadeOut("fast");var i=e.first().data("type"),r=parseInt($("[data-text="+i+"-count]").text())-o;CHV.fn.list_editor.updateUserCounters(e.first().data("type"),o,"-"),e.promise().done(function(){$(document).removeClass(CHV.fn.listingViewer.selectors.bodyShown.substr(1));var i={};if(e.each(function(){$("[data-id="+$(this).data("id")+"]").each(function(){var e=$(this).closest(PF.obj.listing.selectors.content_listing).attr("id");i[e]||(i[e]=0),i[e]+=1})}),1==o?$("[data-id="+$(this).data("id")+"]").remove():e.each(function(){$("[data-id="+$(this).data("id")+"]").remove()}),PF.fn.listing.columnizerQueue(),PF.fn.listing.refresh(),CHV.fn.list_editor.selectionCount(),void 0!==t&&"string"==typeof t&&PF.fn.growl.expirable(t),$(PF.obj.listing.selectors.content_listing_pagination,a).exists()||0!=$(".list-item",a).length||(r=0),0==r)a.html(PF.obj.listing.template.empty),$(PF.obj.listing.selectors.content_listing+":not("+PF.obj.listing.selectors.content_listing_visible+")").data({empty:null,load:"ajax"}),$("[data-content=list-selection][data-tab="+a.attr("id")+"]").addClass("disabled");else if(0==$(PF.obj.listing.selectors.list_item,a).length){if($(PF.obj.listing.selectors.pad_content).height(0),$("[data-action=load-more]",a).exists())return $(PF.obj.listing.selectors.content_listing_visible).data("page",0),$("[data-action=load-more]",a).click(),void(PF.obj.listing.recolumnize=!0);var n=$("[data-pagination=next]",a);if(n.exists()){var s=n.attr("href"),l=PF.fn.deparam(s);return"page"in l&&l.page>1&&(s=s.changeURLParameterValue("page",l.page-1)),void(window.location=s)}}})}},deleteFromList:function(e){if(void 0===t)var t=!0;e=e instanceof jQuery==0?$(e):e;this.removeFromList(e,t?PF.fn._s("The content has been deleted."):null)},moveFromList:function(e,t){if(void 0===t)t=!0;e=e instanceof jQuery==0?$(e):e;this.removeFromList(e,t?PF.fn._s("The content has been moved."):null)},toggleSelectItem:function(e,t){if("boolean"!=typeof t)t=!0;var a,o,i,r=$(".viewer").is(":visible")?$("[data-type=image][data-id="+e.attr("data-id")+"]"):e,n=$("[data-action=select] .btn-icon",r);t?(r.addClass("selected"),a=n.data("icon-selected"),o=n.data("icon-unselected"),i=PF.fn._s("Unselect")):(r.removeClass("selected"),a=n.data("icon-unselected"),o=n.data("icon-selected"),i=PF.fn._s("Select")),n.removeClass(o).addClass(a),$("[data-action=select] .label",r).text(i),CHV.fn.list_editor.selectionCount()},selectItem:function(e){this.toggleSelectItem(e,!0)},unselectItem:function(e){this.toggleSelectItem(e,!1)},clearSelection:function(e){var t=$(PF.obj.listing.selectors.list_item+".selected",PF.obj.listing.selectors[e?"content_listing":"content_listing_visible"]);this.unselectItem(t),this.listMassActionSet("select")},listMassActionSet:function(e){var t="select"==e?"clear":"select",a=$("[data-action=list-"+t+"-all]:visible"),o=a.data("text-"+e+"-all");a.text(o).attr("data-action","list-"+e+"-all")},updateItem:function(e,t,a,o){if(e instanceof jQuery==0)e=$(e);var i=e.data("type"),r="image"==i?t.album:t;if(console.log(e,r,i),this.addAlbumtoModals(r),$("option[value="+r.id_encoded+"]","[name=form-album-id]").html(PF.fn.htmlEncode(r.name_with_privacy_readable_html)),void 0===a)a="edit";if("edit"==a||"move"==a){if("move"==a&&"album"==CHV.obj.resource.type)return void CHV.fn.list_editor.moveFromList(e,o);e.attr("data-description",t.description),"image"==i?(void 0!==t.title&&(e.attr("data-title",t.title),e.find("[title]").attr("title",t.title),$("[data-text=image-title]",e).html(PF.fn.htmlEncode(t.title))),void 0!==t.title_truncated&&$("[data-text=image-title-truncated]",e).html(PF.fn.htmlEncode(t.title_truncated)),void 0!==t.category_id&&e.attr("data-category-id",t.category_id),e.attr({"data-album-id":r.id_encoded,"data-flag":1==t.nsfw?"unsafe":"safe"}),$("[data-content=album-link]",e).attr("href",r.url)):e.attr({"data-privacy":r.privacy,"data-password":r.password,"data-name":r.name}),e.attr("data-privacy",r.privacy),$("[data-text=album-name]",e).html(PF.fn.htmlEncode(r.name)),PF.fn.growl.expirable("edit"==a?PF.fn._s("The content has been edited."):PF.fn._s("The content has been moved."))}},addAlbumtoModals:function(e){var t=!1;$("[name=form-album-id]","[data-modal]").each(function(){e.id_encoded&&!$("option[value="+e.id_encoded+"]",this).exists()&&($(this).append('"),t=!0)}),t&&CHV.fn.list_editor.updateUserCounters("album",1,"+")},updateAlbum:function(e){$("[data-id="+e.id_encoded+"]").each(function(){""!==e.html&&($(this).after(e.html),$(this).remove())})},updateUserCounters:function(e,t,a){if(void 0===a)a="+";var o,i,r=$("[data-text="+e+"-count]"),n=$("[data-text="+e+"-label]"),s=(t=parseInt(t),parseInt(r.html()));switch(a){case"+":o=s+t;break;case"-":o=s-t;break;case"=":o=t}i=o-s;var l=$("[data-text=total-"+r.data("text")+"]"),d=$("[data-text="+l.data("text")+"-label]"),c=parseInt(l.html()),u=c+i;r.text(o),l.text(u),n.text(n.data(1==o?"label-single":"label-plural")),d.text(n.data(1==u?"label-single":"label-plural"))},updateMoveItemLists:function(e,t,a){if(CHV.fn.list_editor.clearSelection(),/image/.test(t))"image"==t?CHV.fn.list_editor.updateItem("[data-type=image][data-id="+a.data("id")+"]",e.image,"move"):(a.each(function(){CHV.fn.list_editor.updateItem("[data-type=image][data-id="+$(this).data("id")+"]",e,"move",!1)}),PF.fn.growl.expirable(PF.fn._s("The content has been moved.")));else{if("album"==CHV.obj.resource.type?CHV.fn.list_editor.moveFromList(a):PF.fn.growl.expirable(PF.fn._s("The content has been moved.")),void 0!==e.albums_old)for(var o=0;o';$("body").append(e)},CHV.fn.import={errorHandler:function(e){PF.fn.growl.call(e.error.message)},reset:function(e){e=parseInt(e);CHV.obj.import.working[e].stats=$.ajax({type:"POST",data:{action:"importReset",id:e}}),CHV.obj.import.working[e].stats.complete(function(t){var a=t.responseJSON;if(a){var o=CHV.fn.import.parseTemplate(a.import);$("[data-id="+a.import.id+"]",CHV.obj.import.sel.root).replaceWith(o),
-"working"!=a.import.status&&clearInterval(CHV.obj.import.working[e].interval)}})},updateStats:function(e){e=parseInt(e);"readyState"in CHV.obj.import.working[e].stats&&4!=CHV.obj.import.working[e].stats.readyState?console.log("Aborting stats timeout call (previous call is still not ready)"):(CHV.obj.import.working[e].stats=$.ajax({type:"POST",data:{action:"importStats",id:e}}),CHV.obj.import.working[e].stats.complete(function(t){var a=t.responseJSON;if(a){var o=CHV.fn.import.parseTemplate(a.import);$("[data-id="+a.import.id+"]",CHV.obj.import.sel.root).replaceWith(o),"working"!=a.import.status&&clearInterval(CHV.obj.import.working[e].interval)}}))},add:{submit:function(){var e=PF.obj.modal.selectors.root;return PF.obj.modal.form_data={action:"importAdd",path:$("[name=form-path]",e).val(),options:{root:$("[name=form-structure]",PF.obj.modal.selectors.root).val()}},!0},deferred:{success:function(e){var t=e.responseJSON;PF.fn.growl.expirable(PF.fn._s("Import job ID %s added successfully, you can process the import now",t.import.id));var a=CHV.fn.import.parseTemplate(t.import);a.insertAfter(CHV.obj.import.sel.header,CHV.obj.import.sel.root),$(CHV.obj.import.sel.root).removeClass("hidden")},error:function(e){CHV.fn.import.errorHandler(e.responseJSON)}}},process:{abortAll:function(e){e=parseInt(e);if(e in CHV.obj.import.working){for(var t in CHV.obj.import.aborted.push(e),CHV.obj.import.working[e].threads)CHV.obj.import.working[e].threads[t].abort();PF.fn.growl.expirable("Aborted all threads for import job ID "+e+", changing status now"),"interval"in CHV.obj.import.working[e]&&(clearInterval(CHV.obj.import.working[e].interval),"abort"in CHV.obj.import.working[e].stats&&CHV.obj.import.working[e].stats.abort())}},xhr:function(e,t){e=parseInt(e);console.log("New XHR for thread #"+t+" for import job ID"),e in CHV.obj.import.working==0&&(CHV.obj.import.working[e]={threads:{},interval:{},stats:{}}),CHV.obj.import.working[e].threads[t]=$.ajax({type:"POST",data:{action:"importProcess",id:e,thread:t}}),CHV.obj.import.working[e].threads[t].complete(function(a){if(400!=a.status){$("[data-id="+e+"]",CHV.obj.import.sel.root).data("status");-1==$.inArray(e,CHV.obj.import.aborted)&&CHV.fn.import.process.xhr(e,t)}else CHV.fn.import.errorHandler(a.responseJSON)})},load:function(){return $("html").data("modal-form-values",""),!0},submit:function(e){var t=PF.obj.modal.selectors.root,a=$("[name=form-threads]",t).val();return 0==a?(PF.fn.growl.expirable(PF.fn._s("Select number of threads")),!1):(PF.obj.modal.form_data={action:"importEdit",id:e,threads:a,values:{status:"working"}},!0)},deferred:{success:function(e){var t=e.responseJSON;PF.fn.growl.expirable(PF.fn._s("Import job ID %s is being processed now",t.import.id));var a=CHV.fn.import.parseTemplate(t.import);$("[data-id="+t.import.id+"]",CHV.obj.import.sel.root).replaceWith(a);for(var o=parseInt(t.request.threads),i=1;i<=o;i++)CHV.fn.import.process.xhr(t.import.id,i);CHV.obj.import.working[t.import.id].interval=setInterval(function(){CHV.fn.import.updateStats(t.import.id)},5e3)},error:function(e){var t=e.responseJSON;900==t.error.code?(console.log("Aborting current working process (status changed)"),CHV.fn.import.process.abortAll(t.id)):CHV.fn.import.errorHandler()}}},delete:{submit:function(e){return PF.obj.modal.form_data={action:"importDelete",id:e},!0},deferred:{success:function(e){var t=e.responseJSON;PF.fn.growl.call(PF.fn._s("Import ID %s removed",t.import.id)),$("[data-id="+t.import.id+"]",CHV.obj.import.sel.root).remove(),1==$("li",CHV.obj.import.sel.root).size()&&$(CHV.obj.import.sel.root).addClass("hidden")},error:function(e){CHV.fn.import.errorHandler(e.responseJSON)}}},parseTemplate:function(e,t){var a=CHV.obj.import.rowTpl;for(var o in CHV.obj.import.importTr)void 0!==e[o]&&(a=a.replaceAll("%"+o+"%",e[o]));a=a.replaceAll("%parse%",e.options.root),a=a.replaceAll("%shortParse%",e.options.root.charAt(0)),a=a.replaceAll("%displayStatus%",CHV.obj.import.statusesDisplay[e.status]);var i=$($.parseHTML(a)).attr("data-object",JSON.stringify(e));return i}};
\ No newline at end of file
+$(function(){function e(e){e=e.originalEvent;var t=!1;if(e.dataTransfer.types)for(var a=0;ae&&(a.height(e),a.closest(".antiscroll-wrap").antiscroll())}}function a(e){e.addClass("list-item-play-gif--loading");var t=e.closest(".list-item"),a=$(".image-container",t),o=$("img",a),i=o.attr("src"),n=".md",s=i.lastIndexOf(n);if(-1==s)n=".th",s=i.lastIndexOf(n);var r=i.substr(0,s)+i.substr(s+n.length,i.length);a.append(a.html()),$load=t.find(".image-container img").eq(1).attr("src",r).addClass("hidden"),$load.imagesLoaded(function(){e.remove(),o.remove(),$(this.elements).removeClass("hidden")})}if($(window).on("resize",function(){CHV.fn.uploader.boxSizer(),"function"==typeof user_background_full_fix&&user_background_full_fix(),CHV.fn.bindSelectableItems(),CHV.fn.listingViewer.placeholderSizing()}),window.opener&&($(window).on("load",function(e){window.opener.postMessage({id:window.name,requestAction:"postSettings"},"*")}),$(window).on("message",function(e){var t=e.originalEvent.data;void 0!==t.id&&void 0!==t.settings&&window.name===t.id&&(CHV.obj.opener.uploadPlugin[t.id]=t.settings)})),$("#home-cover, #maintenance-wrapper, #login").exists()){var o=$("#maintenance-wrapper").exists()?$("#maintenance-wrapper").css("background-image").slice(4,-1).replace(/^\"|\"$/g,""):$(".home-cover-img","#home-cover-slideshow").first().attr("data-src");function i(){$("body").addClass("load"),$("#maintenance-wrapper").exists()||$(".home-cover-img","#home-cover-slideshow").first().css("background-image","url("+o+")").addClass("animate-in--alt").removeAttr("data-src"),setTimeout(function(){setTimeout(function(){$("body").addClass("loaded")},1200),setTimeout(function(){s()},7e3)},600)}var n=function(){setTimeout(function(){s()},8e3)};function s(){var e=$(".home-cover-img[data-src]","#home-cover-slideshow").first(),t=$(".home-cover-img","#home-cover-slideshow");if(0==e.length){if(1==t.length)return;t.first().removeClass("animate-in"),$("#home-cover-slideshow").append(t.first()),setTimeout(function(){$(".home-cover-img:last","#home-cover-slideshow").addClass("animate-in")},20),setTimeout(function(){$(".home-cover-img:not(:last)","#home-cover-slideshow").removeClass("animate-in")},4e3),n()}else{var a=e.attr("data-src");$("").attr("src",a).on("load error",function(){$(this).remove(),e.css("background-image","url("+a+")").addClass("animate-in").removeAttr("data-src"),setTimeout(function(){$(".home-cover-img:not(:last)","#home-cover-slideshow").removeClass("animate-end animate-in--alt")},2e3),n()})}}o?$("").attr("src",o).on("load error",function(){$(this).remove(),i()}):i()}var r=CHV.fn.uploader.selectors.root,l=CHV.fn.uploader.selectors.queue,d=$(r),c=$(l);$(document).on("click","[data-action=top-bar-upload]",function(e){$("body").is("#upload")||1==$(this).data("link")||CHV.fn.uploader.toggle()});var u={tones:{light:{html:"tone-light top-bar-white",top:"white"},dark:{html:"tone-dark top-bar-black",top:"black"}},isDark:function(){return $("html").hasClass("tone-dark")},toggle:function(){var e=this.isDark()?"light":"dark";$("html").removeClass(this.tones.light.html+" "+this.tones.dark.html).addClass(this.tones[e].html),$("body#index").exists()||$("#top-bar").removeClass(this.tones.light.top+" "+this.tones.dark.top).addClass(this.tones[e].top)},save:function(){$.ajax({type:"POST",data:{action:"toggleTone"},cache:!1}),u.aux=u.isDark()},timeout:{},aux:{}};if(u.aux=u.isDark(),$(document).on("click","[data-action=top-bar-tone]",function(e){e.isPropagationStopped()||($("[data-action=top-bar-menu-full]").is(":visible")&&PF.fn.topMenu.hide(),clearTimeout(u.timeout),u.toggle(),u.timeout=setTimeout(function(){u.aux!==u.isDark()&&u.save()},750))}),$("[data-action=close-upload]",d).click(function(){d.is(":animated")||$("[data-action=top-bar-upload]","#top-bar").click()}),$("[data-action=reset-upload]",d).click(function(){CHV.fn.uploader.isUploading&&$("[data-action=cancel-upload-remaining], [data-action=cancel-upload]",d).trigger("click"),CHV.fn.uploader.reset()}),$("[data-action=cancel-upload-remaining], [data-action=cancel-upload]",d).click(function(){CHV.fn.uploader.isUploading=!1,$("[data-action=cancel]",c).click(),Object.size(CHV.fn.uploader.results.success)>0?CHV.fn.uploader.displayResults():CHV.fn.uploader.reset()}),$(document).on("click","[data-action=upload-privacy]:not(disabled)",function(e){e.isDefaultPrevented()||(current_privacy=$(this).data("privacy"),target_privacy="public"==current_privacy?"private":"public",this_lock=$(".icon",this).data("lock"),this_unlock=$(".icon",this).data("unlock"),$(".icon",this).removeClass(this_lock+" "+this_unlock).addClass("public"==current_privacy?this_lock:this_unlock),$(this).data("privacy",target_privacy),$("[data-action=upload-privacy-copy]").html($("[data-action=upload-privacy]").html()),$upload_button=$("[data-action=upload]",d),$upload_button.text($upload_button.data(target_privacy)),$(this).tipTip("hide"))}),$(CHV.fn.uploader.selectors.file+", "+CHV.fn.uploader.selectors.camera).on("change",function(e){$(CHV.fn.uploader.selectors.root).data("shown")?CHV.fn.uploader.add(e):CHV.fn.uploader.toggle({callback:function(e){CHV.fn.uploader.add(e)}},e)}).on("click",function(e){!$(this).data("login-needed")||PF.fn.is_user_logged()}),$(CHV.fn.uploader.selectors.root).exists()&&($("body").on({dragenter:function(t){if(t.preventDefault(),!e(t))return!1;$(CHV.fn.uploader.selectors.dropzone).exists()||$("body").append($('').css({width:"100%",height:"100%",position:"fixed",zIndex:1e3,left:0,top:0}))}}),$(document).on({dragover:function(t){if(t.preventDefault(),!e(t))return!1;$(CHV.fn.uploader.selectors.root).data("shown")||CHV.fn.uploader.toggle({reset:!1})},dragleave:function(e){$(CHV.fn.uploader.selectors.dropzone).remove(),$.isEmptyObject(CHV.fn.uploader.files)&&CHV.fn.uploader.toggle()},drop:function(e){e.preventDefault(),CHV.fn.uploader.add(e),$(CHV.fn.uploader.selectors.dropzone).remove()}},CHV.fn.uploader.selectors.dropzone)),$(document).on("keyup change","[data-action=resize-combo-input]",function(e){var t=$(this).closest("[data-action=resize-combo-input]"),a=$("[name=form-width]",t),o=$("[name=form-height]",t),i=a.data("initial")/o.data("initial"),n={width:Math.round(a.prop("value")/i),height:Math.round(o.prop("value")*i)};$(e.target).is(a)?o.prop("value",Math.round(n.width)):a.prop("value",Math.round(n.height))}),$(document).on("click",l+" [data-action=edit]",function(){for(var e=$(this).closest("li"),t=(e.closest("ul"),e.data("id")),a=CHV.fn.uploader.files[t],o=PF.obj.modal.selectors.root,i=$.extend({},a.formValues||a.parsedMeta),n=["album_id","category_id","nsfw"],s=0;se.height&&(n.height=e.height,n.width=Math.round(n.height*s)),n.width>e.width&&(n.width=e.width,n.height=Math.round(n.width/s)),$.each(i,function(e,t){var i="[name=form-"+e.replace(/_/g,"-")+"]",s=$(i,o);if(!s.exists())return!0;if(s.is(":checkbox"))s.prop("checked",s.attr("value")==t);else if(s.is("select")){var r=s.find("[value="+t+"]");r.exists()||(r=s.find("option:first")),r.prop("selected",!0)}else s.prop("value",t);if("width"==e||"height"==e){var l=n[e],d=a.parsedMeta[e]>l?l:a.parsedMeta[e];s.prop("max",d).data("initial",a.parsedMeta[e]).prop("value",d)}}),"image/gif"!==a.parsedMeta.mimetype&&$("[ data-content=animated-gif-warning]",o).remove(),$(".image-preview",o).append($("",{class:"canvas"}));var r=$(".queue-item[data-id="+t+"] .preview .canvas")[0],l=$(".image-preview .canvas",o)[0];l.width=r.width,l.height=r.height;var d=l.getContext("2d");d.drawImage(r,0,0)},confirm:function(){if(PF.fn.form_modal_has_changed()){var e=!1;return $.each(["width","height"],function(t,a){var i=$("[name=form-"+a+"]",o),n=parseInt(i.val()),s=parseInt(i.attr("min")),r=parseInt(i.attr("max"));if(n>r||n-1&&CHV.fn.uploader.clipboardImages.splice(s,1)}delete CHV.fn.uploader.files[a],CHV.fn.uploader.queueSize(),0==Object.size(CHV.fn.uploader.files)?"success"in CHV.fn.uploader&&"results"in CHV.fn.uploader&&(0!=Object.size(CHV.fn.uploader.results.success)||0!=Object.size(CHV.fn.uploader.results.error))||CHV.fn.uploader.reset():i&&0!==$("li.waiting",t).first().length&&CHV.fn.uploader.upload($("li.waiting",t).first())}}),$(document).on("click","[data-action=upload]",function(){$("[data-group=upload], [data-group=upload-queue-ready]",d).hide(),d.removeClass("queueReady").addClass("queueUploading").find("[data-group=uploading]").show(),CHV.fn.uploader.queueSize(),CHV.fn.uploader.canAdd=!1,$queue_items=$("li",c),$queue_items.addClass("uploading waiting"),CHV.fn.uploader.timestamp=(new Date).getTime(),CHV.fn.uploader.upload($queue_items.first("li"))}),$("body#user").exists()&&PF.obj.listing.query_string.page>1){var m=History.getState();if(m.data&&void 0!==m.data.scrollTop)$(window).scrollTop()!==m.data.scrollTop&&$(window).scrollTop(m.data.scrollTop);else{var f=$("#background-cover").height()-160;$("html, body").animate({scrollTop:f},0)}}$("#top-bar-shade").exists()&&$("#top-bar-shade").css("opacity")&&$("#top-bar-shade").data("initial-opacity",Number($("#top-bar-shade").css("opacity"))),PF.fn.isDevice("phone"),$(window).on("scroll resize",function(){var e=$(window).scrollTop();if(!(e<0)){var t=$("#top-bar"),a=Number(e/($("#background-cover, [data-content=follow-scroll-opacity]").height()-t.height()));a>1&&(a=1),$("#top-bar-shade").data("initial-opacity")&&(a+=$("#top-bar-shade").data("initial-opacity")),$("#top-bar-shade").css({opacity:a}),$("#background-cover-src").css({transform:"translate(0, "+.8*e+"px)"})}}),CHV.fn.bindSelectableItems(),$("body#image").exists()&&($(CHV.obj.image_viewer.selector+" [data-load=full]").length>0?($(document).on("click",CHV.obj.image_viewer.loader,function(e){CHV.fn.viewerLoadImage()}),$(CHV.obj.image_viewer.loader).data("size")>CHV.obj.config.image.load_max_filesize.getBytes()?$(CHV.obj.image_viewer.loader).css("display","block"):CHV.fn.viewerLoadImage(),$(document).bind("DOMSubtreeModified",function(){$("html").height()>$(window).innerHeight()&&!$("html").hasClass("scrollbar-y")&&($("html").addClass("scrollbar-y"),$(document).data({width:$(this).width(),height:$(this).height()}),CHV.fn.image_viewer_full_fix())}),$(window).on("resize",function(){CHV.fn.image_viewer_full_fix()}),$(document).on("keyup",function(e){var t=$(e.target),a=e.charCode||e.keyCode;if(!t.is(":input")&&CHV.obj.image_viewer.$navigation.exists()&&(37==a||39==a)){var o=$("[data-action="+(37==a?"prev":"next")+"]",CHV.obj.image_viewer.$navigation).attr("href");void 0!==o&&""!==o&&(window.location=$("[data-action="+(37==a?"prev":"next")+"]",CHV.obj.image_viewer.$navigation).attr("href"))}})):CHV.fn.viewerImageZoomClass()),$(document).on("click",CHV.obj.image_viewer.container,function(e){if($(this).hasClass("cursor-zoom-in")||$(this).hasClass("cursor-zoom-out")){var t=$(this).hasClass("cursor-zoom-in");if($(this).removeClass("cursor-zoom-in cursor-zoom-out"),t){var a,o=$(this)[0].getBoundingClientRect().width,i=$(this)[0].getBoundingClientRect().height,n=$("img",this).attr("width")/$("img",this).attr("height");void 0===$(this).data("dimentions")&&$(this).data({dimentions:{width:o,height:i},ratio:n}),$("img",this).attr("width")>$(window).width()?($(this).css({width:"100%"}),a=$(this).width(),$(this).css({width:o})):a=$("img",this).attr("width"),$(this).addClass("cursor-zoom-out").css({width:a,height:a/n+"px"})}else $(this).addClass("cursor-zoom-in").css($(this).data("dimentions"));e.preventDefault()}}).on("contextmenu",CHV.obj.image_viewer.container,function(e){if(!CHV.obj.config.image.right_click)return e.preventDefault(),!1}),$(document).on("contextmenu","html.device-mobile a.image-container",function(e){return e.preventDefault(),!1}),$(document).on("keyup","input[data-dashboard-tool]",function(e){if(13==e.keyCode){var t=$("[data-action="+$(this).data("dashboard-tool")+"]");t.click()}}),$(document).on("click","[data-action=dashboardTool]",function(e){e.preventDefault();var t=$(this).data("tool"),a=$(this).data("data"),o=$.extend({},a),i={};for(var n in o){var s=$(o[n]).val();if($(o[n]).prop("disabled")||!s)return;i[n]=$(o[n]),o[n]=s}o.action=t;var r={type:"GET",cache:!1};r.data=o;var l,d=$(this).closest(".input-label"),c=!0;if(0!=c){for(var n in i);PF.fn.loading.inline($(".loading",d),{size:"small",valign:"middle"}),d.find(".btn .text").hide(),$.ajax(r).complete(function(e){var t=e.responseJSON;$(".loading",d).empty(),d.find(".btn .text").show(),200!=t.status_code||void 0===t.success.redirURL?PF.fn.growl.call(t[200==t.status_code?"success":"error"].message):window.location.href=t.success.redirURL})}else PF.fn.growl.expirable(l)}),$(document).on("click","[data-action=openerPostMessage]",function(e){if(window.opener){e.preventDefault();var t="data-action-target",a=$($(this).is("["+t+"]")?$(this).attr(t):this),o=a[a.is(":input")?"val":"html"]();window.opener.postMessage({id:window.name,message:o},"*")}}),$(document).on("click","[data-action=list-tools] [data-action]",function(e){var t=$(e.target),a=t.closest("[data-id]");a&&a.find("[data-action=select]").exists()&&(e.ctrlKey||e.metaKey)&&e.altKey&&(CHV.fn.list_editor.toggleSelectItem(a,!a.hasClass("selected")),e.preventDefault(),e.stopPropagation())}),PF.fn.listing.ajax.callback=function(e){200===e.status&&CHV.fn.list_editor.listMassActionSet("select")},$(document).on("click","[data-action=list-select-all]",function(){CHV.fn.list_editor.selectItem($(".list-item:visible:not(.selected)")),CHV.fn.list_editor.listMassActionSet("clear")}),$(document).on("click","[data-action=list-clear-all]",function(){PF.fn.close_pops(),CHV.fn.list_editor.clearSelection()}),$(document).on("click","[data-action=list-tools] [data-action]",function(e){if(e.isPropagationStopped())return!1;var t=$(this).closest(PF.obj.listing.selectors.list_item+", .viewer"),a=t.data("id");if(void 0!==t.data("type")){o=t.data("type");var o,i=$("[data-type="+o+"][data-id="+a+"]");switch($(this).data("action")){case"select":CHV.fn.list_editor.toggleSelectItem(t,!t.hasClass("selected"));break;case"edit":var n="[data-modal=form-edit-single]";switch(o){case"image":$("[name=form-image-title]",n).attr("value",t.attr("data-title")),$("[name=form-image-description]",n).html(PF.fn.htmlEncode(t.data("description"))),$("[name=form-album-id]",n).find("option").removeAttr("selected"),$("[name=form-album-id]",n).find("[value="+t.data("image"==o?"album-id":"id")+"]").attr("selected",!0),$("[name=form-category-id]",n).find("option").removeAttr("selected"),$("[name=form-category-id]",n).find("[value="+t.data("category-id")+"]").attr("selected",!0),$("[name=form-nsfw]",n).attr("checked","unsafe"==t.data("flag")),$("[name=form-album-name]",n).attr("value",""),$("[name=form-album-description]",n).html(""),$("[name=form-privacy]",n).find("option").removeAttr("selected");break;case"album":$("[data-action=album-switch]",n).remove(),$("[name=form-album-name]",n).attr("value",t.data("name")),$("[name=form-album-description]",n).html(PF.fn.htmlEncode(t.data("description"))),$("[name=form-privacy]",n).find("option").removeAttr("selected"),$("[name=form-privacy]",n).find("[value="+t.data("privacy")+"]").attr("selected",!0),"password"==t.data("privacy")?($("[data-combo-value=password]").show(),$("[name=form-album-password]",n).attr("value",t.data("password"))):($("[data-combo-value=password]").hide(),$("[name=form-album-password]",n).attr("value",""))}PF.fn.modal.call({type:"html",template:$(n).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateItem("[data-type="+o+"][data-id="+a+"]",e.responseJSON[o],"edit")}}},confirm:function(){var e=$(PF.obj.modal.selectors.root);if(("image"==o||"album"==o)&&$("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val())return PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1;if(PF.fn.form_modal_has_changed()){switch(PF.obj.modal.form_data={action:"edit",edit:t.data("type"),single:!0,owner:CHV.obj.resource.user.id,editing:{id:a,description:$("[name=form-"+o+"-description]",e).val()}},o){case"image":PF.obj.modal.form_data.editing.title=$("[name=form-image-title]",e).val(),PF.obj.modal.form_data.editing.category_id=$("[name=form-category-id]",e).val()||null,PF.obj.modal.form_data.editing.nsfw=$("[name=form-nsfw]",e).prop("checked")?1:0;break;case"album":PF.obj.modal.form_data.editing.name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.privacy&&(PF.obj.modal.form_data.editing.password=$("[name=form-album-password]",e).val())}return PF.obj.modal.form_data.editing.new_album=$("[data-content=form-new-album]",e).is(":visible"),PF.obj.modal.form_data.editing.new_album?(PF.obj.modal.form_data.editing.album_name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.album_privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.album_privacy&&(PF.obj.modal.form_data.editing.album_password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.editing.album_description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.editing.album_id=$("[name=form-album-id]",e).val(),!0}PF.fn.modal.close()}});break;case"move":n="[data-modal=form-move-single]";$("[name=form-album-id]",n).find("option").removeAttr("selected"),$("[name=form-album-id]",n).find("[value="+t.data("image"==o?"album-id":"id")+"]").attr("selected",!0),$("[name=form-album-name]",n).attr("value",""),$("[name=form-album-description]",n).html(""),$("[name=form-privacy]",n).find("option").removeAttr("selected"),PF.fn.modal.call({type:"html",template:$(n).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateMoveItemLists(e.responseJSON,o,i)}}},load:function(){},confirm:function(){var e=$(PF.obj.modal.selectors.root);return $("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val()?(PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1):PF.fn.form_modal_has_changed()?(PF.obj.modal.form_data={action:"edit",edit:t.data("type"),single:!0,owner:CHV.obj.resource.user.id,editing:{id:a}},PF.obj.modal.form_data.editing.new_album=$("[data-content=form-new-album]",e).is(":visible"),PF.obj.modal.form_data.editing.new_album?(PF.obj.modal.form_data.editing.album_name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.editing.album_privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.editing.album_privacy&&(PF.obj.modal.form_data.editing.album_password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.editing.album_description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.editing.album_id=$("[name=form-album-id]",e).val(),!0):void PF.fn.modal.close()}});break;case"delete":PF.fn.modal.call({type:"html",template:$("[data-modal=form-delete-single]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){"album"==o&&($("[name=form-album-id]","[data-modal]").find("[value="+a+"]").remove(),CHV.fn.list_editor.updateUserCounters("image",e.responseJSON.success.affected,"-")),CHV.fn.list_editor.deleteFromList(t),CHV.fn.queuePixel()}}},confirm:function(){return PF.obj.modal.form_data={action:"delete",single:!0,delete:t.data("type"),deleting:{id:a}},!0}});break;case"flag":$.ajax({type:"POST",data:{action:"edit",edit:"image",single:!0,editing:{id:a,nsfw:"unsafe"==t.data("flag")?0:1}}}).complete(function(e){var t=e.responseJSON,a=1==t.image.nsfw?"unsafe":"safe";i.attr("data-flag",a).data("flag",a),CHV.fn.list_editor.selectionCount()})}}else console.log("Error: data-type not defined")}),$(".pop-box-menu a","[data-content=list-selection]").click(function(e){var t=$(PF.obj.listing.selectors.content_listing_visible);if(void 0!==t.data("list")){dealing_with=t.data("list");var a=$(PF.obj.listing.selectors.list_item+".selected",t),o=$.map(a,function(e,t){return $(e).data("id")});switch($(this).closest(".pop-btn").click(),$(this).data("action")){case"get-embed-codes":var i="[data-modal=form-embed-codes]",n=[];$("textarea",i).html(""),a.each(function(){var e={image:$.parseJSON(decodeURIComponent($(this).data("object")))};"url"in e.image&&n.push(e)}),CHV.fn.fillEmbedCodes(n,i,"html"),PF.fn.modal.call({type:"html",template:$(i).html(),buttons:!1});break;case"clear":CHV.fn.list_editor.clearSelection(),e.stopPropagation();break;case"move":case"create-album":i="move"==$(this).data("action")?"form-move-multiple":"form-create-album";var s="[data-modal="+i+"]",r=/image/.test(dealing_with)?"album-id":"id";$("[name=form-album-id]",s).find("[value=null]").remove(),$("[name=form-album-id]",s).find("option").removeAttr("selected"),$("[name=form-album-name]",s).attr("value",""),$("[name=form-album-description]",s).html(""),$("[name=form-privacy]",s).find("option").removeAttr("selected");var l=a.first().data(r),d=!0;a.each(function(){if($(this).data(r)!==l)return d=!1,!1}),d||$("[name=form-album-id]",s).prepend('"),$("[name=form-album-id]",s).find("[value="+(d?a.first().data(r):"null")+"]").attr("selected",!0),PF.fn.modal.call({type:"html",template:$(s).html(),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){CHV.fn.list_editor.updateMoveItemLists(e.responseJSON,dealing_with,a)}}},load:function(){},confirm:function(){var e=$(PF.obj.modal.selectors.root),t=!1;if($("[data-content=form-new-album]",e).is(":visible")&&""==$("[name=form-album-name]",e).val())return PF.fn.growl.call(PF.fn._s("You must enter the album name.")),$("[name=form-album-name]",e).highlight(),!1;if($("[data-content=form-new-album]",e).is(":visible")&&(t=!0),PF.fn.form_modal_has_changed()){return PF.obj.modal.form_data={action:t?"create-album":"move",type:dealing_with,owner:CHV.obj.resource.user.id,multiple:!0,album:{ids:o,new:t}},t?(PF.obj.modal.form_data.album.name=$("[name=form-album-name]",e).val(),PF.obj.modal.form_data.album.privacy=$("[name=form-privacy]",e).val(),"password"==PF.obj.modal.form_data.album.privacy&&(PF.obj.modal.form_data.album.password=$("[name=form-album-password]",e).val()),PF.obj.modal.form_data.album.description=$("[name=form-album-description]",e).val()):PF.obj.modal.form_data.album.id=$("[name=form-album-id]",e).val(),!0}PF.fn.modal.close()}});break;case"delete":PF.fn.modal.call({template:$("[data-modal=form-delete-multiple]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){"albums"==dealing_with&&(a.each(function(){$("[name=form-album-id]","[data-modal]").find("[value="+$(this).data("id")+"]").remove()}),CHV.fn.list_editor.updateUserCounters("image",e.responseJSON.success.affected,"-")),CHV.fn.list_editor.deleteFromList(a),CHV.fn.queuePixel()}}},confirm:function(){return PF.obj.modal.form_data={action:"delete",from:"list",delete:dealing_with,multiple:!0,deleting:{ids:o}},!0}});break;case"assign-category":var c=a.first().data("category-id"),u=!0;a.each(function(){if($(this).data("category-id")!==c)return u=!1,!1}),PF.fn.modal.call({type:"html",template:$("[data-modal=form-assign-category]").html(),forced:!0,ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){a.each(function(){var t=e.responseJSON;$(this).data("category-id",t.category_id)}),CHV.fn.list_editor.clearSelection()}}},confirm:function(){var e=$(PF.obj.modal.selectors.root),t=$("[name=form-category-id]",e).val()||null;return u&&c==t?(PF.fn.modal.close(function(){CHV.fn.list_editor.clearSelection()}),!1):(PF.obj.modal.form_data={action:"edit-category",from:"list",multiple:!0,editing:{ids:o,category_id:t}},!0)}});break;case"flag-safe":case"flag-unsafe":var m=$(this).data("action"),f="flag-safe"==m?"safe":"unsafe";PF.fn.modal.call({template:$("[data-modal=form-"+m+"]").html(),button_submit:PF.fn._s("Confirm"),ajax:{url:PF.obj.config.json_api,deferred:{success:function(e){a.each(function(){$(this).removeClass("safe unsafe").addClass(f).removeAttr("data-flag").attr("data-flag",f).data("flag",f)}),CHV.fn.list_editor.clearSelection()}}},confirm:function(){return PF.obj.modal.form_data={action:m,from:"list",multiple:!0,editing:{ids:o,nsfw:"flag-safe"==m?0:1}},!0}})}return!PF.fn.isDevice(["phone","phablet"])&&void 0}console.log("Error: data-list not defined")}),$("body#image").exists()&&$(window).scroll(function(){CHV.obj.topBar.transparencyScrollToggle()}),$(document).on("click","[data-action=disconnect]",function(){var e=$(this),t=e.data("connection");PF.fn.modal.confirm({message:e.data("confirm-message"),ajax:{data:{action:"disconnect",disconnect:t,user_id:CHV.obj.resource.user.id},deferred:{success:function(e){var a=e.responseJSON;$("[data-connection="+t+"]").fadeOut(function(){$($("[data-connect="+t+"]")).fadeIn(),$(this).remove(),0==$("[data-connection]").length&&$("[data-content=empty-message]").show(),PF.fn.growl.expirable(a.success.message)})},error:function(e){var t=e.responseJSON;PF.fn.growl.call(t.error.message)}}}})}),$(document).on("click","[data-action=delete-avatar]",function(){var e=$(".user-settings-avatar"),t=$(".loading-placeholder",e),a=$("#top-bar");t.removeClass("hidden"),PF.fn.loading.inline(t,{center:!0}),$.ajax({type:"POST",data:{action:"delete",delete:"avatar",owner:CHV.obj.resource.user.id}}).complete(function(o){t.addClass("hidden").empty(),200==o.status?(CHV.obj.logged_user.id==CHV.obj.resource.user.id&&($("img.user-image",a).hide(),$(".default-user-image",a).removeClass("hidden")),$(".default-user-image",e).removeClass("hidden").css({opacity:0}),$(".btn-alt",e).closest("div").hide(),$("img.user-image",e).fadeOut(function(){$(".default-user-image",e).animate({opacity:1})})):PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later."))})}),$(document).on("change","[data-content=user-avatar-upload-input]",function(e){e.preventDefault(),e.stopPropagation();var t=$(this),a=$(".user-settings-avatar"),o=$(".loading-placeholder",".user-settings-avatar"),i=$("#top-bar"),n=$(this)[0].files[0];if(!t.data("uploading"))if(0!=/^image\/.*$/.test(n.type))if(n.size>CHV.obj.config.user.avatar_max_filesize.getBytes())PF.fn.growl.call(PF.fn._s("Please select a picture of at most %s size.",CHV.obj.config.user.avatar_max_filesize));else{o.removeClass("hidden"),PF.fn.loading.inline(o,{center:!0}),t.data("uploading",!0);var s=new FormData;s.append("source",n),s.append("action","upload"),s.append("type","file"),s.append("what","avatar"),s.append("owner",CHV.obj.resource.user.id),s.append("auth_token",PF.obj.config.auth_token),avatarXHR=new XMLHttpRequest,avatarXHR.open("POST",PF.obj.config.json_api,!0),avatarXHR.send(s),avatarXHR.onreadystatechange=function(){if(4==this.readyState){var e="json"!==this.responseType?JSON.parse(this.response):this.response,n=e.success.image;o.addClass("hidden").empty(),200==this.status?(change_avatar=function(e){$("img.user-image",e).attr("src",n.url).removeClass("hidden").show()},hide_default=function(e){$(".default-user-image",e).addClass("hidden")},hide_default(a),$(".btn-alt",a).closest("div").show(),change_avatar(a),CHV.obj.logged_user.id==CHV.obj.resource.user.id&&(change_avatar(i),hide_default(i)),PF.fn.growl.expirable(PF.fn._s("Profile image updated."))):PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later.")),t.data("uploading",!1)}}}else PF.fn.growl.call(PF.fn._s("Please select a valid image file type."))}),$(document).on("change","[data-content=user-background-upload-input]",function(e){e.preventDefault(),e.stopPropagation();var t=$(this),a=$("[data-content=user-background-cover]"),o=$("[data-content=user-background-cover-src]"),i=$(".loading-placeholder",a),n=($("#top-bar"),$(this)[0].files[0]);if(!t.data("uploading"))if(0!=/^image\/.*$/.test(n.type))if(n.size>CHV.obj.config.user.background_max_filesize.getBytes())PF.fn.growl.call(PF.fn._s("Please select a picture of at most %s size.",CHV.obj.config.user.background_max_filesize));else{i.removeClass("hidden"),PF.fn.loading.inline(i,{center:!0,size:"big",color:"#FFF"}),t.data("uploading",!0);var s=new FormData;s.append("source",n),s.append("action","upload"),s.append("type","file"),s.append("what","background"),s.append("owner",CHV.obj.resource.user.id),s.append("auth_token",PF.obj.config.auth_token),avatarXHR=new XMLHttpRequest,avatarXHR.open("POST",PF.obj.config.json_api,!0),avatarXHR.send(s),avatarXHR.onreadystatechange=function(){if(4==this.readyState){var e="json"!==this.responseType?JSON.parse(this.response):this.response,n=e.success.image;if(200==this.status){var s=$("");s.attr("src",n.url).imagesLoaded(function(){i.addClass("hidden").empty(),o.css("background-image","url("+n.url+")").hide().fadeIn(),$("[data-content=user-change-background]",a).removeClass("hidden"),a.removeClass("no-background"),$("[data-content=user-upload-background]").hide(),$("[data-content=user-change-background]").show(),PF.fn.growl.expirable(PF.fn._s("Profile background image updated.")),s.remove(),"function"==typeof user_background_full_fix&&user_background_full_fix()})}else i.addClass("hidden").empty(),PF.fn.growl.expirable(PF.fn._s("An error occurred. Please try again later."));t.data("uploading",!1)}}}else PF.fn.growl.call(PF.fn._s("Please select a valid image file type."))}),CHV.fn.user_background={delete:{submit:function(){return PF.obj.modal.form_data={action:"delete",delete:"background",owner:CHV.obj.resource.user.id},!0},deferred:{success:{before:function(e){$("[data-content=user-background-cover-src]").css("background-image","none"),$("[data-content=user-background-cover]").addClass("no-background").height(""),$("[data-content=user-upload-background]").removeClass("hidden").show(),$("[data-content=user-change-background]").hide(),$("#top-bar-shade").remove()},
+done:function(e){PF.fn.modal.close(function(){PF.fn.growl.expirable(PF.fn._s("Profile background image deleted."))})}},error:function(e){PF.fn.growl.expirable(PF.fn._s("Error deleting profile background image."))}}}},CHV.str.mainform="[data-content=main-form]",CHV.obj.timezone={selector:"[data-content=timezone]",input:"#timezone-region"},$(document).on("keyup change",CHV.str.mainform+" :input",function(){$(this).is("[name=username]")&&$("[data-text=username]").text($(this).val())}),$(document).on("change",CHV.obj.timezone.input,function(){var e=$(this).val(),t=$("#timezone-combo-"+e);t.find("option:first").prop("selected",!0),$(CHV.obj.timezone.selector).val(t.val()).change()}),$(document).on("change","[id^=timezone-combo-]",function(){var e=$(this).val();$(CHV.obj.timezone.selector).val(e).change()}),$(document).on("keyup change blur","[name^=new-password]",function(){var e=$("[name=new-password]"),t=$("[name=new-password-confirm]"),a=e.val()==t.val(),o=t.closest(".input-password").find(".input-warning");0==o.exists()&&(o=$("[data-message=new-password-confirm]")),$(this).is(t)&&t.data("touched",!0),t.data("touched")&&o.text(a?"":o.data("text"))[a?"addClass":"removeClass"]("hidden-visibility")}),$(document).on("submit",CHV.obj.mainform,function(){switch($(this).data("type")){case"password":var e=$("[name=new-password]",this),t=$("[name=new-password-confirm]",this);if((""!==e.val()||""!==t.val())&&e.val()!==t.val())return e.highlight(),t.highlight(),PF.fn.growl.expirable(PF.fn._s("Passwords don't match")),!1}}),$(document).on("click","[data-action=check-for-updates]",function(){PF.fn.loading.fullscreen(),CHV.fn.system.checkUpdates(function(e){if(PF.fn.loading.destroy("fullscreen"),200===e.status){var t=e.responseJSON.software;-1==PF.fn.versionCompare(CHV.obj.system_info.version,t.current_version)?PF.fn.modal.simple({title:PF.fn._s("Update available v%s",t.current_version),message:"
"+PF.fn._s("There is an update available for your system. You can automatic download and install this update or go to %s to proceed to download the file.",''+CHEVERETO.source.label+"")+"
"+PF.fn._s("The release notes for this update are:")+'
"})}else CHV.fn.uploader.focus();CHV.fn.uploader.boxSizer()}},$.extend({},h,{orientation:o.exif?o.exif.get("Orientation"):1})),setTimeout(function(){a(e+1)},25)})}else PF.fn.loading.destroy("fullscreen")}var o;if(!this.canAdd){e=e.originalEvent;return e.preventDefault(),e.stopPropagation(),!1}$fileinput=$(this.selectors.file),$fileinput.replaceWith($fileinput=$fileinput.clone(!0));var i=$(this.selectors.upload_item_template).html(),n=[];if(void 0===t){e=e.originalEvent;if(e.preventDefault(),e.stopPropagation(),n=e.dataTransfer||e.target,n=$.makeArray(n.files),e.clipboard){if(o=PF.fn.md5(e.dataURL),-1!=$.inArray(o,this.clipboardImages))return null;this.clipboardImages.push(o)}for(var s=[],r=0;rCHV.obj.config.image.max_filesize.getBytes()?s.push({uid:r,name:d.name.truncate_middle()+" - "+PF.fn._s("File too big.")}):-1!=CHV.obj.config.upload.image_types.indexOf(l)||0!=/android/i.test(navigator.userAgent)?(o&&(d.md5=o),d.fromClipboard=1==e.clipboard,d.uid=r):s.push({uid:r,name:d.name.truncate_middle()+" - "+PF.fn._s("Invalid or unsupported file format.")})}for(r=0;r0&&0==n.length){var u="";for(r=0;r"+PF.fn.htmlEncode(s[r].name)+"";return void PF.fn.modal.simple({title:PF.fn._s("Some files couldn't be added"),message:"
"+u+"
"})}if(0==n.length)return}else{if(t=t.replace(/(<([^>]+)>)/g,"").replace(/(\[([^\]]+)\])/g,""),n=t.match_urls(),!n)return;n=n.array_unique(),n=$.map(n,function(e,t){return{uid:t,name:e,url:e}})}if($.isEmptyObject(this.files))for(r=0;r0){var i=[];for(var o in this.results.error)"object"==typeof this.results.error[o]&&(i[o]=this.results.error[o].error.message);i.length>0&&$(this.selectors.failed_result).html("
"+i.join("
")+"
")}else $(a.error,this.selectors.root).hide();if(!window.opener&&CHV.obj.config.upload.redirect_single_upload&&1==Object.size(this.results.success)&&0==Object.size(this.results.error))return window.location.href=this.results.success[0].image.url_viewer,!1;if($("[data-text=queue-progress]",this.selectors.root).text(100),$("[data-group=uploading]",this.selectors.root).hide(),$(this.selectors.root).removeClass("queueUploading queueHasResults").addClass("queueCompleted"),$(this.selectors.queue).addClass(this.selectors.queue_complete.substring(1)),Object.size(this.results.success)>0&&$("[data-group=upload-result] textarea",this.selectors.root).exists()&&CHV.fn.fillEmbedCodes(this.results.success,CHV.fn.uploader.selectors.root,"val"),Object.size(this.results.success)>0&&Object.size(this.results.error)>0?$(a.mixed+", "+a.success,this.selectors.root).show():Object.size(this.results.success)>0?$(a.success,this.selectors.root).show():Object.size(this.results.error)>0&&$(a.error,this.selectors.root).show(),$(a.success,this.selectors.root).is(":visible")){$(a.success,this.selectors.root).find("[data-group^=user], [data-group=guest]").hide(),$(a.success,this.selectors.root).find("[data-group="+(PF.fn.is_user_logged()?"user":"guest")+"]").show();var n=Object.keys(this.results.success)[0];if(void 0!==this.results.success[n].image.album){var s=[];for(var r in this.results.success){var l=this.results.success[r].image;l.album&&l.album.id_encoded&&-1==s.indexOf(l.album.id_encoded)&&s.push(l.album.id_encoded)}var d={link:null,text:null};if(s.length<=1?(d.link=this.results.success[n].image.album.url,d.text=this.results.success[n].image.album.name):(d.link=this.results.success[n].image.user.url_albums,d.text=PF.fn._s("%s's Albums",this.results.success[n].image.user.name_short_html)),$("[data-text=upload-target]",this.selectors.root).text(d.text),$("[data-link=upload-target]",this.selectors.root).attr("href",d.link),PF.fn.is_user_logged()){var c=s.length>0?"album":"stream";$("[data-group=user-"+c+"]",this.selectors.root).show()}}}if(this.boxSizer(),this.queueStatus="done",window.opener&&void 0!==CHV.obj.opener.uploadPlugin[window.name]){if($('[data-action="copy"]',this.selectors.root).remove(),CHV.obj.opener.uploadPlugin[window.name].hasOwnProperty("autoInsert")&&CHV.obj.opener.uploadPlugin[window.name].autoInsert){var u=$(':input[name="'+CHV.obj.opener.uploadPlugin[window.name].autoInsert+'"]',CHV.fn.uploader.selectors.root),m=u.val();if(m)return window.opener.postMessage({id:window.name,message:m},"*"),void window.close()}}else $('[data-action="openerPostMessage"]',this.selectors.root).remove()}},$.extend(CHV.fn.uploader,$.extend(!0,{},CHV.obj.uploaderReset)),CHV.fn.fillEmbedCodes=function(e,t,a){void 0===a&&(a="val"),$.each(e,function(e,o){if(void 0!==o){var i="id_encoded"in o?o:o.image;if(!i.medium){i.medium={};for(var n=["filename","name","width","height","extension","size","size_formatted","url"],s=0;s0&&$.each(CHV.obj.categories,function(o,i){return void 0!==e&&i.id==e||(i.url_key==$("[name=form-category-url_key]",t).val()?(a=!0,!1):void 0)}),!a||(PF.fn.growl.call(PF.fn._s("Category URL key already being used.")),$("[name=form-category-url_key]",t).highlight(),!1)))},edit:{before:function(e){var t=$(e.target),a=t.data("category-id"),o=CHV.obj.categories[a],i="[data-modal="+t.data("target")+"]";$.each(CHV.fn.category.formFields,function(e,t){e="form-category-"+t,t=o[t];var a=$("[name="+e+"]",i);a.is("textarea")?a.html(PF.fn.htmlEncode(t)):a.attr("value",t)})},submit:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-category-id]",e).val();return!!CHV.fn.category.validateForm(t)&&(PF.obj.modal.form_data={action:"edit",edit:"category",editing:{}},$.each(CHV.fn.category.formFields,function(t,a){PF.obj.modal.form_data.editing[a]=$("[name=form-category-"+a+"]",e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.category,a="[data-content=category][data-category-id="+t.id+"]";$.each(t,function(e,t){$("[data-content=category-"+e+"]",a).html(PF.fn.htmlEncode(t))}),$("[data-link=category-url]").attr("href",t.url),CHV.obj.categories[t.id]=t}}},delete:{before:function(e){var t=$(e.target),a=t.data("category-id"),o=CHV.obj.categories[a];t.attr("data-confirm",t.attr("data-confirm").replace("%s",'"'+o.name+'"'))},submit:function(e){return PF.obj.modal.form_data={action:"delete",delete:"category",deleting:{id:e}},!0},complete:{success:function(e){PF.fn.growl.expirable(PF.fn._s("Category successfully deleted."));var t=e.responseJSON.request.deleting.id;$("[data-content=category][data-category-id="+t+"]").remove(),delete CHV.obj.categories[t]}}},add:{submit:function(){var e=PF.obj.modal.selectors.root;return!!CHV.fn.category.validateForm()&&(PF.obj.modal.form_data={action:"add-category",category:{}},$.each(CHV.fn.category.formFields,function(t,a){"id"!=a&&(PF.obj.modal.form_data.category[a]=$("[name=form-category-"+a+"]",e).val())}),!0)},complete:{success:function(e){var t=e.responseJSON.category,a="[data-content=dashboard-categories-list]",o=$("[data-content=category-dashboard-template]").html();$.each(t,function(e,t){o=o.replace(new RegExp("%"+e.toUpperCase()+"%","g"),t||"")}),$(a).append(o),0==Object.size(CHV.obj.categories)&&(CHV.obj.categories={}),CHV.obj.categories[t.id]=t,PF.fn.growl.call(PF.fn._s("Category %s added.",'"'+t.name+'"'))}}}},CHV.fn.ip_ban={formFields:["id","ip","expires","message"],validateForm:function(e){var t=PF.obj.modal.selectors.root,a=!1,o=$("[name=form-ip_ban-ip]",t).val();return!!CHV.fn.common.validateForm(t)&&(""!==$("[name=form-ip_ban-expires]",t).val()&&0==/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test($("[name=form-ip_ban-expires]",t).val())?(PF.fn.growl.call(PF.fn._s("Invalid expiration date.")),$("[name=form-ip_ban-expires]",t).highlight(),!1):(Object.size(CHV.obj.ip_bans)>0&&$.each(CHV.obj.ip_bans,function(t,i){return void 0!==e&&i.id==e||(i.ip==o?(a=!0,!1):void 0)}),!a||(PF.fn.growl.call(PF.fn._s("IP %s already banned.",o)),$("[name=form-ip_ban-ip]",t).highlight(),!1)))},add:{submit:function(){var e=PF.obj.modal.selectors.root;return!!CHV.fn.ip_ban.validateForm()&&(PF.obj.modal.form_data={action:"add-ip_ban",ip_ban:{}},$.each(CHV.fn.ip_ban.formFields,function(t,a){"id"!=a&&(PF.obj.modal.form_data.ip_ban[a]=$("[name=form-ip_ban-"+a+"]",e).val())}),!0)},complete:{success:function(e){var t=e.responseJSON.ip_ban,a="[data-content=dashboard-ip_bans-list]",o=$("[data-content=ip_ban-dashboard-template]").html();void 0!==o&&($.each(t,function(e,t){o=o.replace(new RegExp("%"+e.toUpperCase()+"%","g"),t||"")}),$(a).append(o)),0==Object.size(CHV.obj.ip_bans)&&(CHV.obj.ip_bans={}),CHV.obj.ip_bans[t.id]=t,$("[data-content=ban_ip]").hide(),$("[data-content=banned_ip]").show(),PF.fn.growl.call(PF.fn._s("IP %s banned.",t.ip))},error:function(e){var t=e.responseJSON.error;PF.fn.growl.call(PF.fn._s(t.message))}}},edit:{before:function(e){var t=$(e.target),a=t.data("ip_ban-id"),o=CHV.obj.ip_bans[a],i="[data-modal="+t.data("target")+"]";$.each(CHV.fn.ip_ban.formFields,function(e,t){e="form-ip_ban-"+t,t=o[t];var a=$("[name="+e+"]",i);a.is("textarea")?a.html(PF.fn.htmlEncode(t)):a.attr("value",t)})},submit:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-ip_ban-id]",e).val();return!!CHV.fn.ip_ban.validateForm(t)&&(PF.obj.modal.form_data={action:"edit",edit:"ip_ban",editing:{}},$.each(CHV.fn.ip_ban.formFields,function(t,a){PF.obj.modal.form_data.editing[a]=$("[name=form-ip_ban-"+a+"]",e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.ip_ban,a="[data-content=ip_ban][data-ip_ban-id="+t.id+"]";$.each(t,function(e,t){$("[data-content=ip_ban-"+e+"]",a).html(PF.fn.htmlEncode(t))}),CHV.obj.ip_bans[t.id]=t},error:function(e){var t=e.responseJSON.error;PF.fn.growl.call(PF.fn._s(t.message))}}},delete:{before:function(e){var t=$(e.target),a=t.data("ip_ban-id"),o=CHV.obj.ip_bans[a];t.attr("data-confirm",t.attr("data-confirm").replace("%s",o.ip))},submit:function(e){return PF.obj.modal.form_data={action:"delete",delete:"ip_ban",deleting:{id:e}},!0},complete:{success:function(e){PF.fn.growl.expirable(PF.fn._s("IP ban successfully deleted."));var t=e.responseJSON.request.deleting.id;$("[data-content=ip_ban][data-ip_ban-id="+t+"]").remove(),delete CHV.obj.ip_bans[t]}}}},CHV.fn.storage={formFields:["id","name","api_id","bucket","server","service","capacity","region","key","secret","url","account_id","account_name"],calling:!1,validateForm:function(){var e=PF.obj.modal.selectors.root,t=$("[name=form-storage-id]",e).val(),a=!0;if($.each($(":input",e),function(e,t){$(this).is(":hidden")?$(this).attr("required")&&$(this).removeAttr("required").attr("data-required",1):1==$(this).attr("data-required")&&$(this).attr("required","required"),$(this).is(":visible")&&""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),a=!1)}),!a)return PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1;var o,i=$("[name=form-storage-capacity]",e),n=i.val();return""!==n&&(0==/^[\d\.]+\s*[A-Za-z]{2}$/.test(n)||void 0===n.getBytes()?o=PF.fn._s("Invalid storage capacity value. Make sure to use a valid format."):void 0!==CHV.obj.storages[t]&&n.getBytes()0&&(t=t.formatBytes(2)),r.attr("value",t))}),$("[data-combo-value]").addClass("soft-hidden"),$(n).removeClass("soft-hidden")},submit:function(){var e=PF.obj.modal.selectors.root;$("[name=form-storage-id]",e).val();return!!CHV.fn.storage.validateForm()&&(PF.obj.modal.form_data={action:"edit",edit:"storage",editing:{}},$.each(CHV.fn.storage.formFields,function(t,a){var o;o="[name=form-storage-"+a+"]","hidden"!==$(o,e).attr("type")&&(o+=":visible"),PF.obj.modal.form_data.editing[a]=$(o,e).val()}),!0)},complete:{success:function(e){var t=e.responseJSON.storage,a="[data-content=storage][data-storage-id="+t.id+"]",o=$("[data-action=toggle-storage-https]",a);$.each(t,function(e,t){$("[data-content=storage-"+e+"]",a).html(PF.fn.htmlEncode(t))}),CHV.obj.storages[t.id]=t,CHV.fn.storage.toggleBoolDisplay(o,1==t.is_https),CHV.fn.queuePixel()},error:function(e){var t=e.responseJSON,a=t.error.message;PF.fn.growl.call(a)}}},add:{submit:function(){if(!CHV.fn.storage.validateForm())return!1;var e=PF.obj.modal.selectors.root;return PF.obj.modal.form_data={action:"add-storage",storage:{}},$.each(CHV.fn.storage.formFields,function(t,a){var o;"id"!=a&&(o="[name=form-storage-"+a+"]","hidden"!==$(o,e).attr("type")&&(o+=":visible"),PF.obj.modal.form_data.storage[a]=$(o,e).val())}),!0},complete:{success:function(e){var t=e.responseJSON.storage,a="[data-content=dashboard-storages-list]",o=$("[data-content=storage-dashboard-template]").html();$.each(t,function(e,t){var a=e.toUpperCase();if("is_https"==e||"is_active"==e)t=CHV.obj.storageTemplate.icon.replace("%TITLE%",CHV.obj.storageTemplate.messages[e]).replace("%ICON%",CHV.obj.storageTemplate.checkboxes[t]).replace("%PROP%",e.replace("is_",""));o=o.replace(new RegExp("%"+a+"%","g"),t||"")}),$(a).append(o),PF.fn.bindtipTip($("[data-storage-id="+t.id+"]")),0==CHV.obj.storages.length&&(CHV.obj.storages={}),CHV.obj.storages[t.id]=t,CHV.fn.queuePixel()},error:function(e){var t=e.responseJSON,a=t.error.message;PF.fn.growl.call(a)}}},toggleBoolDisplay:function(e,t){var a={0:e.data("unchecked-icon"),1:e.data("checked-icon")};e.removeClass(a[0]+" "+a[1]).addClass(a[t?1:0])}},CHV.fn.common={validateForm:function(e){if(void 0===e)e=PF.obj.modal.selectors.root;var t=!0;return $.each($(":input:visible",e),function(e,a){""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),t=!1)}),!!t||(PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1)},updateDoctitle:function(e){void 0!==CHV.obj.page_info&&(CHV.obj.page_info.pre_doctitle=e,CHV.obj.page_info.doctitle=CHV.obj.page_info.pre_doctitle+CHV.obj.page_info.pos_doctitle,document.title=CHV.obj.page_info.doctitle)}},CHV.fn.user={add:{submit:function(){var e=$(PF.obj.modal.selectors.root),t=!0;return $.each($(":input",e),function(e,a){""==$(this).val()&&$(this).attr("required")&&($(this).highlight(),t=!1)}),t?(PF.obj.modal.form_data={action:"add-user",user:{username:$("[name=form-username]",e).val(),email:$("[name=form-email]",e).val(),password:$("[name=form-password]",e).val(),role:$("[name=form-role]",e).val()}},!0):(PF.fn.growl.call(PF.fn._s("Please fill all the required fields.")),!1)},complete:{success:function(e){e.responseJSON;PF.fn.growl.expirable(PF.fn._s("User added successfully."))},error:function(e){var t=e.responseJSON;PF.fn.growl.call(PF.fn._s(t.error.message))}}},delete:{submit:function(){return PF.obj.modal.form_data={action:"delete",delete:"user",owner:CHV.obj.resource.user.id,deleting:CHV.obj.resource.user},!0}}},CHV.fn.submit_resource_delete=function(){return PF.obj.modal.form_data={action:"delete",delete:CHV.obj.resource.type,from:"resource",owner:void 0!==CHV.obj.resource.user?CHV.obj.resource.user.id:null,deleting:CHV.obj.resource},!0},CHV.fn.complete_resource_delete={success:function(e){e.responseJSON;$("body").fadeOut("normal",function(){var e;e="album"==CHV.obj.resource.type||"image"==CHV.obj.resource.type?CHV.obj.resource.parent_url:CHV.obj.resource.user?CHV.obj.resource.user.url:CHV.obj.resource.url,void 0!==e&&(window.location=e+"?deleted")})}},CHV.fn.list_editor={selectionCount:function(){var e=$(PF.obj.listing.selectors.content_listing);e.each(function(){var t=$("[data-content=pop-selection]","[data-content=list-selection][data-tab="+$(this).attr("id")+"]"),a=$(PF.obj.listing.selectors.list_item+".selected",this).length;if(all_count=$(PF.obj.listing.selectors.list_item,this).length,t[a>0?"removeClass":"addClass"]("disabled"),$("[data-text=selection-count]",t).text(a>0?a:""),"images"==e.data("list")&&a>0){var o=$(PF.obj.listing.selectors.list_item+".selected[data-flag=safe]",this).length>0,i=$(PF.obj.listing.selectors.list_item+".selected[data-flag=unsafe]",this).length>0;$("[data-action=flag-safe]",t)[(i?"remove":"add")+"Class"]("hidden"),$("[data-action=flag-unsafe]",t)[(o?"remove":"add")+"Class"]("hidden")}$(this).is(":visible")&&CHV.fn.list_editor.listMassActionSet(all_count==a?"clear":"select")})},removeFromList:function(e,t){if(void 0!==e){e=e instanceof jQuery==0?$(e):e;var a=$(PF.obj.listing.selectors.content_listing_visible),o=e.length;e.fadeOut("fast");var i=e.first().data("type"),n=parseInt($("[data-text="+i+"-count]").text())-o;CHV.fn.list_editor.updateUserCounters(e.first().data("type"),o,"-"),e.promise().done(function(){$(document).removeClass(CHV.fn.listingViewer.selectors.bodyShown.substr(1));var i={};if(e.each(function(){$("[data-id="+$(this).data("id")+"]").each(function(){var e=$(this).closest(PF.obj.listing.selectors.content_listing).attr("id");i[e]||(i[e]=0),i[e]+=1})}),1==o?$("[data-id="+$(this).data("id")+"]").remove():e.each(function(){$("[data-id="+$(this).data("id")+"]").remove()}),PF.fn.listing.columnizerQueue(),PF.fn.listing.refresh(),CHV.fn.list_editor.selectionCount(),void 0!==t&&"string"==typeof t&&PF.fn.growl.expirable(t),$(PF.obj.listing.selectors.content_listing_pagination,a).exists()||0!=$(".list-item",a).length||(n=0),0==n)a.html(PF.obj.listing.template.empty),$(PF.obj.listing.selectors.content_listing+":not("+PF.obj.listing.selectors.content_listing_visible+")").data({empty:null,load:"ajax"}),$("[data-content=list-selection][data-tab="+a.attr("id")+"]").addClass("disabled");else if(0==$(PF.obj.listing.selectors.list_item,a).length){if($(PF.obj.listing.selectors.pad_content).height(0),$("[data-action=load-more]",a).exists())return $(PF.obj.listing.selectors.content_listing_visible).data("page",0),$("[data-action=load-more]",a).click(),void(PF.obj.listing.recolumnize=!0);var s=$("[data-pagination=next]",a);if(s.exists()){var r=s.attr("href"),l=PF.fn.deparam(r);return"page"in l&&l.page>1&&(r=r.changeURLParameterValue("page",l.page-1)),void(window.location=r)}}})}},deleteFromList:function(e){if(void 0===t)var t=!0;e=e instanceof jQuery==0?$(e):e;this.removeFromList(e,t?PF.fn._s("The content has been deleted."):null)},moveFromList:function(e,t){if(void 0===t)t=!0;e=e instanceof jQuery==0?$(e):e;this.removeFromList(e,t?PF.fn._s("The content has been moved."):null)},toggleSelectItem:function(e,t){if("boolean"!=typeof t)t=!0;var a,o,i,n=$(".viewer").is(":visible")?$("[data-type=image][data-id="+e.attr("data-id")+"]"):e,s=$("[data-action=select] .btn-icon",n);t?(n.addClass("selected"),a=s.data("icon-selected"),o=s.data("icon-unselected"),i=PF.fn._s("Unselect")):(n.removeClass("selected"),a=s.data("icon-unselected"),o=s.data("icon-selected"),i=PF.fn._s("Select")),s.removeClass(o).addClass(a),$("[data-action=select] .label",n).text(i),CHV.fn.list_editor.selectionCount()},selectItem:function(e){this.toggleSelectItem(e,!0)},unselectItem:function(e){this.toggleSelectItem(e,!1)},clearSelection:function(e){var t=$(PF.obj.listing.selectors.list_item+".selected",PF.obj.listing.selectors[e?"content_listing":"content_listing_visible"]);this.unselectItem(t),this.listMassActionSet("select")},listMassActionSet:function(e){var t="select"==e?"clear":"select",a=$("[data-action=list-"+t+"-all]:visible"),o=a.data("text-"+e+"-all");a.text(o).attr("data-action","list-"+e+"-all")},updateItem:function(e,t,a,o){if(e instanceof jQuery==0)e=$(e);var i=e.data("type"),n="image"==i?t.album:t;if(console.log(e,n,i),this.addAlbumtoModals(n),$("option[value="+n.id_encoded+"]","[name=form-album-id]").html(PF.fn.htmlEncode(n.name_with_privacy_readable_html)),void 0===a)a="edit";if("edit"==a||"move"==a){if("move"==a&&"album"==CHV.obj.resource.type)return void CHV.fn.list_editor.moveFromList(e,o);e.attr("data-description",t.description),"image"==i?(void 0!==t.title&&(e.attr("data-title",t.title),e.find("[title]").attr("title",t.title),$("[data-text=image-title]",e).html(PF.fn.htmlEncode(t.title))),void 0!==t.title_truncated&&$("[data-text=image-title-truncated]",e).html(PF.fn.htmlEncode(t.title_truncated)),void 0!==t.category_id&&e.attr("data-category-id",t.category_id),e.attr({"data-album-id":n.id_encoded,"data-flag":1==t.nsfw?"unsafe":"safe"}),$("[data-content=album-link]",e).attr("href",n.url)):e.attr({"data-privacy":n.privacy,"data-password":n.password,"data-name":n.name}),e.attr("data-privacy",n.privacy),$("[data-text=album-name]",e).html(PF.fn.htmlEncode(n.name)),PF.fn.growl.expirable("edit"==a?PF.fn._s("The content has been edited."):PF.fn._s("The content has been moved."))}},addAlbumtoModals:function(e){var t=!1;$("[name=form-album-id]","[data-modal]").each(function(){e.id_encoded&&!$("option[value="+e.id_encoded+"]",this).exists()&&($(this).append('"),t=!0)}),t&&CHV.fn.list_editor.updateUserCounters("album",1,"+")},updateAlbum:function(e){$("[data-id="+e.id_encoded+"]").each(function(){""!==e.html&&($(this).after(e.html),$(this).remove())})},updateUserCounters:function(e,t,a){if(void 0===a)a="+";var o,i,n=$("[data-text="+e+"-count]"),s=$("[data-text="+e+"-label]"),r=(t=parseInt(t),parseInt(n.html()));switch(a){case"+":o=r+t;break;case"-":o=r-t;break;case"=":o=t}i=o-r;var l=$("[data-text=total-"+n.data("text")+"]"),d=$("[data-text="+l.data("text")+"-label]"),c=parseInt(l.html()),u=c+i;n.text(o),l.text(u),s.text(s.data(1==o?"label-single":"label-plural")),d.text(s.data(1==u?"label-single":"label-plural"))},updateMoveItemLists:function(e,t,a){if(CHV.fn.list_editor.clearSelection(),/image/.test(t))"image"==t?CHV.fn.list_editor.updateItem("[data-type=image][data-id="+a.data("id")+"]",e.image,"move"):(a.each(function(){CHV.fn.list_editor.updateItem("[data-type=image][data-id="+$(this).data("id")+"]",e,"move",!1)}),PF.fn.growl.expirable(PF.fn._s("The content has been moved.")));else{if("album"==CHV.obj.resource.type?CHV.fn.list_editor.moveFromList(a):PF.fn.growl.expirable(PF.fn._s("The content has been moved.")),void 0!==e.albums_old)for(var o=0;o';$("body").append(e)};
\ No newline at end of file
diff --git a/app/lib/classes/class.image.php b/app/lib/classes/class.image.php
index 8cc5d27..b9fcc18 100644
--- a/app/lib/classes/class.image.php
+++ b/app/lib/classes/class.image.php
@@ -664,32 +664,6 @@ class Image
throw new Exception(_s('Duplicated upload'), 101);
}
- $get_active_storages = Storage::getAll(['is_active' => 1]); // Get all active storages
-
- if ($get_active_storages) {
- // Sequential storage thing
- $sequential_storage = count($get_active_storages) > 1;
- if ($sequential_storage) {
- $storage_id = null;
- $last_used_storage = getSetting('last_used_storage');
- } else {
- $storage_id = $get_active_storages[0]['id'];
- }
-
- $active_storages = [];
- for ($i = 0; $i < count($get_active_storages); $i++) {
- $storage_pointer = $get_active_storages[$i]['id']; // id
- $active_storages[$storage_pointer] = $get_active_storages[$i]; // key fixed array
-
- if (is_null($storage_id) && $last_used_storage == $storage_pointer) {
- $storage_id = $get_active_storages[$i + 1]['id'] ?: $get_active_storages[0]['id'];
- }
- }
-
- // Set the storage array
- $storage = $active_storages[$storage_id];
- }
-
$storage_mode = getSetting('upload_storage_mode');
switch ($storage_mode) {
case 'direct':
diff --git a/app/lib/classes/class.queue.php b/app/lib/classes/class.queue.php
deleted file mode 100644
index 90245d9..0000000
--- a/app/lib/classes/class.queue.php
+++ /dev/null
@@ -1,279 +0,0 @@
-
-
-
- Copyright (C) Rodolfo Berrios A. All rights reserved.
-
- BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA
- http://chevereto.com/license
-
- --------------------------------------------------------------------- */
-
-namespace CHV;
-
-use G;
-use Exception;
-
-class Queue
-{
- public static $max_execution_time;
-
- public static function insert($values)
- {
- try {
- $values = array_merge([
- 'date_gmt' => G\datetimegmt(),
- 'status' => 'pending'
- ], $values);
- DB::insert('queues', $values);
- } catch (Exception $e) {
- throw new QueueException($e->getMessage(), $e->getCode());
- }
- }
-
- public static function process($args)
- {
- try {
- @set_time_limit(180); // Don't run forever
- self::$max_execution_time = ini_get('max_execution_time'); // Store the limit
-
- $args = array_merge(['pixel' => true, $type => null], $args);
-
- if ($args['pixel']) {
- error_reporting(0); // Silence when embeding an image
- }
-
- // Get 250 entries (casual limit)
- $queues_db = DB::get(['table' => 'queues', 'join' => 'LEFT JOIN ' . DB::getTable('storages') . ' ON ' . DB::getTable('queues') .'.queue_join = '. DB::getTable('storages') . '.storage_id'], ['type' => $args['type'], 'status' => 'pending'], 'AND', null, 250);
- $queues = [];
-
- foreach ($queues_db as $k => $v) {
- $queue_item = DB::formatRow($v);
- $queue_item['args'] = json_decode($queue_item['args'], true);
- // Group the things by storage
- if (!array_key_exists($queue_item['storage']['id'], $queues)) {
- $queues[$queue_item['storage']['id']] = ['storage' => $queue_item['storage'], 'files' => []];
- }
- $queues[$queue_item['storage']['id']]['files'][] = G\array_filter_array($queue_item, ['id', 'args'], 'exclusion');
- }
-
- foreach ($queues as $k => $storage_queue) {
-
- // Break the thing if its close to the time limit
- if (!self::canKeepGoing()) {
- break;
- }
-
- $storage = $storage_queue['storage'];
- $storage_files = $storage_queue['files'];
- $storage['api_type'] = Storage::getApiType($storage['api_id']);
-
- $files = [];
- $storage_keys = [];
- $deleted_queue_ids = [];
- $disk_space_freed = 0;
- $disk_space_used = 0;
-
- // Localize the array 'key'
- foreach ($storage_files as $k => $v) {
- $files[$v['args']['key']] = array_merge($v['args'], ['id' => $v['id']]);
- switch ($storage['api_type']) {
- case 's3':
- case 's3compatible':
- $storage_keys[] = ['Key' => $v['args']['key']];
- break;
- case 'azure':
- case 'b2':
- case 'oss':
- case 'gcloud':
- case 'ftp':
- case 'sftp':
- case 'local':
- $storage_keys[] = $v['args']['key'];
- break;
- case 'openstack':
- $storage_keys[] = $storage['bucket'] . '/' . $v['args']['key'];
- break;
- }
- unset($files[$k]);
- $disk_space_used += $v['args']['size'];
- $deleted_queue_ids[] = $v['id']; // Generate the queue_id stock
- }
-
- // Invoke the target storage API
- try {
- $StorageAPI = Storage::requireAPI($storage);
- } catch (Exception $e) {
- self::logAttempt($deleted_queue_ids);
- error_log($e);
- $error = true;
- break;
- }
-
- switch ($storage['api_type']) {
-
- case 's3':
- case 's3compatible':
- try {
- $deleteFromStorage = $StorageAPI->deleteObjects([
- 'Bucket' => $storage['bucket'],
- 'Delete' => [
- 'Objects' => $storage_keys
- ]
- ]);
- } catch (Exception $e) {
- error_log($e);
- $error = true;
- break;
- }
- $deleted_queue_ids = []; // Just in case
- foreach ($deleteFromStorage['Deleted'] as $k => $v) {
- $disk_space_freed += $files[$v['Key']]['size'];
- $deleted_queue_ids[] = $files[$v['Key']]['id'];
- }
- // error_log(var_export($disk_space_freed, true));
- // error_log(var_export($deleted_queue_ids, true));
- break;
-
- case 'openstack':
- try {
- $deleteFromStorage = $StorageAPI->batchDelete($storage_keys);
- } catch (Exception $e) {
- error_log($e);
- $error = true;
- break;
- }
- break;
-
- case 'oss':
- try {
- $deleteFromStorage = $StorageAPI->deleteObjects($storage['bucket'], $storage_keys);
- } catch (\OSS\Core\OSSException $e) {
- error_log($e);
- $error = true;
- break;
- }
-
- $deleted_queue_ids = []; // Just in case
- foreach ($deleteFromStorage as $k => $v) {
- $deleteKey = G\xml2array($v)[0];
- $disk_space_freed += $files[$deleteKey]['size'];
- $deleted_queue_ids[] = $files[$deleteKey]['id'];
- }
- break;
-
- // AKA single object APIs (no multiple or batch delete
- case 'azure':
- case 'b2':
- case 'gcloud':
- case 'ftp':
- foreach ($files as $k => $v) { // No batch operation here
- if (!self::canKeepGoing()) { // Time safe
- break;
- }
- try {
- switch ($storage['api_type']) {
- case 'azure':
- $StorageAPI->deleteBlob($storage['bucket'], $v['key']);
- break;
- case 'b2':
- $StorageAPI->deleteFile([
- 'BucketName' => $storage['bucket'],
- 'FileName' => $v['key']
- ]);
- break;
- case 'gcloud':
- $StorageAPI->objects->delete($storage['bucket'], $v['key']);
- break;
- case 'ftp':
- $StorageAPI->delete($v['key']);
- break;
- }
- $deleted_queue_ids[] = $v['id'];
- $disk_space_freed += $v['size'];
- } catch (Exception $e) {
- error_log($e->getCode() . ' - ' . $e->getMessage());
- }
- }
- if ($storage['api_type'] == 'ftp') {
- $StorageAPI->close(); // Close FTP
- }
- break;
-
- case 'sftp':
- // This thing uses direct rm command (wow, such raw)
- $StorageAPI->deleteMultiple($storage_keys);
- $disk_space_freed = $disk_space_used;
- $StorageAPI->close(); // Close SFTP
- break;
-
- case 'local':
- $StorageAPI->deleteMultiple($storage_keys);
- $deleted_queue_ids = []; // All over again
- foreach ($StorageAPI->deleted as $k => $v) {
- $disk_space_freed += $files[$v]['size'];
- $deleted_queue_ids[] = $files[$v]['id'];
- }
- break;
- }
-
- self::logAttempt($deleted_queue_ids);
-
- if (!$error) {
- DB::increment('storages', ['space_used' => '-' . $disk_space_freed], ['id' => $storage['id']]);
- self::delete($deleted_queue_ids);
- }
- }
- } catch (Exception $e) {
- if ($args['pixel']) {
- error_log($e);
- } else {
- throw new QueueException($e);
- }
- }
- }
-
- public static function delete($ids)
- {
- try {
- if (is_array($ids) && count($ids) > 0) {
- $db = DB::getInstance();
- $db->query('DELETE from ' . DB::getTable('queues') . ' WHERE queue_id IN (' . implode(',', $ids) . ')');
- return $db->exec() ? $db->rowCount() : false;
- } else {
- return DB::delete('queues', ['id' => $ids]) ? 1 : false;
- }
- } catch (Exception $e) {
- throw new QueueException($e);
- }
- }
-
- public static function logAttempt($ids)
- {
- try {
- if (!is_array($ids)) {
- $ids = [$ids];
- }
- $db = DB::getInstance();
- $db->query('UPDATE ' . DB::getTable('queues') . ' SET queue_attempts = queue_attempts + 1, queue_status = IF(queue_attempts > 3, "failed", "pending") WHERE queue_id IN (' . implode(',', $ids) . ')');
- $db->exec();
- } catch (Exception $e) {
- throw new QueueException($e);
- }
- }
-
- public static function canKeepGoing()
- {
- return isSafeToExecute(self::$max_execution_time);
- }
-}
-
-class QueueException extends Exception
-{
-}
diff --git a/app/lib/classes/class.settings.php b/app/lib/classes/class.settings.php
index 7ce2485..4848bd4 100644
--- a/app/lib/classes/class.settings.php
+++ b/app/lib/classes/class.settings.php
@@ -393,19 +393,29 @@ class Settings
$api = 'https://chevereto.com/api/';
include_once G_APP_PATH . 'license/key.php';
$id = explode(':', $license)[0];
+ $info = $api . 'get/info/';
+ if (!defined('G_APP_GITHUB_REPO_URL')) {
+ $info .= '?id=' . $id;
+ $label = 'chevereto.com/panel/downloads';
+ $url = 'https://chevereto.com/panel/downloads';
+ } else {
+ $info .= 'free';
+ $label = G_APP_GITHUB_OWNER . '/' . G_APP_GITHUB_REPO;
+ $url = G_APP_GITHUB_REPO_URL;
+ }
return [
'id' => $id,
'edition' => G_APP_NAME,
'version' => G_APP_VERSION,
'source' => [
- 'label' => !defined('G_APP_GITHUB_REPO_URL') ? 'Chevereto.com/panel/downloads' : (G_APP_GITHUB_OWNER . '/' . G_APP_GITHUB_REPO),
- 'url' => !defined('G_APP_GITHUB_REPO_URL') ? 'https://chevereto.com/panel/downloads' : G_APP_GITHUB_REPO_URL,
+ 'label' => $label,
+ 'url' => $url,
],
'api' => [
'download' => $api . 'download',
'get' => [
- 'info' => ($api . 'get/info/?id=' . $id) . (defined('G_APP_GITHUB_REPO_URL') ? '/free' : null),
+ 'info' => $info,
],
],
];
diff --git a/app/lib/classes/class.upload.php b/app/lib/classes/class.upload.php
index 912c124..2eb82a7 100644
--- a/app/lib/classes/class.upload.php
+++ b/app/lib/classes/class.upload.php
@@ -151,16 +151,7 @@ class Upload
}
}
- /*
- * Set uploaded_file
- * Local storage uploads will be allocated at the target destination
- * External storage will be allocated to the temp directory
- */
- if ($this->storage_id) {
- $this->uploaded_file = G\forward_slash(dirname($this->downstream)) . '/' . Storage::getStorageValidFilename($this->fixed_filename, $this->storage_id, $this->options['filenaming'], $this->destination);
- } else {
- $this->uploaded_file = G\name_unique_file($this->destination, $this->options['filenaming'], $this->fixed_filename);
- }
+ $this->uploaded_file = G\name_unique_file($this->destination, $this->options['filenaming'], $this->fixed_filename);
$this->source = [
'filename' => $this->source_filename, // file.ext
diff --git a/app/license/key.php b/app/license/key.php
index 6d9181c..75a5391 100644
--- a/app/license/key.php
+++ b/app/license/key.php
@@ -1,37 +1,3 @@
[
'label' => _s('PHP version'),
- 'content' => PHP_VERSION . ' �' . php_ini_loaded_file()
+ 'content' => PHP_VERSION . ' 🐘 '. php_ini_loaded_file()
],
'server' => [
'label' => _s('Server'),
@@ -188,14 +188,11 @@ $route = function ($handler) {
$chevereto_urls = [
'Chevereto' => 'https://chevereto.com',
_s('Community') => 'https://chevereto.com/community/',
- _s('Collaboration') => 'https://chevereto.com/community/collaboration/',
_s('Support') => 'https://chevereto.com/support',
- _s('Documentation') => 'https://chevereto.com/docs',
+ _s('Documentation') => 'https://v3-docs.chevereto.com/',
_s('Changelog') => 'https://chevereto.com/changelog',
_s('Bug tracking') => 'https://chevereto.com/bug-tracking',
- 'Trello' => 'https://chevereto.com/go/trello',
- 'Discord' => 'https://chevereto.com/go/discord',
- 'GitHub' => 'https://github.com/Chevereto',
+ 'GitHub' => 'https://github.com/chevereto',
];
$chevereto_links = [];
foreach ($chevereto_urls as $k => $v) {
diff --git a/app/themes/Peafowl/footer.php b/app/themes/Peafowl/footer.php
index 0893579..85bce37 100644
--- a/app/themes/Peafowl/footer.php
+++ b/app/themes/Peafowl/footer.php
@@ -24,5 +24,43 @@ if (is_upload_allowed() && (CHV\getSetting('upload_gui') == 'js' || G\is_route('
+
+
+
+
+
+ Upgrade to premium
+
💎👏💖
+
Upgrading to paid Chevereto allows you to enjoy more features like multiple external storage servers, bulk content importer, manage banners, content likes, user followers, social login signup and more. It also comes with support in case you need help.
+
👍🏾 Keep in mind that Chevereto is made by a single developer. Your purchase helps to sustain ongoing development of this software.
+
You can upgrade now by pasting your license key. If you don't have one you can buy it now with PayPal, AliPay, UnionPay and cryptocurrency.