jQuery(function($){ /* * Load More */ $('#misha_loadmore').click(function(){ $.ajax({ url : misha_loadmore_params.ajaxurl, // AJAX handler data : { 'action': 'loadmorebutton', // the parameter for admin-ajax.php 'query': misha_loadmore_params.posts, // loop parameters passed by wp_localize_script() 'page' : misha_loadmore_params.current_page // current page }, type : 'POST', beforeSend : function ( xhr ) { $('#misha_loadmore').text('Загружаем...', 'oxitext' ); // some type of preloader }, success : function( posts ){ if( posts ) { $('#misha_loadmore').text( 'Еще предложения', 'oxitext' ); $('#misha_posts_wrap').append( posts ); // insert new posts misha_loadmore_params.current_page++; if ( misha_loadmore_params.current_page == misha_loadmore_params.max_page ) $('#misha_loadmore').hide(); // if last page, HIDE the button } else { $('#misha_loadmore').hide(); // if no data, HIDE the button as well } } }); return false; }); /* * Filter */ $('#misha_filters').change(function(){ $.ajax({ url : misha_loadmore_params.ajaxurl, data : $('#misha_filters').serialize(), // form data dataType : 'json', // this data type allows us to receive objects from the server type : 'POST', beforeSend : function(xhr){ $('#misha_filters').find('button').text('Фильтруем...', 'oxitext' ); }, success : function( data ){ // when filter applied: // set the current page to 1 misha_loadmore_params.current_page = 1; // set the new query parameters misha_loadmore_params.posts = data.posts; // set the new max page parameter misha_loadmore_params.max_page = data.max_page; // change the button label back $('#misha_filters').find('button').text('Apply filter'); // insert the posts to the container $('#misha_posts_wrap').html(data.content); // hide load more button, if there are not enough posts for the second page if ( data.max_page < 2 ) { $('#misha_loadmore').hide(); } else { $('#misha_loadmore').show(); } } }); // do not submit the form return false; }); $( '.js-input' ).keyup(function() { if( $(this).val() ) { $(this).addClass('not-empty'); } else { $(this).removeClass('not-empty'); } }); }); jQuery(document).ready(function($){ // on focus $(".wpcf7-form input").focus(function() { $(this).parent().siblings('label').addClass('has-value'); }) // blur input fields on unfocus + if has no value .blur(function() { var text_val = $(this).val(); if(text_val === "") { $(this).parent().siblings('label').removeClass('has-value'); } }); $(".wpcf7-tel").inputmask({ mask: ["+7 (999) 999-99-99", "8 (999) 999-99-99"], jitMasking: 3, showMaskOnHover: false, autoUnmask: true }); });