balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

scripts.js (7978B)


      1 ( function( $ ) {
      2 
      3 	'use strict';
      4 
      5 	if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) {
      6 		return;
      7 	}
      8 
      9 	$( function() {
     10 		var welcomePanel = $( '#welcome-panel' );
     11 		var updateWelcomePanel;
     12 
     13 		updateWelcomePanel = function( visible ) {
     14 			$.post( ajaxurl, {
     15 				action: 'wpcf7-update-welcome-panel',
     16 				visible: visible,
     17 				welcomepanelnonce: $( '#welcomepanelnonce' ).val()
     18 			} );
     19 		};
     20 
     21 		$( 'a.welcome-panel-close', welcomePanel ).click( function( event ) {
     22 			event.preventDefault();
     23 			welcomePanel.addClass( 'hidden' );
     24 			updateWelcomePanel( 0 );
     25 		} );
     26 
     27 		$( '#contact-form-editor' ).tabs( {
     28 			active: wpcf7.activeTab,
     29 			activate: function( event, ui ) {
     30 				$( '#active-tab' ).val( ui.newTab.index() );
     31 			}
     32 		} );
     33 
     34 		$( '#contact-form-editor-tabs' ).focusin( function( event ) {
     35 			$( '#contact-form-editor .keyboard-interaction' ).css(
     36 				'visibility', 'visible' );
     37 		} ).focusout( function( event ) {
     38 			$( '#contact-form-editor .keyboard-interaction' ).css(
     39 				'visibility', 'hidden' );
     40 		} );
     41 
     42 		wpcf7.toggleMail2( 'input:checkbox.toggle-form-table' );
     43 
     44 		$( 'input:checkbox.toggle-form-table' ).click( function( event ) {
     45 			wpcf7.toggleMail2( this );
     46 		} );
     47 
     48 		if ( '' === $( '#title' ).val() ) {
     49 			$( '#title' ).focus();
     50 		}
     51 
     52 		wpcf7.titleHint();
     53 
     54 		$( '.contact-form-editor-box-mail span.mailtag' ).click( function( event ) {
     55 			var range = document.createRange();
     56 			range.selectNodeContents( this );
     57 			window.getSelection().addRange( range );
     58 		} );
     59 
     60 		wpcf7.updateConfigErrors();
     61 
     62 		$( '[data-config-field]' ).change( function() {
     63 			var postId = $( '#post_ID' ).val();
     64 
     65 			if ( ! postId || -1 == postId ) {
     66 				return;
     67 			}
     68 
     69 			var data = [];
     70 
     71 			$( this ).closest( 'form' ).find( '[data-config-field]' ).each( function() {
     72 				data.push( {
     73 					'name': $( this ).attr( 'name' ).replace( /^wpcf7-/, '' ).replace( /-/g, '_' ),
     74 					'value': $( this ).val()
     75 				} );
     76 			} );
     77 
     78 			data.push( { 'name': 'context', 'value': 'dry-run' } );
     79 
     80 			$.ajax( {
     81 				method: 'POST',
     82 				url: wpcf7.apiSettings.getRoute( '/contact-forms/' + postId ),
     83 				beforeSend: function( xhr ) {
     84 					xhr.setRequestHeader( 'X-WP-Nonce', wpcf7.apiSettings.nonce );
     85 				},
     86 				data: data
     87 			} ).done( function( response ) {
     88 				wpcf7.configValidator.errors = response.config_errors;
     89 				wpcf7.updateConfigErrors();
     90 			} );
     91 		} );
     92 
     93 		$( window ).on( 'beforeunload', function( event ) {
     94 			var changed = false;
     95 
     96 			$( '#wpcf7-admin-form-element :input[type!="hidden"]' ).each( function() {
     97 				if ( $( this ).is( ':checkbox, :radio' ) ) {
     98 					if ( this.defaultChecked != $( this ).is( ':checked' ) ) {
     99 						changed = true;
    100 					}
    101 				} else if ( $( this ).is( 'select' ) ) {
    102 					$( this ).find( 'option' ).each( function() {
    103 						if ( this.defaultSelected != $( this ).is( ':selected' ) ) {
    104 							changed = true;
    105 						}
    106 					} );
    107 				} else {
    108 					if ( this.defaultValue != $( this ).val() ) {
    109 						changed = true;
    110 					}
    111 				}
    112 			} );
    113 
    114 			if ( changed ) {
    115 				event.returnValue = wpcf7.saveAlert;
    116 				return wpcf7.saveAlert;
    117 			}
    118 		} );
    119 
    120 		$( '#wpcf7-admin-form-element' ).submit( function() {
    121 			if ( 'copy' != this.action.value ) {
    122 				$( window ).off( 'beforeunload' );
    123 			}
    124 
    125 			if ( 'save' == this.action.value ) {
    126 				$( '#publishing-action .spinner' ).addClass( 'is-active' );
    127 			}
    128 		} );
    129 
    130 		$( '#wpcf7-sendinblue-enable-contact-list, #wpcf7-sendinblue-enable-transactional-email' ).on( 'change', function() {
    131 			if ( $( this ).is( ':checked' ) ) {
    132 				$( this ).closest( 'tr' ).removeClass( 'inactive' );
    133 			} else {
    134 				$( this ).closest( 'tr' ).addClass( 'inactive' );
    135 			}
    136 		} );
    137 
    138 	} );
    139 
    140 	wpcf7.toggleMail2 = function( checkbox ) {
    141 		var $checkbox = $( checkbox );
    142 		var $fieldset = $( 'fieldset',
    143 			$checkbox.closest( '.contact-form-editor-box-mail' ) );
    144 
    145 		if ( $checkbox.is( ':checked' ) ) {
    146 			$fieldset.removeClass( 'hidden' );
    147 		} else {
    148 			$fieldset.addClass( 'hidden' );
    149 		}
    150 	};
    151 
    152 	wpcf7.updateConfigErrors = function() {
    153 		var errors = wpcf7.configValidator.errors;
    154 		var errorCount = { total: 0 };
    155 
    156 		$( '[data-config-field]' ).each( function() {
    157 			$( this ).removeAttr( 'aria-invalid' );
    158 			$( this ).next( 'ul.config-error' ).remove();
    159 
    160 			var section = $( this ).attr( 'data-config-field' );
    161 
    162 			$( this ).attr( 'aria-describedby', 'wpcf7-config-error-for-' + section );
    163 
    164 			if ( errors[ section ] ) {
    165 				var $list = $( '<ul></ul>' ).attr( {
    166 					'id': 'wpcf7-config-error-for-' + section,
    167 					'class': 'config-error'
    168 				} );
    169 
    170 				$.each( errors[ section ], function( i, val ) {
    171 					var $li = $( '<li></li>' ).append(
    172 						wpcf7.iconInCircle( '!' )
    173 					).append(
    174 						$( '<span class="screen-reader-text"></span>' ).text( wpcf7.configValidator.iconAlt )
    175 					).append( ' ' );
    176 
    177 					if ( val.link ) {
    178 						$li.append(
    179 							$( '<a></a>' ).attr( 'href', val.link ).text( val.message )
    180 						);
    181 					} else {
    182 						$li.text( val.message );
    183 					}
    184 
    185 					$li.appendTo( $list );
    186 
    187 					var tab = section
    188 						.replace( /^mail_\d+\./, 'mail.' ).replace( /\..*$/, '' );
    189 
    190 					if ( ! errorCount[ tab ] ) {
    191 						errorCount[ tab ] = 0;
    192 					}
    193 
    194 					errorCount[ tab ] += 1;
    195 
    196 					errorCount.total += 1;
    197 				} );
    198 
    199 				$( this ).after( $list ).attr( { 'aria-invalid': 'true' } );
    200 			}
    201 		} );
    202 
    203 		$( '#contact-form-editor-tabs > li' ).each( function() {
    204 			var $item = $( this );
    205 			$item.find( '.icon-in-circle' ).remove();
    206 			var tab = $item.attr( 'id' ).replace( /-panel-tab$/, '' );
    207 
    208 			$.each( errors, function( key, val ) {
    209 				key = key.replace( /^mail_\d+\./, 'mail.' );
    210 
    211 				if ( key.replace( /\..*$/, '' ) == tab.replace( '-', '_' ) ) {
    212 					var $mark = wpcf7.iconInCircle( '!' );
    213 					$item.find( 'a.ui-tabs-anchor' ).first().append( $mark );
    214 					return false;
    215 				}
    216 			} );
    217 
    218 			var $tabPanelError = $( '#' + tab + '-panel > div.config-error:first' );
    219 			$tabPanelError.empty();
    220 
    221 			if ( errorCount[ tab.replace( '-', '_' ) ] ) {
    222 				$tabPanelError.append( wpcf7.iconInCircle( '!' ) );
    223 
    224 				if ( 1 < errorCount[ tab.replace( '-', '_' ) ] ) {
    225 					var manyErrorsInTab = wpcf7.configValidator.manyErrorsInTab
    226 						.replace( '%d', errorCount[ tab.replace( '-', '_' ) ] );
    227 					$tabPanelError.append( manyErrorsInTab );
    228 				} else {
    229 					$tabPanelError.append( wpcf7.configValidator.oneErrorInTab );
    230 				}
    231 			}
    232 		} );
    233 
    234 		$( '#misc-publishing-actions .misc-pub-section.config-error' ).remove();
    235 
    236 		if ( errorCount.total ) {
    237 			var $warning = $( '<div></div>' )
    238 				.addClass( 'misc-pub-section config-error' )
    239 				.append( wpcf7.iconInCircle( '!' ) );
    240 
    241 			if ( 1 < errorCount.total ) {
    242 				$warning.append(
    243 					wpcf7.configValidator.manyErrors.replace( '%d', errorCount.total )
    244 				);
    245 			} else {
    246 				$warning.append( wpcf7.configValidator.oneError );
    247 			}
    248 
    249 			$warning.append( '<br />' ).append(
    250 				$( '<a></a>' )
    251 					.attr( 'href', wpcf7.configValidator.docUrl )
    252 					.text( wpcf7.configValidator.howToCorrect )
    253 			);
    254 
    255 			$( '#misc-publishing-actions' ).append( $warning );
    256 		}
    257 	};
    258 
    259 	/**
    260 	 * Copied from wptitlehint() in wp-admin/js/post.js
    261 	 */
    262 	wpcf7.titleHint = function() {
    263 		var $title = $( '#title' );
    264 		var $titleprompt = $( '#title-prompt-text' );
    265 
    266 		if ( '' === $title.val() ) {
    267 			$titleprompt.removeClass( 'screen-reader-text' );
    268 		}
    269 
    270 		$titleprompt.click( function() {
    271 			$( this ).addClass( 'screen-reader-text' );
    272 			$title.focus();
    273 		} );
    274 
    275 		$title.blur( function() {
    276 			if ( '' === $(this).val() ) {
    277 				$titleprompt.removeClass( 'screen-reader-text' );
    278 			}
    279 		} ).focus( function() {
    280 			$titleprompt.addClass( 'screen-reader-text' );
    281 		} ).keydown( function( e ) {
    282 			$titleprompt.addClass( 'screen-reader-text' );
    283 			$( this ).unbind( e );
    284 		} );
    285 	};
    286 
    287 	wpcf7.iconInCircle = function( icon ) {
    288 		var $span = $( '<span class="icon-in-circle" aria-hidden="true"></span>' );
    289 		return $span.text( icon );
    290 	};
    291 
    292 	wpcf7.apiSettings.getRoute = function( path ) {
    293 		var url = wpcf7.apiSettings.root;
    294 
    295 		url = url.replace(
    296 			wpcf7.apiSettings.namespace,
    297 			wpcf7.apiSettings.namespace + path );
    298 
    299 		return url;
    300 	};
    301 
    302 } )( jQuery );