( function( $ ) { 'use strict'; if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) { return; } $( function() { var welcomePanel = $( '#welcome-panel' ); var updateWelcomePanel; updateWelcomePanel = function( visible ) { $.post( ajaxurl, { action: 'wpcf7-update-welcome-panel', visible: visible, welcomepanelnonce: $( '#welcomepanelnonce' ).val() } ); }; $( 'a.welcome-panel-close', welcomePanel ).click( function( event ) { event.preventDefault(); welcomePanel.addClass( 'hidden' ); updateWelcomePanel( 0 ); } ); $( '#contact-form-editor' ).tabs( { active: wpcf7.activeTab, activate: function( event, ui ) { $( '#active-tab' ).val( ui.newTab.index() ); } } ); $( '#contact-form-editor-tabs' ).focusin( function( event ) { $( '#contact-form-editor .keyboard-interaction' ).css( 'visibility', 'visible' ); } ).focusout( function( event ) { $( '#contact-form-editor .keyboard-interaction' ).css( 'visibility', 'hidden' ); } ); wpcf7.toggleMail2( 'input:checkbox.toggle-form-table' ); $( 'input:checkbox.toggle-form-table' ).click( function( event ) { wpcf7.toggleMail2( this ); } ); if ( '' === $( '#title' ).val() ) { $( '#title' ).focus(); } wpcf7.titleHint(); $( '.contact-form-editor-box-mail span.mailtag' ).click( function( event ) { var range = document.createRange(); range.selectNodeContents( this ); window.getSelection().addRange( range ); } ); wpcf7.updateConfigErrors(); $( '[data-config-field]' ).change( function() { var postId = $( '#post_ID' ).val(); if ( ! postId || -1 == postId ) { return; } var data = []; $( this ).closest( 'form' ).find( '[data-config-field]' ).each( function() { data.push( { 'name': $( this ).attr( 'name' ).replace( /^wpcf7-/, '' ).replace( /-/g, '_' ), 'value': $( this ).val() } ); } ); data.push( { 'name': 'context', 'value': 'dry-run' } ); $.ajax( { method: 'POST', url: wpcf7.apiSettings.getRoute( '/contact-forms/' + postId ), beforeSend: function( xhr ) { xhr.setRequestHeader( 'X-WP-Nonce', wpcf7.apiSettings.nonce ); }, data: data } ).done( function( response ) { wpcf7.configValidator.errors = response.config_errors; wpcf7.updateConfigErrors(); } ); } ); $( window ).on( 'beforeunload', function( event ) { var changed = false; $( '#wpcf7-admin-form-element :input[type!="hidden"]' ).each( function() { if ( $( this ).is( ':checkbox, :radio' ) ) { if ( this.defaultChecked != $( this ).is( ':checked' ) ) { changed = true; } } else if ( $( this ).is( 'select' ) ) { $( this ).find( 'option' ).each( function() { if ( this.defaultSelected != $( this ).is( ':selected' ) ) { changed = true; } } ); } else { if ( this.defaultValue != $( this ).val() ) { changed = true; } } } ); if ( changed ) { event.returnValue = wpcf7.saveAlert; return wpcf7.saveAlert; } } ); $( '#wpcf7-admin-form-element' ).submit( function() { if ( 'copy' != this.action.value ) { $( window ).off( 'beforeunload' ); } if ( 'save' == this.action.value ) { $( '#publishing-action .spinner' ).addClass( 'is-active' ); } } ); } ); wpcf7.toggleMail2 = function( checkbox ) { var $checkbox = $( checkbox ); var $fieldset = $( 'fieldset', $checkbox.closest( '.contact-form-editor-box-mail' ) ); if ( $checkbox.is( ':checked' ) ) { $fieldset.removeClass( 'hidden' ); } else { $fieldset.addClass( 'hidden' ); } }; wpcf7.updateConfigErrors = function() { var errors = wpcf7.configValidator.errors; var errorCount = { total: 0 }; $( '[data-config-field]' ).each( function() { $( this ).removeAttr( 'aria-invalid' ); $( this ).next( 'ul.config-error' ).remove(); var section = $( this ).attr( 'data-config-field' ); if ( errors[ section ] ) { var $list = $( '