jQuery(function($) { /** * General variables */ var adminbarHeight = $('#wpadminbar').length > 0 ? $('#wpadminbar').height() : 0; var siteheaderHeight = $('.site-header').length > 0 ? $('.site-header').height() : 0; $(window).resize(function() { adminbarHeight = $('#wpadminbar').length > 0 ? $('#wpadminbar').height() : 0; siteheaderHeight = $('.site-header').length > 0 ? $('.site-header').height() : 0; }); /** * Site navigation */ $('.site-nav-toggler').on('click', function() { if ($('body').hasClass('open-site-nav')) { $('body').removeClass('open-site-nav').css('overflow', ''); $('.site-overlay').remove(); } else { $('body').addClass('open-site-nav').css('overflow', 'hidden'); $('.site-nav').css('top', adminbarHeight); $('.site-nav').after('
'); } }); $('body').on('click', '.site-nav-closer, .site-overlay', function(e) { e.stopPropagation(); $('body').removeClass('open-site-nav').css('overflow', ''); $('.site-overlay').remove(); }); $('.site-nav li.menu-item-has-children').on('click', function(e) { e.stopPropagation(); $(this).siblings().children('.sub-menu').slideUp(300); $(this).toggleClass('active').children('.sub-menu').slideToggle(300); }); $('.site-nav a').on('click', function(e) { e.stopPropagation(); }); /** * Table of contents */ if ( $('.table-of-contents').length > 0 ) { $('.entry-content h2, .entry-content h3').each(function() { $(this).attr('id', convertToSlug($(this).text())); if ( $(this).is('h2') ) { $('.table-of-contents .links').append('' + $(this).text() + ''); } else if ( $(this).is('h3') ) { $('.table-of-contents .links').append('' + $(this).text() + ''); } }); } $('.table-of-contents a').on('click', function(e) { e.preventDefault(); var hash = this.hash; location.hash = hash; $('html, body').animate({ scrollTop: $(hash).offset().top - adminbarHeight - siteheaderHeight }, 0); }); if ( location.hash ) { var hash = location.hash; if ( $('.table-of-contents a[href="' + hash + '"]').length > 0 ) { $('.tab-nav a').removeClass('active'); $('.tab-pane').removeClass('active show'); var id = $(hash).parents('.tab-pane').attr('id'); $('a[href="#' + id + '"]').trigger('click'); setTimeout(function() { $('html, body').animate({ scrollTop: $(hash).offset().top - adminbarHeight - siteheaderHeight }, 300); }, 2000); } } /** * Schema faq */ $('.schema-faq-section').on('click', function() { $('.schema-faq-section.active').find('.schema-faq-answer').slideUp(100); if ( $(this).hasClass('active') ) { $('.schema-faq-section.active').removeClass('active'); $(this).find('.schema-faq-answer').slideUp(100); } else { $('.schema-faq-section.active').removeClass('active'); $(this).addClass('active'); $(this).find('.schema-faq-answer').slideDown(100); } }); /** * Rating */ $('.rating').rateYo({ starWidth: '20px', fullStar: true, onSet: function (rating, rateYoInstance) { var $this = $(this); var post_id = $this.data('post_id'); $.ajax({ type: 'POST', url: ajax.ajax_url, data: { 'action' : 'k_rating', 'post_id' : post_id, 'rating' : rating, }, success: function( data, textStatus, jqXHR ) { if ( data.status == true ) { $this.rateYo('option', 'readOnly', true); } else { alert(data.message); } }, error: function( jqXHR, textStatus, errorThrown ) { alert( jqXHR.responseText ); } }); } }); /** * Login */ $('.form-comment').on('submit', function(e) { e.preventDefault(); $form = $(this); $form.find('[type="submit"]').append(''); $form.find('.alert').remove(); $.ajax({ type: 'POST', url: ajax.ajax_url, data: $form.serialize(), success: function( data, textStatus, jqXHR ) { $form.find('[type="submit"]').find('.icon').remove(); if( data.status == true ) { $form.append('