1/* global jQuery:false */ 2/* global WRITER_ANCORA_STORAGE:false */ 3 4jQuery(document).ready(function() { 5 "use strict"; 6 WRITER_ANCORA_STORAGE['theme_init_counter'] = 0; 7 writer_ancora_init_actions(); 8}); 9 10jQuery(window).on('beforeunload', function() { 11 "use strict"; 12 // Show preloader 13 jQuery('body.preloader>.outer_wrap,body.preloader>.body_wrap,body.preloader>.writer_ancora_profiler').css({opacity:0}); //.animate({opacity:0}, 'fast'); 14 if (jQuery.browser && !jQuery.browser.safari) jQuery('#page_preloader').css({display: 'block', opacity: 0}).animate({opacity:0.8}, 300); // jQuery('#page_preloader').show(); //css({display: 'block', opacity: 0}).animate({opacity:1}, 300); 15}); 16 17 18// Theme init actions 19function writer_ancora_init_actions() { 20 "use strict"; 21 22 if (WRITER_ANCORA_STORAGE['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length==0 && WRITER_ANCORA_STORAGE['theme_init_counter']++ < 30) { 23 setTimeout(writer_ancora_init_actions, 200); 24 return; 25 } 26 27 jQuery('.vc_editor').find('.vc_trx_column_item').each(function (key, value) { 28 var classList = jQuery(value).children().first()[0].className.split(/\s+/), 29 colSizeClassPattern = /column-\d+_\d+/; 30 31 classList.forEach(function(entry) { 32 if (colSizeClassPattern.test(entry) != null) { 33 jQuery(value).first().addClass(entry); 34 } 35 }); 36 }); 37 38 if (WRITER_ANCORA_STORAGE['use_ajax_views_counter']) { 39 jQuery(document).ready(function() { 40 setTimeout(function(){ 41 jQuery.post(WRITER_ANCORA_STORAGE['ajax_url'], { 42 action: 'post_counter', 43 nonce: WRITER_ANCORA_STORAGE['ajax_nonce'], 44 post_id: WRITER_ANCORA_STORAGE['post_id'], 45 views: WRITER_ANCORA_STORAGE['views'] 46 }); 47 }, 10); 48 }); 49 } 50 51 // Hide preloader 52 jQuery('body.preloader>.outer_wrap,body.preloader>.body_wrap,body.preloader>.writer_ancora_profiler').animate({opacity:1}, 'slow'); 53 jQuery('#page_preloader').hide(); 54 55 // Check for Retina display 56 if (writer_ancora_is_retina()) { 57 writer_ancora_set_cookie('writer_ancora_retina', 1, 365); 58 } 59 60 writer_ancora_ready_actions(); 61 writer_ancora_resize_actions(); 62 writer_ancora_scroll_actions(); 63 64 // Resize handlers 65 jQuery(window).resize(function() { 66 "use strict"; 67 writer_ancora_resize_actions(); 68 writer_ancora_scroll_actions() 69 }); 70 71 // Scroll handlers 72 jQuery(window).scroll(function() { 73 "use strict"; 74 writer_ancora_scroll_actions(); 75 }); 76} 77 78 79 80// Theme first load actions 81//============================================== 82function writer_ancora_ready_actions() { 83 "use strict"; 84 85 // Widgets decoration 86 //---------------------------------------------- 87 88 // Decorate nested lists in widgets and side panels 89 jQuery('.widget ul > li').each(function() { 90 if (jQuery(this).find('ul').length > 0) { 91 jQuery(this).addClass('has_children'); 92 } 93 }); 94 95 96 // Archive widget decoration 97 jQuery('.widget_archive a').each(function() { 98 var val = jQuery(this).html().split(' '); 99 if (val.length > 1) { 100 val[val.length-1] = '<span>' + val[val.length-1] + '</span>'; 101 jQuery(this).html(val.join(' ')) 102 } 103 }); 104 105 // Calendar handlers - change months 106 jQuery('.widget_calendar, .wp-block-calendar').on('click', '.month_prev a, .month_next a', function(e) { 107 "use strict"; 108 var calendar = jQuery(this).parents('.wp-calendar'); 109 var m = jQuery(this).data('month'); 110 var y = jQuery(this).data('year'); 111 var pt = jQuery(this).data('type'); 112 jQuery.post(WRITER_ANCORA_STORAGE['ajax_url'], { 113 action: 'calendar_change_month', 114 nonce: WRITER_ANCORA_STORAGE['ajax_nonce'], 115 month: m, 116 year: y, 117 post_type: pt 118 }).done(function(response) { 119 var rez = {}; 120 try { 121 rez = JSON.parse(response); 122 } catch (e) { 123 rez = { error: WRITER_ANCORA_STORAGE['ajax_error'] }; 124 console.log(response); 125 } 126 if (rez.error === '') { 127 calendar.parent().fadeOut(200, function() { 128 jQuery(this).find('.wp-calendar').remove(); 129 jQuery(this).append(rez.data).fadeIn(200); 130 }); 131 } 132 }); 133 e.preventDefault(); 134 return false; 135 }); 136 137 138 139 // Media setup 140 //---------------------------------------------- 141 142 // Video background init 143 jQuery('.video_background').each(function() { 144 var youtube = jQuery(this).data('youtube-code'); 145 if (youtube) { 146 jQuery(this).tubular({videoId: youtube}); 147 } 148 }); 149 150 151 152 // Menu 153 //---------------------------------------------- 154 155 // Clone side menu for responsive 156 if (jQuery('ul#menu_side').length > 0) { 157 jQuery('ul#menu_side').clone().removeAttr('id').removeClass('menu_side_nav').addClass('menu_side_responsive').insertAfter('ul#menu_side'); 158 writer_ancora_show_current_menu_item(jQuery('.menu_side_responsive'), jQuery('.sidebar_outer_menu_responsive_button')); 159 } 160 161 // Clone main menu for responsive 162 if (jQuery('.menu_main_nav_area ul#menu_main').length > 0) { 163 var menu_responsive = jQuery('.menu_main_nav_area ul#menu_main').clone().removeAttr('id').removeClass('menu_main_nav').addClass('menu_main_responsive'); 164 jQuery('.menu_main_nav_area ul#menu_main').parent().parent().append(menu_responsive); 165 writer_ancora_show_current_menu_item(jQuery('.menu_main_responsive'), jQuery('.top_panel_style_1 .menu_main_responsive_button, .top_panel_style_2 .menu_main_responsive_button')); 166 } 167 168 // Responsive menu button 169 jQuery('.menu_main_responsive_button, .sidebar_outer_menu_responsive_button').on('click', function(e){ 170 "use strict"; 171 if (jQuery(this).hasClass('menu_main_responsive_button')) 172 jQuery('.menu_main_responsive').slideToggle(); 173 else { 174 jQuery(this).toggleClass('icon-down').toggleClass('icon-up'); 175 jQuery('.menu_side_responsive').slideToggle(); 176 } 177 e.preventDefault(); 178 return false;
179 }); 180 181 // Push menu button 182 jQuery('.menu_pushy_button').on('click', function(e){ 183 "use strict"; 184 jQuery('body').addClass('pushy-active').css('overflow', 'hidden'); 185 jQuery('.site-overlay').fadeIn('fast'); 186 e.preventDefault(); 187 return false; 188 }); 189 jQuery('.pushy .close-pushy,.site-overlay').on('click', function(e){ 190 jQuery('body').removeClass('pushy-active').css('overflow', 'visible'); 191 jQuery('.site-overlay').fadeOut('fast'); 192 e.preventDefault(); 193 return false; 194 }); 195 196 // Side menu widgets button 197 jQuery('.sidebar_outer_widgets_button').on('click', function(e){ 198 "use strict"; 199 jQuery('.sidebar_outer_widgets').slideToggle(); 200 e.preventDefault(); 201 return false; 202 }); 203 204 // Add arrows in responsive menu 205 jQuery('.menu_main_responsive .menu-item-has-children > a, .menu_side_responsive .menu-item-has-children > a, .menu_pushy_nav_area .menu-item-has-children > a').prepend('<span class="open_child_menu"></span>'); 206 207 // Submenu click handler for the responsive menu 208 jQuery('.menu_main_responsive, .menu_side_responsive, .menu_pushy_nav_area').on('click', 'li a,li a .open_child_menu', function(e) { 209 "use strict"; 210 var is_menu_main = jQuery(this).parents('.menu_main_responsive').length > 0; 211 var $a = jQuery(this).hasClass('open_child_menu') ? jQuery(this).parent() : jQuery(this); 212 if ((!is_menu_main || jQuery('body').hasClass('responsive_menu')) && $a.parent().hasClass('menu-item-has-children')) { 213 if ($a.siblings('ul:visible').length > 0) 214 $a.siblings('ul').slideUp().parent().removeClass('opened'); 215 else { 216 jQuery(this).parents('li').siblings('li').find('ul:visible').slideUp().parent().removeClass('opened'); 217 $a.siblings('ul').slideDown().parent().addClass('opened'); 218 } 219 } 220 // Ignore link for parent menu items 221 if (jQuery(this).hasClass('open_child_menu') || $a.attr('href')=='#') { 222 e.preventDefault(); 223 return false; 224 } 225 }); 226 227 // Init superfish menus 228 writer_ancora_init_sfmenu('.menu_main_nav_area ul#menu_main, ul#menu_user, ul#menu_side'); 229 230 // Slide effect for main menu 231 if (WRITER_ANCORA_STORAGE['menu_slider']) { 232 jQuery('#menu_main').spasticNav({ 233 color: WRITER_ANCORA_STORAGE['accent2_color'] 234 }); 235 } 236 237 // Show table of contents for the current page 238 if (WRITER_ANCORA_STORAGE['toc_menu'] != 'no') { 239 writer_ancora_build_page_toc(); 240 } 241 242 // One page mode for menu links (scroll to anchor) 243 jQuery('#toc, ul#menu_main li, ul#menu_user li, ul#menu_side li, ul#menu_footer li, ul#menu_pushy li').on('click', 'a', function(e) { 244 "use strict"; 245 var href = jQuery(this).attr('href'); 246 if (href===undefined) return; 247 var pos = href.indexOf('#'); 248 if (pos < 0 || href.length == 1) return; 249 if (jQuery(href.substr(pos)).length > 0) { 250 var loc = window.location.href; 251 var pos2 = loc.indexOf('#'); 252 if (pos2 > 0) loc = loc.substring(0, pos2); 253 var now = pos==0; 254 if (!now) now = loc == href.substring(0, pos); 255 if (now) { 256 writer_ancora_document_animate_to(href.substr(pos)); 257 writer_ancora_document_set_location(pos==0 ? loc + href : href); 258 e.preventDefault(); 259 return false; 260 } 261 } 262 }); 263 264 265 // Store height of the top and side panels 266 WRITER_ANCORA_STORAGE['top_panel_height'] = 0; 267 WRITER_ANCORA_STORAGE['side_panel_height'] = 0; 268 269 270 // Pagination 271 //---------------------------------------------- 272 273 // Page navigation (style slider) 274 jQuery('.pager_cur').on('click', function(e) { 275 "use strict"; 276 jQuery('.pager_slider').slideDown(300, function() { 277 writer_ancora_init_shortcodes(jQuery('.pager_slider').eq(0)); 278 }); 279 e.preventDefault(); 280 return false; 281 }); 282 283 284 // View More button 285 jQuery('#viewmore_link').on('click', function(e) { 286 "use strict"; 287 if (!WRITER_ANCORA_STORAGE['viewmore_busy'] && !jQuery(this).hasClass('viewmore_empty')) { 288 jQuery(this).parent().addClass('loading'); 289 WRITER_ANCORA_STORAGE['viewmore_busy'] = true; 290 jQuery.post(WRITER_ANCORA_STORAGE['ajax_url'], { 291 action: 'view_more_posts', 292 nonce: WRITER_ANCORA_STORAGE['ajax_nonce'], 293 page: +WRITER_ANCORA_STORAGE['viewmore_page'] + 1, 294 data: WRITER_ANCORA_STORAGE['viewmore_data'], 295 vars: WRITER_ANCORA_STORAGE['viewmore_vars'] 296 }).done(function(response) { 297 "use strict"; 298 var rez = {};
299 try { 300 rez = JSON.parse(response); 301 } catch (e) { 302 rez = { error: WRITER_ANCORA_STORAGE['ajax_error'] }; 303 console.log(response); 304 } 305 jQuery('#viewmore_link').parent().removeClass('loading'); 306 WRITER_ANCORA_STORAGE['viewmore_busy'] = false; 307 if (rez.error === '') { 308 var posts_container = jQuery('.content').eq(0); 309 if (posts_container.find('.isotope_wrap').length > 0) posts_container = posts_container.find('.isotope_wrap').eq(0); 310 if (posts_container.hasClass('isotope_wrap')) { 311 posts_container.data('last-width', 0).append(rez.data); 312 WRITER_ANCORA_STORAGE['isotope_init_counter'] = 0; 313 writer_ancora_init_appended_isotope(posts_container, rez.filters); 314 } else 315 jQuery('#viewmore').before(rez.data); 316 317 WRITER_ANCORA_STORAGE['viewmore_page']++; 318 if (rez.no_more_data==1) { 319 jQuery('#viewmore_link').addClass('viewmore_empty').parent().hide(); 320 } 321 322 writer_ancora_init_post_formats(); 323 writer_ancora_init_shortcodes(posts_container); 324 writer_ancora_scroll_actions(); 325 } 326 }); 327 } 328 e.preventDefault(); 329 return false; 330 }); 331 332 333 // Woocommerce 334 //---------------------------------------------- 335 336 // Change display mode 337 jQuery('.woocommerce,.woocommerce-page').on('click', '.mode_buttons a', function(e) { 338 "use strict"; 339 var mode = jQuery(this).hasClass('woocommerce_thumbs') ? 'thumbs' : 'list'; 340 writer_ancora_set_cookie('writer_ancora_shop_mode', mode, 365); 341 jQuery(this).siblings('input').val(mode).parents('form').get(0).submit(); 342 e.preventDefault(); 343 return false; 344 }); 345 // Added to cart 346 jQuery('body').bind('added_to_cart', function() { 347 "use strict"; 348 // Update amount on the cart button 349 var total = jQuery('.menu_user_cart .total .amount').text(); 350 if (total != undefined) { 351 jQuery('.top_panel_cart_button .cart_summa').text(total); 352 } 353 // Update count items on the cart button 354 var cnt = 0; 355 jQuery('.menu_user_cart .cart_list li').each(function() { 356 var q = jQuery(this).find('.quantity').html().split(' ', 2); 357 if (!isNaN(q[0])) 358 cnt += Number(q[0]); 359 }); 360 var items = jQuery('.top_panel_cart_button .cart_items').text().split(' '); 361 items[0] = cnt; 362 jQuery('.top_panel_cart_button .cart_items').text(items[0]+' '+items[1]); 363 // Update data-attr on button 364 jQuery('.top_panel_cart_button').data({ 365 'items': cnt ? cnt : 0, 366 'summa': total ? total : 0 367 }); 368 }); 369 // Show cart 370 jQuery('.top_panel_middle .top_panel_cart_button').on('click', function(e) { 371 "use strict"; 372 jQuery(this).siblings('.sidebar_cart').slideToggle(); 373 e.preventDefault(); 374 return false; 375 }); 376 377 // Add buttons to quantity on first run 378 if (jQuery('.woocommerce div.quantity .q_inc,.woocommerce-page div.quantity .q_inc').length == 0) { 379 var woocomerce_inc_dec = '<span class="q_inc"></span><span class="q_dec"></span>'; 380 jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').append(woocomerce_inc_dec); 381 jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').on('click', '>span', function(e) { 382 woocomerce_inc_dec_click(jQuery(this)); 383 e.preventDefault(); 384 return false; 385 }); 386 } 387// Add buttons to quantity after the cart is updated 388 jQuery(document.body).on('updated_wc_div', function() { 389 if (jQuery('.woocommerce div.quantity .q_inc,.woocommerce-page div.quantity .q_inc').length == 0) { 390 jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').append(woocomerce_inc_dec); 391 jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').on('click', '>span', function(e) { 392 woocomerce_inc_dec_click(jQuery(this)); 393 e.preventDefault(); 394 return false; 395 }); 396 } 397 });
398 // Inc/Dec quantity on buttons inc/dec 399 function woocomerce_inc_dec_click(button) { 400 var f = button.siblings( 'input' ); 401 if (button.hasClass( 'q_inc' )) { 402 f.val( ( f.val() == '' ? 0 : parseInt( f.val(), 10 ) ) + 1 ).trigger( 'change' ); 403 } else { 404 f.val( Math.max( 0, ( f.val() == '' ? 0 : parseInt( f.val(), 10 ) ) - 1 ) ).trigger( 'change' ); 405 } 406 } 407 408 409 // Popup login and register windows 410 //---------------------------------------------- 411 jQuery('.popup_link').addClass('inited').on('click', function(e){ 412 var popup = jQuery(jQuery(this).attr('href')); 413 if (popup.length === 1) { 414 writer_ancora_hide_popup(jQuery(popup.hasClass('popup_login') ? '.popup_registration' : '.popup_login' )); 415 writer_ancora_toggle_popup(popup); 416 } 417 e.preventDefault(); 418 return false; 419 }); 420 jQuery('.popup_wrap').on('click', '.popup_close', function(e){ 421 var popup = jQuery(this).parent(); 422 if (popup.length === 1) { 423 writer_ancora_hide_popup(popup); 424 } 425 e.preventDefault(); 426 return false; 427 }); 428 429 430 431 432 // Bookmarks 433 //---------------------------------------------- 434 435 // Add bookmark 436 jQuery('.bookmarks_add').on('click', function(e) { 437 "use strict"; 438 var title = window.document.title.split('|')[0]; 439 var url = window.location.href; 440 var list = jQuery.cookie('writer_ancora_bookmarks'); 441 var exists = false; 442 if (list) { 443 try { 444 list = JSON.parse(list); 445 } catch (e) {} 446 if (list.length) { 447 for (var i=0; i<list.length; i++) { 448 if (list[i].url == url) { 449 exists = true; 450 break; 451 } 452 } 453 } 454 } else 455 list = new Array(); 456 if (!exists) { 457 var message_popup = writer_ancora_message_dialog('<label for="bookmark_title">'+WRITER_ANCORA_STORAGE['strings']['bookmark_title']+'</label><br><input type="text" id="bookmark_title" name="bookmark_title" value="'+title+'">', WRITER_ANCORA_STORAGE['strings']['bookmark_add'], null, 458 function(btn, popup) { 459 "use strict"; 460 if (btn != 1) return; 461 title = message_popup.find('#bookmark_title').val(); 462 list.push({title: title, url: url}); 463 jQuery('.bookmarks_list').append('<li><a href="'+url+'" class="bookmarks_item">'+title+'<span class="bookmarks_delete icon-cancel" title="'+WRITER_ANCORA_STORAGE['strings']['bookmark_del']+'"></span></a></li>'); 464 jQuery.cookie('writer_ancora_bookmarks', JSON.stringify(list), {expires: 365, path: '/'}); 465 setTimeout(function () {writer_ancora_message_success(WRITER_ANCORA_STORAGE['strings']['bookmark_added'], WRITER_ANCORA_STORAGE['strings']['bookmark_add']);}, WRITER_ANCORA_STORAGE['message_timeout']/4); 466 }); 467 } else 468 writer_ancora_message_warning(WRITER_ANCORA_STORAGE['strings']['bookmark_exists'], WRITER_ANCORA_STORAGE['strings']['bookmark_add']); 469 e.preventDefault(); 470 return false; 471 }); 472 473 // Delete bookmark 474 jQuery('.bookmarks_list').on('click', '.bookmarks_delete', function(e) { 475 "use strict"; 476 var idx = jQuery(this).parent().index(); 477 var list = jQuery.cookie('writer_ancora_bookmarks'); 478 if (list) { 479 try { 480 list = JSON.parse(list); 481 } catch (e) {} 482 if (list.length) { 483 list.splice(idx, 1); 484 jQuery.cookie('writer_ancora_bookmarks', JSON.stringify(list), {expires: 365, path: '/'}); 485 } 486 } 487 jQuery(this).parent().remove(); 488 e.preventDefault(); 489 return false; 490 }); 491 492 // Checkbox with "I agree..." 493 if (jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited)').length > 0) { 494 jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited)') 495 .addClass('inited') 496 .on('change', function(e) { 497 if (jQuery(this).get(0).checked) 498 jQuery(this).parents('form').find('button,input[type="submit"]').removeAttr('disabled'); 499 else 500 jQuery(this).parents('form').find('button,input[type="submit"]').attr('disabled', 'disabled'); 501 }).trigger('change'); 502 } 503 504 505 // Other settings 506 //------------------------------------ 507 508 // Scroll to top button 509 jQuery('.scroll_to_top').on('click', function(e) { 510 "use strict"; 511 jQuery('html,body').animate({ 512 scrollTop: 0 513 }, 'slow'); 514 e.preventDefault(); 515 return false;
516 }); 517 518 // Show system message 519 writer_ancora_show_system_message(); 520 521 // Init post format specific scripts 522 writer_ancora_init_post_formats(); 523 524 // Init shortcodes scripts 525 writer_ancora_init_shortcodes(jQuery('body').eq(0)); 526 527 // Init hidden elements (if exists) 528 if (window.writer_ancora_init_hidden_elements) writer_ancora_init_hidden_elements(jQuery('body').eq(0)); 529 530} //end ready 531 532 533 534 535// Scroll actions 536//============================================== 537 538// Do actions when page scrolled 539function writer_ancora_scroll_actions() { 540 "use strict"; 541 542 // Call skin specific action (if exists) 543 //---------------------------------------------- 544 if (window.writer_ancora_skin_scroll_actions) writer_ancora_skin_scroll_actions(); 545 546 // Call theme specific action (if exists) 547 //---------------------------------------------- 548 if (window.writer_ancora_theme_scroll_actions) writer_ancora_theme_scroll_actions(); 549 550 var scroll_offset = jQuery(window).scrollTop(); 551 var scroll_to_top_button = jQuery('.scroll_to_top'); 552 var adminbar_height = Math.max(0, jQuery('#wpadminbar').height()); 553 554 if (WRITER_ANCORA_STORAGE['top_panel_height'] == 0) WRITER_ANCORA_STORAGE['top_panel_height'] = jQuery('.top_panel_wrap').height(); 555 556 // Scroll to top button show/hide 557 if (scroll_offset > WRITER_ANCORA_STORAGE['top_panel_height']) 558 scroll_to_top_button.addClass('show'); 559 else 560 scroll_to_top_button.removeClass('show'); 561 562 // Fix/unfix top panel 563 if (!jQuery('body').hasClass('responsive_menu') && WRITER_ANCORA_STORAGE['menu_fixed']) { 564 var slider_height = 0; 565 if (jQuery('.top_panel_below .slider_wrap').length > 0) { 566 slider_height = jQuery('.top_panel_below .slider_wrap').height(); 567 if (slider_height < 10) { 568 slider_height = jQuery('.slider_wrap').hasClass('.slider_fullscreen') ? jQuery(window).height() : WRITER_ANCORA_STORAGE['slider_height']; 569 } 570 } 571 if (scroll_offset <= slider_height + WRITER_ANCORA_STORAGE['top_panel_height']) { 572 if (jQuery('body').hasClass('top_panel_fixed')) { 573 jQuery('body').removeClass('top_panel_fixed'); 574 } 575 } else if (scroll_offset > slider_height + WRITER_ANCORA_STORAGE['top_panel_height']) { 576 if (!jQuery('body').hasClass('top_panel_fixed') && jQuery(document).height() > jQuery(window).height()*1.5) { 577 jQuery('.top_panel_fixed_wrap').height(WRITER_ANCORA_STORAGE['top_panel_height']); 578 jQuery('.top_panel_wrap').css('marginTop', '-150px').animate({'marginTop': 0}, 500); 579 jQuery('body').addClass('top_panel_fixed'); 580 } 581 } 582 } 583 584 // Fix/unfix side panel 585 if (jQuery('.sidebar_outer').length > 0) { 586 if (WRITER_ANCORA_STORAGE['side_panel_height'] == 0) 587 WRITER_ANCORA_STORAGE['side_panel_height'] = jQuery('.sidebar_outer_logo_wrap').outerHeight() + jQuery('.sidebar_outer_menu').outerHeight() + jQuery('.sidebar_outer_widgets').outerHeight(); 588 if (scroll_offset + jQuery(window).height() > WRITER_ANCORA_STORAGE['side_panel_height'] + 100) { 589 if (jQuery('.sidebar_outer').css('position')!=='fixed') { 590 jQuery('.sidebar_outer').css({ 591 'position': 'fixed', 592 'top': Math.min(0, jQuery(window).height() - WRITER_ANCORA_STORAGE['side_panel_height'] - 100) + 'px', 593 }); 594 } 595 } else { 596 if (jQuery('.sidebar_outer').css('position')=='fixed') { 597 jQuery('.sidebar_outer').css({ 598 'position': 'absolute', 599 'top': 0 600 }); 601 } 602 } 603 } 604 605 // TOC current items 606 jQuery('#toc .toc_item').each(function() { 607 "use strict"; 608 var id = jQuery(this).find('a').attr('href'); 609 var pos = id.indexOf('#'); 610 if (pos < 0 || id.length == 1) return; 611 var loc = window.location.href; 612 var pos2 = loc.indexOf('#'); 613 if (pos2 > 0) loc = loc.substring(0, pos2); 614 var now = pos==0; 615 if (!now) now = loc == href.substring(0, pos); 616 if (!now) return; 617 var off = jQuery(id).offset().top; 618 var id_next = jQuery(this).next().find('a').attr('href'); 619 var off_next = id_next ? jQuery(id_next).offset().top : 1000000; 620 if (off < scroll_offset + jQuery(window).height()*0.8 && scroll_offset + WRITER_ANCORA_STORAGE['top_panel_height'] < off_next) 621 jQuery(this).addClass('current'); 622 else 623 jQuery(this).removeClass('current'); 624 }); 625 626 // Infinite pagination 627 writer_ancora_infinite_scroll() 628 629 // Parallax scroll 630 writer_ancora_parallax_scroll(); 631 632 // Scroll actions for shortcodes 633 writer_ancora_animation_shortcodes(); 634} 635 636 637// Infinite Scroll 638function writer_ancora_infinite_scroll() { 639 "use strict"; 640 if (WRITER_ANCORA_STORAGE['viewmore_busy']) return; 641 var infinite = jQuery('#viewmore.pagination_infinite'); 642 if (infinite.length > 0) { 643 var viewmore = infinite.find('#viewmore_link:not(.viewmore_empty)'); 644 if (viewmore.length > 0) { 645 if (jQuery(window).scrollTop() + jQuery(window).height() + 100 >= infinite.offset().top) { 646 viewmore.eq(0).trigger('click'); 647 } 648 } 649 } 650} 651 652// Parallax scroll 653function writer_ancora_parallax_scroll(){ 654 "use strict"; 655 jQuery('.sc_parallax').each(function(){ 656 var windowHeight = jQuery(window).height(); 657 var scrollTops = jQuery(window).scrollTop(); 658 var offsetPrx = Math.max(jQuery(this).offset().top, windowHeight); 659 if ( offsetPrx <= scrollTops + windowHeight ) { 660 var speed = Number(jQuery(this).data('parallax-speed')); 661 var xpos = jQuery(this).data('parallax-x-pos'); 662 var ypos = Math.round((offsetPrx - scrollTops - windowHeight) * speed + (speed < 0 ? windowHeight*speed : 0)); 663 jQuery(this).find('.sc_parallax_content').css('backgroundPosition', xpos+' '+ypos+'px'); 664 // Uncomment next line if you want parallax video (else - video position is static) 665 jQuery(this).find('div.sc_video_bg').css('top', ypos+'px'); 666 } 667 }); 668} 669 670 671 672 673 674// Resize actions 675//============================================== 676 677// Do actions when page scrolled 678function writer_ancora_resize_actions() { 679 "use strict"; 680 681 // Call skin specific action (if exists) 682 //---------------------------------------------- 683 if (window.writer_ancora_skin_resize_actions) writer_ancora_skin_resize_actions(); 684 685 // Call theme specific action (if exists) 686 //---------------------------------------------- 687 if (window.writer_ancora_theme_resize_actions) writer_ancora_theme_resize_actions(); 688 689 writer_ancora_responsive_menu(); 690 writer_ancora_video_dimensions(); 691 writer_ancora_resize_video_background(); 692 writer_ancora_resize_fullscreen_slider(); 693 writer_ancora_resize_alter_portfolio(); 694} 695 696 697// Check window size and do responsive menu 698function writer_ancora_responsive_menu() { 699 "use strict"; 700 if (writer_ancora_is_responsive_need(WRITER_ANCORA_STORAGE['menu_responsive'])) { 701 if (!jQuery('body').hasClass('responsive_menu')) { 702 jQuery('body').removeClass('top_panel_fixed').addClass('responsive_menu'); 703 if (jQuery('body').hasClass('menu_relayout')) 704 jQuery('body').removeClass('menu_relayout'); 705 if (jQuery('ul.menu_main_nav').hasClass('inited')) { 706 jQuery('ul.menu_main_nav').removeClass('inited').superfish('destroy'); 707 } 708 if (jQuery('ul.menu_side_nav').hasClass('inited')) { 709 jQuery('ul.menu_side_nav').removeClass('inited').superfish('destroy'); 710 } 711 } 712 } else { 713 if (jQuery('body').hasClass('responsive_menu')) { 714 jQuery('body').removeClass('responsive_menu'); 715 jQuery('.menu_main_responsive').hide(); 716 jQuery('.menu_side_responsive').hide(); 717 writer_ancora_init_sfmenu('ul.menu_main_nav,ul.menu_side_nav'); 718 jQuery('.menu_main_nav_area').show(); 719 } 720 if (writer_ancora_is_responsive_need(WRITER_ANCORA_STORAGE['menu_relayout'])) 721 jQuery('body').addClass('menu_relayout'); 722 else if (jQuery('body').hasClass('menu_relayout')) 723 jQuery('body').removeClass('menu_relayout'); 724 } 725 if (!jQuery('.top_panel_wrap').hasClass('menu_show')) jQuery('.top_panel_wrap').addClass('menu_show'); 726 // Show widgets block on the sidebar outer (if sidebar not responsive and widgets are hidden) 727 if (jQuery('.sidebar_outer').length > 0 && jQuery('.sidebar_outer').css('position')=='absolute' && jQuery('.sidebar_outer_widgets:visible').length==0) 728 jQuery('.sidebar_outer_widgets').show(); 729} 730 731 732// Check if responsive menu need 733function writer_ancora_is_responsive_need(max_width) { 734 "use strict"; 735 var rez = false;
736 if (max_width > 0) { 737 var w = window.innerWidth; 738 if (w == undefined) { 739 w = jQuery(window).width()+(jQuery(window).height() < jQuery(document).height() || jQuery(window).scrollTop() > 0 ? 16 : 0); 740 } 741 rez = max_width > w; 742 } 743 return rez; 744} 745 746 747// Fit video frames to document width 748function writer_ancora_video_dimensions() { 749 "use strict"; 750 jQuery('.sc_video_frame').each(function() { 751 "use strict"; 752 var frame = jQuery(this).eq(0); 753 var player = frame.parent(); 754 var ratio = (frame.data('ratio') ? frame.data('ratio').split(':') : (frame.find('[data-ratio]').length>0 ? frame.find('[data-ratio]').data('ratio').split(':') : [16,9])); 755 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 756 var w_attr = frame.data('width'); 757 var h_attr = frame.data('height'); 758 if (!w_attr || !h_attr) return; 759 var percent = (''+w_attr).substr(-1)=='%'; 760 w_attr = parseInt(w_attr); 761 h_attr = parseInt(h_attr); 762 var w_real = Math.min(percent || frame.parents('.columns_wrap').length>0 ? 10000 : w_attr, frame.parents('div,article').width()), 763 h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr); 764 if (parseInt(frame.attr('data-last-width'))==w_real) return; 765 if (percent) { 766 frame.height(h_real); 767 } else { 768 frame.css({'width': w_real+'px', 'height': h_real+'px'}); 769 } 770 frame.attr('data-last-width', w_real); 771 }); 772 jQuery('video.sc_video,video.wp-video-shortcode').each(function() { 773 "use strict"; 774 var video = jQuery(this).eq(0); 775 var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]); 776 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 777 var mejs_cont = video.parents('.mejs-video'); 778 var frame = video.parents('.sc_video_frame'); 779 var w_attr = frame.length>0 ? frame.data('width') : video.data('width'); 780 var h_attr = frame.length>0 ? frame.data('height') : video.data('height'); 781 if (!w_attr || !h_attr) { 782 w_attr = video.attr('width'); 783 h_attr = video.attr('height'); 784 if (!w_attr || !h_attr) return; 785 video.data({'width': w_attr, 'height': h_attr}); 786 } 787 var percent = (''+w_attr).substr(-1)=='%'; 788 w_attr = parseInt(w_attr); 789 h_attr = parseInt(h_attr); 790 var w_real = Math.round(mejs_cont.length > 0 ? Math.min(percent ? 10000 : w_attr, mejs_cont.parents('div,article').width()) : video.width()), 791 h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr); 792 if (parseInt(video.attr('data-last-width'))==w_real) return; 793 if (mejs_cont.length > 0 && mejs) { 794 writer_ancora_set_mejs_player_dimensions(video, w_real, h_real); 795 } 796 if (percent) { 797 video.height(h_real); 798 } else { 799 video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'}); 800 } 801 video.attr('data-last-width', w_real); 802 }); 803 jQuery('video.sc_video_bg').each(function() { 804 "use strict"; 805 var video = jQuery(this).eq(0); 806 var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]); 807 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 808 var mejs_cont = video.parents('.mejs-video'); 809 var container = mejs_cont.length>0 ? mejs_cont.parent() : video.parent(); 810 var w = container.width(); 811 var h = container.height(); 812 var w1 = Math.ceil(h*ratio); 813 var h1 = Math.ceil(w/ratio); 814 if (video.parents('.sc_parallax').length > 0) { 815 var windowHeight = jQuery(window).height(); 816 var speed = Number(video.parents('.sc_parallax').data('parallax-speed')); 817 var h_add = Math.ceil(Math.abs((windowHeight-h)*speed)); 818 if (h1 < h + h_add) { 819 h1 = h + h_add; 820 w1 = Math.ceil(h1 * ratio); 821 } 822 } 823 if (h1 < h) { 824 h1 = h; 825 w1 = Math.ceil(h1 * ratio); 826 } 827 if (w1 < w) { 828 w1 = w; 829 h1 = Math.ceil(w1 / ratio); 830 } 831 var l = Math.round((w1-w)/2); 832 var t = Math.round((h1-h)/2); 833 if (parseInt(video.attr('data-last-width'))==w1) return; 834 if (mejs_cont.length > 0) { 835 writer_ancora_set_mejs_player_dimensions(video, w1, h1); 836 mejs_cont.css({ 837 'top': -t+'px' 838 }); 839 } else 840 video.css({ 841 'top': -t+'px' 842 }); 843 video.attr({'width': w1, 'height': h1, 'data-last-width':w1}).css({'width':w1+'px', 'height':h1+'px'}); 844 if (video.css('opacity')==0) video.animate({'opacity': 1}, 3000); 845 }); 846 jQuery('iframe').each(function() { 847 "use strict"; 848 var iframe = jQuery(this).eq(0); 849 var ratio = (iframe.data('ratio')!=undefined ? iframe.data('ratio').split(':') : (iframe.find('[data-ratio]').length>0 ? iframe.find('[data-ratio]').data('ratio').split(':') : [16,9])); 850 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 851 var w_attr = iframe.attr('width'); 852 var h_attr = iframe.attr('height'); 853 var frame = iframe.parents('.sc_video_frame'); 854 if (frame.length > 0) { 855 w_attr = frame.data('width'); 856 h_attr = frame.data('height'); 857 } 858 if (!w_attr || !h_attr) { 859 return; 860 } 861 var percent = (''+w_attr).substr(-1)=='%'; 862 w_attr = parseInt(w_attr); 863 h_attr = parseInt(h_attr); 864 var w_real = frame.length > 0 ? frame.width() : iframe.width(), 865 h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr); 866 if (parseInt(iframe.attr('data-last-width'))==w_real) return; 867 iframe.css({'width': w_real+'px', 'height': h_real+'px'}); 868 }); 869} 870 871// Resize fullscreen video background 872function writer_ancora_resize_video_background() { 873 "use strict"; 874 var bg = jQuery('.video_bg'); 875 if (bg.length < 1) 876 return; 877 if (WRITER_ANCORA_STORAGE['media_elements_enabled'] && bg.find('.mejs-video').length == 0) { 878 setTimeout(writer_ancora_resize_video_background, 100); 879 return; 880 } 881 var video = bg.find('video'); 882 var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]); 883 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 884 var w = bg.width(); 885 var h = bg.height(); 886 var w1 = Math.ceil(h*ratio); 887 var h1 = Math.ceil(w/ratio); 888 if (h1 < h) { 889 h1 = h; 890 w1 = Math.ceil(h1 * ratio); 891 } 892 if (w1 < w) { 893 w1 = w; 894 h1 = Math.ceil(w1 / ratio); 895 } 896 var l = Math.round((w1-w)/2); 897 var t = Math.round((h1-h)/2); 898 if (bg.find('.mejs-container').length > 0) { 899 writer_ancora_set_mejs_player_dimensions(bg.find('video'), w1, h1);
900 bg.find('.mejs-container').css({'left': -l+'px', 'top': -t+'px'}); 901 } else 902 bg.find('video').css({'left': -l+'px', 'top': -t+'px'}); 903 bg.find('video').attr({'width': w1, 'height': h1}).css({'width':w1+'px', 'height':h1+'px'}); 904} 905 906// Set Media Elements player dimensions 907function writer_ancora_set_mejs_player_dimensions(video, w, h) { 908 "use strict"; 909 if (mejs) { 910 for (var pl in mejs.players) { 911 if (mejs.players[pl].media.src == video.attr('src')) { 912 if (mejs.players[pl].media.setVideoSize) { 913 mejs.players[pl].media.setVideoSize(w, h); 914 } 915 mejs.players[pl].setPlayerSize(w, h); 916 mejs.players[pl].setControlsSize(); 917 } 918 } 919 } 920} 921 922// Resize Fullscreen Slider 923function writer_ancora_resize_fullscreen_slider() { 924 "use strict"; 925 var slider_wrap = jQuery('.slider_wrap.slider_fullscreen'); 926 if (slider_wrap.length < 1) 927 return; 928 var slider = slider_wrap.find('.sc_slider_swiper'); 929 if (slider.length < 1) 930 return; 931 var h = jQuery(window).height() - jQuery('#wpadminbar').height() - (jQuery('body').hasClass('top_panel_above') && !jQuery('body').hasClass('.top_panel_fixed') ? jQuery('.top_panel_wrap').height() : 0); 932 slider.height(h); 933} 934 935// Resize Alter portfolio elements 936function writer_ancora_resize_alter_portfolio() { 937 "use strict"; 938 var wrap = jQuery('.isotope_wrap.inited'); 939 if (wrap.length==0) return; 940 wrap.each(function() { 941 "use strict"; 942 var alter = jQuery(this).find('.post_item_alter'); 943 if (alter.length==0) return; 944 var single = alter.find('.post_featured img[data-alter-items-w="1"]').eq(0); 945 if (single.length != 1) return; 946 var w_real = single.width(); 947 var h_real = single.height(); 948 var space = Number(single.data('alter-item-space')); 949 var relayout = false; 950 alter.find('.post_featured img').each(function() { 951 "use strict"; 952 var items_w = Number(jQuery(this).data('alter-items-w')); 953 var items_h = Number(jQuery(this).data('alter-items-h')); 954 if (items_h > 1) { 955 jQuery(this).height(Math.round(items_h*h_real+(items_h-1)*(space+1))); 956 relayout = true; 957 } else if (items_w > 1) { 958 jQuery(this).height(h_real); 959 relayout = true; 960 } 961 }); 962 if (relayout) { 963 jQuery(this).isotope('layout'); 964 } 965 }); 966} 967 968 969 970 971 972// Navigation 973//============================================== 974 975// Init Superfish menu 976function writer_ancora_init_sfmenu(selector) { 977 "use strict"; 978 jQuery(selector).show().each(function() { 979 if (writer_ancora_is_responsive_need() && (jQuery(this).attr('id')=='menu_main' || jQuery(this).attr('id')=='menu_side')) return; 980 jQuery(this).addClass('inited').superfish({ 981 delay: 500, 982 animation: { 983 opacity: 'show' 984 }, 985 animationOut: { 986 opacity: 'hide' 987 }, 988 speed: WRITER_ANCORA_STORAGE['css_animation'] ? 500 : (WRITER_ANCORA_STORAGE['menu_slider'] ? 300 : 200), 989 speedOut: WRITER_ANCORA_STORAGE['css_animation'] ? 500 : (WRITER_ANCORA_STORAGE['menu_slider'] ? 300 : 200),
990 autoArrows: false, 991 dropShadows: false, 992 onBeforeShow: function(ul) { 993 if (jQuery(this).parents("ul").length > 1){ 994 var w = jQuery(window).width(); 995 var par_offset = jQuery(this).parents("ul").offset().left; 996 var par_width = jQuery(this).parents("ul").outerWidth(); 997 var ul_width = jQuery(this).outerWidth(); 998 if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0) 999 jQuery(this).addClass('submenu_left'); 1000 else 1001 jQuery(this).removeClass('submenu_left'); 1002 } 1003 if (WRITER_ANCORA_STORAGE['css_animation']) { 1004 jQuery(this).removeClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_out']); 1005 jQuery(this).addClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_in']); 1006 } 1007 }, 1008 onBeforeHide: function(ul) { 1009 if (WRITER_ANCORA_STORAGE['css_animation']) { 1010 jQuery(this).removeClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_in']); 1011 jQuery(this).addClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_out']); 1012 } 1013 } 1014 }); 1015 }); 1016} 1017 1018 1019// Build page TOC from the tag's id 1020function writer_ancora_build_page_toc() { 1021 "use strict"; 1022 var toc = '', toc_count = 0; 1023 jQuery('[id^="toc_"],.sc_anchor').each(function(idx) { 1024 "use strict"; 1025 var obj = jQuery(this); 1026 var id = obj.attr('id'); 1027 var url = obj.data('url'); 1028 var icon = obj.data('icon'); 1029 if (!icon) icon = 'icon-circle-dot'; 1030 var title = obj.attr('title'); 1031 var description = obj.data('description'); 1032 var separator = obj.data('separator'); 1033 toc_count++; 1034 toc += '<div class="toc_item'+(separator=='yes' ? ' toc_separator' : '')+'">' 1035 +(description ? '<div class="toc_description">'+description+'</div>' : '') 1036 +'<a href="'+(url ? url : '#'+id)+'" class="toc_icon'+(title ? ' with_title' : '')+' '+icon+'">'+(title ? '<span class="toc_title">'+title+'</span>' : '')+'</a>' 1037 +'</div>'; 1038 }); 1039 if (toc_count > (WRITER_ANCORA_STORAGE['toc_menu_home'] ? 1 : 0) + (WRITER_ANCORA_STORAGE['toc_menu_top'] ? 1 : 0)) { 1040 if (jQuery('#toc').length > 0) 1041 jQuery('#toc .toc_inner').html(toc); 1042 else 1043 jQuery('body').append('<div id="toc" class="toc_'+WRITER_ANCORA_STORAGE['toc_menu']+'"><div class="toc_inner">'+toc+'</div></div>'); 1044 } 1045} 1046 1047 1048// Show current page title on the responsive menu button 1049function writer_ancora_show_current_menu_item(menu, button) { 1050 "use strict"; 1051 menu.find('a').each(function () { 1052 var menu_link = jQuery(this); 1053 if (menu_link.text() == "") { 1054 return; 1055 } 1056 if (menu_link.attr('href') == window.location.href) 1057 button.text(menu_link.text()); 1058 }); 1059} 1060 1061 1062 1063// Isotope 1064//===================================================== 1065 1066// First init isotope containers 1067function writer_ancora_init_isotope() { 1068 "use strict"; 1069 1070 var all_images_complete = true; 1071 1072 // Check if all images in isotope wrapper are loaded 1073 jQuery('.isotope_wrap:not(.inited)').each(function () { 1074 "use strict"; 1075 all_images_complete = all_images_complete && writer_ancora_check_images_complete(jQuery(this)); 1076 }); 1077 // Wait for images loading 1078 if (!all_images_complete && WRITER_ANCORA_STORAGE['isotope_init_counter']++ < 30) { 1079 setTimeout(writer_ancora_init_isotope, 200); 1080 return; 1081 } 1082 1083 // Isotope filters handler 1084 jQuery('.isotope_filters:not(.inited)').addClass('inited').on('click', 'a', function(e) { 1085 "use strict"; 1086 jQuery(this).parents('.isotope_filters').find('a').removeClass('active'); 1087 jQuery(this).addClass('active'); 1088 1089 var selector = jQuery(this).data('filter'); 1090 jQuery(this).parents('.isotope_filters').siblings('.isotope_wrap').eq(0).isotope({ 1091 filter: selector 1092 }); 1093 1094 if (selector == '*') 1095 jQuery('#viewmore_link').fadeIn(); 1096 else 1097 jQuery('#viewmore_link').fadeOut(); 1098 1099 e.preventDefault(); 1100 return false; 1101 }); 1102 1103 // Init isotope script 1104 jQuery('.isotope_wrap:not(.inited)').each(function() { 1105 "use strict"; 1106 1107 var isotope_container = jQuery(this); 1108 1109 // Init shortcodes 1110 writer_ancora_init_shortcodes(isotope_container); 1111 1112 // If in scroll container - no init isotope 1113 if (isotope_container.parents('.sc_scroll').length > 0) { 1114 isotope_container.addClass('inited').find('.isotope_item').animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); }); 1115 return; 1116 } 1117 1118 // Init isotope with timeout 1119 setTimeout(function() { 1120 isotope_container.addClass('inited').isotope({ 1121 itemSelector: '.isotope_item', 1122 animationOptions: { 1123 duration: 750, 1124 easing: 'linear', 1125 queue: false 1126 } 1127 }); 1128 1129 // Show elements 1130 isotope_container.find('.isotope_item').animate({opacity: 1}, 200, function () { 1131 jQuery(this).addClass('isotope_item_show'); 1132 }); 1133 1134 // Resize Alter portfolio elements 1135 writer_ancora_resize_alter_portfolio(); 1136 1137 }, 500); 1138 1139 }); 1140} 1141 1142function writer_ancora_init_appended_isotope(posts_container, filters) { 1143 "use strict"; 1144 1145 if (posts_container.parents('.sc_scroll_horizontal').length > 0) return; 1146 1147 if (!writer_ancora_check_images_complete(posts_container) && WRITER_ANCORA_STORAGE['isotope_init_counter']++ < 30) { 1148 setTimeout(function() { writer_ancora_init_appended_isotope(posts_container, filters); }, 200); 1149 return; 1150 }
1151 // Add filters 1152 var flt = posts_container.siblings('.isotope_filter'); 1153 for (var i in filters) { 1154 if (flt.find('a[data-filter=".flt_'+i+'"]').length == 0) { 1155 flt.append('<a href="#" class="isotope_filters_button" data-filter=".flt_'+i+'">'+filters[i]+'</a>'); 1156 } 1157 } 1158 // Init shortcodes in added elements 1159 writer_ancora_init_shortcodes(posts_container); 1160 // Get added elements 1161 var elems = posts_container.find('.isotope_item:not(.isotope_item_show)'); 1162 // Notify isotope about added elements with timeout 1163 setTimeout(function() { 1164 posts_container.isotope('appended', elems); 1165 // Show appended elements 1166 elems.animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); }); 1167 }, 500); 1168} 1169 1170 1171 1172// Shortcodes init 1173//===================================================== 1174 1175function writer_ancora_init_shortcodes(cont) { 1176 "use strict"; 1177 1178 // Call theme specific action (if exists) 1179 if (window.writer_ancora_theme_sc_init) writer_ancora_theme_sc_init(cont); 1180 1181 // Call core shortcodes action (if exists) 1182 if (window.writer_ancora_sc_init) writer_ancora_sc_init(cont); 1183} 1184 1185function writer_ancora_animation_shortcodes() { 1186 "use strict"; 1187 if (window.writer_ancora_sc_animation) writer_ancora_sc_animation(); 1188} 1189 1190 1191 1192// Post formats init 1193//===================================================== 1194 1195function writer_ancora_init_post_formats() { 1196 "use strict"; 1197 1198 // Call theme specific action (if exists) 1199 if (window.writer_ancora_theme_init_post_formats) writer_ancora_theme_init_post_formats(); 1200 1201 // MediaElement init 1202 writer_ancora_init_media_elements(jQuery('body')); 1203 1204 // Isotope first init 1205 if (jQuery('.isotope_wrap:not(.inited)').length > 0) { 1206 WRITER_ANCORA_STORAGE['isotope_init_counter'] = 0; 1207 writer_ancora_init_isotope(); 1208 } 1209 1210 // Hover Effect 'Dir' 1211 if (jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').length > 0) { 1212 jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').each(function() { 1213 jQuery(this).addClass('inited').hoverdir(); 1214 }); 1215 } 1216 1217 // Popup init 1218 if (WRITER_ANCORA_STORAGE['popup_engine'] == 'pretty') { 1219 jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'prettyPhoto[slideshow]'); 1220 var images = jQuery("a[rel*='prettyPhoto']:not(.inited):not(.esgbox):not([data-rel*='pretty']):not([rel*='magnific']):not([data-rel*='magnific'])").addClass('inited'); 1221 try { 1222 images.prettyPhoto({ 1223 social_tools: '', 1224 theme: 'facebook', 1225 deeplinking: false 1226 }); 1227 } catch (e) {}; 1228 } else if (WRITER_ANCORA_STORAGE['popup_engine']=='magnific') { 1229 jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'magnific'); 1230 var images = jQuery("a[rel*='magnific']:not(.inited):not(.esgbox):not(.prettyphoto):not([rel*='pretty']):not([data-rel*='pretty'])").addClass('inited'); 1231 try { 1232 images.magnificPopup({ 1233 type: 'image', 1234 mainClass: 'mfp-img-mobile', 1235 closeOnContentClick: true, 1236 closeBtnInside: true, 1237 fixedContentPos: true, 1238 midClick: true, 1239 preloader: true, 1240 tLoading: WRITER_ANCORA_STORAGE['strings']['magnific_loading'], 1241 gallery:{ 1242 enabled: true 1243 }, 1244 image: { 1245 tError: WRITER_ANCORA_STORAGE['strings']['magnific_error'], 1246 verticalFit: true 1247 } 1248 }); 1249 } catch (e) {}; 1250 } 1251 1252 1253 // Add hover icon to products thumbnails 1254 jQuery(".post_item_product .product .images a.woocommerce-main-image:not(.hover_icon)").addClass('hover_icon hover_icon_view'); 1255 1256 1257 // Likes counter 1258 if (jQuery('.post_counters_likes:not(.inited)').length > 0) { 1259 jQuery('.post_counters_likes:not(.inited)') 1260 .addClass('inited') 1261 .on('click', function(e) { 1262 var button = jQuery(this); 1263 var inc = button.hasClass('enabled') ? 1 : -1; 1264 var post_id = button.data('postid'); 1265 var likes = Number(button.data('likes'))+inc; 1266 var cookie_likes = writer_ancora_get_cookie('writer_ancora_likes'); 1267 if (cookie_likes === undefined || cookie_likes===null) cookie_likes = ''; 1268 jQuery.post(WRITER_ANCORA_STORAGE['ajax_url'], { 1269 action: 'post_counter', 1270 nonce: WRITER_ANCORA_STORAGE['ajax_nonce'], 1271 post_id: post_id, 1272 likes: likes 1273 }).done(function(response) { 1274 var rez = {}; 1275 try { 1276 rez = JSON.parse(response); 1277 } catch (e) { 1278 rez = { error: WRITER_ANCORA_STORAGE['ajax_error'] }; 1279 console.log(response); 1280 } 1281 if (rez.error === '') { 1282 if (inc == 1) { 1283 var title = button.data('title-dislike'); 1284 button.removeClass('enabled').addClass('disabled'); 1285 cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ','; 1286 } else { 1287 var title = button.data('title-like'); 1288 button.removeClass('disabled').addClass('enabled'); 1289 cookie_likes = cookie_likes.replace(','+post_id+',', ','); 1290 }
1291 button.data('likes', likes).attr('title', title).find('.post_counters_number').html(likes); 1292 writer_ancora_set_cookie('writer_ancora_likes', cookie_likes, 365); 1293 } else { 1294 writer_ancora_message_warning(WRITER_ANCORA_STORAGE['strings']['error_like']); 1295 } 1296 }); 1297 e.preventDefault(); 1298 return false; 1299 }); 1300 } 1301 1302 // Add video on thumb click 1303 if (jQuery('.sc_video_play_button:not(.inited)').length > 0) { 1304 jQuery('.sc_video_play_button:not(.inited)').each(function() { 1305 "use strict"; 1306 jQuery(this) 1307 .addClass('inited') 1308 .animate({opacity: 1}, 1000) 1309 .on('click', function (e) { 1310 "use strict"; 1311 if (!jQuery(this).hasClass('sc_video_play_button')) return; 1312 var video = jQuery(this).removeClass('sc_video_play_button hover_icon_play').data('video'); 1313 if (video!=='') { 1314 jQuery(this).empty().html(video); 1315 writer_ancora_video_dimensions(); 1316 var video_tag = jQuery(this).find('video'); 1317 var w = video_tag.width(); 1318 var h = video_tag.height(); 1319 writer_ancora_init_media_elements(jQuery(this)); 1320 // Restore WxH attributes, because Chrome broke it! 1321 jQuery(this).find('video').css({'width':w, 'height': h}).attr({'width':w, 'height': h}); 1322 } 1323 e.preventDefault(); 1324 return false; 1325 }); 1326 }); 1327 } 1328 1329 // Tribe Events buttons 1330 jQuery('a.tribe-events-read-more,.tribe-events-button,.tribe-events-nav-previous a,.tribe-events-nav-next a,.tribe-events-widget-link a,.tribe-events-viewmore a').addClass('sc_button sc_button_style_filled'); 1331} 1332 1333 1334function writer_ancora_init_media_elements(cont) { 1335 "use strict"; 1336 if (WRITER_ANCORA_STORAGE['media_elements_enabled'] && cont.find('audio,video').length > 0) { 1337 if (window.mejs) { 1338 if (typeof window.mejs.MepDefaults != 'undefined') window.mejs.MepDefaults.enableAutosize = false; 1339 if (typeof window.mejs.MediaElementDefaults != 'undefined') window.mejs.MediaElementDefaults.enableAutosize = false; 1340 cont.find('audio:not(.wp-audio-shortcode),video:not(.wp-video-shortcode)').each(function() { 1341 if (jQuery(this).parents('.mejs-mediaelement').length == 0 1342 && jQuery( this ).parents( '.wp-block-video' ).length == 0 1343 && ! jQuery( this ).hasClass( 'wp-block-cover__video-background' ) 1344 && !jQuery(this).parent().hasClass('wp-playlist')) { 1345 var media_tag = jQuery(this); 1346 var settings = { 1347 enableAutosize: true, 1348 videoWidth: -1, // if set, overrides <video width> 1349 videoHeight: -1, // if set, overrides <video height> 1350 audioWidth: '100%', // width of audio player 1351 audioHeight: 30, // height of audio player 1352 success: function(mejs) { 1353 var autoplay, loop; 1354 if ( 'flash' === mejs.pluginType ) { 1355 autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay; 1356 loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop; 1357 autoplay && mejs.addEventListener( 'canplay', function () { 1358 mejs.play(); 1359 }, false ); 1360 loop && mejs.addEventListener( 'ended', function () { 1361 mejs.play(); 1362 }, false ); 1363 } 1364 media_tag.parents('.sc_audio,.sc_video').addClass('inited sc_show'); 1365 } 1366 }; 1367 jQuery(this).mediaelementplayer(settings); 1368 } 1369 }); 1370 } else 1371 setTimeout(function() { writer_ancora_init_media_elements(cont); }, 400); 1372 } 1373} 1374 1375 1376 1377 1378 1379 1380// Popups and system messages 1381//============================================== 1382 1383// Show system message (bubble from previous page) 1384function writer_ancora_show_system_message() { 1385 "use strict"; 1386 if (WRITER_ANCORA_STORAGE['system_message'] && WRITER_ANCORA_STORAGE['system_message']['message']) { 1387 if (WRITER_ANCORA_STORAGE['system_message']['status'] == 'success') 1388 writer_ancora_message_success(WRITER_ANCORA_STORAGE['system_message']['message'], WRITER_ANCORA_STORAGE['system_message']['header']); 1389 else if (WRITER_ANCORA_STORAGE['system_message']['status'] == 'info') 1390 writer_ancora_message_info(WRITER_ANCORA_STORAGE['system_message']['message'], WRITER_ANCORA_STORAGE['system_message']['header']); 1391 else if (WRITER_ANCORA_STORAGE['system_message']['status'] == 'error' || WRITER_ANCORA_STORAGE['system_message']['status'] == 'warning') 1392 writer_ancora_message_warning(WRITER_ANCORA_STORAGE['system_message']['message'], WRITER_ANCORA_STORAGE['system_message']['header']); 1393 } 1394} 1395 1396// Toggle popups 1397function writer_ancora_toggle_popup(popup) { 1398 "use strict"; 1399 if (popup.css('display')!='none') 1400 writer_ancora_hide_popup(popup); 1401 else 1402 writer_ancora_show_popup(popup); 1403} 1404 1405// Show popups 1406function writer_ancora_show_popup(popup) { 1407 "use strict"; 1408 if (popup.css('display')=='none') { 1409 if (WRITER_ANCORA_STORAGE['css_animation']) 1410 popup.show().removeClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_out']).addClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_in']); 1411 else 1412 popup.slideDown(); 1413 } 1414} 1415 1416// Hide popups 1417function writer_ancora_hide_popup(popup) { 1418 "use strict"; 1419 if (popup.css('display')!='none') { 1420 if (WRITER_ANCORA_STORAGE['css_animation']) 1421 popup.removeClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_in']).addClass('animated fast '+WRITER_ANCORA_STORAGE['menu_animation_out']).delay(500).hide(); 1422 else 1423 popup.fadeOut(); 1424 } 1425} 1426 1427 1428 1429 1430// Forms validation 1431//------------------------------------------------------- 1432 1433// Contact form handlers 1434function writer_ancora_sc_form_validate(form){ 1435 "use strict"; 1436 var url = form.attr('action'); 1437 if (url == '') return false;
1438 form.find('input').removeClass('error_fields_class'); 1439 var error = false; 1440 var form_custom = form.data('formtype')=='form_custom'; 1441 if (!form_custom) { 1442 error = writer_ancora_form_validate(form, { 1443 error_message_show: true, 1444 error_message_time: 4000, 1445 error_message_class: "sc_infobox sc_infobox_style_error", 1446 error_fields_class: "error_fields_class", 1447 exit_after_first_error: false, 1448 rules: [ 1449 { 1450 field: "username", 1451 min_length: { value: 1, message: WRITER_ANCORA_STORAGE['strings']['name_empty'] }, 1452 max_length: { value: 60, message: WRITER_ANCORA_STORAGE['strings']['name_long'] } 1453 }, 1454 { 1455 field: "email", 1456 min_length: { value: 7, message: WRITER_ANCORA_STORAGE['strings']['email_empty'] }, 1457 max_length: { value: 60, message: WRITER_ANCORA_STORAGE['strings']['email_long'] }, 1458 mask: { value: WRITER_ANCORA_STORAGE['email_mask'], message: WRITER_ANCORA_STORAGE['strings']['email_not_valid'] } 1459 }, 1460 { 1461 field: "message", 1462 min_length: { value: 1, message: WRITER_ANCORA_STORAGE['strings']['text_empty'] }, 1463 max_length: { value: WRITER_ANCORA_STORAGE['contacts_maxlength'], message: WRITER_ANCORA_STORAGE['strings']['text_long'] } 1464 } 1465 ] 1466 }); 1467 } 1468 if (!error && url!='#') { 1469 jQuery.post(url, { 1470 action: "send_form", 1471 nonce: WRITER_ANCORA_STORAGE['ajax_nonce'], 1472 type: form.data('formtype'), 1473 data: form.serialize() 1474 }).done(function(response) { 1475 "use strict"; 1476 var rez = {}; 1477 try { 1478 rez = JSON.parse(response); 1479 } catch (e) { 1480 rez = { error: WRITER_ANCORA_STORAGE['ajax_error'] }; 1481 console.log(response); 1482 } 1483 var result = form.find(".result").toggleClass("sc_infobox_style_error", false).toggleClass("sc_infobox_style_success", false); 1484 if (rez.error === '') { 1485 form.get(0).reset(); 1486 result.addClass("sc_infobox_style_success").html(WRITER_ANCORA_STORAGE['strings']['send_complete']); 1487 var return_url = form.find('input[name="return_url"]'); 1488 if (return_url.length > 0 && return_url.val()!='') { 1489 setTimeout(function() { 1490 "use strict"; 1491 window.location.href = return_url.val(); 1492 }, 3300); 1493 } 1494 } else { 1495 result.addClass("sc_infobox_style_error").html(WRITER_ANCORA_STORAGE['strings']['send_error'] + ' ' + rez.error); 1496 } 1497 result.fadeIn().delay(3000).fadeOut(); 1498 }); 1499 } 1500 return !error; 1501}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.