(function(jQuery){ if(jQuery(".wpcf7c-elm-step1").length != 0) { // 瀵捐薄鏈夈倞 jQuery(".wpcf7c-elm-step1").each(function(){ // 瑕伄銉曘偐銉笺儬銈掓绱 var parent = jQuery(this).parents("form"); if(parent.attr("wpcf7c") == undefined) { // elm-submit銈抯ubmit銉溿偪銉炽伕銈傘偦銉冦儓 parent.find(".wpcf7-submit").addClass("wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); parent.find(".ajax-loader").addClass("wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); // ajax鐢↖D閫€閬?鍑︾悊娓堛伩銉曘儵銈般偦銉冦儓 var hidden_wpcf7 = parent.find("input[name=_wpcf7]"); var _wpcf7 = hidden_wpcf7.val(); parent.attr("wpcf7c", _wpcf7); parent.attr("step", 1); hidden_wpcf7.after(''); //parent.find("input[name=_wpcf7]").val(""); // 涓嶈瑕佺礌闈炶〃绀 parent.find(".wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step3").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step1").removeClass("wpcf7c-force-hide"); // 鎴汇仯銇︾法闆嗐儨銈裤兂鎸欏嫊 parent.find(".wpcf7c-btn-back").on("click", function(){ wpcf7c_to_step1(parent, true); return false; }); } }); } })(jQuery); var wpcf7c_to_step1 = function(parent, scroll){ parent.find(".wpcf7c-conf").each(function(){ // 瑕儠銈┿兗銉 var parent_form = jQuery(this).parents("form"); jQuery(this).removeAttr("disabled").removeAttr("readonly").removeClass("wpcf7c-conf"); }); jQuery(".wpcf7c-conf-hidden").remove(); parent.find(".wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step3").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step1").removeClass("wpcf7c-force-hide"); parent.find("input[name=_wpcf7c]").val("step1"); var responseOutput = parent.find('div.wpcf7-response-output'); responseOutput.removeClass("wpcf7c-force-hide"); responseOutput.removeClass("wpcf7-mail-sent-ng"); responseOutput.css("display", "none"); parent.find(".ajax-loader").addClass("wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); // 銈广儬銉笺偤銈广偗銉兗銉 if(scroll) { // 銈广儬銉笺偤銈广偗銉兗銉 setTimeout(function() { wpcf7c_scroll(parent.find("input[name=_wpcf7_unit_tag]").val()) }, 100); } } var wpcf7c_step1 = function(unit_tag){ // 纰鸿獚瀹屼簡 // 瀵捐薄銉曘偐銉笺儬妞滅储 //var elm_unit_tag = jQuery.find("input[name=_wpcf7_unit_tag]"); jQuery(jQuery.find("input[name=_wpcf7_unit_tag]")).each(function(){ if(jQuery(this).val() == unit_tag) { var parent = jQuery(this).parents("form"); var responseOutput = parent.find('div.wpcf7-response-output'); responseOutput.addClass("wpcf7c-force-hide"); // 纰鸿獚鐢婚潰琛ㄧず // 銉嗐偔銈广儓銈ㄣ儶銈倰浼搞伆銇 parent.find("textarea").each(function(){ if(this.scrollHeight > this.offsetHeight){ this.style.height = (this.scrollHeight + 10) + 'px'; } }); parent.find("textarea").attr("readonly", true).addClass("wpcf7c-conf"); parent.find("select").each(function(){ jQuery(this).attr("readonly", true).attr("disabled", true).addClass("wpcf7c-conf"); jQuery(this).after( jQuery('').attr("name", jQuery(this).attr("name")).val(jQuery(this).val()).addClass("wpcf7c-conf-hidden") ); }); parent.find("input").each(function(){ switch(jQuery(this).attr("type")) { case "submit": case "button": case "hidden": case "image": // 銇伀銈傘仐銇亜 break; case "radio": case "checkbox": // 閬告姙銇曘倢銇︺亜銈嬨倐銇仩銇戝鍑 jQuery(this).attr("readonly", true).attr("disabled", true).addClass("wpcf7c-conf"); if(jQuery(this).is(":checked")) { jQuery(this).after( jQuery('').attr("name", jQuery(this).attr("name")).val(jQuery(this).val()).addClass("wpcf7c-conf-hidden") ); } break; case "file": jQuery(this).attr("readonly", true).addClass("wpcf7c-elm-step1").addClass("wpcf7c-force-hide"); jQuery(this).after( jQuery('').attr("name", (jQuery(this).attr("name") + "_conf")).val(jQuery(this).val()).addClass("wpcf7c-conf-hidden").addClass("wpcf7c-conf").attr("readonly", true).attr("disabled", true) ); break; default: jQuery(this).attr("readonly", true).addClass("wpcf7c-conf"); jQuery(this).after( jQuery('').attr("name", jQuery(this).attr("name")).val(jQuery(this).val()).addClass("wpcf7c-conf-hidden") ); break; } }); // 琛ㄧず鍒囨浛 parent.find(".wpcf7c-elm-step1").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step3").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step2").removeClass("wpcf7c-force-hide"); parent.find(".ajax-loader").removeClass("wpcf7c-force-hide"); parent.find("input[name=_wpcf7c]").val("step2"); // 銈广儬銉笺偤銈广偗銉兗銉 setTimeout(function() { wpcf7c_scroll(unit_tag) }, 100); } }); } var wpcf7c_scroll = function(unit_tag) { // 銈ㄣ儵銉笺伄鏅傘仾銇┿伀銈兂銈兗銇俱仹銈广偗銉兗銉 jQuery(jQuery.find("input[name=_wpcf7_unit_tag]")).each(function(){ if(jQuery(this).val() == unit_tag) { var parent = jQuery(this).parents("form"); var speed = 1000; var position = parent.offset().top; if(jQuery('.wpcf7c-anchor').length != 0) { position = jQuery('.wpcf7c-anchor').offset().top; } jQuery("html, body").animate({scrollTop:position}, speed, "swing"); } }); } var wpcf7c_step2 = function(unit_tag){ // 纰鸿獚瀹屼簡 // 瀵捐薄銉曘偐銉笺儬妞滅储 //var elm_unit_tag = jQuery.find("input[name=_wpcf7_unit_tag]"); jQuery(jQuery.find("input[name=_wpcf7_unit_tag]")).each(function(){ if(jQuery(this).val() == unit_tag) { var parent = jQuery(this).parents("form"); var responseOutput = parent.find('div.wpcf7-response-output'); responseOutput.removeClass("wpcf7c-force-hide"); // step1鐘舵厠銇敾闈㈣〃绀 wpcf7c_to_step1(parent); // step3銇绱犮亴銇傘倢銇般€併仢銈屻伀鍒囥倞鏇裤亪銈 if(parent.find(".wpcf7c-elm-step3").length != 0) { // 琛ㄧず鍒囨浛 parent.find(".wpcf7c-elm-step1").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step2").addClass("wpcf7c-force-hide"); parent.find(".wpcf7c-elm-step3").removeClass("wpcf7c-force-hide"); } } }); } var wpcf7c_step2_error = function(unit_tag) { jQuery(jQuery.find("input[name=_wpcf7_unit_tag]")).each(function(){ if(jQuery(this).val() == unit_tag) { var parent = jQuery(this).parents("form"); var responseOutput = parent.find('div.wpcf7-response-output'); responseOutput.removeClass("wpcf7c-force-hide"); } }); } document.addEventListener( 'wpcf7submit', function( event ) { switch ( event.detail.status ) { case 'wpcf7c_confirmed': wpcf7c_step1(event.detail.id); break; case 'mail_sent': wpcf7c_step2(event.detail.id); break; } }, false );