1
|
function WMP_EDIT_IMAGES(){var JSObject=this;this.type="wmp_editimages",this.form,this.DOMDoc,this.send_btn,this.deletingIcon=!1,this.deletingLogo=!1,this.init=function(){WMPJSInterface=window.parent.WMPJSInterface,this.send_btn=jQuery("#"+this.type+"_send_btn",this.DOMDoc).get(0),this.form=this.DOMDoc.getElementById(this.type+"_form"),this.addButtonsActions(),null!=this.form&&this.initValidation()},this.initValidation=function(){this.validator=jQuery("#"+this.form.id,this.DOMDoc).validate({rules:{wmp_editimages_icon:{accept:"png|jpg|jpeg|gif"},wmp_editimages_logo:{accept:"png"}},messages:{wmp_editimages_icon:{accept:"Please add a png, gif or jpeg image."},wmp_editimages_logo:{accept:"Please add a png image format with a transparent background."}},errorPlacement:function(e,t){var o=t[0].id.split("_"),c=o.length>1?o[o.length-1]:o[0],n=jQuery("#error_"+c+"_container",JSObject.DOMDoc);e.appendTo(n)},errorElement:"span"});var $Icon=jQuery("#"+this.type+"_icon",this.DOMDoc),$RemoveIconLink=jQuery("#"+this.type+"_icon_removenew",this.DOMDoc);$Icon.bind("change",function(){$Icon.focus(),$Icon.blur(),this.files[0]&&jQuery("#fakefileicon").val(this.files[0].name),$RemoveIconLink.css("display","block")}),$RemoveIconLink.bind("click",function(){jQuery("#fakefileicon").val(""),$Icon.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_icon"),$RemoveIconLink.css("display","none")});var $EditIconLink=jQuery("."+this.type+"_changeicon",this.DOMDoc);$EditIconLink.length>0&&$EditIconLink.click(function(){"none"==jQuery("."+JSObject.type+"_uploadicon",JSObject.DOMDoc).css("display")&&($Icon.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_icon"),jQuery("#fakefileicon").val(""),$RemoveIconLink.css("display","none"),jQuery("."+JSObject.type+"_uploadicon",JSObject.DOMDoc).show(),""!=jQuery("#"+JSObject.type+"_currenticon",JSObject.DOMDoc).attr("src")&&jQuery("."+JSObject.type+"_changeicon_cancel",JSObject.DOMDoc).show(),"block"==jQuery("."+JSObject.type+"_iconcontainer",JSObject.DOMDoc).css("display")&&jQuery("."+JSObject.type+"_iconcontainer",JSObject.DOMDoc).hide())});var $CancelEditIconLink=jQuery("."+this.type+"_changeicon_cancel a",this.DOMDoc);$CancelEditIconLink.length>0&&$CancelEditIconLink.click(function(){"block"==jQuery("."+JSObject.type+"_uploadicon",JSObject.DOMDoc).css("display")&&($Icon.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_icon"),jQuery("#fakefileicon").val(""),jQuery("."+JSObject.type+"_uploadicon",JSObject.DOMDoc).hide(),jQuery(this).parent().hide(),"none"==jQuery("."+JSObject.type+"_iconcontainer",JSObject.DOMDoc).css("display")&&""!=jQuery("#"+JSObject.type+"_currenticon",JSObject.DOMDoc).attr("src")&&jQuery("."+JSObject.type+"_iconcontainer",JSObject.DOMDoc).show())});var $DeleteIconLink=jQuery("."+this.type+"_deleteicon",this.DOMDoc);if($DeleteIconLink.length>0){var href=$DeleteIconLink.get(0).href;$DeleteIconLink.get(0).href="javascript:void(0);",$DeleteIconLink.click(function(){var isConfirmed=confirm("This app icon is used when the app is added to the homescreen. Are you sure you want to remove it?");isConfirmed&&jQuery.get(ajaxurl,{action:"wmp_theme_editimages",type:"delete",source:"icon"},function(responseJSON){var JSON=eval("("+responseJSON+")"),response=Boolean(Number(String(JSON.status)));if(JSObject.deletingIcon=!1,1==response){jQuery("#"+JSObject.type+"_currenticon",JSObject.DOMDoc).attr("src",""),$EditIconLink.trigger("click");var message="The app icon has been removed.";WMPJSInterface.Loader.display({message:message})}else{var message="There was an error. Please try again in few seconds.";WMPJSInterface.Loader.display({message:message})}})})}var $Logo=jQuery("#"+this.type+"_logo",this.DOMDoc),$RemoveLogoLink=jQuery("#"+this.type+"_logo_removenew",this.DOMDoc);$Logo.bind("change",function(){$Logo.focus(),$Logo.blur(),this.files[0]&&jQuery("#fakefilelogo").val(this.files[0].name),$RemoveLogoLink.css("display","block")}),$RemoveLogoLink.bind("click",function(){jQuery("#fakefilelogo").val(""),$Logo.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_logo"),$RemoveLogoLink.css("display","none")});var $EditLogoLink=jQuery("."+this.type+"_changelogo",this.DOMDoc);$EditLogoLink.length>0&&$EditLogoLink.click(function(){"none"==jQuery("."+JSObject.type+"_uploadlogo",JSObject.DOMDoc).css("display")&&($Logo.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_logo"),jQuery("#fakefilelogo").val(""),$RemoveLogoLink.css("display","none"),jQuery("."+JSObject.type+"_uploadlogo",JSObject.DOMDoc).show(),"none"!=jQuery("#"+JSObject.type+"_currentlogo",JSObject.DOMDoc).css("background-image")&&jQuery("."+JSObject.type+"_changelogo_cancel",JSObject.DOMDoc).show(),"block"==jQuery("."+JSObject.type+"_logocontainer",JSObject.DOMDoc).css("display")&&jQuery("."+JSObject.type+"_logocontainer",JSObject.DOMDoc).hide())});var $CancelEditLogoLink=jQuery("."+this.type+"_changelogo_cancel a",this.DOMDoc);$CancelEditLogoLink.length>0&&$CancelEditLogoLink.click(function(){"block"==jQuery("."+JSObject.type+"_uploadlogo",JSObject.DOMDoc).css("display")&&($Logo.val(""),jQuery(JSObject.form).validate().element("#"+JSObject.type+"_logo"),jQuery("#fakefilelogo").val(""),jQuery("."+JSObject.type+"_uploadlogo",JSObject.DOMDoc).hide(),jQuery(this).parent().hide(),"none"==jQuery("."+JSObject.type+"_logocontainer",JSObject.DOMDoc).css("display")&&"none"!=jQuery("#"+JSObject.type+"_currentlogo",JSObject.DOMDoc).css("background-image")&&jQuery("."+JSObject.type+"_logocontainer",JSObject.DOMDoc).show())});var $DeleteLogoLink=jQuery("."+this.type+"_deletelogo",this.DOMDoc);if($DeleteLogoLink.length>0){var href=$DeleteLogoLink.get(0).href;$DeleteLogoLink.get(0).href="javascript:void(0);",$DeleteLogoLink.click(function(){var isConfirmed=confirm("This app logo is used on the cover of your app. Are you sure you want to remove it?");isConfirmed&&jQuery.get(ajaxurl,{action:"wmp_theme_editimages",type:"delete",source:"logo"},function(responseJSON){var JSON=eval("("+responseJSON+")"),response=Boolean(Number(String(JSON.status)));if(JSObject.deletingIcon=!1,1==response){jQuery("#"+JSObject.type+"_currentlogo",JSObject.DOMDoc).css("background-image","none"),$EditLogoLink.trigger("click");var message="The app logo has been removed.";WMPJSInterface.Loader.display({message:message})}else{var message="There was an error. Please try again in few seconds.";WMPJSInterface.Loader.display({message:message})}})})}},this.displayImage=function(e,t){"icon"==e?(jQuery("#"+JSObject.type+"_icon",JSObject.DOMDoc).val(""),jQuery("#fakefileicon").val(""),jQuery("."+JSObject.type+"_uploadicon",JSObject.DOMDoc).hide(),jQuery("."+JSObject.type+"_changeicon_cancel",JSObject.DOMDoc).hide(),jQuery("#"+JSObject.type+"_currenticon",JSObject.DOMDoc).attr("src",t),jQuery("."+JSObject.type+"_iconcontainer",JSObject.DOMDoc).css("display","block")):"logo"==e&&(jQuery("#"+JSObject.type+"_logo",JSObject.DOMDoc).val(""),jQuery("#fakefilelogo").val(""),jQuery("."+JSObject.type+"_uploadlogo",JSObject.DOMDoc).hide(),jQuery("."+JSObject.type+"_changelogo_cancel",JSObject.DOMDoc).hide(),jQuery("#"+JSObject.type+"_currentlogo",JSObject.DOMDoc).css("background-image","url("+t+")"),jQuery("."+JSObject.type+"_logocontainer",JSObject.DOMDoc).css("display","block"))},this.addButtonsActions=function(){jQuery(this.send_btn).unbind("click"),jQuery(this.send_btn).bind("click",function(){JSObject.disableButton(this),JSObject.validate()}),JSObject.enableButton(this.send_btn),jQuery("#"+JSObject.type+"_warning a.close-x",JSObject.DOMDoc).on("click",function(){jQuery("#"+JSObject.type+"_warning",JSObject.DOMDoc).hide()})},this.enableButton=function(e){jQuery(e).css("cursor","pointer"),jQuery(e).animate({opacity:1},100)},this.disableButton=function(e){jQuery(e).unbind("click"),jQuery(e).animate({opacity:.4},100),jQuery(e).css("cursor","default")},this.scrollToError=function(e){var t=jQuery("html,body",JSObject.DOMDoc),o=parseInt(jQuery("html,body").scrollTop())||parseInt(jQuery("body").scrollTop()),c=t.get(0).clientHeight;parseInt(t.offset().top);e<o?jQuery(t).animate({scrollTop:e-20},1e3):e>o+c&&jQuery(t).animate({scrollTop:o+c},1e3)},this.validate=function(){jQuery(this.form).validate().form();var e=[];for(var t in this.validator.invalid){var o=jQuery(this.form[t]);e.push(o.offset().top)}0==e.length?this.sendData():(e.sort(function(e,t){return e-t}),JSObject.scrollToError(e[0]),JSObject.addButtonsActions())},this.submitForm=function(){return WMPJSInterface.AjaxUpload.dosubmit(JSObject.form,{onStart:JSObject.startUploadingData,onComplete:JSObject.completeUploadingData})},this.sendData=function(){jQuery("#"+this.form.id,this.DOMDoc).unbind("submit"),jQuery("#"+this.form.id,this.DOMDoc).bind("submit",function(){JSObject.submitForm()}),jQuery("#"+this.form.id,this.DOMDoc).submit(),JSObject.disableButton(JSObject.send_btn)},this.startUploadingData=function(){return WMPJSInterface.Preloader.start(),setTimeout(function(){var e=JSObject.form.elements;for(nElems=e.length,j=0;j<nElems;j++)e[j].disabled=!0},300),!0},this.completeUploadingData=function(responseJSON){jQuery("#"+JSObject.form.id,JSObject.DOMDoc).unbind("submit"),jQuery("#"+JSObject.form.id,JSObject.DOMDoc).bind("submit",function(){return!1}),WMPJSInterface.Preloader.remove(100);var JSON=eval("("+responseJSON+")"),response=Boolean(Number(String(JSON.status)));if(void 0!=JSON.uploaded_icon&&JSObject.displayImage("icon",JSON.uploaded_icon),void 0!=JSON.uploaded_logo&&JSObject.displayImage("logo",JSON.uploaded_logo),1==response&&0==JSON.messages.length){var message="Your app has been successfully modified!";WMPJSInterface.Loader.display({message:message})}else if(0==JSON.messages.length){var message="There was an error. Please reload the page and try again.";WMPJSInterface.Loader.display({message:message})}else for(i=0;i<JSON.messages.length;i++)WMPJSInterface.Loader.display({message:JSON.messages[i]});setTimeout(function(){var e=JSObject.form.elements;for(nElems=e.length,j=0;j<nElems;j++)e[j].disabled=!1},300),JSObject.addButtonsActions()}}
|