1 line
6.4 KiB
JavaScript
1 line
6.4 KiB
JavaScript
!function(r){const{__:e}=wp.i18n,s={person:e("Website Owner Name"),organization:e("Organization Name","wp-schema-pro"),Webshop:e("Webshop Name","wp-schema-pro"),personblog:e("Website Owner Name","wp-schema-pro"),Smallbusiness:e("Blog Website Name","wp-schema-pro"),Otherbusiness:e("Business Name","wp-schema-pro")},t={init(){const s=this;this.customFieldDependecy(),this.customImageSelect(),this.initRepeater(),this.toolTips(),this.regenerateSchema(),r("select.wp-select2").each(function(e,t){s.init_target_rule_select2(t)})},regenerateSchema(){r("#wpsp-regenerate-schema").click(function(){r(this).next("span.spinner").addClass("is-active"),jQuery.ajax({url:ajaxurl,type:"post",dataType:"json",data:{action:"regenerate_schema",nonce:r(this).data("nonce")}}).success(function(){r("#wpsp-regenerate-schema").next("span.spinner").removeClass("is-active"),r("#wpsp-regenerate-notice").show().delay(2e3).fadeOut()})})},toolTips(){r(document).on("click",".wp-schema-pro-tooltip-icon",function(e){e.preventDefault(),r(".wp-schema-pro-tooltip-wrapper").removeClass("activate"),r(this).parent().addClass("activate")}),r(document).on("click",function(e){r(e.target).hasClass("wp-schema-pro-tooltip-description")||r(e.target).hasClass("wp-schema-pro-tooltip-icon")||0!==r(e.target).closest(".wp-schema-pro-tooltip-description").length||r(".wp-schema-pro-tooltip-wrapper").removeClass("activate")})},customImageSelect(){let s;window.inputWrapper="",r(document.body).on("click",".image-field-wrap .aiosrs-image-select",function(e){e.preventDefault(),window.inputWrapper=r(this).closest("td"),s=wp.media({button:{text:"Select Image",close:!1},states:[new wp.media.controller.Library({title:"Select Custom Image",library:wp.media.query({type:"image"}),multiple:!1})]}),s.on("select",function(){var e=s.state().get("selection").first().toJSON();const t=window.inputWrapper.find(".image-field-wrap img");0===t.length?window.inputWrapper.find(".image-field-wrap").append('<a href="#" class="aiosrs-image-select img"><img src="'+e.url+'" /></a>'):t.attr("src",e.url),window.inputWrapper.find(".image-field-wrap").addClass("bsf-custom-image-selected"),window.inputWrapper.find(".single-image-field").val(e.id),s.close()}),s.open()}),r(document).on("click",".aiosrs-image-remove",function(e){e.preventDefault();const t=r(this).closest("td");t.find(".image-field-wrap").removeClass("bsf-custom-image-selected"),t.find(".single-image-field").val(""),t.find(".image-field-wrap img").removeAttr("src")}),window.inputWrapper=""},customFieldDependecy(){jQuery(document).on("change","#post-body-content .wp-schema-pro-custom-option-select, .aiosrs-pro-setup-wizard-content.general-setting-content-wrap .wp-schema-pro-custom-option-select",function(){const e=jQuery(this).next(".custom-field-wrapper");e.css("display","none"),"custom"===jQuery(this).val()&&e.css("display","")}),jQuery(document).on("change",'select[name="wp-schema-pro-general-settings[site-represent]"]',function(){const e=jQuery(this).closest("table"),t=e.find(".wp-schema-pro-site-logo-wrap"),s=e.find(".wp-schema-pro-site-name-wrap"),a=e.find(".wp-schema-pro-person-name-wrap");s.css("display","none"),a.css("display","none"),""!==jQuery(this).val()&&("organization"===jQuery(this).val()||"Webshop"===jQuery(this).val()||"Smallbusiness"===jQuery(this).val()||"Otherbusiness"===jQuery(this).val()?(t.css("display",""),s.css("display","")):(a.css("display",""),t.css("display","")))}),jQuery(document).on("change",'select[name="wp-schema-pro-general-settings[site-represent]"]',function(){var e=jQuery(this).val();""!==jQuery(this).val()&&e in s&&r(".wpsp-organization-label").text(s[e])}),jQuery(document).on("change",'select[name="wp-schema-pro-corporate-contact[contact-type]"]',function(){const e=jQuery(this).closest("table"),t=e.find(".wp-schema-pro-other-wrap");t.css("display","none"),""!==jQuery(this).val()&&"other"===jQuery(this).val()&&t.css("display","")}),r("#add-row").on("click",function(){const e=r(".empty-row.screen-reader-text").clone(!0);return e.removeClass("empty-row screen-reader-text"),e.insertBefore("#repeatable-fieldset-one >tr:last"),!1}),r(".remove-row").on("click",function(){return r(this).parents("tr").remove(),!1})},initRepeater(){r(document).on("click",".bsf-repeater-add-new-btn",function(e){e.preventDefault();const t=r(this),s=t.closest(".bsf-aiosrs-schema-type-wrap"),a=s.find(".aiosrs-pro-repeater-table-wrap").length,n=s.find(".aiosrs-pro-repeater-table-wrap").first().clone();n.find("input, textarea, select").each(function(){r(this).val("");var e=void 0!==r(this).attr("name")?r(this).attr("name").replace("[0]","["+a+"]"):"",t=void 0!==r(this).attr("class")?r(this).attr("class").replace("-0-","-"+a+"-"):"",s=void 0!==r(this).attr("id")?r(this).attr("id").replace("-0-","-"+a+"-"):"";r(this).attr("name",e),r(this).attr("class",t),r(this).attr("id",s)}),n.insertBefore(t)}),r(document).on("click",".bsf-repeater-close",function(e){e.preventDefault();const t=r(this),s=t.closest(".bsf-aiosrs-schema-type-wrap"),a=s.find("> .aiosrs-pro-repeater-table-wrap").length;1<a&&t.closest(".aiosrs-pro-repeater-table-wrap").remove()})},init_target_rule_select2(e){r(e).select2({placeholder:"Search Fields...",ajax:{url:ajaxurl,dataType:"json",method:"post",delay:250,data(e){return{nonce_ajax:AIOSRS_search.search_field,q:e.term,page:e.page,action:"bsf_get_specific_pages"}},processResults(e){return{results:e}},cache:!0},minimumInputLength:2})}};r(document).ready(function(){r(".wp-select2").select2(),r(".wpsp-setup-configuration-settings").select2(),function(){const e=jQuery('select[name="wp-schema-pro-general-settings[site-represent]"]'),t=e.closest("table"),s=t.find(".wp-schema-pro-site-logo-wrap"),a=t.find(".wp-schema-pro-site-name-wrap"),n=t.find(".wp-schema-pro-person-name-wrap");a.css("display","none"),n.css("display","none"),""!==e.val()&&("organization"===e.val()||"Webshop"===e.val()||"Smallbusiness"===e.val()||"Otherbusiness"===e.val()?(s.css("display",""),a.css("display","")):(n.css("display",""),s.css("display","")))}(),function(){const e=jQuery('select[name="wp-schema-pro-general-settings[site-represent]"]'),t=e.val();""!==e&&t in s&&r(".wpsp-organization-label").text(s[t])}(),r("#add-row").on("click",function(){const e=r(".empty-row.screen-reader-text").clone(!0);return e.removeClass("empty-row screen-reader-text"),e.insertBefore("#repeatable-fieldset-one tbody>tr:last"),!1}),r(".remove-row").on("click",function(){return r(this).parents("tr").remove(),!1})}),r(function(){t.init()})}(jQuery); |