1/* global jQuery, TRUTH_STORAGE */ 2 3jQuery( document ).ready( function() { 4 5 "use strict"; 6 7 var ready_busy = true; 8 9 var theme_init_counter = 0; 10 11 var $window = jQuery( window ), 12 $document = jQuery( document ), 13 $body = jQuery( 'body' ); 14 15 var $body_wrap, 16 $page_wrap, 17 $header, 18 $footer, 19 $menu_side_wrap, 20 $menu_side_logo; 21 22 var _header_height = 0, 23 _footer_height = 0; 24 25 var $page_content_wrap, 26 $content, 27 $sidebar, 28 $cur_page_title_tag, 29 // Single post parts 30 $single_nav_links_fixed, 31 $single_post_info_fixed, 32 $single_post_scrollers, 33 $stretch_width; 34 35 var $nav_link_infinite; 36 37 38 // Update links after the new post added 39 $document.on( 'action.new_post_added', update_jquery_links ); 40 $document.on( 'action.got_ajax_response', update_jquery_links ); 41 $document.on( 'action.init_hidden_elements', update_jquery_links ); 42 var first_run = true; 43 function update_jquery_links(e) { 44 if ( first_run && e && e.namespace == 'init_hidden_elements' ) { 45 first_run = false; 46 return; 47 } 48 $body_wrap = jQuery( '.body_wrap' ), 49 $page_wrap = jQuery( '.page_wrap' ), 50 $header = jQuery( '.top_panel' ), 51 _header_height = $header.length === 0 ? 0 : $header.height(), 52 $footer = jQuery( '.footer_wrap' ), 53 _footer_height = $footer.length === 0 ? 0 : $footer.height(), 54 $menu_side_wrap = jQuery( '.menu_side_wrap' ), 55 $menu_side_logo = $menu_side_wrap.find( '.sc_layouts_logo' ); 56 $page_content_wrap = jQuery( '.page_content_wrap' ); 57 $content = jQuery( '.content' ); 58 $sidebar = jQuery( '.sidebar:not(.sidebar_fixed_placeholder)' ); 59 $cur_page_title_tag = jQuery('.sc_layouts_title_caption, head title').eq(0); 60 $nav_link_infinite = jQuery( '.nav-links-infinite' ); 61 // Single post parts 62 $single_nav_links_fixed = jQuery( '.nav-links-single.nav-links-fixed' ); 63 $single_post_info_fixed = jQuery( '.post_info_vertical.post_info_vertical_fixed' ); 64 $single_post_scrollers = jQuery( '.nav-links-single-scroll' ); 65 $stretch_width = jQuery( '.trx-stretch-width' ); 66 } 67 update_jquery_links(); 68 69 70 // Init actions 71 //----------------------------------- 72 73 // Init intersection observer 74 truth_intersection_observer_init(); 75 76 // Init all other actions 77 truth_init_actions(); 78 79 function truth_init_actions() { 80 81 if (TRUTH_STORAGE['vc_edit_mode'] && jQuery( '.vc_empty-placeholder' ).length === 0 && theme_init_counter++ < 30) { 82 setTimeout( truth_init_actions, 200 ); 83 return; 84 } 85 86 // Resize handlers 87 $window.on( 'resize', function() { 88 truth_resize_actions(); 89 } ); 90 91 // Scroll handlers 92 TRUTH_STORAGE['scroll_busy'] = true; 93 $window.on( 'scroll', function() { 94 if (window.requestAnimationFrame) { 95 if ( ! TRUTH_STORAGE['scroll_busy']) { 96 window.requestAnimationFrame( function() { 97 truth_scroll_actions(); 98 }); 99 TRUTH_STORAGE['scroll_busy'] = true; 100 } 101 } else { 102 truth_scroll_actions(); 103 } 104 } ); 105 106 // Add scheme class and js support 107 document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/,'js' ); 108 if (document.documentElement.className.indexOf( TRUTH_STORAGE['site_scheme'] ) == -1) { 109 document.documentElement.className += ' ' + TRUTH_STORAGE['site_scheme']; 110 } 111 112 // First call to init core actions 113 truth_ready_actions(); 114 truth_resize_actions(); 115 truth_scroll_actions(); 116 117 } // truth_init_actions 118 119 120 // Theme first load actions 121 //============================================== 122 function truth_ready_actions() { 123 124 // Skip to content link 125 $body 126 .on( 'focus', 'a.truth_skip_link', function() { 127 if ( ! $body.hasClass( 'show_outline' ) ) { 128 $body.addClass( 'show_outline' ); 129 } 130 } ) 131 .on( 'click', 'a.truth_skip_link', function() { 132 var id = jQuery(this).attr('href'); 133 jQuery(id).focus(); 134 } ); 135 136 137 // Detect the keyboard usage to show outline around links and fields 138 $body.on( 'keydown', 'a,input,textarea,select,span[tabindex]', function( e ) { 139 if ( 9 == e.which ) { 140 if ( ! $body.hasClass( 'show_outline' ) ) { 141 $body.addClass( 'show_outline' ); 142 } 143 } 144 } ); 145 146 147 // Menus 148 //------------------------------------- 149 $document 150 .on( 'keyup', function(e) { 151 if ( e.keyCode == 27 ) { 152 if ( jQuery( '.menu_mobile.opened' ).length == 1 ) { 153 truth_mobile_menu_close(); 154 e.preventDefault(); 155 return false;
156 } 157 } 158 } ) 159 .on( 'action.trx_addons_inner_links_click', function( e, link_obj, original_e ) { 160 if ( $body.hasClass( 'menu_mobile_opened' ) ) { 161 // Removing class before menu closing animations started 162 // is need to animate inner links and scrolling to the anchor 163 $body.removeClass( 'menu_mobile_opened' ); 164 truth_mobile_menu_close(); 165 } 166 } ); 167 168 169 // Pagination 170 //------------------------------------ 171 172 // Infinite scroll in the blog streampages 173 $document.on( 'action.scroll_truth', function(e) { 174 truth_infinite_scroll_in_blog(); 175 } ); 176 177 // Infinite scroll in the single posts 178 $document.on( 'action.scroll_truth', function(e) { 179 truth_infinite_scroll_in_single(); 180 } ); 181 182 // Mark single post as readed 183 if ( $body.hasClass('single') ) { 184 truth_add_to_read_list( jQuery('.content > article[data-post-id]').data('post-id') ); 185 } 186 187 // Mark readed posts 188 $document.on( 'action.init_hidden_elements', function( e, cont ) { 189 var read_list = truth_get_storage('truth_post_read'); 190 if ( read_list && read_list.charAt(0) == '[' ) { 191 read_list = JSON.parse( read_list ); 192 for ( var p = 0; p < read_list.length; p++ ) { 193 var read_post = cont.find('[data-post-id="' + read_list[ p ] + '"]'); 194 if ( ! read_post.hasClass('full_post_read') && ! read_post.parent().hasClass('content') ) { 195 read_post.addClass('full_post_read'); 196 } 197 } 198 } 199 } ); 200 201 202 // Comments 203 //------------------------------------ 204 205 // Scroll to comments (if hidden) 206 if ( location.hash == '#comments' || location.hash == '#respond' ) { 207 var $show_comments_button = jQuery( '.show_comments_button' ); 208 if ( $show_comments_button.length == 1 && ! $show_comments_button.hasClass( 'opened' ) ) { 209 $show_comments_button.trigger( 'click' ); 210 truth_document_animate_to( location.hash ); 211 } 212 } 213 214 // Other settings 215 //------------------------------------ 216 $document.trigger( 'action.ready_truth' ); 217 218 // Blocks with stretch width 219 //---------------------------------------------- 220 // Action to prepare stretch blocks in the third-party plugins 221 $document.trigger( 'action.prepare_stretch_width' ); 222 // Wrap stretch blocks 223 $stretch_width = jQuery( '.trx-stretch-width' ); 224 $stretch_width.wrap( '<div class="trx-stretch-width-wrap"></div>' ); 225 $stretch_width.after( '<div class="trx-stretch-width-original"></div>' ); 226 truth_stretch_width(); 227 228 // Add theme-specific handlers on 'action.init_hidden_elements' 229 //--------------------------------------------------------------- 230 $document.on( 'action.init_hidden_elements', truth_init_post_formats ); 231 $document.on( 'action.init_hidden_elements', truth_add_toc_to_sidemenu ); 232 233 // Init hidden elements 234 $document.trigger( 'action.init_hidden_elements', [$body.eq(0)] ); 235 236 } // truth_ready_actions 237 238 239 240 // Post formats init 241 //===================================================== 242 function truth_init_post_formats(e, cont) { 243 244 // Menu 245 truth_init_menus( cont ); 246 247 // Wrap select with .select_container 248 truth_add_select_container( cont ); 249 250 // Use Bideo or Tubular to play a local video 251 truth_init_bg_video( cont ); 252 253 // Tabs 254 truth_init_tabs( cont ); 255 256 // Accordion 257 truth_init_accordion( cont ); 258 259 // Sidebar open/close 260 truth_init_sidebar_control( cont ); 261 262 // Masonry posts 263 truth_init_masonry( cont ); 264 265 // Load more 266 truth_init_load_more( cont ); 267 268 // Open single post right in the blog or in the shortcode "Blogger" 269 truth_init_load_single_post( cont ); 270 271 // MediaElement init 272 truth_init_media_elements( cont ); 273 274 // Video play button 275 truth_init_video_play_button( cont ); 276 277 // Show/Hide Comments 278 truth_init_comments_button( cont ); 279 280 // Show comments block when link '#comments' or '#respond' is clicked 281 truth_init_comments_links( cont ); 282 283 // Checkbox with "I agree..." 284 truth_init_checkbox_i_agree( cont ); 285 286 } // truth_init_post_formats 287 288 289 // Wrap select with .select_container 290 function truth_add_select_container( cont ) { 291 if ( $body.hasClass( 'wp-admin' ) || $body.hasClass( 'wp-customizer' ) ) { 292 return; 293 } 294 var selector = truth_apply_filters( 295 'truth_filter_select_container_selector', 296 'select:not(.esg-sorting-select):not([class*="trx_addons_attrib_"]):not(#rating)' //:not([size]) 297 ); 298 if ( selector ) { 299 cont.find( selector ).each( function() { 300 var $self = jQuery( this ); 301 if ( $self.css( 'display' ) != 'none' 302 && $self.parents( '.select_container' ).length === 0 303 && ! $self.next().hasClass( 'select2' ) 304 && ! $self.hasClass( 'select2-hidden-accessible' ) 305 && ! $self.hasClass( 'components-select-control__input' ) 306 ) { 307 var add_class = ''; 308 if ( $self.prop( 'size' ) > 1 ) { 309 add_class += ' select_container_multirows'; 310 } 311 if ( $self.prop( 'multiple' ) ) { 312 add_class += ' select_container_multiple'; 313 } 314 $self.wrap( '<div class="select_container' + add_class + '"></div>' ); 315 // Bubble submit() up for widget "Categories" 316 if ( $self.parents( truth_apply_filters( 'truth_filter_bubble_submit_form', '.widget_categories' ) ).length > 0 ) { 317 $self.parent().get(0).submit = function() { 318 jQuery(this).closest('form').eq(0).submit(); 319 }; 320 } 321 } 322 } ); 323 } 324 } 325 // Add select_container on 'ajaxComplete' 326 $document.on( 'ajaxComplete', function(e) {
327 // Trigger event after timeout to allow other scripts add elements on the page 328 setTimeout( function() { 329 truth_add_select_container( $body ); 330 }, 100 ); 331 } ); 332 333 334 // Use Bideo or Tubular to play a local video 335 function truth_init_bg_video( cont ) { 336 var $top_panel_with_bg_video = cont.find( '.top_panel.with_bg_video:not(.inited)' ).addClass( 'inited' ); 337 if ( TRUTH_STORAGE['background_video'] && $top_panel_with_bg_video.length > 0 && window.Bideo ) { 338 // Waiting 10ms after mejs init 339 setTimeout( 340 function() { 341 $top_panel_with_bg_video.prepend( '<video id="background_video" loop muted></video>' ); 342 var bv = new Bideo(); 343 bv.init( 344 { 345 // Video element 346 videoEl: document.querySelector( '#background_video' ), 347 348 // Container element 349 container: document.querySelector( '.top_panel' ), 350 351 // Resize 352 resize: true, 353 354 // autoplay: false, 355 356 isMobile: window.matchMedia( '(max-width: 768px)' ).matches, 357 358 playButton: document.querySelector( '#background_video_play' ), 359 pauseButton: document.querySelector( '#background_video_pause' ), 360 361 // Array of objects containing the src and type 362 // of different video formats to add 363 // For example: 364 // src: [ 365 // { src: 'night.mp4', type: 'video/mp4' } 366 // { src: 'night.webm', type: 'video/webm;codecs="vp8, vorbis"' } 367 // ] 368 src: [ 369 { 370 src: TRUTH_STORAGE['background_video'], 371 type: 'video/' + truth_get_file_ext( TRUTH_STORAGE['background_video'] ) 372 } 373 ], 374 375 // What to do once video loads (initial frame) 376 onLoad: function () { 377 //document.querySelector('#background_video_cover').style.display = 'none'; 378 } 379 } 380 ); 381 }, 10 382 ); 383 384 // Use Tubular to play video from Youtube 385 } else if ( jQuery.fn.tubular ) { 386 cont.find( '#background_video:not(.inited)' ).each( function() { 387 var $self = jQuery( this ).addClass( 'inited' ); 388 var youtube_code = $self.data( 'youtube-code' ); 389 if ( youtube_code ) { 390 $self.tubular( { videoId: youtube_code } ); 391 jQuery( '#tubular-player' ).appendTo( $self ).show(); 392 jQuery( '#tubular-container,#tubular-shield' ).remove(); 393 } 394 } ); 395 } 396 } 397 398 399 // Init media elements 400 //-------------------------------------------- 401 TRUTH_STORAGE['mejs_attempts'] = 0; 402 function truth_init_media_elements(cont) { 403 var audio_selector = truth_apply_filters( 'truth_filter_mediaelements_audio_selector', 'audio:not(.inited):not([src*=".ogg"])' ), 404 video_selector = truth_apply_filters( 'truth_filter_mediaelements_video_selector', 'video:not(.inited):not([nocontrol
404s]):not([controls="0"]):not([controls="false"]):not([controls="no"])' ), //:not([autoplay]) 405 media_selector = audio_selector + ( audio_selector && video_selector ? ',' : '') + video_selector; 406 if (TRUTH_STORAGE['use_mediaelements'] && cont.find( media_selector ).length > 0) { 407 if ( window.mejs ) { 408 if (window.mejs.MepDefaults) { 409 window.mejs.MepDefaults.enableAutosize = true; 410 } 411 if (window.mejs.MediaElementDefaults) { 412 window.mejs.MediaElementDefaults.enableAutosize = true; 413 } 414 // Disable init for video[autoplay] 415 cont.find( 416 // Old shortcode 'wp-video' 417 'video.wp-video-shortcode[autoplay],' 418 + 'video.wp-video-shortcode[nocontrols],' 419 + 'video.wp-video-shortcode[controls="0"],' 420 + 'video.wp-video-shortcode[controls="false"],' 421 + 'video.wp-video-shortcode[controls="no"],' 422 // New block 'video' 423 + '.wp-block-video > video[autoplay],' 424 + '.wp-block-video > video[nocontrols],' 425 + '.wp-block-video > video[controls="0"],' 426 + '.wp-block-video > video[controls="false"],' 427 + '.wp-block-video > video[controls="no"]' 428 ) 429 .removeClass('wp-video-shortcode'); 430 // Init mediaelements 431 cont.find( media_selector ).each( 432 function() { 433 var $self = jQuery( this ); 434 // If item now invisible 435 if ($self.parents( 'div:hidden,section:hidden,article:hidden' ).length > 0) { 436 return; 437 } 438 var not_init_in_containers = truth_apply_filters( 'truth_filter_mediaelements_not_init_in_containers', 439 '.mejs-mediaelement' 440 + ',.wp-block-cover' 441 + ',.wp-block-video' 442 + ',.wp-block-media-text' 443 + ',.elementor-background-video-container' 444 + ',.elementor-widget-video' 445 + ',.with_video_autoplay' 446 + ',.slider-slide' 447 + ',.sc_layouts_title' 448 // + ',.mfp-content' 449 // Uncomment the next row to 450 // disable mediaelements init on the Elementor's video shortcode 451 // to support a video ratio, specified in a shortcode parameters 452 // + ',.elementor-fit-aspect-ratio' 453 ); 454 if ( ! $self.hasClass( 'no-mejs' ) 455 && ! $self.hasClass( 'no-mediaelement' ) 456 && ! $self.hasClass( 'wp-block-cover__video-background' ) 457 // && ! $self.attr( 'autoplay' ) 458 && $self.addClass( 'inited' ).parents( not_init_in_containers ).length === 0 459 && ( TRUTH_STORAGE['init_all_mediaelements'] 460 || ( ! $self.hasClass( 'wp-audio-shortcode' ) 461 && ! $self.hasClass( 'wp-video-shortcode' ) 462 && ! $self.parent().hasClass( 'wp-playlist' ) 463 ) 464 ) 465 ) { 466 // Fix for iOS 467 if ( truth_browser_is_ios( true ) ) { 468 // Video on the single car and property pages should be preloaded to show the poster 469 if ( $self.parents( '.cars_page_video_wrap,.properties_page_video_wrap' ).length ) { 470 $self.attr( { 471 'preload': 'auto' 472 } ); 473 } 474 } 475 476 var settings = { 477 enableAutosize: true, 478 videoWidth: '100%', 479 videoHeight: '100%', 480 audioWidth: '100%', 481 audioHeight: 40, 482 success: function(mejs) { 483 if ( mejs.pluginType && 'flash' === mejs.pluginType && mejs.attributes ) { 484 mejs.attributes.autoplay 485 && 'false' !== mejs.attributes.autoplay 486 && mejs.addEventListener( 'canplay', function () { mejs.play(); }, false ); 487 mejs.attributes.loop 488 && 'false' !== mejs.attributes.loop 489 && mejs.addEventListener( 'ended', function () { mejs.play(); }, false ); 490 } 491 } 492 }; 493 494 // If video is inside a container, get the container's width 495 if ( $self.is( 'video' ) ) { 496 var media_cont = $self.parents('.sc_layouts_popup').eq(0); 497 // If video is inside a popup 498 if ( media_cont.length ) { 499 var w_attr = $self.attr( 'width' ), 500 h_attr = $self.attr( 'height' ), 501 h_cont = truth_window_height() * 0.75; // This coefficient must be the less than max-height of the popup (in the layouts.scss) 502 if ( w_attr && h_attr ) { 503 settings.videoWidth = w_attr * h_cont / h_attr; 504 settings.videoHeight = h_cont; 505 media_cont.parents( '.mfp-content' ).eq(0).css( { 'min-width': 'unset' } ); 506 } 507 } else { 508 // Uncomment (remove false) to set the container's dimensions as the video's dimensions 509 // Default dimensions are set 100% width and 100% height 510 if ( false ) { 511 var media_cont = $self.parents('.post_video').eq(0); 512 if ( media_cont.length === 0 ) { 513 media_cont = $self.parents('.video_frame').eq(0); 514 if ( media_cont.length === 0 ) { 515 media_cont = $self.parent(); 516 } 517 } 518 if ( media_cont.length > 0 ) { 519 settings.videoWidth = media_cont.width(); 520 settings.videoHeight = media_cont.height(); 521 } 522 } 523 } 524 } 525 $self.mediaelementplayer( settings ); 526 } 527 } 528 ); 529 } else if ( TRUTH_STORAGE['mejs_attempts']++ < 5 ) { 530 setTimeout( function() { truth_init_media_elements( cont ); }, 400 ); 531 } 532 } 533 // Init all media elements after first run 534 setTimeout( function() { TRUTH_STORAGE['init_all_mediaelements'] = true; }, 1000 ); 535 } 536 537 538 // Video play button 539 function truth_init_video_play_button( cont ) { 540 cont.find( '.post_featured.with_thumb .post_video_hover:not(.post_video_hover_popup):not(.inited)' ) 541 .addClass( 'inited' ) 542 .on( 'click', function(e) { 543 var $self = jQuery( this ), 544 $post_featured = $self.parents( '.post_featured' ).eq(0).addClass( 'post_video_play' ); 545 // Replace a content of the container with the video player 546 if ( typeof trx_addons_insert_video_iframe === 'function' ) { 547 trx_addons_insert_video_iframe( $post_featured.find( '.post_video' ), $self.data('video') ); 548 } else { 549 $post_featured.find( '.post_video' ).html( $self.data( 'video' ) ); 550 } 551 $document.trigger( 'action.init_hidden_elements', [ $post_featured ] ); 552 $window.trigger( 'resize' ); 553 e.preventDefault(); 554 return false;
555 } ) 556 .parents('.post_featured') 557 .on( 'click', function(e) { 558 var $self = jQuery(this); 559 if ( ! $self.hasClass( 'post_video_play' ) && ! jQuery( e.target ).is( 'a' ) && ! jQuery( e.target ).parents( 'a' ).length ) { 560 jQuery(this).find( '.post_video_hover' ).trigger( 'click' ); 561 e.preventDefault(); 562 return false; 563 } 564 } ); 565 } 566 567 568 // Accordion 569 function truth_init_accordion( cont ) { 570 if (jQuery.ui && jQuery.ui.accordion) { 571 cont.find( '.truth_accordion:not(.inited)' ).each( function () { 572 var $self = jQuery( this ); 573 var headers = $self.data( 'headers' ) || '.truth_accordion_title'; 574 // Get height style 575 var height_style = $self.data( 'height-style' ) || 'content'; 576 // Get collapsible 577 var collapsible = $self.data( 'collapsible' ) || false; 578 // Get initially opened tab 579 var init = $self.data( 'active' ); 580 var active = false; 581 if ( isNaN( init ) ) { 582 init = 0; 583 active = $self.find( headers + '[data-active="true"]' ).eq( 0 ); 584 if ( active.length > 0 ) { 585 while ( ! active.parent().hasClass( 'truth_accordion' ) ) { 586 active = active.parent(); 587 } 588 init = active.index(); 589 if ( isNaN( init ) || init < 0 ) init = 0; 590 } 591 } else { 592 init = Math.max( 0, init ); 593 } 594 595 // Init accordion 596 $self.addClass( 'inited' ).accordion( { 597 'active': init, 598 'collapsible': collapsible, 599 'header': headers, 600 'heightStyle': height_style, 601 'create': function( event, ui ) { 602 if ( ui.panel.length > 0 && ! ready_busy ) { 603 $document.trigger( 'action.create_accordion', [ui.panel] ); 604 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 605 } else if ( active !== false && active.length > 0 ) { 606 // If headers and panels wrapped into div 607 active.find( '>' + headers ).trigger( 'click' ); 608 } 609 }, 610 'activate': function( event, ui ) { 611 if ( ui.oldPanel.length > 0 && ! ready_busy ) { 612 $document.trigger( 'action.deactivate_accordion', [ui.oldPanel] ); 613 } 614 if ( ui.newPanel.length > 0 && ! ready_busy ) { 615 $document.trigger( 'action.activate_accordion', [ui.newPanel] ); 616 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 617 $window.trigger( 'resize' ); 618 } 619 } 620 } ); 621 } ); 622 } 623 } 624 625 626 // Tabs 627 function truth_init_tabs( cont ) { 628 if ( jQuery.ui && jQuery.ui.tabs ) { 629 cont.find( '.truth_tabs:not(.inited)' ).each( function () { 630 var $self = jQuery( this ); 631 // Get initially opened tab 632 var init = $self.data( 'active' ); 633 if ( isNaN( init ) ) { 634 init = 0; 635 var active = $self.find( '> ul > li[data-active="true"]' ).eq( 0 ); 636 if ( active.length > 0 ) { 637 init = active.index(); 638 if (isNaN( init ) || init < 0) { 639 init = 0; 640 } 641 } 642 } else { 643 init = Math.max( 0, init ); 644 } 645 // Init tabs 646 $self.addClass( 'inited' ).tabs( { 647 active: init, 648 show: { 649 effect: 'fadeIn', 650 duration: 300 651 }, 652 hide: { 653 effect: 'fadeOut', 654 duration: 300 655 }, 656 create: function( event, ui ) { 657 if ( ui.panel.length > 0 && ! ready_busy ) { 658 $document.trigger( 'action.create_tab', [ui.panel] ); 659 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 660 } 661 }, 662 activate: function( event, ui ) { 663 if ( ui.oldPanel.length > 0 && ! ready_busy ) { 664 $document.trigger( 'action.deactivate_tab', [ui.oldPanel] ); 665 } 666 if ( ui.newPanel.length > 0 && ! ready_busy ) { 667 $document.trigger( 'action.activate_tab', [ui.newPanel] ); 668 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 669 $window.trigger('resize'); 670 } 671 } 672 } ); 673 // AJAX loader 674 if ( $self.hasClass( 'truth_tabs_ajax' ) ) { 675 // AJAX loader for the tabs 676 $self.on( 'tabsbeforeactivate', function( event, ui ) { 677 if ( ui.newPanel.data( 'need-content' ) ) { 678 truth_tabs_ajax_content_loader( ui.newPanel, 1, ui.oldPanel ); 679 } 680 } ); 681 // AJAX loader for the pages in the tabs 682 $self.on( 'click', '.nav-links a', function(e) { 683 var $self = jQuery( this );
684 var panel = $self.parents( '.truth_tabs_content' ); 685 var page = 1; 686 var href = $self.attr( 'href' ); 687 var pos = -1; 688 if ( ( pos = href.lastIndexOf( '/page/' ) ) != -1 ) { 689 page = Number( href.substr( pos + 6 ).replace( "/", "" ) ); 690 if ( ! isNaN( page )) { 691 page = Math.max( 1, page ); 692 } 693 } 694 truth_tabs_ajax_content_loader( panel, page ); 695 e.preventDefault(); 696 return false; 697 } ); 698 } 699 } ); 700 } 701 } 702 703 704 // Pagination and AJAX loaders 705 //============================================== 706 707 // Load the tab's content 708 function truth_tabs_ajax_content_loader(panel, page, oldPanel) { 709 if (panel.html().replace( /\s/g, '' ) === '') { 710 var height = oldPanel === undefined ? panel.height() : oldPanel.height(); 711 if (isNaN( height ) || height < 100) { 712 height = 100; 713 } 714 panel.html( '<div class="truth_tab_holder" style="min-height:' + height + 'px;"></div>' ); 715 } else { 716 panel.find( '> *' ).addClass( 'truth_tab_content_remove' ); 717 } 718 panel.data( 'need-content', false ).addClass( 'truth_loading' ); 719 jQuery.post( 720 TRUTH_STORAGE['ajax_url'], { 721 nonce: TRUTH_STORAGE['ajax_nonce'], 722 action: 'truth_ajax_get_posts', 723 blog_template: panel.data( 'blog-template' ), 724 blog_style: panel.data( 'blog-style' ), 725 posts_per_page: panel.data( 'posts-per-page' ), 726 cat: panel.data( 'cat' ), 727 parent_cat: panel.data( 'parent-cat' ), 728 post_type: panel.data( 'post-type' ), 729 taxonomy: panel.data( 'taxonomy' ), 730 page: page 731 } 732 ).done( function( response ) { 733 panel.removeClass( 'truth_loading' ); 734 var rez = {}; 735 try { 736 rez = JSON.parse( response ); 737 } catch (e) { 738 rez = { error: TRUTH_STORAGE['msg_ajax_error'] }; 739 console.log( response ); 740 } 741 if (rez.error !== '') { 742 panel.html( '<div class="truth_error">' + rez.error + '</div>' ); 743 } else { 744 // Get inline styles and add to the page styles 745 if ( rez.css !== '' ) { 746 truth_import_inline_styles( '<style id="truth-inline-styles-inline-css">' + rez.css + '</style>' ); 747 } 748 // Append posts 749 panel 750 .prepend( rez.data ) 751 .fadeIn( 752 function() { 753// truth_document_animate_to('#content_skip_link_anchor'); 754 $document.trigger( 'action.init_hidden_elements', [panel] ); 755 $window.trigger( 'scroll' ); 756 // Remove old content 757 setTimeout( function() { 758 panel 759 .find( '.truth_tab_holder,.truth_tab_content_remove' ).remove(); 760 $window.trigger( 'scroll' ); 761 }, 300 ); 762 } 763 ); 764 $document.trigger('action.after_add_content', [panel]); 765 } 766 $document.trigger( 'action.got_ajax_response', { 767 action: 'truth_ajax_get_posts', 768 result: rez, 769 panel: panel 770 } ); 771 } ); 772 } // truth_tabs_ajax_content_loader 773 774 775 // Load more 776 function truth_init_load_more( cont ) { 777 cont.find( '.nav-load-more:not(.inited)' ) 778 .addClass( 'inited' ) 779 .on( 'click', function(e) { 780 var more = jQuery( this ); 781 if ( more.data( 'load_more_link_busy' ) ) { 782 return false; 783 } 784 var page = Number( more.data( 'page' ) ); 785 var max_page = Number( more.data( 'max-page' ) ); 786 if ( page >= max_page ) { 787 more.parent().addClass( 'all_items_loaded' ).hide(); 788 return false; 789 } 790 more.data( 'load_more_link_busy', true ) 791 .parent().addClass( 'loading' ); 792 793 var panel = more.parents( '.truth_tabs_content' ); 794 795 // Load simple page content 796 if (panel.length === 0) { 797 jQuery.get( 798 location.href, { 799 paged: page + 1 800 } 801 ).done( 802 function(response) { 803 // Get inline styles and add to the page styles 804 truth_import_inline_styles( response ); 805 // Get tags 'link' from response and add its to the 'head' 806 truth_import_tags_link( response ); 807 // Get new posts and append to the .posts_container 808 var $response = jQuery( response ); 809 var $response_posts_container = $response.find('.content .posts_container'); 810 if ( $response_posts_container.length === 0 ) { 811 $response_posts_container = $response.find('.posts_container'); 812 } 813 if ( $response_posts_container.length > 0 ) { 814 truth_loadmore_add_items( 815 $content.find( '.posts_container' ).eq( 0 ), 816 $response_posts_container.find( 817 '> .masonry_item,' 818 + '> div[class*="column-"],' 819 + '> article' 820 ) 821 ); 822 } 823 $document.trigger( 'action.got_ajax_response', { 824 action: 'load_more_next_page', 825 result: response 826 }); 827 } 828 ); 829
830 // Load tab's panel content 831 } else { 832 jQuery.post( 833 TRUTH_STORAGE['ajax_url'], { 834 nonce: TRUTH_STORAGE['ajax_nonce'], 835 action: 'truth_ajax_get_posts', 836 blog_template: panel.data( 'blog-template' ), 837 blog_style: panel.data( 'blog-style' ), 838 posts_per_page: panel.data( 'posts-per-page' ), 839 cat: panel.data( 'cat' ), 840 parent_cat: panel.data( 'parent-cat' ), 841 post_type: panel.data( 'post-type' ), 842 taxonomy: panel.data( 'taxonomy' ), 843 page: page + 1 844 } 845 ).done( 846 function(response) { 847 var rez = {}; 848 try { 849 rez = JSON.parse( response ); 850 } catch (e) { 851 rez = { error: TRUTH_STORAGE['msg_ajax_error'] }; 852 console.log( response ); 853 } 854 if (rez.error !== '') { 855 panel.html( '<div class="truth_error">' + rez.error + '</div>' ); 856 } else { 857 // Get inline styles and add to the page styles 858 if ( rez.css !== '' ) { 859 truth_import_inline_styles( '<style id="truth-inline-styles-inline-css">' + rez.css + '</style>' ); 860 } 861 // Get new posts and append to the .posts_container 862 truth_loadmore_add_items( 863 panel.find( '.posts_container' ), 864 jQuery( rez.data ).find( 865 '> .masonry_item,' 866 + '> div[class*="column-"],' 867 + '> article' 868 ) 869 ); 870 } 871 $document.trigger( 'action.got_ajax_response', { 872 action: 'truth_ajax_get_posts', 873 result: rez, 874 panel: panel 875 }); 876 } 877 ); 878 } 879 880 // Append items to the container 881 function truth_loadmore_add_items(container, items) { 882 if (container.length > 0 && items.length > 0) { 883 items.addClass( 'just_loaded_items' ); 884 container.append( items ); 885 $document.trigger('action.after_add_content', [container]); 886 var just_loaded_items = container.find( '.just_loaded_items' ); 887 if ( container.hasClass( 'masonry_wrap' ) ) { 888 just_loaded_items.addClass( 'hidden' ); 889 truth_when_images_loaded( 890 just_loaded_items, function() { 891 just_loaded_items.removeClass( 'hidden' ); 892 container.masonry( 'appended', items ).masonry(); 893 // Remove TOC if exists (rebuild on init_hidden_elements) 894 jQuery( '#toc_menu' ).remove(); 895 // Trigger actions to init new elements 896 TRUTH_STORAGE['init_all_mediaelements'] = true; 897 $document.trigger( 'action.init_hidden_elements', [container.parent()] ); 898 } 899 ); 900 } else { 901 just_loaded_items.removeClass( 'just_loaded_items hidden' ); 902 // Remove TOC if exists (rebuild on init_hidden_elements) 903 jQuery( '#toc_menu' ).remove(); 904 // Trigger actions to init new elements 905 TRUTH_STORAGE['init_all_mediaelements'] = true; 906 $document.trigger( 'action.init_hidden_elements', [container.parent()] ); 907 } 908 more.data( 'page', page + 1 ).parent().removeClass( 'loading' ); 909 } 910 if ( page + 1 >= max_page ) { 911 more.parent().addClass( 'all_items_loaded' ).hide(); 912 } 913 more.data( 'load_more_link_busy', false ); 914 // Fire 'window.resize' 915 $window.trigger( 'resize' ); 916 // Fire 'window.scroll' 917 $window.trigger( 'scroll' ); 918 } 919 920 e.preventDefault(); 921 return false; 922 } 923 ); 924 } 925 926 927 // Open single post right in the blog or in the shortcode "Blogger" 928 function truth_init_load_single_post( cont ) { 929 cont.find( '.posts_container:not(.inited_open_full_post),.sc_blogger_content.sc_item_posts_container:not(.inited_open_full_post)' ) 930 .addClass( 'inited_open_full_post' ) 931 .on( 'click', 'a', function(e) { 932 var link = jQuery(this), 933 link_url = link.attr( 'href' ), 934 post = link.parents( '.post_item,.sc_blogger_item' ).eq(0), 935 post_url = post.find( '.post_title > a,.entry-title > a' ).attr( 'href' ), 936 posts_container = post.parents('.posts_container,.sc_item_posts_container').eq(0); 937 if ( link_url && post_url && link_url == post_url 938 && ( posts_container.hasClass('open_full_post') || TRUTH_STORAGE['open_full_post'] ) 939 && ! posts_container.hasClass('no_open_full_post') 940 && ! posts_container.hasClass('columns_wrap') 941 && ! posts_container.hasClass('masonry_wrap') 942 && posts_container.find('.sc_blogger_grid_wrap').length === 0 943 && posts_container.find('.masonry_wrap').length === 0 944 && posts_container.parents('.wp-block-columns').length === 0 945 && ( posts_container.parents('.wpb_column').length === 0 || posts_container.parents('.wpb_column').eq(0).hasClass('vc_col-sm-12') ) 946 && ( posts_container.parents('.elementor-column').length === 0 || posts_container.parents('.elementor-column').eq(0).hasClass('elementor-col-100') ) 947 ) { 948 posts_container.find('.full_post_opened').removeClass('full_post_opened').show(); 949 posts_container.find('.full_post_content').remove(); 950 post.addClass('full_post_loading'); 951 jQuery.get( truth_add_to_url( post_url, { 'action': 'full_post_loading' } ) ).done( function( response ) { 952 if ( response ) { 953 var $response = jQuery( response ); 954 var post_content = $response.find('.content'); 955 if ( post_content.length > 0 ) { 956 // Get inline styles from response 957 var inline_styles = response.match( /<style[^>]*id="trx_addons-inline-styles-inline-css"[^>]*>([^<]*)<\/style>/ ); 958 if ( inline_styles ) { 959 jQuery( '#trx_addons-inline-styles-inline-css' ).append( inline_styles[1] ); 960 } 961 // Get tags 'link' from response and add its to the 'head' 962 truth_import_tags_link( response ); 963 // Animate to posts_container 964 var cs = post.offset().top - ( post.parents('.posts_container').length > 0 ? 100 : 200 ); 965 truth_document_animate_to( cs ); 966 // Insert new content 967 post.after( 968 '<div class="full_post_content">' 969 + '<button class="full_post_close" data-post-url="' + post_url + '"></button>' 970 + post_content.html() 971 + '</div>' 972 ) 973 .removeClass('full_post_loading') 974 .addClass('full_post_opened') 975 .hide() // instead .slideUp('fast') 976 .next().slideDown( 'slow', function() { 977 // Trigger actions to init new elements after posts_container is shown 978 TRUTH_STORAGE['init_all_mediaelements'] = true; 979 $document.trigger( 'action.init_hidden_elements', [posts_container] ); 980 $window.trigger( 'resize' ); 981 } ); 982 truth_full_post_read_change_state(); 983 // Close full post content on click 984 post.next().find('.full_post_close') 985 .on( 'click', function(e) { 986 var content = jQuery(this).parent(), 987 cs = content.offset().top - (content.parents('.posts_container').length > 0 ? 100 : 200), 988 post = content.prev(); 989 content.remove(); 990 truth_full_post_read_change_state(); 991 post 992 .removeClass('full_post_opened') 993 .slideDown(); 994 truth_document_animate_to( cs, 0 ); 995 e.preventDefault(); 996 return false;
997 } ); 998 // Remove TOC if exists (rebuild on init_hidden_elements) 999 jQuery( '#toc_menu' ).remove(); 1000 } 1001 $document.trigger( 'action.got_ajax_response', { 1002 action: 'full_post_loading', 1003 result: response 1004 } ); 1005 } 1006 } ); 1007 e.preventDefault(); 1008 return false; 1009 } 1010 } ); 1011 } 1012 1013 1014 // Infinite scroll in the blog archive page 1015 function truth_infinite_scroll_in_blog() { 1016 if ( ! $nav_link_infinite || $nav_link_infinite.length === 0 || $nav_link_infinite.hasClass( 'all_items_loaded' ) ) { 1017 return; 1018 } 1019 var container = $content.find( '> .posts_container,> .blog_archive > .posts_container,> .truth_tabs > .truth_tabs_content:visible > .posts_container' ).eq( 0 ); 1020 if ( container.length == 1 && container.offset().top + container.height() < truth_window_scroll_top() + truth_window_height() * 1.5 ) { 1021 $nav_link_infinite.find( 'a' ).trigger( 'click' ); 1022 } 1023 } 1024 1025 1026 // Infinite scroll in the single post 1027 function truth_infinite_scroll_in_single() { 1028 if ( $single_post_scrollers.length === 0 ) { 1029 return; 1030 } 1031 1032 var container = TRUTH_STORAGE['which_block_load'] == 'article' 1033 ? $content.eq( 0 ) 1034 : $page_content_wrap.eq( 0 ), 1035 cur_page_link = $single_post_scrollers.length ? $single_post_scrollers.eq(0).data( 'cur-post-link' ) : location.href, 1036 cur_page_title = $single_post_scrollers.length ? $single_post_scrollers.eq(0).data( 'cur-post-title' ) : ( $cur_page_title_tag.length ? $cur_page_title_tag.length : '' ); 1037 1038 $single_post_scrollers.each( function() { 1039 var inf = jQuery(this), 1040 link = inf.data('post-link'), 1041 off = inf.offset().top, 1042 st = truth_window_scroll_top(), 1043 wh = truth_window_height(); 1044 1045 // Change location url 1046 if ( inf.hasClass('nav-links-single-scroll-loaded') ) { 1047 if (link && off < st + wh / 2) { 1048 cur_page_link = link; 1049 cur_page_title = inf.data('post-title'); 1050 } 1051 1052 // Load next post 1053 } else if ( ! inf.hasClass('truth_loading') && link && off < st + wh * 2) { 1054 truth_add_to_read_list( container.find( '.previous_post_content:last-child > article[data-post-id]').data('post-id')); 1055 inf.addClass('truth_loading'); 1056 jQuery.get( truth_add_to_url( link, { 'action': 'prev_post_loading' } ) ).done( 1057 function( response ) { 1058 // Get inline styles and add to the page styles 1059 truth_import_inline_styles( response ); 1060 // Get tags 'link' from response and add its to the 'head' 1061 truth_import_tags_link( response ); 1062 // Get article and add it to the page 1063 var $response = jQuery( response ), 1064 $response_page_content_wrap = $response.find( '.page_content_wrap' ), 1065 $response_content = $response.find( '.content' ), 1066 $response_sidebar = $response.find( '.sidebar' ), 1067 $response_post_content = TRUTH_STORAGE['which_block_load'] == 'article' 1068 ? $response_content 1069 : $response_page_content_wrap; 1070 if ( $response_post_content.length > 0 ) { 1071 var html = $response_post_content.html(), 1072 response_body_classes = TRUTH_STORAGE['which_block_load'] == 'article' 1073 ? null 1074 : response.match(/<body[^>]*class="([^"]*)"/); 1075 if ( TRUTH_STORAGE['which_block_load'] == 'wrapper' ) { 1076 if ( $response_sidebar.length === 0 1077 && ! response_body_classes 1078 && ! $body.hasClass( 'expand_content' ) 1079 && ! $body.hasClass( 'narrow_content' ) 1080 ) { 1081 $response_post_content.find( '.content' ).width( '100%' ); 1082 html = $response_post_content.html(); 1083 } else if ( $response_sidebar.length > 0 && $body.hasClass( 'narrow_content' ) ) { 1084 $response_post_content.find( '.post_item_single.post_type_post' ).width( '100%' ); 1085 html = $response_post_content.html(); 1086 } 1087 } 1088 container.append( 1089 '<div class="previous_post_content' 1090 + ( response_body_classes 1091 ? ' ' + response_body_classes[1] 1092 : '' ) 1093 + ( $response_page_content_wrap.attr( 'data-single-style' ) !== undefined 1094 ? ' single_style_' + $response_page_content_wrap.attr( 'data-single-style' ) 1095 : '' 1096 ) 1097 + '">' 1098 + html 1099 + '</div>' 1100 ); 1101 inf.removeClass('truth_loading').addClass( 'nav-links-single-scroll-loaded' ); 1102 // Remove TOC if exists (rebuild on init_hidden_elements) 1103 jQuery( '#toc_menu' ).remove(); 1104 // Trigger actions to init new elements 1105 TRUTH_STORAGE['init_all_mediaelements'] = true; 1106 $document 1107 .trigger( 'action.new_post_added', [container] ) 1108 .trigger( 'action.init_hidden_elements', [container] ); 1109 $window.trigger( 'resize' ); 1110 } 1111 $document.trigger( 'action.got_ajax_response', { 1112 action: 'prev_post_loading', 1113 result: response 1114 }); 1115 } 1116 ); 1117 } 1118 } ); 1119 if ( cur_page_link != location.href ) { 1120 truth_document_set_location( cur_page_link ); 1121 jQuery( '.sc_layouts_title_caption,head title' ).html( cur_page_title ); 1122 } 1123 } 1124 1125 1126 // Menu navigation 1127 //============================================== 1128 1129 // Init menus after the page is loaded 1130 function truth_init_menus( cont ) { 1131 1132 // Stretch sidemenu after the logo is loaded 1133 if ( $body.hasClass( 'menu_side_present' ) && $menu_side_logo.length && ! $menu_side_logo.hasClass( 'inited_stretch' ) ) { 1134 $menu_side_logo.addClass( 'inited_stretch' ); 1135 if ( ! truth_is_images_loaded( $menu_side_logo ) ) { 1136 truth_when_images_loaded( $menu_side_logo, function() { 1137 truth_stretch_sidemenu(); 1138 } ); 1139 } 1140 } 1141 1142 var $menus = cont.find( '.sc_layouts_menu:not(.inited_kbd)' ).addClass( 'inited_kbd' ); 1143 // Keyboard navigation in the menus 1144 $menus 1145 .on( 'keydown', 'li > a', function(e) { 1146 var handled = false, 1147 link = jQuery( this ), 1148 li = link.parent(), 1149 ul = li.parent(), 1150 li_parent = ul.parent().prop( 'tagName' ) == 'LI' ? ul.parent() : false, 1151 item = false;
1152 if ( 32 == e.which ) { // Space 1153 link.trigger( 'click' ); 1154 handled = true; 1155 } else if ( 27 == e.which ) { // Esc 1156 if ( li_parent ) { 1157 item = li_parent.find( '> a' ); 1158 if ( item.length > 0 ) { 1159 item.get(0).focus(); 1160 } 1161 } 1162 handled = true; 1163 } else if ( 37 == e.which ) { // Left 1164 if ( li_parent ) { 1165 item = li_parent.find( '> a' ); 1166 if ( item.length > 0 ) { 1167 item.get(0).focus(); 1168 } 1169 } else if ( li.index() > 0 ) { 1170 item = li.prev().find( '> a' ); 1171 if ( item.length > 0 ) { 1172 item.eq(0).focus(); 1173 } 1174 } 1175 handled = true; 1176 } else if ( 38 == e.which ) { // Top 1177 if ( li.index() > 0 ) { 1178 item = li.prev().find( '> a' ); 1179 if ( item.length > 0 ) { 1180 item.get(0).focus(); 1181 } 1182 } else if ( li_parent ) { 1183 item = li_parent.find( '> a' ); 1184 if ( item.length > 0 ) { 1185 item.get(0).focus(); 1186 } 1187 } 1188 handled = true; 1189 } else if ( 39 == e.which ) { // Right 1190 if ( li_parent ) { 1191 if ( li.find( '> ul' ).length == 1 ) { 1192 item = li.find( '> ul > li:first-child a' ); 1193 if ( item.length > 0 ) { 1194 item.get(0).focus(); 1195 } 1196 } 1197 } else if ( li.next().prop( 'tagName' ) == 'LI' ) { 1198 item = li.next().find( '> a' ); 1199 if ( item.length > 0 ) { 1200 item.get(0).focus(); 1201 } 1202 } 1203 handled = true; 1204 } else if ( 40 == e.which ) { // Bottom 1205 if ( li_parent || li.find( '> ul' ).length === 0 ) { 1206 if ( li.next().prop( 'tagName' ) == 'LI' ) { 1207 item = li.next().find( '> a' ); 1208 if ( item.length > 0 ) { 1209 item.get(0).focus(); 1210 } 1211 } 1212 } else if ( li.find( '> ul' ).length == 1 ) { 1213 item = li.find( '> ul > li:first-child a' ); 1214 if ( item.length > 0 ) { 1215 item.get(0).focus(); 1216 } 1217 } 1218 handled = true; 1219 } 1220 if ( handled ) { 1221 if ( ! $body.hasClass( 'show_outline' ) ) { 1222 $body.addClass( 'show_outline' ); 1223 } 1224 e.preventDefault(); 1225 return false; 1226 } 1227 return true; 1228 } ); 1229 1230 // Add images to the menu items with classes image-xxx 1231 $menus.find( 'li[class*="image-"]' ).each( 1232 function() { 1233 var $self = jQuery( this ); 1234 var classes = $self.attr( 'class' ).split( ' ' ); 1235 var icon = ''; 1236 for (var i = 0; i < classes.length; i++) { 1237 if (classes[i].indexOf( 'image-' ) >= 0) { 1238 icon = classes[i].replace( 'image-', '' ); 1239 break; 1240 } 1241 } 1242 if (icon) { 1243 $self.find( '>a' ).css( 'background-image', 'url(' + TRUTH_STORAGE['theme_url'] + 'trx_addons/css/icons.png/' + icon + '.png' ); 1244 } 1245 } 1246 ); 1247 1248 // Open/Close side menu 1249 cont.find( '.menu_side_button:not(.inited)' ) 1250 .addClass( 'inited' ) 1251 .on( 'click', function( e ) { 1252 jQuery( this ).parent().toggleClass( 'opened' ); 1253 e.preventDefault(); 1254 return false; 1255 } ); 1256 1257 // Add arrows to the mobile menu 1258 // and close the mobile menu on a link with url is clicked 1259 // (to prevent display a mobile menu after 'Back' pressed) 1260 cont.find( '.menu_mobile:not(.inited_arrows),.sc_layouts_menu_dir_vertical:not(.inited_arrows)' ) 1261 .addClass( 'inited_arrows' ) 1262 .find( '.menu-item-has-children > a' ) 1263 .append( '<span class="open_child_menu"></span>' ).end() 1264 .find ( 'a:not([href="#"])' ) 1265 .on( 'click', function(e) { 1266 if ( ! jQuery( e.target ).hasClass( 'open_child_menu' ) ) { 1267 truth_mobile_menu_close(); 1268 } 1269 } ); 1270 1271 // Open/Close mobile menu 1272 function truth_mobile_menu_open() { 1273 var $menu = cont.find( '.menu_mobile' ); 1274 $menu 1275 .addClass( 'opened' ) 1276 .prev( '.menu_mobile_overlay' ).fadeIn(); 1277 $body.addClass( 'menu_mobile_opened' ); 1278 $document 1279 .trigger( 'action.stop_wheel_handlers' ) 1280 .trigger( 'action.mobile_menu_open', [$menu] ); 1281 } 1282 function truth_mobile_menu_close() { 1283 var $menu = cont.find( '.menu_mobile' ); 1284 $document.trigger( 'action.mobile_menu_close', [$menu] ); 1285 setTimeout( function() { 1286 $menu 1287 .removeClass( 'opened' ) 1288 .prev( '.menu_mobile_overlay' ).fadeOut(); 1289 $body.removeClass( 'menu_mobile_opened' ); 1290 $document.trigger( 'action.start_wheel_handlers' ); 1291 }, truth_apply_filters( 'truth_filter_mobile_menu_close_timeout', 0, $menu ) ); 1292 } 1293 1294 cont.find( '.sc_layouts_menu_mobile_button > a:not(.inited_click),.menu_mobile_button:not(.inited_click),.menu_mobile_description:not(.inited_click)' ) 1295 .addClass( 'inited_click' ) 1296 .on( 'click', function( e ) { 1297 var $self = jQuery( this ); 1298 if ( $self.parent().hasClass( 'sc_layouts_menu_mobile_button_burger' ) 1299 && $self.next().hasClass( 'sc_layouts_menu_popup' ) 1300 ) { 1301 return; // Not use 'return false' - it break event bubble and popup is not open 1302 } 1303 truth_mobile_menu_open(); 1304 e.preventDefault(); 1305 return false;
1306 } 1307 ); 1308 1309 cont.find( '.menu_mobile_overlay:not(.inited_click)' ) 1310 .addClass( 'inited_click' ) 1311 .on( 'click', function(e){ 1312 truth_mobile_menu_close(); 1313 e.preventDefault(); 1314 return false; 1315 } ); 1316 cont.find( '.menu_mobile_close:not(.inited_click)' ) 1317 .addClass( 'inited_click' ) 1318 .on( 'click', function(e){ 1319 truth_mobile_menu_close(); 1320 e.preventDefault(); 1321 return false; 1322 } ) 1323 .on( 'keyup', function(e) { 1324 if (e.keyCode == 13) { 1325 if (jQuery( '.menu_mobile.opened' ).length == 1) { 1326 truth_mobile_menu_close(); 1327 e.preventDefault(); 1328 return false; 1329 } 1330 } 1331 } ) 1332 .on( 'focus', function() { 1333 if ( ! $body.hasClass( 'menu_mobile_opened' ) ) { 1334 jQuery( '#content_skip_link_anchor' ).focus(); 1335 } 1336 } ); 1337 1338 // Open/Close mobile submenu 1339 cont.find( '.menu_mobile:not(.inited_click),.sc_layouts_menu_dir_vertical:not([class*="sc_layouts_submenu_"]):not(.inited_click),.sc_layouts_menu.sc_layouts_submenu_dropdown:not(.inited_click)' ) 1340 .addClass( 'inited_click' ) 1341 .on( 'click', 'li a .open_child_menu,li a', function(e) { 1342 var $self = jQuery( this ); 1343 var $a = $self.hasClass( 'open_child_menu' ) ? $self.parent() : $self; 1344 if ($a.parent().hasClass( 'menu-item-has-children' )) { 1345 if ($a.attr( 'href' ) == '#' || $self.hasClass( 'open_child_menu' )) { 1346 if ($a.siblings( 'ul:visible' ).length > 0) { 1347 $a.siblings( 'ul' ).slideUp().parent().removeClass( 'opened' ); 1348 } else { 1349 $self.parents( 'li' ).eq(0).siblings( 'li' ).find( 'ul.sub-menu:visible,ul.sc_layouts_submenu:visible' ).slideUp().parent().removeClass( 'opened' ); 1350 $a.siblings( 'ul' ).slideDown( 1351 function() { 1352 var $self = jQuery( this ); 1353 // Init layouts 1354 if ( ! $self.hasClass( 'layouts_inited' ) && $self.parents( '.menu_mobile' ).length > 0) { 1355 $self.addClass( 'layouts_inited' ); 1356 $document.trigger( 'action.init_hidden_elements', [$self] ); 1357 } 1358 } 1359 ).parent().addClass( 'opened' ); 1360 } 1361 } 1362 } 1363 if ( ! $self.hasClass( 'open_child_menu' ) && $self.parents( '.menu_mobile' ).length > 0 && truth_is_local_link( $a.attr( 'href' ) )) { 1364 jQuery( '.menu_mobile_close' ).trigger( 'click' ); 1365 } 1366 if ( $self.hasClass( 'open_child_menu' ) || $a.attr( 'href' ) == '#' ) { 1367 e.preventDefault(); 1368 return false; 1369 } 1370 } ) 1371 .on( 'keyup', 'li a', function(e) { 1372 if ( e.keyCode == 9 ) { 1373 jQuery(this).find( '.open_child_menu' ).trigger( 'click' ); 1374 } 1375 } ); 1376 1377 if ( ! TRUTH_STORAGE['trx_addons_exist'] || jQuery( '.top_panel.top_panel_default .sc_layouts_menu_default' ).length > 0) { 1378 // Init superfish menus 1379 truth_init_sfmenu( '.sc_layouts_menu:not(.inited):not(.sc_layouts_submenu_dropdown) > ul:not(.inited)' ); 1380 // Show menu 1381 jQuery( '.sc_layouts_menu:not(.inited)' ).each( 1382 function() { 1383 var $self = jQuery( this ); 1384 if ( $self.find( '>ul.inited' ).length == 1 ) { 1385 $self.addClass( 'inited' ); 1386 } 1387 } 1388 ); 1389 // Generate 'scroll' event after the menu is showed 1390 $window.trigger( 'scroll' ); 1391 } 1392 } 1393 1394 1395 // Init Superfish menu 1396 function truth_init_sfmenu(selector) {
1397 jQuery( selector ).show().each( 1398 function() { 1399 var $self = jQuery( this ); 1400 // Do not init the mobile menu - only add class 'inited' 1401 if ($self.addClass( 'inited' ).parents( '.menu_mobile' ).length > 0) { 1402 return; 1403 } 1404 var animation_in = $self.parent().data( 'animation_in' ); 1405 if (animation_in == undefined) { 1406 animation_in = "none"; 1407 } 1408 var animation_out = $self.parent().data( 'animation_out' ); 1409 if (animation_out == undefined) { 1410 animation_out = "none"; 1411 } 1412 $self.superfish( 1413 { 1414 delay: 300, 1415 animation: { 1416 opacity: 'show' 1417 }, 1418 animationOut: { 1419 opacity: 'hide' 1420 }, 1421 speed: animation_in != 'none' ? 500 : 200, 1422 speedOut: animation_out != 'none' ? 300 : 200, 1423 autoArrows: false, 1424 dropShadows: false, 1425 onBeforeShow: function(ul) { 1426 var $self = jQuery( this ), 1427 $ul = $self.parents( "ul" ); 1428 var par_offset = 0, 1429 par_width = 0, 1430 ul_width = 0, 1431 ul_height = 0; 1432 // Detect horizontal position (left | right) 1433 if ( $ul.length > 1 ) { 1434 var w = $page_wrap.width(); 1435 par_offset = $ul.eq(0).offset().left; 1436 par_width = $ul.eq(0).outerWidth(); 1437 ul_width = $self.outerWidth(); 1438 if (par_offset + par_width + ul_width > w - 20 && par_offset - ul_width > 0) { 1439 $self.addClass( 'submenu_left' ); 1440 } else { 1441 $self.removeClass( 'submenu_left' ); 1442 } 1443 } 1444 // Shift vertical if menu going out the window 1445 if ( $self.parents( '.top_panel' ).length > 0 ) { 1446 ul_height = $self.outerHeight(); 1447 par_offset = 0; 1448 var w_height = truth_window_height(), 1449 row = $self.parents( '.sc_layouts_row' ).eq(0), 1450 row_offset = 0, 1451 row_height = 0, 1452 par = $self.parent(); 1453 while (row.length > 0) { 1454 row_offset += row.outerHeight(); 1455 if (row.hasClass( 'sc_layouts_row_fixed_on' )) { 1456 break; 1457 } 1458 row = row.prev(); 1459 } 1460 while (par.length > 0) { 1461 par_offset += par.position().top + par.parent().position().top; 1462 row_height = par.outerHeight(); 1463 if (par.position().top === 0) { 1464 break; 1465 } 1466 par = par.parents( 'li' ).eq(0); 1467 } 1468 if (row_offset + par_offset + ul_height > w_height) { 1469 if (par_offset > ul_height) { 1470 $self.css( { 1471 'top': 'auto', 1472 'bottom': '-1.4em' 1473 } ); 1474 } else { 1475 $self.css( { 1476 'top': '-' + (par_offset - row_height - 2) + 'px', 1477 'bottom': 'auto' 1478 } ); 1479 } 1480 } 1481 } 1482 // Animation in 1483 if (animation_in != 'none') { 1484 $self.removeClass( 'animated faster ' + animation_out ); 1485 $self.addClass( 'animated fast ' + animation_in ); 1486 } 1487 }, 1488 onBeforeHide: function(ul) { 1489 if (animation_out != 'none') { 1490 var $self = jQuery( this ); 1491 $self.removeClass( 'animated fast ' + animation_in ); 1492 $self.addClass( 'animated faster ' + animation_out ); 1493 } 1494 }, 1495 onShow: function(ul) { 1496 var $self = jQuery( this ); 1497 // Init layouts 1498 if ( ! $self.hasClass( 'layouts_inited' )) { 1499 $self.addClass( 'layouts_inited' ); 1500 $document.trigger( 'action.init_hidden_elements', [$self] ); 1501 } 1502 } 1503 } 1504 ); 1505 } 1506 ); 1507 } // truth_init_sfmenu 1508 1509 1510 // Add TOC in the side menu 1511 // Make this function global because it used in the elementor.js 1512 function truth_add_toc_to_sidemenu() { 1513 if ( jQuery( '.menu_side_inner' ).length > 0 && jQuery( '#toc_menu' ).length > 0 ) { 1514 jQuery( '#toc_menu' ).appendTo( '.menu_side_inner' ); 1515 truth_stretch_sidemenu(); 1516 } 1517 } 1518 1519 1520 // Sidebar open/close 1521 function truth_init_sidebar_control( cont ) { 1522 cont.find( '.sidebar_control:not(.inited)' ) 1523 .addClass( 'inited' ) 1524 .on( 'click', function( e ) { 1525 var $self = jQuery( this ), 1526 $parent = $self.parent(); 1527 $parent.toggleClass( 'opened' ); 1528 if ( $body.hasClass( 'sidebar_small_screen_above' ) ) { 1529 var $next = $self.next(); 1530 $next.slideToggle(); 1531 if ( $parent.hasClass( 'opened' ) ) { 1532 setTimeout( function() { 1533 $document.trigger( 'action.init_hidden_elements', [$next] ); 1534 }, 310 ); 1535 } 1536 } 1537 e.preventDefault(); 1538 return false;
1539 } ); 1540 } 1541 1542 1543 // Masonry posts 1544 function truth_init_masonry( cont ) { 1545 cont.find( truth_apply_filters( 'truth_filter_masonry_wrap', '.masonry_wrap' ) ).each( function() { 1546 var masonry_wrap = jQuery( this ); 1547 if ( masonry_wrap.parents( 'div:hidden,article:hidden' ).length > 0) return; 1548 if ( ! masonry_wrap.hasClass( 'inited' ) ) { 1549 masonry_wrap.addClass( 'inited' ); 1550 truth_when_images_loaded( masonry_wrap, function() { 1551 setTimeout( function() { 1552 masonry_wrap.masonry( { 1553 itemSelector: truth_apply_filters( 'truth_filter_masonry_item', '.masonry_item' ), 1554 columnWidth: truth_apply_filters( 'truth_filter_masonry_item', '.masonry_item' ), 1555 percentPosition: true 1556 } ); 1557 $window.trigger('resize'); 1558 $window.trigger('scroll'); 1559 }, truth_apply_filters( 'truth_filter_masonry_init', 10 ) ); 1560 }); 1561 } else { 1562 setTimeout( function() { 1563 masonry_wrap.masonry(); // Relayout after activate tab 1564 }, truth_apply_filters( 'truth_filter_masonry_reinit', 510 ) ); 1565 } 1566 } ); 1567 } 1568 1569 // Show/Hide Comments 1570 function truth_init_comments_button( cont ) { 1571 cont.find( '.show_comments_button:not(.inited)' ) 1572 .addClass( 'inited' ) 1573 .on( 'click', function(e) { 1574 var bt = jQuery(this); 1575 if ( bt.attr( 'href' ) == '#' ) { 1576 bt.toggleClass( 'opened' ).text( bt.data( bt.hasClass( 'opened' ) ? 'hide' : 'show' ) ); 1577 var $comments_wrap = bt.parent().next(); //jQuery( '.comments_wrap' ) 1578 $comments_wrap.slideToggle( function() { 1579 $comments_wrap.toggleClass( 'opened' ); 1580 $window.trigger( 'scroll' ); 1581 }); 1582 e.preventDefault(); 1583 return false; 1584 } 1585 } ); 1586 } 1587 1588 1589 // Show comments block when link '#comments' or '#respond' is clicked 1590 function truth_init_comments_links( cont ) { 1591 cont.find( 'a[href$="#comments"]:not(.inited),a[href$="#respond"]:not(.inited)' ) 1592 .addClass( 'inited' ) 1593 .on( 'click', function(e) { 1594 var $self = jQuery(this); 1595 if ( truth_is_local_link( $self.attr( 'href') ) ) { 1596 var $prev_post_content = $self.parents( '.previous_post_content' ), 1597 $comments_wrap = $prev_post_content.length 1598 ? $prev_post_content.find( '.comments_wrap' ).eq(0) 1599 : jQuery( '.comments_wrap' ).eq(0), 1600 $show_comments_button = $comments_wrap.prev().find('.show_comments_button '); 1601 if ( $comments_wrap.length ) { 1602 if ( $comments_wrap.css( 'display' ) == 'none' ) { 1603 if ($show_comments_button.length ) { 1604 $show_comments_button.trigger( 'click' ); 1605 } 1606 } 1607 if ($show_comments_button.length ) { 1608 truth_document_animate_to( $show_comments_button.offset().top ); 1609 } 1610 } 1611 } 1612 } ); 1613 } 1614 1615 1616 // Checkbox with "I agree..." 1617 function truth_init_checkbox_i_agree( cont ) { 1618 var $i_agree = cont.find('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited)' 1619 + ',input[type="checkbox"][name="gdpr_terms"]:not(.inited)' 1620 + ',input[type="checkbox"][name="wpgdprc"]:not(.inited)' 1621 + ',input[type="checkbox"][name="AGREE_TO_TERMS"]:not(.inited)' 1622 + ',input[type="checkbox"][name="acceptance"]:not(.inited)' 1623 ); 1624 if ( $i_agree.length > 0 ) { 1625 if ( true ) { // New way: On click Submit button - checkbox is checked 1626 $i_agree.each( function() { 1627 var chk = jQuery( this ), 1628 form = chk.parents('form'); 1629 chk.addClass( 'inited' ); 1630 form.find( 'button,input[type="submit"]' ).on( 'click', function(e) { 1631 if ( ! chk.get(0).checked ) { 1632 form.find('.trx_addons_message_box').remove(); 1633 form.append( 1634 '<div class="trx_addons_message_box trx_addons_message_box_error">' 1635 + TRUTH_STORAGE['msg_i_agree_error'] 1636 + '</div>' 1637 ); 1638 var error_msg = form.find('.trx_addons_message_box'); 1639 error_msg.fadeIn(); 1640 setTimeout( function() { 1641 error_msg.fadeOut( function() { 1642 error_msg.remove(); 1643 } ); 1644 }, 3000 ); 1645 e.preventDefault(); 1646 return false; 1647 } 1648 } ); 1649 } ); 1650 } else { // Old way: Disable Submit button while checkbox is not checked 1651 $i_agree 1652 .addClass('inited') 1653 .on('change', function(e) { 1654 var $self = jQuery(this), 1655 $bt = $self.parents('form').find('button,input[type="submit"]'); 1656 if ($self.get(0).checked) { 1657 $bt.removeAttr('disabled'); 1658 } else { 1659 $bt.attr('disabled', 'disabled'); 1660 } 1661 }) 1662 .trigger('change'); 1663 } 1664 } 1665 } 1666 1667 1668 // Init intersection observer 1669 //============================================== 1670 function truth_intersection_observer_init() { 1671 1672 if ( typeof IntersectionObserver != 'undefined' ) { 1673 // Create observer 1674 if ( typeof TRUTH_STORAGE['intersection_observer'] == 'undefined' ) { 1675 TRUTH_STORAGE['intersection_observer'] = new IntersectionObserver( function(entries) {
1676 entries.forEach( function( entry ) { 1677 truth_intersection_observer_in_out( jQuery(entry.target), entry.isIntersecting || entry.intersectionRatio > 0 ? 'in' : 'out', entry ); 1678 } ); 1679 }, 1680 { 1681 root: null, // avoiding 'root' or setting it to 'null' sets it to default value: viewport 1682 rootMargin: '1px', // increase (if positive) or decrease (if negative) root area 1683 // 1px is used instead 0px to avoid a problem with appear sticky elements when window is scrolled down 1684 threshold: 0 // 0.0 - 1.0: 0.0 - fired when top of the object enter in the viewport 1685 // 0.5 - fired when half of the object enter in the viewport 1686 // 1.0 - fired when the whole object enter in the viewport 1687 } 1688 ); 1689 } 1690 } else { 1691 // Emulate IntersectionObserver behaviour 1692 $window.on( 'scroll', function() { 1693 if ( typeof TRUTH_STORAGE['intersection_observer_items'] != 'undefined' ) { 1694 for ( var i in TRUTH_STORAGE['intersection_observer_items'] ) { 1695 if ( ! TRUTH_STORAGE['intersection_observer_items'][i] || TRUTH_STORAGE['intersection_observer_items'][i].length === 0 ) { 1696 continue; 1697 } 1698 var item = TRUTH_STORAGE['intersection_observer_items'][i], 1699 item_top = item.offset().top, 1700 item_height = item.height(); 1701 truth_intersection_observer_in_out( item, item_top + item_height > truth_window_scroll_top() && item_top < truth_window_scroll_top() + truth_window_height() ? 'in' : 'out' ); 1702 } 1703 } 1704 } ); 1705 } 1706 1707 // Change state of the entry 1708 window.truth_intersection_observer_in_out = function( item, state, entry ) { 1709 var callback = null; 1710 if ( state == 'in' ) { 1711 if ( ! item.hasClass( 'truth_in_viewport' ) ) { 1712 item.addClass( 'truth_in_viewport' ); 1713 callback = item.data('trx-addons-intersection-callback'); 1714 if ( callback ) { 1715 callback( item, true, entry ); 1716 } 1717 } 1718 } else { 1719 if ( item.hasClass( 'truth_in_viewport' ) ) { 1720 item.removeClass( 'truth_in_viewport' ); 1721 callback = item.data('trx-addons-intersection-callback'); 1722 if ( callback ) { 1723 callback( item, false, entry ); 1724 } 1725 } 1726 } 1727 }; 1728 1729 // Add elements to the observer 1730 window.truth_intersection_observer_add = function( items, callback ) { 1731 items.each( function() { 1732 var $self = jQuery( this ), 1733 id = $self.attr( 'id' ); 1734 if ( ! $self.hasClass( 'truth_intersection_inited' ) ) { 1735 if ( ! id ) { 1736 id = 'io-' + ( '' + Math.random() ).replace('.', ''); 1737 $self.attr( 'id', id ); 1738 } 1739 $self.addClass( 'truth_intersection_inited' ); 1740 if ( callback ) { 1741 $self.data( 'trx-addons-intersection-callback', callback ); 1742 } 1743 if ( typeof TRUTH_STORAGE['intersection_observer_items'] == 'undefined' ) { 1744 TRUTH_STORAGE['intersection_observer_items'] = {}; 1745 } 1746 TRUTH_STORAGE['intersection_observer_items'][id] = $self; 1747 if ( typeof TRUTH_STORAGE['intersection_observer'] !== 'undefined' ) { 1748 TRUTH_STORAGE['intersection_observer'].observe( $self.get(0) ); 1749 } 1750 } 1751 } ); 1752 }; 1753 1754 // Remove elements from the observer 1755 window.truth_intersection_observer_remove = function( items ) { 1756 items.each( function() { 1757 var $self = jQuery( this ), 1758 id = $self.attr( 'id' ); 1759 if ( $self.hasClass( 'truth_intersection_inited' ) ) { 1760 $self.removeClass( 'truth_intersection_inited' ); 1761 delete TRUTH_STORAGE['intersection_observer_items'][id]; 1762 if ( typeof TRUTH_STORAGE['intersection_observer'] !== 'undefined' ) { 1763 TRUTH_STORAGE['intersection_observer'].unobserve( $self.get(0) ); 1764 } 1765 } 1766 } ); 1767 }; 1768 } 1769 1770 1771 1772 // Scroll actions 1773 //============================================== 1774 1775 // Do actions when page scrolled 1776 function truth_scroll_actions() { 1777 1778 // Call theme/plugins specific action (if exists) 1779 $document.trigger( 'action.scroll_truth' ); 1780 1781 // Fix/unfix sidebar 1782 truth_fix_sidebar(); 1783 1784 // Fix/unfix nav links 1785 truth_fix_nav_links(); 1786 1787 // Fix/unfix share links 1788 truth_fix_share_links(); 1789 1790 // Shift top and footer panels when header position is 'Under content' 1791 truth_shift_under_panels(); 1792 1793 // Show full post reading progress 1794 truth_full_post_reading(); 1795 1796 // Set flag about scroll actions are finished 1797 TRUTH_STORAGE['scroll_busy'] = false;
1798 } 1799 1800 // Add post_id to the readed list 1801 function truth_add_to_read_list(post_id) { 1802 if ( post_id > 0 ) { 1803 var read_list = truth_get_storage('truth_post_read'); 1804 if ( read_list && read_list.charAt(0) == '[' ) { 1805 read_list = JSON.parse(read_list); 1806 } else { 1807 read_list = []; 1808 } 1809 if ( read_list.indexOf(post_id) == -1 ) { 1810 read_list.push(post_id); 1811 } 1812 truth_set_storage('truth_post_read', JSON.stringify(read_list)); 1813 } 1814 } 1815 1816 var fpr_bt, fpr_cont, fpr_cs, fpr_ch, fpr_pw; 1817 function truth_full_post_read_change_state() { 1818 fpr_bt = jQuery('.full_post_close'); 1819 if ( fpr_bt.length == 1 ) { 1820 fpr_cont = fpr_bt.parent(); 1821 fpr_cs = fpr_cont.offset().top; 1822 fpr_ch = fpr_cont.height(); 1823 fpr_pw = fpr_bt.find('.full_post_progress'); 1824 } 1825 } 1826 1827 // Show full post reading progress 1828 function truth_full_post_reading() { 1829 if ( typeof fpr_bt == 'undefined' ) { 1830 truth_full_post_read_change_state(); 1831 } 1832 if ( fpr_bt.length == 1 ) { 1833 var ws = truth_window_scroll_top(), 1834 wh = truth_window_height(); 1835 if ( ws > fpr_cs ) { 1836 if ( ! fpr_pw || fpr_pw.length === 0 ) { 1837 fpr_bt.append( 1838 '<span class="full_post_progress">' 1839 + '<svg viewBox="0 0 50 50">' 1840 + '<circle class="full_post_progress_bar" cx="25" cy="25" r="22"></circle>' 1841 + '</svg>' 1842 + '</span>' 1843 ); 1844 fpr_pw = fpr_bt.find('.full_post_progress'); 1845 } 1846 var bar = fpr_pw.find('.full_post_progress_bar'), 1847 bar_max = parseFloat( bar.css('stroke-dasharray') ); 1848 if ( fpr_cs + fpr_ch > ws + wh ) { 1849 var now = fpr_cs + fpr_ch - ( ws + wh ), 1850 delta = bar.data('delta'); 1851 if ( delta == undefined ) { 1852 delta = now; 1853 bar.data('delta', delta); 1854 } 1855 bar.css( 'stroke-dashoffset', Math.min( 1, now / delta ) * bar_max + 'px' ); 1856 if ( now / delta < 0.5 ) { 1857 var post = fpr_cont.prev(), 1858 post_id = post.data('post-id'); 1859 post.addClass('full_post_read'); 1860 truth_add_to_read_list(post_id); 1861 } 1862 } else if ( ! fpr_bt.hasClass('full_post_read_complete') ) { 1863 fpr_bt.addClass('full_post_read_complete'); 1864 } else if ( fpr_cs + fpr_ch + wh / 3 < ws + wh ) { 1865 fpr_bt.trigger( 'click' ); 1866 } 1867 } else { 1868 // Disabled (add false &&) to prevent remove a progress bar when scroll to top 1869 if ( false && fpr_pw.length !== 0 ) { 1870 fpr_pw.remove(); 1871 fpr_pw = null; 1872 } 1873 } 1874 } 1875 } // truth_full_post_reading 1876 1877 // Shift top and footer panels when header position is 'Under content' 1878 function truth_shift_under_panels() { 1879 1880 if ($body.hasClass( 'header_position_under' ) && ! truth_browser_is_mobile()) { 1881 1882 // Disable 'under' behavior on small screen 1883 if ( $body.hasClass( 'mobile_layout' ) ) { //truth_window_width() < TRUTH_STORAGE['mobile_breakpoint_underpanels_off'] ) { 1884 if ( $header.css( 'position' ) == 'fixed' ) { 1885 // Header 1886 $header.css( 1887 { 1888 'position': 'relative', 1889 'left': 'auto', 1890 'top': 'auto', 1891 'width': 'auto', 1892 'transform': 'none', 1893 'zIndex': 3 1894 } 1895 ); 1896 $header.find( '.top_panel_mask' ).hide(); 1897 // Content 1898 $page_content_wrap.css( 1899 { 1900 'marginTop': 0, 1901 'marginBottom': 0, 1902 'zIndex': 2 1903 } 1904 ); 1905 // Footer 1906 $footer.css( 1907 { 1908 'position': 'relative', 1909 'left': 'auto', 1910 'bottom': 'auto', 1911 'width': 'auto', 1912 'transform': 'none', 1913 'zIndex': 1 1914 } 1915 ); 1916 $footer.find( '.top_panel_mask' ).hide(); 1917 } 1918 return; 1919 } 1920 1921 // Header 1922 var delta = 50; 1923 var scroll_offset = truth_window_scroll_top(); 1924 var header_height = _header_height; 1925 var shift = ! (/Chrome/.test( navigator.userAgent ) && /Google Inc/.test( navigator.vendor )) 1926 || $header.find( '.slider_engine_revo' ).length === 0 1927 ? 0 //1.2 // Parallax speed (if 0 - disable parallax) 1928 : 0; 1929 var mask = $header.find( '.top_panel_mask' ); 1930 var mask_opacity = 0; 1931 var css = {}; 1932 if (mask.length === 0) { 1933 $header.append( '<div class="top_panel_mask"></div>' ); 1934 mask = $header.find( '.top_panel_mask' ); 1935 } 1936 if ( $header.css( 'position' ) !== 'fixed' ) { 1937 $page_content_wrap.css( 1938 { 1939 'zIndex': 5, 1940 'marginTop': header_height + 'px' 1941 } 1942 ); 1943 $header.css( 1944 { 1945 'position': 'fixed', 1946 'left': 0, 1947 'top': truth_adminbar_height() + 'px', 1948 'width': '100%', 1949 'zIndex': 3 1950 } 1951 ); 1952 } else { 1953 $page_content_wrap.css( 'marginTop', header_height + 'px' ); 1954 } 1955 if (scroll_offset > 0) { 1956 var offset = scroll_offset; // - truth_adminbar_height(); 1957 if (offset <= header_height) { 1958 mask_opacity = Math.max( 0, Math.min( 0.8, (offset - delta) / header_height ) ); 1959 // Don't shift header with Revolution slider in Chrome 1960 if (shift) { 1961 $header.css( 'transform', 'translate3d(0px, ' + (-Math.round( offset / shift )) + 'px, 0px)' ); 1962 } 1963 mask.css( 1964 { 1965 'opacity': mask_opacity, 1966 'display': offset === 0 ? 'none' : 'block' 1967 } 1968 ); 1969 } else { 1970 if (shift) { 1971 $header.css( 'transform', 'translate3d(0px, ' + (-Math.round( offset / shift )) + 'px, 0px)' ); 1972 } 1973 } 1974 } else { 1975 if (shift) { 1976 $header.css( 'transform', 'none' ); 1977 } 1978 if (mask.css( 'display' ) != 'none') { 1979 mask.css( 1980 { 1981 'opacity': 0, 1982 'display': 'none' 1983 } 1984 ); 1985 } 1986 } 1987 1988 // Footer 1989 var footer_height = Math.min( _footer_height, truth_window_height() ); 1990 var footer_visible = (scroll_offset + truth_window_height()) - ( $header.outerHeight() + $page_content_wrap.outerHeight() ); 1991 if ( $footer.css( 'position' ) !== 'fixed' ) { 1992 $page_content_wrap.css( 1993 { 1994 'marginBottom': footer_height + 'px' 1995 } 1996 ); 1997 $footer.css( 1998 { 1999 'position': 'fixed', 2000 'left': 0, 2001 'bottom': 0, 2002 'width': '100%', 2003 'zIndex': 2 2004 } 2005 ); 2006 } else { 2007 $page_content_wrap.css( 'marginBottom', footer_height + 'px' ); 2008 } 2009 if ( footer_visible > 0 ) { 2010 if ( $footer.css( 'zIndex' ) == 2 ) { 2011 $footer.css( 'zIndex', 4 ); 2012 } 2013 mask = $footer.find( '.top_panel_mask' ); 2014 if (mask.length === 0) { 2015 $footer.append( '<div class="top_panel_mask"></div>' ); 2016 mask = $footer.find( '.top_panel_mask' ); 2017 } 2018 if (footer_visible <= footer_height) { 2019 mask_opacity = Math.max( 0, Math.min( 0.8, (footer_height - footer_visible) / footer_height ) ); 2020 // Don't shift header with Revolution slider in Chrome 2021 if (shift) { 2022 $footer.css( 'transform', 'translate3d(0px, ' + Math.round( (footer_height - footer_visible) / shift ) + 'px, 0px)' ); 2023 } 2024 mask.css( 2025 { 2026 'opacity': mask_opacity, 2027 'display': footer_height - footer_visible <= 0 ? 'none' : 'block' 2028 } 2029 ); 2030 } else { 2031 if (shift) { 2032 $footer.css( 'transform', 'none' ); 2033 } 2034 if (mask.css( 'display' ) != 'none') { 2035 mask.css( 2036 { 2037 'opacity': 0, 2038 'display': 'none' 2039 } 2040 ); 2041 } 2042 } 2043 } else { 2044 if ( $footer.css( 'zIndex' ) == 4 ) { 2045 $footer.css( 'zIndex', 2 ); 2046 } 2047 } 2048 } 2049 } // truth_shift_under_panels 2050 2051 2052 // Fix/unfix footer 2053 function truth_fix_footer() { 2054 if ( $body.hasClass( 'header_position_under' ) && ! truth_browser_is_mobile() ) { 2055 if ( $footer.length > 0 ) { 2056 var ft_height = $footer.outerHeight( false ), 2057 pc = $page_content_wrap, 2058 pc_offset = pc.offset().top, 2059 pc_height = pc.height(); 2060 if ( pc_offset + pc_height + ft_height < truth_window_height() ) { 2061 if ( $footer.css( 'position' ) != 'absolute' ) { 2062 $footer.css( { 2063 'position': 'absolute', 2064 'left': 0, 2065 'bottom': 0, 2066 'width' :'100%' 2067 } ); 2068 } 2069 } else { 2070 if ( $footer.css( 'position' ) != 'relative' ) { 2071 $footer.css( { 2072 'position': 'relative', 2073 'left': 'auto', 2074 'bottom': 'auto' 2075 } ); 2076 } 2077 } 2078 } 2079 } 2080 } // truth_fix_footer 2081 2082 // Fix/unfix sidebar 2083 function truth_fix_sidebar(force) { 2084 // Fix sidebar only if css sticky behaviour is not used 2085 if ( $body.hasClass( 'fixed_blocks_sticky' ) ) { 2086 return; 2087 } 2088 $sidebar.each( function() { 2089 var sb = jQuery( this ); 2090 var content = sb.siblings( '.content' ); 2091 var old_style = ''; 2092 2093 if ( content.length == 0 ) { 2094 return; 2095 } 2096 2097 // Unfix when sidebar is under content 2098 if (content.css( 'float' ) == 'none') { 2099 old_style = sb.data( 'old_style' ); 2100 if (old_style !== undefined) { 2101 sb.attr( 'style', old_style ).removeAttr( 'data-old_style' ); 2102 } 2103 2104 } else { 2105 2106 var sb_height = sb.outerHeight(); 2107 var sb_shift = 30; 2108 var content_height = content.outerHeight(); 2109 var content_top = content.offset().top; 2110 var content_shift = content.position().top; 2111 2112 // If sidebar shorter then content and page scrolled below the content's top 2113 if (sb_height < content_height && truth_window_scroll_top() + truth_fixed_rows_height() > content_top) { 2114 2115 var sb_init = { 2116 'position': 'undefined', 2117 'float': 'none', 2118 'top': 'auto', 2119 'bottom': 'auto', 2120 'marginLeft': '0', 2121 'marginRight': '0' 2122 }; 2123 2124 if (typeof TRUTH_STORAGE['scroll_offset_last'] == 'undefined') { 2125 TRUTH_STORAGE['sb_top_last'] = content_top; 2126 TRUTH_STORAGE['scroll_offset_last'] = truth_window_scroll_top(); 2127 TRUTH_STORAGE['scroll_dir_last'] = 1; 2128 } 2129 var scroll_dir = truth_window_scroll_top() - TRUTH_STORAGE['scroll_offset_last']; 2130 if (scroll_dir === 0) { 2131 scroll_dir = TRUTH_STORAGE['scroll_dir_last']; 2132 } else { 2133 scroll_dir = scroll_dir > 0 ? 1 : -1; 2134 } 2135 2136 var sb_big = sb_height + sb_shift >= truth_window_height() - truth_fixed_rows_height(), 2137 sb_top = sb.offset().top; 2138 2139 if (sb_top < 0) { 2140 sb_top = TRUTH_STORAGE['sb_top_last']; 2141 } 2142 2143 // If sidebar height greater then window height 2144 if (sb_big) { 2145 2146 // If change scrolling dir 2147 if (scroll_dir != TRUTH_STORAGE['scroll_dir_last'] && sb.css( 'position' ) == 'fixed') { 2148 sb_init.position = 'absolute';
2149 sb_init.top = sb_top + content_shift - content_top; 2150 2151 // If scrolling down 2152 } else if (scroll_dir > 0) { 2153 if (truth_window_scroll_top() + truth_window_height() >= content_top + content_height) { 2154 sb_init.position = 'absolute'; 2155 sb_init.bottom = 0; 2156 } else if (truth_window_scroll_top() + truth_window_height() >= (sb.css( 'position' ) == 'absolute' ? sb_top : content_top) + sb_height + sb_shift) { 2157 sb_init.position = 'fixed'; 2158 sb_init.bottom = sb_shift; 2159 } 2160 2161 // If scrolling up 2162 } else { 2163 if (truth_window_scroll_top() + truth_fixed_rows_height() <= sb_top) { 2164 sb_init.position = 'fixed'; 2165 sb_init.top = truth_fixed_rows_height(); 2166 } 2167 } 2168 2169 // If sidebar height less then window height 2170 } else { 2171 if (truth_window_scroll_top() + truth_fixed_rows_height() >= content_top + content_height - sb_height) { 2172 sb_init.position = 'absolute'; 2173 sb_init.bottom = 0; 2174 } else { 2175 sb_init.position = 'fixed'; 2176 sb_init.top = truth_fixed_rows_height(); 2177 } 2178 } 2179 2180 if (force && sb_init.position == 'undefined' && sb.css('position') == 'absolute') { 2181 sb_init.position = 'absolute'; 2182 if (sb.css('top') != 'auto') { 2183 sb_init.top = sb.css('top'); 2184 } else { 2185 sb_init.bottom = sb.css('bottom'); 2186 } 2187 } 2188 2189 // Check bounds 2190 if ( sb_init.position == 'absolute' || sb_init.position == 'undefined' ) { 2191 if ( sb_init.top == 'auto' && sb_init.bottom == 'auto' ) { 2192 sb_init.top = sb.offset().top; 2193 } 2194 if ( sb_init.top != 'auto' ) { 2195 if ( sb_init.top + sb_height > content_height ) { 2196 sb_init.position = 'absolute'; 2197 sb_init.top = content_shift + content_height - sb_height; 2198 force = true; 2199 } 2200 if ( sb_init.top + sb_height <= content_shift + content_height && sb_init.top >= truth_window_scroll_top() + truth_window_height() ) { 2201 sb_init.position = 'fixed'; 2202 sb_init.top = 'auto'; 2203 sb_init.bottom = sb_shift; 2204 force = true; 2205 } 2206 } 2207 } else if ( sb_init.position == 'fixed' ) { 2208 if ( sb_init.top == 'auto' && sb_init.bottom == 'auto' && sb.css('top') != 'auto') { 2209 sb_init.top = parseFloat( sb.css('top') ); 2210 } 2211 if ( sb_init.top != 'auto' && truth_window_scroll_top() + sb_init.top + sb_height > content_top + content_height ) { 2212 sb_init.position = 'absolute'; 2213 sb_init.top = content_shift + content_height - sb_height; 2214 force = true; 2215 } 2216 } 2217 2218 // Set new position of the sidebar 2219 if (sb_init.position != 'undefined') { 2220 // Insert placeholder before sidebar 2221 var style = sb.attr('style'); 2222 if (!style) style = ''; 2223 if (!sb.prev().hasClass('sidebar_fixed_placeholder')) { 2224 sb.css(sb_init); 2225 TRUTH_STORAGE['scroll_dir_last'] = 0; 2226 sb.before('<div class="sidebar_fixed_placeholder '+sb.attr('class')+'"' 2227 + (sb.data('sb') ? ' data-sb="' + sb.data('sb') + '"' : '') 2228 + '></div>'); 2229 } 2230 // Detect horizontal position 2231 if ( sb_init.position == 'absolute' && $body.hasClass( 'body_style_fullwide' ) && $body.hasClass( 'sidebar_right' ) ) { 2232 sb_init.left = sb.parent().innerWidth() - sb.prev().width() - parseFloat( sb.parent().css( 'paddingLeft' ) ); 2233 } else if ( sb_init.position == 'fixed' || $body.hasClass('body_style_fullwide') || $body.hasClass('body_style_fullscreen') ) { 2234 sb_init.left = sb.prev().offset().left; 2235 } else { 2236 sb_init.left = sb.prev().position().left; 2237 } 2238 sb_init.right = 'auto'; 2239 sb_init.width = sb.prev().width() + parseFloat(sb.prev().css('paddingLeft')) + parseFloat(sb.prev().css('paddingRight')); 2240 // Set position 2241 if (force 2242 || sb.css('position') != sb_init.position 2243 || TRUTH_STORAGE['scroll_dir_last'] != scroll_dir 2244 || sb.width() != sb_init.width) { 2245 if (sb.data('old_style') === undefined) { 2246 sb.attr('data-old_style', style); 2247 } 2248 sb.css(sb_init); 2249 } 2250 } 2251 2252 TRUTH_STORAGE['sb_top_last'] = sb_top; 2253 TRUTH_STORAGE['scroll_offset_last'] = truth_window_scroll_top(); 2254 TRUTH_STORAGE['scroll_dir_last'] = scroll_dir; 2255 2256 } else { 2257 2258 // Unfix when page scrolling to top 2259 old_style = sb.data( 'old_style' ); 2260 if (old_style !== undefined) { 2261 sb.attr( 'style', old_style ).removeAttr( 'data-old_style' ); 2262 if (sb.prev().hasClass('sidebar_fixed_placeholder')) { 2263 sb.prev().remove(); 2264 } 2265 } 2266 2267 } 2268 } 2269 } ); 2270 } // truth_fix_sidebar 2271 2272 // Fix/unfix .nav_links_fixed 2273 function truth_fix_nav_links() { 2274 if ( $single_nav_links_fixed.length >
2274 0 && $single_nav_links_fixed.css( 'position' ) == 'fixed') { 2275 var window_bottom = truth_window_scroll_top() + truth_window_height(), 2276 article = jQuery('.post_item_single'), 2277 article_top = article.length > 0 ? article.offset().top : truth_window_height(), 2278 article_bottom = article_top + ( article.length > 0 ? article.height() * 2 / 3 : 0 ), 2279 footer_top = $footer.length > 0 ? $footer.offset().top : 100000; 2280 if ( article_bottom < window_bottom && footer_top > window_bottom ) { 2281 if ( ! $single_nav_links_fixed.hasClass('nav-links-visible') ) { 2282 $single_nav_links_fixed.addClass('nav-links-visible'); 2283 } 2284 } else { 2285 if ( $single_nav_links_fixed.hasClass('nav-links-visible') ) { 2286 $single_nav_links_fixed.removeClass('nav-links-visible'); 2287 } 2288 } 2289 } 2290 } 2291 2292 // Fix/unfix .post_info_vertical_fixed 2293 function truth_fix_share_links() { 2294 if ( $single_post_info_fixed.length > 0 ) { 2295 var frh = truth_fixed_rows_height() + 10, 2296 st = truth_window_scroll_top() + frh; 2297 $single_post_info_fixed.each( function() { 2298 var share_links = jQuery(this), 2299 share_links_top = share_links.offset().top, 2300 share_links_left = share_links.offset().left, 2301 share_links_height = share_links.height(), 2302 share_links_position = share_links.css( 'position' ), 2303 article = share_links.parents('.post_content'), 2304 article_top = article.offset().top, 2305 article_bottom = article_top + article.height(); 2306 if ( share_links_position == 'absolute') { 2307 if ( st >= article_top && st + share_links_height < article_bottom ) { 2308 share_links 2309 .data('abs-pos', { 2310 'left': share_links.css('left'), 2311 'top': share_links.css('top')}) 2312 .addClass('post_info_vertical_fixed_on') 2313 .css({ 2314 'top': frh, 2315 'left': share_links_left 2316 }); 2317 } 2318 } else if ( share_links_position == 'fixed' ) { 2319 if ( st < article_top ) { 2320 if ( share_links.hasClass( 'post_info_vertical_fixed_on' ) ) { 2321 var abs_pos = share_links.data('abs-pos'); 2322 share_links 2323 .removeClass( 'post_info_vertical_fixed_on' ) 2324 .css({ 2325 'top': abs_pos.top, 2326 'left': abs_pos.left 2327 }); 2328 } 2329 } else if ( st + share_links_height >= article_bottom ) { 2330 share_links.fadeOut(); 2331 } else if ( share_links.css('display') == 'none' ) { 2332 share_links.fadeIn(); 2333 } 2334 } 2335 }); 2336 } 2337 } 2338 2339 2340 2341 2342 // Resize actions 2343 //============================================== 2344 2345 // Do actions when page scrolled 2346 function truth_resize_actions(cont) { 2347 2348 // Update global values 2349 _header_height = $header.length === 0 ? 0 : $header.height(); 2350 _footer_height = $footer.length === 0 ? 0 : $footer.height(); 2351 2352 // Call handlers 2353 truth_check_layout(); 2354 truth_fix_sidebar(true); 2355 truth_fix_footer(); 2356 truth_fix_nav_links(); 2357 truth_stretch_width( cont ); 2358 truth_stretch_bg_video(); 2359 truth_vc_row_fullwidth_to_boxed( cont ); 2360 truth_stretch_sidemenu(); 2361 truth_resize_video( cont ); 2362 truth_shift_under_panels(); 2363 2364 // Call theme/plugins specific action (if exists) 2365 //---------------------------------------------- 2366 $document.trigger( 'action.resize_truth', [cont] ); 2367 } 2368 2369 // Stretch sidemenu (if present) 2370 function truth_stretch_sidemenu() { 2371 var toc_items = $menu_side_wrap.find( '.toc_menu_item' ); 2372 if (toc_items.length === 0) { 2373 return; 2374 } 2375 var toc_items_height = truth_window_height() 2376 - truth_adminbar_height() 2377 - $menu_side_logo.outerHeight() 2378 - toc_items.length; 2379 var th = Math.floor( toc_items_height / toc_items.length ); 2380 var th_add = toc_items_height - th * toc_items.length; 2381 if (TRUTH_STORAGE['menu_side_stretch'] && toc_items.length >= 5 && th >= 30) { 2382 toc_items.find( ".toc_menu_description,.toc_menu_icon" ).css( 2383 { 2384 'height': th + 'px', 2385 'lineHeight': th + 'px' 2386 } 2387 ); 2388 toc_items.eq( 0 ).find( ".toc_menu_description,.toc_menu_icon" ).css( 2389 { 2390 'height': (th + th_add) + 'px', 2391 'lineHeight': (th + th_add) + 'px' 2392 } 2393 ); 2394 } 2395 //$menu_side_wrap.find('#toc_menu').height(toc_items_height + toc_items.length - toc_items.eq(0).height()); 2396 } 2397 2398 // Scroll sidemenu (if present) 2399 $document.on( 'action.toc_menu_item_active', function() { 2400 var toc_menu = $menu_side_wrap.find( '#toc_menu' ); 2401 if (toc_menu.length === 0) { 2402 return; 2403 } 2404 var toc_items = toc_menu.find( '.toc_menu_item' ); 2405 if (toc_items.length === 0) { 2406 return; 2407 } 2408 var th = toc_items.eq( 0 ).height(),
2409 toc_menu_pos = parseFloat( toc_menu.css( 'top' ) ), 2410 toc_items_height = toc_items.length * th, 2411 menu_side_height = truth_window_height() 2412 - truth_adminbar_height() 2413 - $menu_side_logo.outerHeight() 2414 - $menu_side_logo.next( '.toc_menu_item' ).outerHeight(); 2415 if ( toc_items_height > menu_side_height ) { 2416 var toc_item_active = $menu_side_wrap.find( '.toc_menu_item_active' ).eq( 0 ); 2417 if ( toc_item_active.length == 1 ) { 2418 var toc_item_active_pos = (toc_item_active.index() + 1) * th; 2419 if (toc_menu_pos + toc_item_active_pos > menu_side_height - th) { 2420 toc_menu.css( 'top', Math.max( -toc_item_active_pos + 3 * th, menu_side_height - toc_items_height ) ); 2421 } else if (toc_menu_pos < 0 && toc_item_active_pos < -toc_menu_pos + 2 * th) { 2422 toc_menu.css( 'top', Math.min( -toc_item_active_pos + 3 * th, 0 ) ); 2423 } 2424 } 2425 } else if ( toc_menu_pos < 0 ) { 2426 toc_menu.css( 'top', 0 ); 2427 } 2428 } ); 2429 2430 // Check for mobile layout 2431 function truth_check_layout() { 2432 var resize = true; 2433 if ( $body.hasClass( 'no_layout' ) ) { 2434 $body.removeClass( 'no_layout' ); 2435 resize = false; 2436 } 2437 var w = window.innerWidth; 2438 if (w == undefined) { 2439 w = truth_window_width() + ( truth_window_height() < truth_document_height() || truth_window_scroll_top() > 0 ? 16 : 0 ); 2440 } 2441 if ( w < TRUTH_STORAGE['mobile_layout_width'] ) { 2442 if ( ! $body.hasClass( 'mobile_layout' )) { 2443 $body.removeClass( 'desktop_layout' ).addClass( 'mobile_layout' ); 2444 $document.trigger( 'action.switch_to_mobile_layout' ); 2445 if (resize) { 2446 $window.trigger( 'resize' ); 2447 } 2448 } 2449 } else { 2450 if ( ! $body.hasClass( 'desktop_layout' )) { 2451 $body.removeClass( 'mobile_layout' ).addClass( 'desktop_layout' ); 2452 jQuery( '.menu_mobile' ).removeClass( 'opened' ); 2453 jQuery( '.menu_mobile_overlay' ).hide(); 2454 $document.trigger( 'action.switch_to_desktop_layout' ); 2455 if ( resize ) { 2456 $window.trigger( 'resize' ); 2457 } 2458 } 2459 } 2460 if (TRUTH_STORAGE['mobile_device'] || truth_browser_is_mobile()) { 2461 $body.addClass( 'mobile_device' ); 2462 } 2463 } 2464 2465 // Stretch area to full window width 2466 function truth_stretch_width(cont) { 2467 if (cont === undefined) { 2468 cont = $body; 2469 } 2470 $stretch_width.each( 2471 function() { 2472 var $el = jQuery( this ); 2473 var $el_cont = $el.parents( '.page_wrap' ); 2474 var $el_cont_offset = 0; 2475 if ($el_cont.length === 0) { 2476 $el_cont = $window; 2477 } else { 2478 $el_cont_offset = $el_cont.offset().left; 2479 } 2480 var $el_full = $el.next( '.trx-stretch-width-original' ); 2481 var el_margin_left = parseInt( $el.css( 'margin-left' ), 10 ); 2482 var el_margin_right = parseInt( $el.css( 'margin-right' ), 10 ); 2483 var offset = $el_cont_offset - $el_full.offset().left - el_margin_left; 2484 var width = $el_cont.width(); 2485 if ( ! $el.hasClass( 'inited' )) { 2486 $el.addClass( 'inited invisible' ); 2487 $el.css( 2488 { 2489 'position': 'relative', 2490 'box-sizing': 'border-box' 2491 } 2492 ); 2493 } 2494 $el.css( 2495 { 2496 'left': offset, 2497 'width': $el_cont.width() 2498 } 2499 ); 2500 if ( ! $el.hasClass( 'trx-stretch-content' ) ) { 2501 var padding = Math.max( 0, -1 * offset ); 2502 var paddingRight = Math.max( 0, width - padding - $el_full.width() + el_margin_left + el_margin_right ); 2503 $el.css( { 'padding-left': padding + 'px', 'padding-right': paddingRight + 'px' } ); 2504 } 2505 $el.removeClass( 'invisible' ); 2506 } 2507 ); 2508 } // truth_stretch_width 2509 2510 // Resize video frames 2511 function truth_resize_video(cont) { 2512 if (cont === undefined) { 2513 cont = $body; 2514 } 2515 // Resize tags 'video' 2516 cont.find( 'video' ).each( function() { 2517 var $self = jQuery( this ); 2518 // If item now invisible 2519 if ( ( ! TRUTH_STORAGE['resize_tag_video'] && $self.parents('.mejs-mediaelement').length === 0 ) 2520 || $self.hasClass( 'trx_addons_resize' ) 2521 || $self.hasClass( 'trx_addons_noresize' ) 2522 || $self.parents( 'div:hidden,section:hidden,article:hidden' ).length > 0 2523 ) { 2524 return; 2525 } 2526 var video = $self.addClass( 'truth_resize' ).eq( 0 ); 2527 var ratio = (video.data( 'ratio' ) !== undefined ? video.data( 'ratio' ).split( ':' ) : [16,9]); 2528 ratio = ratio.length != 2 || ratio[0] === 0 || ratio[1] === 0 ? 16 / 9 : ratio[0] / ratio[1]; 2529 var mejs_cont = video.parents( '.mejs-video' ).eq(0); 2530 var mfp_cont = video.parents( '.mfp-content' ).eq(0); 2531 var w_attr = video.data( 'width' ); 2532 var h_attr = video.data( 'height' ); 2533 if ( ! w_attr || ! h_attr) { 2534 w_attr = video.attr( 'width' ); 2535 h_attr = video.attr( 'height' ); 2536 if ( ! w_attr || ! h_attr) { 2537 return; 2538 }
2539 video.data( {'width': w_attr, 'height': h_attr} ); 2540 } 2541 var percent = ('' + w_attr).slice( -1 ) == '%'; 2542 w_attr = parseInt( w_attr, 10 ); 2543 h_attr = parseInt( h_attr, 10 ); 2544 var par = mejs_cont.length > 0 ? mejs_cont.parents('.post_video,.post_featured').eq(0) : video.parents('.post_video,.post_featured').eq(0); 2545 if ( ! par.length ) { 2546 par = mejs_cont.length > 0 ? mejs_cont.parents('div,section,article').eq(0) : video.parents('div,section,article').eq(0); 2547 } 2548 var w_real = Math.ceil( Math.min( percent ? 10000 : w_attr, par.width() ) ); 2549 if ( mfp_cont.length > 0 ) { 2550 w_real = Math.max( mfp_cont.width(), w_real ); 2551 } 2552 var h_real = Math.ceil( percent ? w_real / ratio : w_real / w_attr * h_attr ); 2553 if ( parseInt( video.attr( 'data-last-width' ), 10 ) == w_real ) { 2554 return; 2555 } 2556 if ( percent ) { 2557 video.height( h_real ); 2558 } else if ( video.parents( '.wp-video-playlist' ).length > 0 ) { 2559 if ( mejs_cont.length === 0 ) { 2560 video.attr( {'width': w_real, 'height': h_real} ); 2561 } 2562 } else { 2563 video.attr( {'width': w_real, 'height': h_real} ).css( {'width': w_real + 'px', 'height': h_real + 'px'} ); 2564 // If a height of the video is less than h_real - a max-height is applied, recalculate the width 2565 var h_video = video.height(); 2566 if ( h_video < h_real ) { 2567 w_real = Math.ceil( w_real * h_video / h_real ); 2568 h_real = h_video; 2569 video.attr( {'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'} ); 2570 } 2571 // Set dimensions for Media Elements player 2572 if ( mejs_cont.length > 0 ) { 2573 truth_set_mejs_player_dimensions( video, w_real, h_real ); 2574 } 2575 } 2576 video.attr( 'data-last-width', w_real ); 2577 } ); 2578 2579 // Resize tags 'iframe' 2580 if ( TRUTH_STORAGE['resize_tag_iframe'] ) { 2581 cont.find( '.video_frame iframe,iframe' ).each( function() { 2582 var $self = jQuery( this ); 2583 // If item now invisible 2584 if ( $self.hasClass( 'trx_addons_resize' ) 2585 || $self.hasClass( 'trx_addons_noresize' ) 2586 || $self.parent().is( 'rs-bgvideo' ) 2587 || $self.parents( 'rs-slide' ).length > 0 2588 || $self.addClass( 'truth_resize' ).parents( 'div:hidden,section:hidden,article:hidden' ).length > 0 2589 || document.fullscreenElement 2590 || document.mozFullScreenElement 2591 || document.webkitFullscreenElement 2592 || document.msFullscreenElement 2593 ) { 2594 return; 2595 } 2596 var iframe = $self.eq( 0 ); 2597 if (iframe.length === 0 || iframe.attr( 'src' ) === undefined || iframe.attr( 'src' ).indexOf( 'soundcloud' ) > 0) { 2598 return; 2599 } 2600 var w_attr = iframe.attr( 'width' ); 2601 var h_attr = iframe.attr( 'height' ); 2602 if ( ! w_attr || ! h_attr || w_attr <= truth_apply_filters( 'truth_filter_noresize_iframe_width', 325 ) ) { 2603 return; 2604 } 2605 var ratio = iframe.data( 'ratio' ) !== undefined 2606 ? iframe.data( 'ratio' ).split( ':' ) 2607 : ( iframe.parent().data( 'ratio' ) !== undefined 2608 ? iframe.parent().data( 'ratio' ).split( ':' ) 2609 : ( iframe.find( '[data-ratio]' ).length > 0 2610 ? iframe.find( '[data-ratio]' ).data( 'ratio' ).split( ':' ) 2611 : [w_attr, h_attr] 2612 ) 2613 ); 2614 ratio = ratio.length != 2 || ratio[0] === 0 || ratio[1] === 0 ? 16 / 9 : ratio[0] / ratio[1]; 2615 var percent = ( '' + w_attr ).slice( -1 ) == '%'; 2616 w_attr = parseInt( w_attr, 10 ); 2617 h_attr = parseInt( h_attr, 10 ); 2618 var par = iframe.parents( '.post_video,.post_featured' ).eq(0); 2619 if ( ! par.length ) { 2620 par = iframe.parents( '.mfp-content' ).eq(0); 2621 if ( ! par.length ) { 2622 par = iframe.parents( 'div,section,article' ).eq(0); 2623 } 2624 } 2625 var contains = iframe.data('contains-in-parent')=='1' || iframe.hasClass('contains-in-parent'), 2626 nostretch = iframe.data('no-stretch-to-parent')=='1' || iframe.hasClass('no-stretch-to-parent'), 2627 pw = Math.ceil( par.width() ), 2628 ph = Math.ceil( par.height() ), 2629 w_real = nostretch ? Math.min( w_attr, pw ) : pw, 2630 h_real = Math.ceil( percent ? w_real / ratio : w_real / w_attr * h_attr ); 2631 if ( contains && par.css( 'position' ) == 'absolute' && h_real > ph) { 2632 h_real = ph;
2633 w_real = Math.ceil( percent ? h_real * ratio : h_real * w_attr / h_attr ); 2634 } 2635 if (parseInt( iframe.attr( 'data-last-width' ), 10 ) == w_real) { 2636 return; 2637 } 2638 iframe.css( {'width': w_real + 'px', 'height': h_real + 'px'} ); 2639 iframe.attr( 'data-last-width', w_real ); 2640 } ); 2641 } 2642 } // truth_resize_video 2643 2644 // Set Media Elements player dimensions 2645 function truth_set_mejs_player_dimensions(video, w, h) { 2646 if (mejs) { 2647 for (var pl in mejs.players) { 2648 if (mejs.players[pl].media.src == video.attr( 'src' )) { 2649 if (mejs.players[pl].media.setVideoSize) { 2650 mejs.players[pl].media.setVideoSize( w, h ); 2651 } else if (mejs.players[pl].media.setSize) { 2652 mejs.players[pl].media.setSize( w, h ); 2653 } 2654 mejs.players[pl].setPlayerSize( w, h ); 2655 mejs.players[pl].setControlsSize(); 2656 } 2657 } 2658 } 2659 } 2660 2661 // Stretch background video 2662 function truth_stretch_bg_video() { 2663 var video_wrap = jQuery( 'div#background_video,.tourmaster-background-video' ); 2664 if (video_wrap.length === 0) { 2665 return; 2666 } 2667 var cont = video_wrap.hasClass( 'tourmaster-background-video' ) ? video_wrap.parent() : video_wrap, 2668 w = cont.width(), 2669 h = cont.height(), 2670 video = video_wrap.find( '>iframe,>video' ); 2671 if (w / h < 16 / 9) { 2672 w = h / 9 * 16; 2673 } else { 2674 h = w / 16 * 9; 2675 } 2676 video 2677 .attr( {'width': w, 'height': h} ) 2678 .css( {'width': w, 'height': h} ); 2679 } 2680 2681 // Recalculate width of the vc_row[data-vc-full-width="true"] when content boxed or menu_side=='left|right' 2682 $document.on('vc-full-width-row action.before_resize_trx_addons', function(e, container) { 2683 truth_vc_row_fullwidth_to_boxed( jQuery(container) ); 2684 }); 2685 function truth_vc_row_fullwidth_to_boxed(cont) { 2686 if ( $body.hasClass( 'body_style_boxed' ) 2687 || $body.hasClass( 'menu_side_present' ) 2688 || parseInt($page_wrap.css('paddingLeft'), 10) > 0 2689 ) { 2690 if (cont === undefined || ! cont.hasClass( '.vc_row' ) || ! cont.data( 'vc-full-width' )) { 2691 cont = jQuery( '.vc_row[data-vc-full-width="true"]' ); 2692 } 2693 var rtl = jQuery( 'html' ).attr( 'dir' ) == 'rtl'; 2694 var page_wrap_pl = parseInt( $page_wrap.css('paddingLeft'), 10 ); 2695 if ( isNaN( page_wrap_pl ) ) { 2696 page_wrap_pl = 0; 2697 } 2698 var page_wrap_pr = parseInt( $page_wrap.css('paddingRight'), 10 ); 2699 if ( isNaN( page_wrap_pr ) ) { 2700 page_wrap_pr = 0; 2701 } 2702 var page_wrap_width = $page_wrap.outerWidth() - page_wrap_pl - page_wrap_pr; 2703 var content_wrap = $page_content_wrap.find( '.content_wrap' ); 2704 var content_wrap_width = content_wrap.width(); 2705 var indent = ( page_wrap_width - content_wrap_width ) / 2; 2706 cont.each( function() { 2707 var $self = jQuery( this ); 2708 var mrg = parseInt( $self.css( 'marginLeft' ), 10 ); 2709 var stretch_content = $self.attr( 'data-vc-stretch-content' ); 2710 var stretch_row = $self.attr( 'data-vc-full-width' ); 2711 var in_content = $self.parents( '.content_wrap' ).length > 0; 2712 $self.css( { 2713 'width': in_content && ! stretch_content && ! stretch_row ? Math.min( page_wrap_width, content_wrap_width ) : page_wrap_width, 2714 'left': rtl ? 'auto' : ( in_content ? -indent : 0 ) - mrg, 2715 'right': ! rtl ? 'auto' : ( n_content ? -indent : 0 ) - mrg, 2716 'padding-left': stretch_content ? 0 : indent + mrg, 2717 'padding-right': stretch_content ? 0 : indent + mrg 2718 } ); 2719 } ); 2720 } 2721 } 2722 2723 ready_busy = false; 2724 2725} );
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.