1/** 2 * Init scripts 3 * 4 * @package ThemeREX Addons 5 * @since v1.0 6 */ 7 8/* global jQuery, TRX_ADDONS_STORAGE */ 9 10(function() { 11 12 "use strict"; 13 14 // Start on DOM ready 15 jQuery( document ).ready( function() { 16 17 var ready_busy = true; 18 19 var vc_init_counter = 0; 20 21 var parallax_controller = null; 22 23 var requestAnimationFrame = trx_addons_request_animation_frame(); 24 25 var $window = jQuery( window ), 26 $document = jQuery( document ), 27 $html = jQuery( 'html' ), 28 $body = jQuery( 'body' ); 29 30 var $page_preloader = jQuery('#page_preloader'), 31 $scroll_to_top = jQuery('.trx_addons_scroll_to_top'), 32 $scroll_progress = $scroll_to_top.find('.trx_addons_scroll_progress'); 33 34 var _video_sticky_fade = true; 35 36 var $show_on_scroll, 37 $banner_placeholder, 38 $animated_elements, 39 $animated_hover, 40 $video_sticky, 41 $fixed_columns, 42 $stack_sections, 43 $parallax_wrap, 44 $video_tags, 45 $iframe_tags, 46 $video_autoplay, 47 $video_autoplay_yt, 48 $video_hovers_yt = false, 49 $sections_with_id; 50 51 52 // Set body classes according User Agent 53 var classes = trx_addons_browser_classes(); 54 for ( var ua in classes ) { 55 if ( $body.hasClass( 'ua_' + ua ) ) { 56 if ( ! classes[ua] ) { 57 $body.removeClass( 'ua_' + ua ); 58 } 59 } else if ( classes[ua] ) { 60 $body.addClass( 'ua_' + ua ); 61 } 62 } 63 64 // Update links and values after the new post added 65 $document.on( 'action.got_ajax_response', update_jquery_links ); 66 $document.on( 'action.init_hidden_elements', update_jquery_links ); 67 var first_run = true; 68 function update_jquery_links(e) { 69 if ( first_run && e && e.namespace == 'init_hidden_elements' ) { 70 first_run = false; 71 return; 72 } 73 $show_on_scroll = jQuery('.trx_addons_show_on_scroll'); 74 $banner_placeholder = jQuery('.trx_addons_banner_placeholder'); 75 $animated_elements = jQuery('[data-post-animation^="animated"]:not(.animated)'); 76 $animated_hover = jQuery('[data-hover-animation^="animated"]:not(.animated)'); 77 $video_sticky = jQuery('.trx_addons_video_sticky'); 78 $fixed_columns = jQuery('.sc_column_fixed'); 79// if ( $body.hasClass( 'fixed_blocks_sticky' ) && $fixed_columns.length > 0 ) { 80// $fixed_columns.each(function() { 81// jQuery(this).parents('.e-con,.elementor-section,.vc_row').eq(0).toggleClass( 'trx_addons_has_fixed_columns', true ); 82// } ); 83// } 84 $stack_sections = jQuery('.sc_stack_section_on:not(.elementor-element-edit-mode)'); 85 if ( $stack_sections.length > 0 ) { 86 $body.addClass( 'sc_stack_section_present ' + ( window.trx_addons_browser_is_ios() ? 'ua_ios' : 'ua_not_ios' ) ); 87 } 88 $sections_with_id = jQuery( '.e-con[id], .elementor-section[id], .elementor-menu-anchor[id]' ).filter( function() { 89 var id = jQuery(this).attr('id'); 90 return id && id.trim() !== ''; 91 } ); 92 $parallax_wrap = jQuery('.sc_parallax_wrap' ); 93 $video_tags = jQuery('video'); 94 $iframe_tags = jQuery('iframe'); // ',.video_frame iframe' 95 // Load Youtube API to enable autoplay videos from Youtube in the iframe on click on the button 'Play' on iOS devices 96 if ( trx_addons_browser_is_ios() ) { 97 $video_hovers_yt = jQuery('.video_hover[data-video*="youtu"],.post_video_hover[data-video*="youtu"],.trx_addons_video_list_controller_item[data-video*="youtu"]'); 98 if ( $video_hovers_yt.length > 0 ) { 99 embedYoutubeAPI(); 100 } 101 } 102 trx_addons_find_video_autoplay(); 103 } 104 update_jquery_links(); 105 106 // Update autoplay videos 107 function trx_addons_find_video_autoplay() { 108 $video_autoplay = jQuery('.with_video_autoplay'); 109 $video_autoplay_yt = $video_autoplay.find('iframe[src*="youtu"]'); 110 } 111 112 113 // Page preloader 114 //----------------------------------------- 115 116 // Show preloader 117 window.trx_addons_show_preloader = function() { 118 if ( $page_preloader.length > 0 && ( ! jQuery.browser || ! jQuery.browser.safari ) && ! $body.hasClass( 'ua_safari' ) ) { 119 // Trigger action to allow the theme redefine a preloader 120 $page_preloader.data('done', false); 121 $document.trigger( 'action.page_preloader', [$page_preloader] ); 122 // If preloader not redefined - display it 123 if ( ! $page_preloader.data('done') ) { 124 $page_preloader 125 .css( { 126 display: 'block', 127 opacity: 0 128 } ) 129 .animate( { 130 opacity: $page_preloader.data('opacity') 131 }, 300); 132 setTimeout( trx_addons_hide_preloader, 5000 ); 133 } 134 } 135 }; 136 137 // Hide preloader 138 window.trx_addons_hide_preloader = function() { 139 if ( $page_preloader.length > 0 ) { 140 $page_preloader.data('done', false); 141 $document.trigger( 'action.page_preloader_hide', [$page_preloader] ); 142 // If preloader not redefined - hide it 143 if ( ! $page_preloader.data('done') && $page_preloader.css('opacity') > 0 ) { 144 $page_preloader.animate( 145 { 146 opacity: 0 147 }, 148 800, 149 function() { 150 jQuery(this).css( { display: 'none' } ); 151 } 152 ); 153 } 154 } 155 }; 156 157 if ( $page_preloader.length > 0 ) { 158 $page_preloader.data('opacity', $page_preloader.css('opacity')); 159 160 // Show preloader 161 $window.on( 'beforeunload', function(e) { 162 if ( typeof e.srcElement == 'undefined' 163 || typeof e.srcElement.activeElement == 'undefined' 164 || typeof e.srcElement.activeElement.href == 'undefined' 165 || e.srcElement.activeElement.href.indexOf('//') === 0 166 || e.srcElement.activeElement.href.indexOf('http:') === 0 167 || e.srcElement.activeElement.href.indexOf('https:') === 0 168 ) { 169 trx_addons_show_preloader(); 170 } 171 } ); 172 $document.on( 'action.before_new_page_content', function( e, $link, show ) { 173 if ( show || show === undefined ) { 174 trx_addons_show_preloader(); 175 } 176 } ); 177 $document.on( 'action.after_new_page_content', function( e, $link ) { 178 trx_addons_hide_preloader(); 179 } ); 180 181 182 // Disable preloader on the links with 'tel:' or 'mailto:' or similar (not 'http:' or 'https:') 183 $document.on( 'click', 'a', function() { 184 var href = jQuery(this).attr('href'); 185 if ( href !== undefined && href.indexOf('//') !== 0 && href.indexOf('http:') !== 0 && href.indexOf('https:') !== 0 ) { 186 setTimeout( function() { 187 if ( $page_preloader.css( 'display' ) == 'block' ) { 188 $page_preloader.css( { 189 display: 'none', 190 opacity: 0 191 } ); 192 } 193 }, 1 ); 194 } 195 } ); 196 } 197 198 // Page first load actions 199 //============================================== 200 $document.on('action.init_trx_addons', function() { 201 // Close panel on ESC is pressed 202 $document.on('keyup', function(e) { 203 if (e.keyCode === 27) { 204 jQuery( '.sc_layouts_panel_opened' ).each( function() { 205 trx_addons_close_panel( jQuery(this) ); 206 } ); 207 } 208 }); 209 } ); 210 211 // Init intersection observer 212 trx_addons_intersection_observer_init(); 213 214 // Init all other actions 215 trx_addons_init_actions(); 216 217 218 // Init actions 219 //-------------------------------------- 220 function trx_addons_init_actions() { 221 if (typeof TRX_ADDONS_STORAGE == 'undefined') { 222 window.TRX_ADDONS_STORAGE = { 223 'vc_edit_mode': false, 224 'popup_engine': 'magnific' 225 }; 226 } 227 if (TRX_ADDONS_STORAGE['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length === 0 && vc_init_counter++ < 30) { 228 setTimeout(trx_addons_init_actions, 200); 229 return; 230 } 231 232 $document.trigger('action.before_init_trx_addons'); 233 234 // Hide preloader 235 trx_addons_hide_preloader(); 236 237 // Show system message 238 var msg = jQuery('.trx_addons_message_box_system'),
239 msg_delay = 5000; 240 if (msg.length > 0) { 241 setTimeout(function() { 242 msg.fadeIn().delay(msg_delay).fadeOut(); 243 }, 1000); 244 var login = jQuery('.trx_addons_login_link'); 245 if (msg.hasClass('trx_addons_message_box_error') && login.length > 0) { 246 setTimeout(function() { 247 login.trigger('click'); 248 }, 2000+msg_delay); 249 } 250 } 251 252 // Shift page down to display hash-link if menu is fixed 253 // (except WooCommerce product page, because WooCommerce has own handler of the hash url) 254 if (typeof TRX_ADDONS_STORAGE['animate_to_hash']=='undefined' && !$body.hasClass('single-product')) { 255 TRX_ADDONS_STORAGE['animate_to_hash'] = true; 256 setTimeout(function() { 257 var $mc4form = false; 258 259 // Hack for MailChimp - use our scroll to form, because his method damage layouts in the Chrome 260 if (window.mc4wp_forms_config && window.mc4wp_forms_config.submitted_form && window.mc4wp_forms_config.submitted_form.element_id) { 261 trx_addons_document_animate_to(window.mc4wp_forms_config.submitted_form.element_id); 262 263 } else if ( TRX_ADDONS_STORAGE['animate_to_mc4wp_form_submitted'] && ( $mc4form = jQuery( '.mc4wp-form-submitted' ) ).length ) { 264 trx_addons_document_animate_to( $mc4form ); 265 266 // Shift page down on fixed rows height 267 } else if ( location.hash !== '' 268 && location.hash != '#' 269 && location.hash.indexOf('/') == -1 270 && location.hash.indexOf('&') == -1 271 && location.hash.indexOf(';') == -1 272 && location.hash.indexOf('%') == -1 273 && location.hash.indexOf('=') == -1 274 ) { 275 trx_addons_document_animate_to( location.hash ); 276 } 277 }, 600); 278 } 279 280 // Check for Retina display 281 if ( TRX_ADDONS_STORAGE['allow_cookie_is_retina'] ) { 282 var is_retina = trx_addons_is_retina() ? 1 : 0; 283 if ( trx_addons_get_cookie( 'trx_addons_is_retina' ) !== is_retina ) { 284 trx_addons_set_cookie( 'trx_addons_is_retina', trx_addons_is_retina() ? 1 : 0 ); 285 } 286 } else { 287 if ( trx_addons_get_cookie( 'trx_addons_is_retina' ) !== null ) { 288 trx_addons_del_cookie( 'trx_addons_is_retina' ); 289 } 290 } 291 292 // On switch to mobile layout: hide hover animations 293 $document.on( 'action.switch_to_mobile_layout', function() { 294 jQuery('[data-hover-animation^="animated"]').each(function() { 295 var $self = jQuery(this); 296 var animation = $self.data('hover-animation'); 297 var animation_out = $self.data('animation-out'); 298 if (animation_out === undefined) animation_out = "none"; 299 $self.removeClass(animation + ' ' + animation_out); 300 }); 301 }); 302 303 // Init core elements 304 trx_addons_ready_actions(); 305 306 // Call plugins specific action (if exists) 307 //---------------------------------------------- 308 $document.trigger('action.before_ready_trx_addons'); 309 $document.trigger('action.ready_trx_addons'); 310 $document.trigger('action.after_ready_trx_addons'); 311 312 // Add ready actions to the hidden elements actions 313 $document.on( 'action.init_hidden_elements', function( e, cont ) { 314 trx_addons_ready_actions(e, cont); 315 316 // Generate 'resize' event after hidden elements are inited 317 //$window.trigger('resize'); 318 319 // Generate 'scroll' event after hidden elements are inited 320 $window.trigger('scroll'); 321 } ); 322 323 // Add our handlers after the VC init 324 var vc_js = false; 325 $document.on('vc_js', function() { 326 if ( ! vc_js ) { 327 vc_js = true; 328 trx_addons_add_handlers(); 329 } 330 }); 331 332 // Add our handlers if VC is no activated 333 setTimeout(function() { 334 if ( ! vc_js ) { 335 trx_addons_add_handlers(); 336 } 337 }, 1); 338 339 // Add our handlers 340 function trx_addons_add_handlers() { 341 342 // Resize handlers 343 //----------------------- 344 // First run 345 trx_addons_resize_actions(); 346 // Add handler 347 $window.on( 'resize', function() { 348 trx_addons_resize_actions(); 349 } ); 350 351 // Scroll handlers 352 //----------------------- 353 function trx_addons_scroll_start( force ) { 354 if ( requestAnimationFrame && ! force ) { 355 if ( ! TRX_ADDONS_STORAGE['scroll_busy'] ) { 356 TRX_ADDONS_STORAGE['scroll_busy'] = true; 357 requestAnimationFrame( trx_addons_scroll_actions ); 358 } 359 } else { 360 TRX_ADDONS_STORAGE['scroll_busy'] = true; 361 trx_addons_scroll_actions(); 362 } 363 } 364 // First run 365 trx_addons_scroll_start(); 366 // Add handler 367 $window.on( 'scroll', function() { 368 trx_addons_scroll_start(); 369 } ); 370 371 // Smooth scroll via GSAP TweenMax (if loaded) 372 if ( TRX_ADDONS_STORAGE['smooth_scroll'] > 0 && typeof TweenMax != 'undefined' ) { 373 var $scroll_target = $window; 374 var scroll_time = trx_addons_apply_filters( 'trx_addons_filter_smooth_scroll_time', 0.8 ); // 0.6 375 var scroll_distance = trx_addons_apply_filters( 'trx_addons_filter_smooth_scroll_distance', 400 ); // 400 376 var ie_mobile = -1 !== navigator.userAgent.indexOf("IEMobile"), 377 is_mobile = trx_addons_browser_is_mobile() || $body.hasClass('ua_mobile'); 378 var scroll_busy = false;
379 var scroll_coef = trx_addons_apply_filters( 'trx_addons_filter_smooth_scroll_coef', { 380 start: 0.2, 381 multi: 1.5, 382 max: 1.5, 383 value: 0.2 384 } ); 385 var scroll_delta = 0; 386 var scroll_tween = null; 387 var clear_scroll_busy = trx_addons_throttle( function() { 388 scroll_busy = false; 389 if ( scroll_tween ) { 390 scroll_tween.kill(); 391 scroll_tween = false; 392 } 393 }, scroll_time * 1000 + 10, true ); 394 395 $html.addClass('smooth_scroll'); 396 397 window.smooth_scroll_listener = function( event ) { 398 if ( trx_addons_window_width() < 768 ) { 399 return; 400 } 401 if ( ! scroll_busy ) { 402 var depth = 8; 403 var $target = jQuery( event.target ); 404 $scroll_target = $window; 405 while( depth-- >= 0 ) { 406 if ( [ 'scroll', 'auto' ].indexOf( $target.css('overflow-y') ) >= 0 ) { 407 $scroll_target = $target; 408 break; 409 } 410 $target = $target.parents( 'div,section,nav,ul' ).eq(0); 411 } 412 } 413 if ( $scroll_target != $window ) { 414 scroll_busy = true; 415 setTimeout( function() { scroll_busy = false; }, scroll_time + 10 ); 416 return; 417 } 418 event.preventDefault(); 419 var delta = event.wheelDelta / 120 || -event.detail / 3; 420 if ( trx_addons_browser_is_ios() ) delta = Math.max( -1, Math.min( 1, delta ) ); 421 scroll_coef.value = scroll_busy && scroll_delta * delta > 0 ? Math.min( scroll_coef.max, scroll_coef.value * scroll_coef.multi ) : scroll_coef.start; 422 scroll_delta = delta; 423 var scroll_top = $scroll_target.scrollTop(); 424 var scroll_to = scroll_top - parseInt( delta * scroll_coef.value * scroll_distance, 10 ); 425 scroll_busy = true; 426 if ( scroll_tween ) { 427 scroll_tween.kill(); 428 } 429 scroll_tween = TweenMax.to( $scroll_target, scroll_time, { 430 onStart: function() { 431 scroll_busy = true; 432 clear_scroll_busy(); 433 trx_addons_do_action( 'trx_addons_action_smooth_scroll_start', this, $scroll_target, scroll_to, scroll_time ); 434 }, 435 onInterrupt: function() { 436 scroll_busy = false; 437 scroll_tween = null; 438 trx_addons_do_action( 'trx_addons_action_smooth_scroll_interrupt', this, $scroll_target, scroll_to, scroll_time ); 439 }, 440 onComplete: function() { 441 scroll_busy = false; 442 scroll_tween = null; 443 trx_addons_do_action( 'trx_addons_action_smooth_scroll_complete', this, $scroll_target, scroll_to, scroll_time ); 444 }, 445 onUpdate: function() { 446 trx_addons_do_action( 'trx_addons_action_smooth_scroll_update', this, $scroll_target, scroll_to, scroll_time ); 447 }, 448 scrollTo: { 449 y: scroll_to, 450 autoKill: true 451 }, 452 ease: trx_addons_apply_filters( 'trx_addons_filter_smooth_scroll_ease', Power1.easeOut ), // Power1 (easest) - Power4 (sharpest) 453// autoKill: true, 454 overwrite: true, // 5 455 tween_value: 100 456 } ); 457 }; 458 459 window.smooth_scroll_disable = function() { 460 if (typeof smooth_scroll_listener !== 'undefined') { 461 window.removeEventListener( 'mousewheel', smooth_scroll_listener, { 462 passive: false 463 } ); 464 window.removeEventListener( 'DOMMouseScroll', smooth_scroll_listener, { 465 passive: false 466 } ); 467 } 468 }; 469 470 window.smooth_scroll_enable = function() { 471 if (typeof smooth_scroll_listener !== 'undefined') { 472 window.addEventListener( 'mousewheel', smooth_scroll_listener, { 473 passive: false 474 } ); 475 window.addEventListener( 'DOMMouseScroll', smooth_scroll_listener, { 476 passive: false 477 } ); 478 } 479 }; 480 481 // Add listener if is not a touch device 482 if ( ! ie_mobile && ! $html.hasClass( 'touch' ) ) { 483 smooth_scroll_enable(); 484 } 485 } 486 487 // Inject our code to the VC function wpb_prepare_tab_content() 488 // to init our elements on the new VC tabs, tour and accordion activation 489 typeof window.wpb_prepare_tab_content == "function" 490 && typeof window.wpb_prepare_tab_content_old == "undefined" 491 && (window.wpb_prepare_tab_content_old = window.wpb_prepare_tab_content) 492 && (window.wpb_prepare_tab_content = function(e, ui) { 493 // Call ThemeREX Addons actions 494 if (typeof ui.newPanel !== 'undefined' && ui.newPanel.length > 0) { 495 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 496 } else if (typeof ui.panel !== 'undefined' && ui.panel.length > 0) { 497 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 498 } 499 // Call old VC handler 500 window.wpb_prepare_tab_content_old(e, ui); 501 } ); 502 // Inject our code in the VC function vc_accordionActivate() 503 // to init our elements on the old VC accordion activation 504 typeof window.vc_accordionActivate == "function" 505 && typeof window.vc_accordionActivate_old == "undefined" 506 && (window.vc_accordionActivate_old = window.vc_accordionActivate) 507 && (window.vc_accordionActivate = function(e, ui) { 508 // Call ThemeREX Addons actions 509 if (typeof ui.newPanel !== 'undefined' && ui.newPanel.length > 0) { 510 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 511 } else if (typeof ui.panel !== 'undefined' && ui.panel.length > 0) { 512 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 513 } 514 // Call old VC handler 515 window.vc_accordionActivate_old(e, ui); 516 } ); 517 } 518 $document.trigger('action.init_trx_addons'); 519 $document.trigger('action.after_init_trx_addons'); 520 } // trx_addons_init_actions 521 522 // Init components on DOM ready 523 //============================================== 524 function trx_addons_ready_actions(e, container) { 525 526 if (container === undefined) container = $body; 527 // Maybe comment ? (because this function is called on 'action.init_hidden_elements') 528 //update_jquery_links(); 529 530 // Animate to the page-inner links 531 //---------------------------------------------- 532 if (TRX_ADDONS_STORAGE['animate_inner_links'] > 0 && !container.hasClass('animate_to_inited')) { 533 container 534 .addClass('animate_to_inited') 535 .on('click', 'a[href*="#"]', function(e) { 536 var link_obj = jQuery(this); 537 var link_parent = link_obj.parent(); 538 // Skip tabs and accordions 539 if ( link_obj.hasClass('trx_addons_panel_link') // sc_layouts_panel 540 || link_obj.hasClass('trx_addons_popup_link') // sc_layouts_popup 541 || link_obj.attr('href').indexOf( '#elementor-action' ) >= 0 // Elementor's actions 542 || link_parent.parent().hasClass('trx_addons_tabs_titles') // trx_addons_tabs 543 || link_parent.parents('.wc-tabs').length > 0 // WooCommerce tabs on the single product page 544 || link_parent.hasClass('elementor-tab-title') // Elementor's tabs 545 || link_parent.parents('ul[class*="tabs"]').length > 0 // All other tabs 546 || link_obj.hasClass('vc_pagination-trigger') // pagination in VC tabs 547 || link_obj.hasClass('ui-tabs-anchor') // old VC tour 548 || link_parent.hasClass('vc_tta-tab') // new VC tabs, old VC tabs, new VC tour 549 || link_parent.hasClass('vc_tta-panel-title') // new VC accordion 550 || link_parent.hasClass('wpb_accordion_header') // old VC accordion 551 ) { 552 return true; 553 } 554 var href = link_obj.attr('href'); 555 if ( ! href || href == '#' ) return true; 556 if ( trx_addons_is_local_link(href) ) { 557 var pos = href.indexOf('#'); 558 if ( pos >= 0 ) { 559 href = href.substr( pos ); 560 if ( jQuery(href).length > 0 ) { 561 // Removing class before menu closing animations started 562 // is need to animate inner links and scrolling to the anch
562or 563 // Attention! Is a temporary (theme-specific) solution - 564 // it must be placed to the theme's init script. 565 if ( $body.hasClass( 'menu_mobile_opened' ) ) { 566 $body.removeClass( 'menu_mobile_opened' ); 567 } 568 $document.trigger( 'action.trx_addons_inner_links_click', [ link_obj, e ] ); 569 trx_addons_document_animate_to( href ); 570 e.preventDefault(); 571 return false; 572 } 573 } 574 } 575 }); 576 } 577 578 // Add parameters target="_blank" and rel="nofollow" to all external links 579 //------------------------------------------------------------------------ 580 if (TRX_ADDONS_STORAGE['add_target_blank'] > 0) { 581 jQuery('a').filter(function() { 582 return this.hostname 583 && this.hostname !== location.hostname 584 && this.pathname 585 && ['.png', '.jpg', '.gif'].indexOf( this.pathname.slice( -4 ) ) < 0; 586 }).each( function() { 587 var link = jQuery(this), 588 rel = link.attr('rel'); 589 if ( link.attr('target') != '_blank' ) { 590 link.attr('target', '_blank'); 591 } 592 if ( ! rel || rel.indexOf('nofollow') == -1 ) { 593 link.attr('rel', ( rel ? rel + ' ' : '' ) + 'nofollow'); 594 } 595 }); 596 } 597 598 // Hide empty figcaptions 599 jQuery('figcaption').each( function() { 600 var $self = jQuery(this); 601 if ( $self.text() === '' ) { 602 $self.hide(); 603 } 604 }); 605 606 // Tabs 607 //------------------------------------ 608 if (jQuery.ui && jQuery.ui.tabs) { 609 var $tabs = container.find('.trx_addons_tabs:not(.inited)'); 610 if ( $tabs.length > 0) { 611 $tabs.each( function() { 612 var $self = jQuery(this); 613 // Get initially opened tab 614 var init = $self.data('active'); 615 if (isNaN(init)) { 616 init = 0; 617 var active = $self.find('> ul > li[data-active="true"]').eq(0); 618 if (active.length > 0) { 619 init = active.index(); 620 if (isNaN(init) || init < 0) init = 0; 621 } 622 } else { 623 init = Math.max(0, init); 624 } 625 // Get disabled tabs 626 var disabled = []; 627 $self.find('> ul > li[data-disabled="true"]').each( function() { 628 disabled.push(jQuery(this).index()); 629 }); 630 // Init tabs 631 $self.addClass('inited').tabs({ 632 active: init, 633 disabled: disabled, 634 show: { 635 effect: 'fadeIn', 636 duration: 300 637 }, 638 hide: { 639 effect: 'fadeOut', 640 duration: 300 641 }, 642 create: function( event, ui ) { 643 if ( ui.panel.length > 0 && ! ready_busy ) { 644 $document.trigger( 'action.create_tab', [ui.panel] ); 645 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 646 } 647 }, 648 activate: function( event, ui ) { 649 if ( ui.oldPanel.length > 0 && ! ready_busy ) { 650 $document.trigger( 'action.deactivate_tab', [ui.oldPanel] ); 651 } 652 if ( ui.newPanel.length > 0 && ! ready_busy ) { 653 $document.trigger( 'action.activate_tab', [ui.newPanel] ); 654 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 655 $window.trigger( 'resize' ); 656 } 657 } 658 }); 659 }); 660 } 661 } 662 663 664 // Accordion 665 //------------------------------------ 666 if (jQuery.ui && jQuery.ui.accordion) { 667 var $accordion = container.find('.trx_addons_accordion:not(.inited)'); 668 if ( $accordion.length > 0) { 669 $accordion.each(function () { 670 // Get headers selector 671 var accordion = jQuery(this); 672 var headers = accordion.data('headers') || 'h5'; 673 // Get height style 674 var height_style = accordion.data('height-style') || 'content'; 675 // Get collapsible 676 var collapsible = accordion.data('collapsible') || false; 677 // Get initially opened tab 678 var init = accordion.data('active'); 679 var active = false; 680 if ( isNaN( init ) ) { 681 init = 0; 682 active = accordion.find( headers + '[data-active="true"]' ).eq(0); 683 if ( active.length > 0 ) { 684 while ( ! active.parent().hasClass( 'trx_addons_accordion' ) ) { 685 active = active.parent(); 686 } 687 init = active.index(); 688 if ( isNaN( init ) || init < 0 ) init = 0; 689 } 690 } else { 691 init = Math.max( 0, init ); 692 } 693 // Init accordion 694 accordion.addClass('inited').accordion({ 695 active: init, 696 collapsible: collapsible, 697 header: headers, 698 heightStyle: height_style, 699 create: function( event, ui ) { 700 if ( ui.panel.length > 0 && ! ready_busy ) { 701 $document.trigger( 'action.create_accordion', [ui.panel] ); 702 $document.trigger( 'action.init_hidden_elements', [ui.panel] ); 703 } else if ( active !== false && active.length > 0 ) { 704 // If headers and panels wrapped into div 705 active.find('>'+headers).trigger('click'); 706 } 707 }, 708 activate: function( event, ui ) { 709 if (ui.oldPanel.length > 0 && ! ready_busy) { 710 $document.trigger( 'action.deactivate_accordion', [ui.oldPanel] ); 711 } 712 if (ui.newPanel.length > 0 && ! ready_busy) { 713 $document.trigger( 'action.activate_accordion', [ui.newPanel] ); 714 $document.trigger( 'action.init_hidden_elements', [ui.newPanel] ); 715 $window.trigger( 'resize' ); 716 } 717 } 718 }); 719 }); 720 } 721 } 722 723 // Color Picker 724 //---------------------------------------------------------------- 725 var cp = container.find('.trx_addons_color_selector:not(.inited)'), 726 cp_created = false;
727 if (cp.length > 0) { 728 cp.addClass('inited').each( function() { 729 var $self = jQuery(this); 730 // Internal ColorPicker 731 if ( $self.hasClass('iColorPicker') ) { 732 if (!cp_created) { 733 trx_addons_color_picker(); 734 cp_created = true; 735 } 736 trx_addons_change_field_colors($self); 737 $self 738 .on('focus', function (e) { 739 trx_addons_color_picker_show(null, jQuery(this), function(fld, clr) { 740 fld.val(clr).trigger('change'); 741 trx_addons_change_field_colors(fld); 742 }); 743 }) 744 .on('change', function(e) { 745 trx_addons_change_field_colors(jQuery(this)); 746 }); 747 748 // WP ColorPicker - Iris 749 } else if (typeof jQuery.fn.wpColorPicker != 'undefined') { 750 $self.wpColorPicker({ 751 // you can declare a default color here, 752 // or in the data-default-color attribute on the input 753 //defaultColor: false, 754 755 // hide the color picker controls on load 756 //hide: true, 757 758 // show a group of common colors beneath the square 759 // or, supply an array of colors to customize further 760 //palettes: true, 761 762 // a callback to fire whenever the color changes to a valid color 763 change: function(e, ui){ 764 jQuery(e.target).val(ui.color).trigger('change'); 765 }, 766 767 // a callback to fire when the input is emptied or an invalid color 768 clear: function(e) { 769 jQuery(e.target).prev().trigger('change'); 770 } 771 }); 772 } 773 }); 774 } 775 776 // Change colors of the field 777 function trx_addons_change_field_colors(fld) { 778 var clr = fld.val(), 779 hsb = trx_addons_hex2hsb(clr); 780 fld.css({ 781 'backgroundColor': clr, 782 'color': hsb['b'] < 70 ? '#fff' : '#000' 783 }); 784 } 785 786 787 // Range Slider 788 //------------------------------------ 789 if (jQuery.ui && jQuery.ui.slider) { 790 var $range_slider = container.find('.trx_addons_range_slider:not(.inited)'); 791 if ($range_slider.length > 0) { 792 $range_slider.each( function () { 793 // Get parameters 794 var range_slider = jQuery(this); 795 var linked_field = range_slider.data('linked_field'); 796 if (linked_field===undefined) linked_field = range_slider.prev('input[type="hidden"]'); 797 else linked_field = jQuery('#'+linked_field); 798 if (linked_field.length == 0) return; 799 var range_slider_cur = range_slider.find('> .trx_addons_range_slider_label_cur'); 800 var range_slider_min = range_slider.find('> .trx_addons_range_slider_label_min'); 801 var range_slider_max = range_slider.find('> .trx_addons_range_slider_label_max'); 802 var range_slider_type = range_slider.data('range'); 803 if (range_slider_type===undefined) range_slider_type = 'min'; 804 var values = linked_field.val().split(','); 805 var minimum = range_slider.data('min'); 806 if (minimum===undefined) minimum = 0; 807 var maximum = range_slider.data('max'); 808 if (maximum===undefined) maximum = 0; 809 var step = range_slider.data('step'); 810 if (step===undefined) step = 1; 811 // Init range slider 812 var init_obj = { 813 range: range_slider_type, 814 min: minimum, 815 max: maximum, 816 step: step, 817 slide: function(event, ui) { 818 trx_addons_range_slider_update_current_values_position(ui, range_slider_type === 'min' ? [ui.value] : ui.values); 819 }, 820 change: function(event, ui) { 821 trx_addons_range_slider_update_current_values_position(ui, range_slider_type === 'min' ? [ui.value] : ui.values); 822 }, 823 create: function(event, ui) { 824 trx_addons_range_slider_update_current_values_position(ui, values); 825 } 826 }; 827 if (range_slider_type === true) { 828 init_obj.values = values; 829 } else { 830 init_obj.value = values[0]; 831 } 832 range_slider.addClass('inited').slider(init_obj); 833 834 // Update position of labels with the current values 835 function trx_addons_range_slider_update_current_values_position(ui, cur_values) { 836 linked_field.val( cur_values.join(',') ).trigger('change'); 837 for (var i=0; i < cur_values.length; i++) { 838 range_slider_cur.eq(i) 839 .html(cur_values[i]) 840 .css('left', Math.max(0, Math.min(100, (cur_values[i]-minimum)*100/(maximum-minimum)))+'%'); 841 if ( range_slider_type !== 'min' && range_slider_cur.eq(i).css( 'display' ) == 'none' ) { 842 if ( i == 0 ) { 843 range_slider_min.html( cur_values[i] ); 844 } else { 845 range_slider_max.html( cur_values[i] ); 846 } 847 } 848 } 849 } 850 }); 851 } 852 } 853 854 855 // Select2 856 //------------------------------------ 857 if (jQuery.fn && jQuery.fn.select2) { 858 container.find('.trx_addons_select2:not(.inited)').addClass('inited').select2(); 859 } 860 861 862 // Media player 863 //---------------------------------------------- 864 if ( TRX_ADDONS_STORAGE['mediaplayer_icons_selector_allowed'] ) { 865 $document.on( 'action.init_hidden_elements', function( e, cont ) { 866 if ( cont === undefined || ! cont.length ) cont = $body; 867 var buttons = { play: 'playpause', pause: 'playpause', volume: 'volume', mute: 'volume', fullscreen: 'fullscreen', unfullscreen: 'fullscreen' }; 868 // Find all mediaelement players and replace icons if in the tag <audio> or <video> present data-icon-media-play="html code" 869 cont.find( 'mediaelementwrapper audio:not(.trx_media_icons_inited), mediaelementwrapper video:not(.trx_media_icons_inited)' ).each( function() { 870 var $self = jQuery( this ).addClass( 'trx_media_icons_inited' ), 871 $mejs_inner = $self.closest( '.mejs-inner' ); 872 for ( var b in buttons ) { 873 var icon = $self.data( 'icon-media-' + b ); 874 if ( icon !== undefined && icon !== '' ) { 875 $mejs_inner.find( '.mejs-' + buttons[b] + '-button button' ).addClass('mejs-button-with-icon').append( icon.replace( ' class="', ' class="mejs-button-icon-' + b + ' ' ) ); 876 } 877 } 878 } ); 879 } ); 880 } 881 882 // Video player 883 //---------------------------------------------- 884 885 // Play video on hover (for desktops) or on touchstart (for mobile devices) 886 var $play_on_hover = container.find( '.trx_addons_video_hover:not(.inited)' ); 887 var touchstart_just_fired = false;
888 if ( $play_on_hover.length > 0 ) { 889 $play_on_hover 890 .addClass( 'inited' ) 891 .on( 'mouseenter touchstart', function(e) { 892 var $self = jQuery( this ); 893 if ( ! $self.hasClass( 'trx_addons_video_hover_play' ) && ( e.type != 'touchstart' || ! touchstart_just_fired ) ) { 894 $self 895 .data( 'trx-addons-user-actions', 1 ) 896 .removeClass( 'trx_addons_video_hover_pause' ) 897 .addClass( 'trx_addons_video_hover_play' ) 898 .find( 'video' ).get(0).play(); 899 touchstart_just_fired = true; 900 setTimeout( function() { 901 touchstart_just_fired = false; 902 }, 300 ); 903 } 904 } ) 905 .on( 'mouseleave touchstart', function(e) { 906 var $self = jQuery( this ); 907 if ( $self.hasClass( 'trx_addons_video_hover_play' ) && ( e.type != 'touchstart' || ! touchstart_just_fired ) ) { 908 $self 909 .data( 'trx-addons-user-actions', 1 ) 910 .removeClass( 'trx_addons_video_hover_play' ) 911 .addClass( 'trx_addons_video_hover_pause' ) 912 .find( 'video' ).get(0).pause(); 913 $self 914 .find( '.trx_addons_video_subtitle_text' ) 915 .one( typeof window.trx_addons_transition_end != 'undefined' ? trx_addons_transition_end() : 'transitionend', function() { 916 $self.removeClass( 'trx_addons_video_hover_pause' ); 917 } ); 918 touchstart_just_fired = true; 919 setTimeout( function() { 920 touchstart_just_fired = false; 921 }, 300 ); 922 } 923 } ); 924 // Autoplay/pause video on enter/leave to the viewport (if an option "autoplay" is on) 925 var $play_on_hover_autoplay = $play_on_hover.find( 'video[data-autoplay="1"]' ); 926 if ( $play_on_hover_autoplay.length > 0 ) { 927 trx_addons_intersection_observer_add( $play_on_hover_autoplay, function( item, enter ) { 928 if ( item.data( 'trx-addons-user-actions' ) ) { 929 trx_addons_intersection_observer_remove( item ); 930 } else if ( enter ) { 931 item 932 .addClass( 'trx_addons_video_hover_play' ) 933 .get(0).play(); 934 } else { 935 item 936 .removeClass( 'trx_addons_video_hover_play' ) 937 .get(0).pause(); 938 } 939 } ); 940 } 941 } 942 943 // Video frame 'Play' button 944 var $video_hover = container.find('.trx_addons_video_player.with_cover .video_hover:not(.inited)'); 945 if ( $video_hover.length > 0 ) { 946 $video_hover 947 .addClass( 'inited' ) 948 .on( 'click', function(e) { 949 var $self = jQuery( this ); 950 951 // If video in the popup 952 if ( $self.hasClass( 'trx_addons_popup_link' ) ) { 953 return true; 954 } 955 956 // Replace a content of the container with the video player 957 trx_addons_insert_video_iframe( $self.parents('.trx_addons_video_player').eq(0).addClass('video_play').find('.video_embed'), $self.data('video') ); 958 959 // If video in the slide 960 var slider = $self.parents('.slider_swiper').eq(0); 961 if ( slider.length > 0 ) { 962 var id = slider.attr('id'); 963 if ( typeof TRX_ADDONS_STORAGE['swipers'][id].autoplay != 'undefined' ) { 964 TRX_ADDONS_STORAGE['swipers'][id].autoplay.stop(); 965 // If slider have controller - stop it too 966 id = slider.data('controller'); 967 if ( id && TRX_ADDONS_STORAGE['swipers'][id+'_swiper'] ) { 968 TRX_ADDONS_STORAGE['swipers'][id+'_swiper'].autoplay.stop(); 969 } 970 } 971 } else { 972 $self.fadeOut(); 973 } 974 975 e.preventDefault(); 976 977 $document.trigger( 'action.init_hidden_elements', [$self.parents('.trx_addons_video_player').eq(0)] ); 978 $window.trigger('resize'); 979 980 return false; 981 }) 982 .parents('.trx_addons_video_player') 983 .on( 'click', function(e) { 984 var $self = jQuery(this); 985 if ( ! $self.hasClass('video_play') ) { 986 jQuery(this).find('.video_hover').trigger('click'); 987 e.preventDefault(); 988 return false; 989 } 990 } ); 991 } 992 993 // Video player controller 994 var $video_controller = container.find('.trx_addons_video_list_controller_wrap:not(.inited)'); 995 if ($video_controller.length > 0) { 996 // Init controller 997 $video_controller 998 .addClass('inited') 999 .on('click', '.trx_addons_video_list_controller_item > a[href="#"]', function(e) { 1000 1001 e.preventDefault(); 1002 1003 var item = jQuery(this).parent(), 1004 video = item.data('video'), 1005 title = item.data('title'), 1006 video_wrap = item.parents('.trx_addons_video_list').find('.trx_addons_video_list_video_wrap .trx_addons_video_player').parent(); 1007 1008 if ( ! item.hasClass('trx_addons_video_list_controller_item_active') && video && video_wrap.length == 1 ) { 1009 item.parent().find('.trx_addons_video_list_controller_item_active').removeClass('trx_addons_video_list_controller_item_active'); 1010 item.addClass('trx_addons_video_list_controller_item_active');
1011 var autoplay = video_wrap.find('.with_video_autoplay'); 1012 if ( autoplay.length ) { 1013 autoplay 1014 .removeClass( 'with_video_autoplay video_autoplay_inited video_autoplay_started' ) 1015 .find('video_frame_controls').remove(); 1016 trx_addons_intersection_observer_remove( autoplay ); 1017 trx_addons_find_video_autoplay(); 1018 } 1019 video_wrap 1020 .fadeTo( 300, 0, function() { 1021 video_wrap.height( video_wrap.height() ); 1022 // Replace a content of the container with the video player 1023 trx_addons_insert_video_iframe( video_wrap, video ); 1024 // Add a title 1025 if ( title ) { 1026 video_wrap.append( title ); 1027 } 1028 video_wrap.find('video').removeAttr('width').removeAttr('height'); 1029 $document.trigger( 'action.init_hidden_elements', [video_wrap] ); 1030 $window.trigger( 'resize' ); 1031 video_wrap.height('auto'); 1032 } ) 1033 .fadeTo( 300, 1, function() { 1034 if ( item.data( 'autoplay' ) > 0 && video_wrap.find( '.trx_addons_video_player .video_hover').length > 0 ) { 1035 video_wrap.find( '.trx_addons_video_player .video_hover').eq(0).trigger( 'click' ); 1036 } 1037 } ); 1038 } 1039 1040 return false; 1041 }); 1042 // Preload cover images 1043 setTimeout( function() { 1044 $video_controller.find('[data-video]').each( function() { 1045 var video = jQuery(this).data('video'); 1046 if ( video ) { 1047 var img = jQuery('img', video); 1048 if ( img.length ) { 1049 var obj = new Image(); 1050 obj.src = img.attr('src'); 1051 } 1052 } 1053 } ); 1054 }, trx_addons_apply_filters('trx_addons_filter_video_controller_preload_images_timeout', 0) ); 1055 } 1056 1057 // Video sticky 1058 $video_sticky.each( function() { 1059 1060 var video = jQuery(this); 1061 1062 // Close button 1063 video 1064 .find( '.trx_addons_video_sticky_close:not(.inited)' ) 1065 .addClass( 'inited' ) 1066 .on( 'click', function( e ) { 1067 1068 e.preventDefault(); 1069 1070 jQuery(this).hide(); 1071 1072 trx_addons_intersection_observer_remove( video ); 1073 1074 if ( _video_sticky_fade ) { 1075 video.addClass('trx_addons_video_sticky_on_fade').stop().animate({opacity:0}
1075, 300, function() { 1076 video.parents('.post_featured').removeClass( 'with_video_sticky_on' ); 1077 video.height('auto').removeClass( 'trx_addons_video_sticky trx_addons_video_sticky_on trx_addons_video_sticky_on_fade' ).stop().animate({'opacity': 1}, 500); 1078 $video_sticky = jQuery('.trx_addons_video_sticky'); 1079 $window.trigger('resize'); 1080 }); 1081 } else { 1082 video.parents('.post_featured').removeClass( 'with_video_sticky_on' ); 1083 video.height('auto').removeClass('trx_addons_video_sticky trx_addons_video_sticky_on'); 1084 $video_sticky = jQuery('.trx_addons_video_sticky'); 1085 $window.trigger('resize'); 1086 } 1087 1088 return false; 1089 } ); 1090 1091 // Fix / Unfix sticky video to the bottom of the viewport (window) 1092 trx_addons_intersection_observer_add( video, function( item, enter, entry ) { 1093 var video = item, 1094 video_top = video.offset().top, 1095 video_height = video.height(); 1096 if ( ! enter ) { 1097 if ( ( typeof entry != 'object' || entry.boundingClientRect.top < 0 ) 1098 && ! video.hasClass('trx_addons_video_sticky_on') 1099 ) { 1100 // Stick video only if it present in .video_frame 1101 if ( video.find( '.video_frame' ).html().trim().length > 30 ) { 1102 video.parents('.post_featured').addClass( 'with_video_sticky_on' ); 1103 if ( _video_sticky_fade ) { 1104 video.height( video_height ).css('opacity', 0).addClass( 'trx_addons_video_sticky_on' ).stop().animate({opacity:1}, 500); 1105 } else { 1106 video.height( video_height ).addClass( 'trx_addons_video_sticky_on' ); 1107 } 1108 } 1109 } 1110 } else { 1111 if ( video.hasClass('trx_addons_video_sticky_on') && ! video.hasClass('trx_addons_video_sticky_on_fade') ) { 1112 if ( _video_sticky_fade ) { 1113 video.addClass('trx_addons_video_sticky_on_fade').stop().animate({opacity:0}
1113, 300, function() { 1114 video.parents('.post_featured').removeClass( 'with_video_sticky_on' ); 1115 video.height('auto').removeClass( 'trx_addons_video_sticky_on trx_addons_video_sticky_on_fade' ).stop().animate({'opacity': 1}, 500); 1116 $window.trigger('resize'); 1117 }); 1118 } else { 1119 video.parents('.post_featured').removeClass( 'with_video_sticky_on' ); 1120 video.height('auto').removeClass( 'trx_addons_video_sticky_on' ); 1121 $window.trigger('resize'); 1122 } 1123 } 1124 } 1125 } ); 1126 } ); 1127 1128 // Show autoplaing videos from not controlled sources 1129 $video_autoplay.each( function() { 1130 var $self = jQuery(this); 1131 if ( $self.find('iframe[src*="youtu"]').length === 0 ) { 1132 $self.find('.video_frame').addClass('video_frame_visible'); 1133 } 1134 } ); 1135 1136 // Trigger 'resize' event on the button 'Fullscreen' is clicked inside the MediaElement player 1137 // Add a handler after the timeout to allow a theme to init the player on the video tag 1138 setTimeout( function() { 1139 container 1140 .find('.mejs-fullscreen-button:not(.resize_inited)') 1141 .addClass('resize_inited') 1142 .on( 'click', 'button', function() { 1143 setTimeout( function() { 1144 $window.trigger('resize'); 1145 }, 100 ); 1146 } ); 1147 }, 100 ); 1148 1149 // Popups & Panels 1150 //---------------------------------------------- 1151 1152 // PrettyPhoto Engine 1153 if (TRX_ADDONS_STORAGE['popup_engine'] == 'pretty') { 1154 // Display lightbox on click on the image 1155 container 1156 .find( trx_addons_apply_filters( 'pretty-init-images', 1157 'a[href$="jpg"]:not(.inited):not([target="_blank"]):not([download])' 1158 +',a[href$="jpeg"]:not(.inited):not([target="_blank"]):not([download])' 1159 +',a[href$="png"]:not(.inited):not([target="_blank"]):not([download])' 1160 +',a[href$="gif"]:not(.inited):not([target="_blank"]):not([download])' 1161 ) 1162 ) 1163 .each( function() { 1164 var $self = jQuery(this); 1165 if ( ! $self.parent().hasClass('woocommerce-product-gallery__image')) { 1166 $self.attr('rel', 'prettyPhoto[slideshow]'); 1167 } 1168 }); 1169 var images = container.find( trx_addons_apply_filters( 'pretty-init-images-selector', 1170 'a[rel*="prettyPhoto"]' 1171 + ':not(.inited)' 1172 + ':not(.esgbox)' 1173 + ':not(.fancybox)' 1174 + ':not([target="_blank"])' 1175 + ':not([data-rel*="pretty"])' 1176 + ':not([rel*="magnific"])' 1177 + ':not([data-rel*="magnific"])' 1178 + ':not([data-elementor-lightbox-slideshow])' 1179 + ':not([data-elementor-open-lightbox="yes"])' 1180 + ':not([data-elementor-open-lightbox="default"])' 1181 ) 1182 ).addClass('inited'); 1183 if ( images.length > 0 ) { 1184 try { 1185 images.prettyPhoto( trx_addons_apply_filters( 'pretty-init-images-params', { 1186 social_tools: '', 1187 theme: 'facebook', 1188 deeplinking: false 1189 } ) ); 1190 } catch (e) {} 1191 } 1192 1193 // or Magnific Popup Engine 1194 } else if (TRX_ADDONS_STORAGE['popup_engine']=='magnific' && typeof jQuery.fn.magnificPopup != 'undefined') { 1195 // Display lightbox on click on the image 1196 container 1197 .find( trx_addons_apply_filters( 'mfp-init-images', 1198 'a[href$="jpg"]:not(.inited):not([target="_blank"]):not([download])' 1199 +',a[href$="jpeg"]:not(.inited):not([target="_blank"]):not([download])' 1200 +',a[href$="png"]:not(.inited):not([target="_blank"]):not([download])' 1201 +',a[href$="gif"]:not(.inited):not([target="_blank"]):not([download])' 1202 ) 1203 ) 1204 .each( function() { 1205 var $self = jQuery(this); 1206 if ( trx_addons_apply_filters( 'mfp-init-images-allow', 1207 $self.closest('.cq-dagallery').length === 0 1208 && $self.closest('.woocommerce-product-gallery__image').length === 0 1209 && ! $self.hasClass('prettyphoto') 1210 && ! $self.hasClass('esgbox'), 1211 $self 1212 ) 1213 ) { 1214 $self.attr('rel', 'magnific'); 1215 } 1216 }); 1217 var images = container.find( trx_addons_apply_filters( 'mfp-init-images-selector', 1218 'a[rel*="magnific"]' 1219 + ':not(.inited)' 1220 + ':not(.esgbox)' 1221 + ':not(.fancybox)' 1222 + ':not([target="_blank"])' 1223 + ':not([download])' 1224 + ':not(.prettyphoto)' 1225 + ':not([rel*="pretty"])' 1226 + ':not([data-rel*="pretty"])' 1227 + ':not([data-elementor-lightbox-slideshow])' 1228 + ':not([data-elementor-open-lightbox="yes"])' 1229 + ':not([data-elementor-open-lightbox="default"])' 1230 ) 1231 ).addClass('inited'); 1232 if ( images.length > 0 ) { 1233 // Unbind prettyPhoto 1234 setTimeout(function() { images.off('click.prettyphoto'); }, 100); 1235 // Bind Magnific 1236 try { 1237 images.magnificPopup( trx_addons_apply_filters( 'mfp-init-images-p
1237arams', { 1238 type: 'image', 1239 mainClass: 'mfp-img-mobile', 1240 closeOnContentClick: true, 1241 closeBtnInside: true, 1242 fixedContentPos: true, 1243 midClick: true, 1244 //removalDelay: 500, 1245 preloader: true, 1246 tLoading: TRX_ADDONS_STORAGE['msg_magnific_loading'], 1247 tClose: TRX_ADDONS_STORAGE['msg_magnific_close'], 1248 closeMarkup: '<button title="%title%" aria-label="%title%" type="button" class="mfp-close"><span class="mfp-close-icon">×</span></button>', 1249 gallery:{ 1250 enabled: true 1251 }, 1252 image: { 1253 tError: TRX_ADDONS_STORAGE['msg_magnific_error'], 1254 verticalFit: true, 1255 titleSrc: function(item) { 1256 var title = '', 1257 $el = typeof item.el != 'undefined' ? jQuery( item.el ) : null; 1258 if ( $el && $el.length > 0 ) { 1259 var $next = $el.next(); 1260 if ( $next.length > 0 && $next.get(0).tagName == 'FIGCAPTION' ) { 1261 title = $next.text(); 1262 } else if ( $el.attr( 'title' ) ) { 1263 title = $el.attr( 'title' ); 1264 } else { 1265 var $img = $el.find( 'img' ); 1266 if ( $img.length > 0 ) { 1267 title = $img.attr( 'alt' ); 1268 if ( ! title ) { 1269 title = $img.data('caption'); 1270 } 1271 } 1272 } 1273 } 1274 return title; 1275 } 1276 }, 1277 zoom: { 1278 enabled: true, 1279 duration: 300, 1280 easing: 'ease-in-out', 1281 opener: function(openerElement) { 1282 // openerElement is the element on which popup was initialized, in this case its <a> tag 1283 // you don't need to add "opener" option if this code matches your needs, it's defailt one. 1284 if (!openerElement.is('img')) { 1285 if (openerElement.parents('.trx_addons_hover').find('img').length > 0) 1286 openerElement = openerElement.parents('.trx_addons_hover').find('img'); 1287 else if (openerElement.find('img').length > 0) 1288 openerElement = openerElement.find('img'); 1289 else if (openerElement.siblings('img').length > 0) 1290 openerElement = openerElement.siblings('img'); 1291 else if (openerElement.parent().parent().find('img').length > 0) 1292 openerElement = openerElement.parent().parent().find('img'); 1293 } 1294 return openerElement; 1295 } 1296 }, 1297 callbacks: { 1298 beforeClose: function(){ 1299 jQuery('.mfp-figure figcaption').hide(); 1300 jQuery('.mfp-figure .mfp-arrow').hide(); 1301 } 1302 } 1303 } ) ); 1304 } catch (e) {} 1305 } 1306 1307 // Prepare links to popups & panels 1308 //---------------------------------------- 1309 var on_leaving_site = [], 1310 in_page_edit_mode = $body.hasClass('elementor-editor-active') 1311 || $body.hasClass('wp-admin') 1312 || $body.hasClass('block-editor-page'); 1313 // Init popups and panels links 1314 container.find('.sc_layouts_popup:not(.inited),.sc_layouts_panel:not(.inited)').each( function() { 1315 var $self = jQuery(this), 1316 id = $self.attr('id'), 1317 show = false; 1318 if (!id) return; 1319 var is_panel = $self.hasClass('sc_layouts_panel'), 1320 link = jQuery('a[href="#'+id+'"],' + ( is_panel ? '.trx_addons_panel_link[data-panel-id="'+id+'"]' : '.trx_addons_popup_link[data-popup-id="'+id+'"]' ) ); 1321 if (link.length === 0) { 1322 $body.append('<a href="#'+id+'" class="trx_addons_hidden"></a>'); 1323 link = jQuery('a[href="#'+id+'"]'); 1324 } 1325 if ($self.hasClass('sc_layouts_show_on_page_load')) { 1326 show = true; 1327 } else if ($self.hasClass('sc_layouts_show_on_page_load_once') && trx_addons_get_cookie('trx_addons_show_on_page_load_once_'+id) != '1') { 1328 trx_addons_set_cookie('trx_addons_show_on_page_load_once_'+id, '1'); 1329 show = true; 1330 } else if ($self.hasClass('sc_layouts_show_on_page_close') && trx_addons_get_cookie('trx_addons_show_on_page_close_'+id) != '1') { 1331 on_leaving_site.push({ 1332 link: link, 1333 id: id 1334 }); 1335 } 1336 if (show) { 1337 // Display popups (panels) on the page (site) load 1338 if ( ! in_page_edit_mode ) { 1339 setTimeout( function() { 1340 link.trigger('click'); 1341 }, $self.data('delay') > 0 ? $self.data('delay') * 1000 : 0 ); 1342 } 1343 } 1344 link 1345 .addClass(is_panel ? 'trx_addons_panel_link' : 'trx_addons_popup_link') 1346 .data('panel', $self); 1347 $self 1348 .addClass('inited') 1349 .on('click', '.sc_layouts_panel_close', function(e) { 1350 trx_addons_close_panel($self); 1351 e.preventDefault(); 1352 return false;
1353 }); 1354 }); 1355 1356 // Display popup when user leaving site 1357 if ( on_leaving_site.length > 0 && ! in_page_edit_mode ) { 1358 var showed = false; 1359 $window.on( 'mousemove', function(e) { 1360 if ( showed ) return; 1361 var y = typeof e.clientY != 'undefined' ? e.clientY : 999; 1362 if ( y < trx_addons_adminbar_height() + 15 ) { 1363 showed = true; 1364 on_leaving_site.forEach( function(item) { 1365 item.link.trigger('click'); 1366 trx_addons_set_cookie('trx_addons_show_on_page_close_'+item.id, '1'); 1367 }); 1368 } 1369 } ); 1370 } 1371 1372 // Display lightbox on click on the popup link 1373 container.find( trx_addons_apply_filters( 'mfp-init-popup-selector', ".trx_addons_popup_link:not(.popup_inited)" ) ) 1374 .addClass('popup_inited') 1375 .magnificPopup( trx_addons_apply_filters( 'mfp-init-popup-params', { 1376 type: 'inline', 1377 focus: 'input', 1378 removalDelay: trx_addons_apply_filters('trx_addons_filter_close_popup_timeout', 0), 1379 tLoading: TRX_ADDONS_STORAGE['msg_magnific_loading'], 1380 tClose: TRX_ADDONS_STORAGE['msg_magnific_close'], 1381 closeBtnInside: true, 1382 closeMarkup: '<button title="%title%" aria-label="%title%" type="button" class="mfp-close"><span class="mfp-close-icon">×</span></button>', 1383 callbacks: { 1384 // Will fire when this before popup is opened 1385 // this - is Magnific Popup object 1386 beforeAppend: function () { 1387 var $mfp = this; 1388 // Prepare content for the popup 1389 $document.trigger('action.prepare_popup_elements', [$mfp.content, $mfp]); 1390 }, 1391 beforeOpen: function() { 1392 var $mfp = this; 1393 $document.trigger('action.open_popup_elements', [$mfp.content]); 1394 // Add in animation (separately popup and bg overlay) 1395 var wrap_animation_in = mfp_get_animation( $mfp, 'wrap', 'open' ), 1396 bg_animation_in = mfp_get_animation( $mfp, 'bg', 'open' ); 1397 if ( bg_animation_in ) { 1398 $mfp.bgOverlay.addClass(bg_animation_in); 1399 } 1400 if ( wrap_animation_in ) { 1401 $mfp.wrap.addClass(wrap_animation_in); 1402 } 1403 }, 1404 // Will fire when this exact popup is opened 1405 // this - is Magnific Popup object 1406 open: function () { 1407 // Get saved content or store it (if first open occured) 1408 trx_addons_prepare_popup_content(this.content, true); 1409 }, 1410 beforeClose: function() { 1411 var $mfp = this; 1412 $document.trigger('action.close_popup_elements', [$mfp.content]); 1413 // Add out animation (separately popup and bg overlay) 1414 var wrap_animation_in = mfp_get_animation( $mfp, 'wrap', 'open' ), 1415 bg_animation_in = mfp_get_animation( $mfp, 'bg', 'open' ), 1416 wrap_animation_out = mfp_get_animation( $mfp, 'wrap', 'close' ), 1417 bg_animation_out = mfp_get_animation( $mfp, 'bg', 'close' ), 1418 delay = wrap_animation_out 1419 ? trx_addons_apply_filters( 'mfp-init-popup-animations-duration', 1420 wrap_animation_out.indexOf('faster') != -1 1421 ? 300 1422 : ( wrap_animation_out.indexOf('fast') != -1 1423 ? 500 1424 : ( wrap_animation_out.indexOf('normal') != -1 1425 ? 800 1426 : ( wrap_animation_out.indexOf('slow') != -1 1427 ? 2000 1428 : ( wrap_animation_out.indexOf('slower') != -1 1429 ? 3000 1430 : 1000 1431 ) 1432 ) 1433 ) 1434 ), 1435 wrap_animation_out 1436 ) 1437 : 0; 1438 $mfp.st.removalDelay += delay; 1439 if ( bg_animation_out ) { 1440 setTimeout( function() { 1441 $mfp.bgOverlay.removeClass(bg_animation_in).addClass(bg_animation_out); 1442 }, $mfp.st.removalDelay - delay ); 1443 } 1444 if ( wrap_animation_out ) { 1445 setTimeout( function() { 1446 $mfp.wrap.removeClass(wrap_animation_in).addClass(wrap_animation_out); 1447 }, $mfp.st.removalDelay - delay ); 1448 } 1449 }, 1450 close: function () { 1451 var $mfp = this; 1452 // Save and remove content before closing 1453 // if its contain video, audio or iframe 1454 trx_addons_close_panel($mfp.content); 1455 }, 1456 // resize event triggers only when height is changed or layout forced 1457 resize: function () { 1458 var $mfp = this; 1459 trx_addons_resize_actions(jQuery($mfp.content)); 1460 } 1461 } 1462 } ) ); 1463 1464 // Return animation name for popup 1465 var mfp_get_animation = function( mfp, item, event, defa ) { 1466 var defaults = trx_addons_apply_filters( 'mfp-init-popup-animations', { 1467 'wrap_open': 'fadeIn animated fast', 1468 'wrap_close': 'fadeOut animated fast', 1469 'bg_open': 'fadeIn animated fast', 1470 'bg_close': 'fadeOut animated fast' 1471 } ); 1472 return mfp.st.el.attr('data-popup-'+item+'-'+event+'-animation') 1473 ? mfp.st.el.attr('data-popup-'+item+'-'+event+'-animation') 1474 : trx_addons_apply_filters( 'mfp-init-popup-'+item+'-'+event+'-animation', defa ? defa
1474: defaults[item+'_'+event] ); 1475 }; 1476 1477 // Open panel on click on the panel link 1478 container.find( trx_addons_apply_filters( 'init-panel-selector', ".trx_addons_panel_link:not(.panel_inited)" ) ) 1479 .addClass('panel_inited') 1480 .on('click', function(e) { 1481 var panel = jQuery(this).data('panel'); 1482 if ( ! panel.hasClass( 'sc_layouts_panel_opened' ) ) { 1483 $document.trigger('action.prepare_popup_elements', [panel]); 1484 trx_addons_prepare_popup_content(panel, true); 1485 panel.addClass('sc_layouts_panel_opened'); 1486 $document.trigger('action.opened_popup_elements', [panel]); 1487 if (panel.prev().hasClass('sc_layouts_panel_hide_content')) panel.prev().addClass('sc_layouts_panel_opened'); 1488 $body.addClass('sc_layouts_panel_opened sc_layouts_panel_opened_' + panel.data('panel-position')); 1489 var panel_class = panel.data('panel-class'); 1490 if ( panel_class ) { 1491 $body.addClass( panel_class + '_opened' ); 1492 } 1493 } else { 1494 trx_addons_close_panel(panel); 1495 } 1496 e.preventDefault(); 1497 return false; 1498 }); 1499 1500 // Close panel on click on the modal cover 1501 container.find('.sc_layouts_panel_hide_content:not(.inited)') 1502 .addClass('inited') 1503 .on('click', function(e) { 1504 trx_addons_close_panel(jQuery(this).next()); 1505 e.preventDefault(); 1506 return false; 1507 }); 1508 1509 // Close panel 1510 window.trx_addons_close_panel = function(panel) { 1511 if ( panel.hasClass('sc_layouts_panel') ) { 1512 $document.trigger('action.close_popup_elements', [panel]); 1513 } 1514 setTimeout( function() { 1515 panel.removeClass('sc_layouts_panel_opened'); 1516 if (panel.prev().hasClass('sc_layouts_panel_hide_content')) { 1517 panel.prev().removeClass('sc_layouts_panel_opened'); 1518 } 1519 $body.removeClass('sc_layouts_panel_opened sc_layouts_panel_opened_left sc_layouts_panel_opened_right sc_layouts_panel_opened_top sc_layouts_panel_opened_bottom'); 1520 var panel_class = panel.data('panel-class'); 1521 if ( panel_class ) { 1522 $body.removeClass( panel_class + '_opened' ); 1523 } 1524 if ( panel.data('popup-content') !== undefined ) { 1525 setTimeout( function() { panel.empty(); }, 500 ); 1526 } 1527 }, trx_addons_apply_filters('trx_addons_filter_close_panel_timeout', panel.hasClass('sc_layouts_panel') && panel.data('animation-delay') !== undefined ? panel.data('animation-delay') : 0, panel) ); 1528 }; 1529 1530 // Get saved content for panel or popup or store it (if first open occured) 1531 window.trx_addons_prepare_popup_content = function(container, autoplay) { 1532 var wrapper = jQuery(container); 1533 // Store popup content to the data-param or restore it when popup open again (second time) 1534 // if popup contains audio or video or iframe 1535 if (wrapper.data('popup-content') === undefined) { 1536 var iframe = wrapper.find('iframe'); 1537 if ( wrapper.find('audio').length 1538 || wrapper.find('video').length 1539 || ( iframe.length 1540 && ( ( iframe.data('src') && iframe.data('src').search(/(youtu|vimeo|daily|facebook|instagram.com)/i) > 0 ) 1541 || 1542 ( iframe.attr('src') && iframe.attr('src').search(/(youtu|vimeo|daily|facebook|instagram.com)/i) > 0 ) 1543 ) 1544 ) 1545 ) { 1546 wrapper.data( 'popup-content', wrapper.html() ); 1547 } 1548 } else { 1549 wrapper.html( wrapper.data('popup-content') ); 1550 // Remove class 'inited' to reinit elements 1551 wrapper.find('.inited').removeClass('inited'); 1552 } 1553 // Replace src with data-src 1554 wrapper.find('[data-src]').each(function() { 1555 jQuery(this).attr( 'src', jQuery(this).data('src') ); 1556 }); 1557 // Init hidden elements 1558 $document.trigger( 'action.init_hidden_elements', [wrapper] ); 1559 // Init third-party plugins in the popup 1560 $document.trigger( 'action.init_popup_elements', [wrapper] ); 1561 // If popup contain embedded video - add autoplay 1562 if (autoplay) trx_addons_set_autoplay(wrapper); 1563 // If popup contain essential grid 1564 var frame = wrapper.find('.esg-grid'); 1565 if ( frame.length > 0 ) { 1566 var wrappers = [".esg-tc.eec", ".esg-lc.eec", ".esg-rc.eec", ".esg-cc.eec", ".esg-bc.eec"]; 1567 for (var i = 0; i < wrappers.length; i++) { 1568 frame.find(wrappers[i]+'>'+wrappers[i]).unwrap(); 1569 } 1570 } 1571 // Call resize actions for the new content 1572 $window.trigger('resize'); 1573 }; 1574 } 1575 1576 1577 // Views counter via AJAX 1578 //-------------------------------------- 1579 if ( TRX_ADDONS_STORAGE['ajax_views'] && ! TRX_ADDONS_STORAGE['post_views_counter_inited'] ) {
1580 TRX_ADDONS_STORAGE['post_views_counter_inited'] = true; 1581 $document.on( 'action.ready_trx_addons', function() { 1582 setTimeout( function() { 1583 jQuery.post( TRX_ADDONS_STORAGE['ajax_url'], { 1584 action: 'post_counter', 1585 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 1586 post_id: TRX_ADDONS_STORAGE['post_id'], 1587 views: 1 1588 } ).done( function( response ) { 1589 var rez = trx_addons_parse_ajax_response( response ); 1590 if ( rez.error === '' ) { 1591 jQuery('.post_meta_single .post_meta_views .post_meta_number,.sc_layouts_title_meta .post_meta_views .post_meta_number').html(rez.counter); 1592 } 1593 $document.trigger( 'action.got_ajax_response', { 1594 action: 'post_counter', 1595 result: rez 1596 } ); 1597 } ); 1598 }, 10 ); 1599 } ); 1600 } 1601 1602 1603 // Likes counter 1604 //--------------------------------------------- 1605 var $likes = container.find('a.post_meta_likes:not(.inited),a.comment_counters_likes:not(.inited)'); 1606 if ($likes.length > 0) { 1607 var likes_busy = false; 1608 $likes 1609 .addClass('inited') 1610 .on('click', function(e) { 1611 if ( ! likes_busy) { 1612 likes_busy = true; 1613 var button = jQuery(this); 1614 var inc = button.hasClass('enabled') ? 1 : -1; 1615 var post_id = button.hasClass('post_meta_likes') ? button.data('postid') : button.data('commentid'); 1616 var cookie_likes = trx_addons_get_cookie(button.hasClass('post_meta_likes') ? 'trx_addons_likes' : 'trx_addons_comment_likes'); 1617 if (cookie_likes === undefined || cookie_likes===null) cookie_likes = ''; 1618 jQuery.post( TRX_ADDONS_STORAGE['ajax_url'], { 1619 action: button.hasClass('post_meta_likes') ? 'post_counter' : 'comment_counter', 1620 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 1621 post_id: post_id, 1622 likes: inc 1623 }).done( function( response ) { 1624 var rez = trx_addons_parse_ajax_response( response ); 1625 if ( rez.error === '' ) { 1626 var counter = rez.counter; 1627 if ( inc == 1 ) { 1628 var title = button.data('title-dislike'); 1629 button.removeClass('enabled trx_addons_icon-heart-empty').addClass('disabled trx_addons_icon-heart'); 1630 cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ','; 1631 } else { 1632 var title = button.data('title-like'); 1633 button.removeClass('disabled trx_addons_icon-heart').addClass('enabled trx_addons_icon-heart-empty'); 1634 cookie_likes = cookie_likes.replace(','+post_id+',', ','); 1635 } 1636 button.data('likes', counter).attr('title', title).find(button.hasClass('post_meta_likes') ? '.post_meta_number' : '.comment_counters_number').html(counter); 1637 trx_addons_set_cookie( button.hasClass('post_meta_likes') ? 'trx_addons_likes' : 'trx_addons_comment_likes', cookie_likes, 365 * 24 * 60 * 60 * 1000); 1638 } else { 1639 alert(TRX_ADDONS_STORAGE['msg_error_like']); 1640 } 1641 likes_busy = false; 1642 $document.trigger( 'action.got_ajax_response', { 1643 action: button.hasClass('post_meta_likes') ? 'post_counter' : 'comment_counter', 1644 result: rez 1645 }); 1646 }); 1647 } 1648 e.preventDefault(); 1649 return false; 1650 }); 1651 } 1652 1653 1654 // Emotions counter 1655 //--------------------------------------------- 1656 var $emotions = container.find('.trx_addons_emotions:not(.inited)'); 1657 if ($emotions.length > 0) { 1658 var emotions_busy = false; 1659 $emotions 1660 .addClass('inited') 1661 .on('click', '.trx_addons_emotions_item', function(e) { 1662 if (!emotions_busy) { 1663 emotions_busy = true; 1664 var button = jQuery(this); 1665 var button_active = button.parent().find('.trx_addons_emotions_active'); 1666 var post_id = button.data('postid'); 1667 jQuery.post(TRX_ADDONS_STORAGE['ajax_url'], { 1668 action: 'post_counter', 1669 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 1670 post_id: post_id, 1671 emotion_inc: button.data('slug'), 1672 emotion_dec: button_active.length > 0 ? button_active.data('slug') : '', 1673 }).done( function( response ) { 1674 var rez = trx_addons_parse_ajax_response( response ); 1675 if ( rez.error === '' ) { 1676 var cookie_likes = trx_addons_get_cookie('trx_addons_emotions'), 1677 cookie_likes_new = ','; 1678 if ( cookie_likes ) { 1679 cookie_likes = cookie_likes.split(','); 1680 for ( var i=0; i < cookie_likes.length; i++ ) { 1681 if ( cookie_likes[i] === '' ) continue; 1682 var tmp = cookie_likes[i].split('='); 1683 if ( tmp[0] != post_id ) { 1684 cookie_likes_new += cookie_likes[i] + ','; 1685 } 1686 } 1687 } 1688 cookie_likes = cookie_likes_new; 1689 if (button_active.length > 0) { 1690 button_active.removeClass('trx_addons_emotions_active'); 1691 } 1692 if (button_active.length == 0 || button.data('slug') != button_active.data('slug')) { 1693 button.addClass('trx_addons_emotions_active'); 1694 cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + '=' + button.data('slug') + ','; 1695 } 1696 for (var i in rez.counter) { 1697 button.parent().find('[data-slug="'+i+'"] .trx_addons_emotions_item_number').html(rez.counter[i]); 1698 } 1699 trx_addons_set_cookie('trx_addons_emotions', cookie_likes, 365 * 24 * 60 * 60 * 1000); 1700 } else { 1701 alert(TRX_ADDONS_STORAGE['msg_error_like']); 1702 } 1703 emotions_busy = false;
1704 $document.trigger( 'action.got_ajax_response', { 1705 action: 'post_counter', 1706 result: rez 1707 }); 1708 }); 1709 } 1710 e.preventDefault(); 1711 return false; 1712 }); 1713 } 1714 1715 1716 // Socials share 1717 //---------------------------------------------- 1718 var $share_caption = container.find('.socials_share .socials_caption:not(.inited)'); 1719 if ($share_caption.length > 0) { 1720 $share_caption.each(function() { 1721 jQuery(this).addClass('inited').on('click', function(e) { 1722 jQuery(this).siblings('.social_items').slideToggle(); //.toggleClass('opened'); 1723 e.preventDefault(); 1724 return false; 1725 }); 1726 }); 1727 } 1728 var $share_items = container.find('.socials_share .social_items:not(.inited)'); 1729 if ($share_items.length > 0) { 1730 $share_items.each(function() { 1731 jQuery(this) 1732 .addClass('inited') 1733 .on('click', '.social_item_popup', function(e) { 1734 var url = jQuery(this).data('link'); 1735 window.open(url, '_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=480, height=400, toolbar=0, status=0'); 1736 e.preventDefault(); 1737 return false; 1738 }) 1739 .on('click', '.social_item[data-copy-link-url]', function(e) { 1740 var $self = jQuery(this), 1741 url = $self.data('copy-link-url'); 1742 if ( url != '' ) { 1743 trx_addons_copy_to_clipboard( url ); 1744 var msg = $self.data('message') ? $self.data('message') : TRX_ADDONS_STORAGE['msg_copied']; 1745 if ( msg ) { 1746 $self.attr('data-tooltip-text', msg); 1747 setTimeout( function() { 1748 $self.removeAttr('data-tooltip-text'); 1749 }, 3000 ); 1750 } 1751 } 1752 e.preventDefault(); 1753 return false; 1754 }); 1755 }); 1756 } 1757 1758 1759 // Banners 1760 //----------------------------------------------- 1761 $banner_placeholder.each( function() { 1762 var item = jQuery(this); 1763 if ( item.data('banner-show') == 'permanent' ) { 1764 // Show banner on page load 1765 if ( ! item.hasClass( 'inited' ) ) { 1766 item.addClass( 'inited' ); 1767 setTimeout( function() { 1768 item.after( item.data( 'banner' ) ); 1769 var banner = item.next(); 1770 item.remove(); 1771 if ( banner.hasClass( 'banner_hidden' ) ) { 1772 trx_addons_when_images_loaded( banner, function() { 1773 banner.slideDown(); 1774 } ); 1775 } 1776 }, item.data('banner-delay') ? item.data('banner-delay') : 0 ); 1777 } 1778 } else if ( item.data('banner-show') == 'scroll' ) { 1779 // Show banner on enter in the viewport 1780 trx_addons_intersection_observer_add( item, function( item, enter ) { 1781 if ( ! item.hasClass('inited') && enter ) { 1782 item.addClass('inited'); 1783 trx_addons_intersection_observer_remove( item ); 1784 setTimeout( function() { 1785 item.after( item.data( 'banner' ) ); 1786 var banner = item.next(); 1787 item.remove(); 1788 if ( banner.hasClass( 'banner_hidden' ) ) { 1789 trx_addons_when_images_loaded( banner, function() { 1790 banner.slideDown(); 1791 } ); 1792 } 1793 }, item.data('banner-delay') ? item.data('banner-delay') : 0 ); 1794 } 1795 } ); 1796 } 1797 } ); 1798 1799 1800 // Widgets decoration 1801 //---------------------------------------------- 1802 1803 // Decorate nested lists in widgets and side panels 1804 container.find('.widget ul > li').each(function() { 1805 var $self = jQuery(this); 1806 if ($self.find('ul').length > 0) { 1807 $self.addClass('has_children'); 1808 } 1809 }); 1810 1811 // Archive widget decoration 1812 container.find('.widget_archive a:not(.inited)').each(function() { 1813 var $self = jQuery(this).addClass('inited'); 1814 var val = $self.html().split(' '); 1815 if (val.length > 1) { 1816 val[val.length-1] = '<span>' + val[val.length-1] + '</span>'; 1817 $self.html(val.join(' ')); 1818 } 1819 }); 1820 1821 1822 // Menu 1823 //---------------------------------------------- 1824 // Prepare menus (if menu cache is used) 1825 jQuery('.sc_layouts_menu_nav:not(.inited_cache),.trx-addons-nav-menu:not(.inited_cache),.trx-addons-mobile-menu:not(.inited_cache)').each(function() { 1826 var $self = jQuery(this).addClass('inited_cache'); 1827 if ($self.find('.current-menu-item').length == 0 || $body.hasClass('blog_template')) { 1828 if (TRX_ADDONS_STORAGE['menu_cache'] === undefined) TRX_ADDONS_STORAGE['menu_cache'] = []; 1829 var id = $self.attr('id'); 1830 if (id === undefined) { 1831 id = ( $self.hasClass ( 'sc_layouts_menu_nav' ) 1832 ? 'sc_layouts_menu_nav_' 1833 : ( $self.hasClass ( 'trx-addons-nav-menu' ) 1834 ? 'trx-addons-nav-menu-' 1835 : 'trx-addons-mobile-menu-' 1836 ) 1837 ) + trx_addons_get_unique_id(); 1838 $self.attr('id', id); 1839 } 1840 TRX_ADDONS_STORAGE['menu_cache'].push('#'+id); 1841 } 1842 }); 1843 if (TRX_ADDONS_STORAGE['menu_cache'] && TRX_ADDONS_STORAGE['menu_cache'].length > 0) { 1844 // Mark the current menu item and its parent items in the cached menus 1845 var href = window.location.href; 1846 if ( href.slice(-1) == '/' ) { 1847 href = href.slice( 0, -1 ); 1848 } 1849 var href2 = href.indexOf( '#' ) == -1 && href.indexOf( '?' ) == -1 ? href + '/' : ''; 1850 for (var i = 0; i < TRX_ADDONS_STORAGE['menu_cache'].length; i++) { 1851 var menu = jQuery( TRX_ADDONS_STORAGE['menu_cache'][i]+':not(.prepared)' ); 1852 if ( menu.length === 0 ) { 1853 continue; 1854 } 1855 menu.addClass( 'prepared' ); 1856 menu.find( 'li' ).removeClass( 'current-menu-ancestor current-menu-parent current-menu-item current_page_item trx-addons-active-item' ); 1857 menu.find( 'a[href="'+href+'"]' + ( href2 ? ',a[href="'+href2+'"]' : '' ) ).each( function( idx ) { 1858 var li = jQuery(this).parent(); 1859 li.addClass( 'current-menu-item trx-addons-active-item' ); 1860 if ( li.hasClass( 'menu-item-object-page' ) ) { 1861 li.addClass('current_page_item'); 1862 } 1863 // Mark all parent items as 'current-menu-ancestor' and closest as 'current-menu-parent' 1864 li = li.parents( 'li' ); 1865 for ( var j = 0; j < li.length; j++ ) { 1866 li.addClass( 'current-menu-ancestor' + ( j == 0 ? ' current-menu-parent' : '' ) ); 1867 } 1868 } ); 1869 } 1870 } 1871 1872 1873 // Forms 1874 //------------------------------------ 1875 1876 // Remove 'error_field' class on any key pressed in the field 1877 jQuery("form:not([data-inited-validation])") 1878 .attr('data-inited-validation', 1) 1879 .on('change', 'input,select,textarea', function() { 1880 var $self = jQuery(this), 1881 $wrap = $self.parents('.error_field'); 1882 if ( $self.val() !== '' ) { 1883 if ( $self.hasClass( 'error_field' ) ) { 1884 $self.removeClass('error_field'); 1885 } else if ( $wrap.length > 0 ) { 1886 $wrap.removeClass('error_field'); 1887 } 1888 } 1889 }); 1890 1891 // Comment form 1892 jQuery("form#commentform:not(.inited_validation)") 1893 .addClass( 'inited_validation' ) 1894 .on( 'submit', function(e) { 1895 var rez = trx_addons_comments_validate( jQuery(this) ); 1896 if (!rez) { 1897 e.preventDefault(); 1898 } 1899 return rez; 1900 } ); 1901 1902 // Comments form 1903 function trx_addons_comments_validate(form) { 1904 form.find('input').removeClass('error_field'); 1905 var comments_args = { 1906 error_message_text: TRX_ADDONS_STORAGE['msg_validation_error'], // Global error message text (if don't write in checked field) 1907 error_message_show: true, // Display or not error message 1908 error_message_time: 4000, // Error message display time 1909 error_message_class: 'trx_addons_message_box trx_addons_message_box_error', // Class appended to error message block 1910 error_fields_class: 'error_field', // Class appended to error fields 1911 exit_after_first_error: false, // Cancel validation and exit after first error 1912 rules: [ 1913 { 1914 field: 'comment', 1915 min_length: { value: 1, message: TRX_ADDONS_STORAGE['msg_text_empty'] } 1916 } 1917 ] 1918 }; 1919 if (form.find('.comments_author input[aria-required="true"]').length > 0) { 1920 comments_args.rules.push( 1921 { 1922 field: 'author', 1923 min_length: { value: 1, message: TRX_ADDONS_STORAGE['msg_name_empty']}, 1924 max_length: { value: 60, message: TRX_ADDONS_STORAGE['msg_name_long']} 1925 } 1926 ); 1927 } 1928 if (form.find('.comments_email input[aria-required="true"]').length > 0) { 1929 comments_args.rules.push( 1930 { 1931 field: 'email', 1932 min_length: { value: 1, message: TRX_ADDONS_STORAGE['msg_email_empty']}, 1933 max_length: { value: 60, message: TRX_ADDONS_STORAGE['msg_email_long']}, 1934 mask: { value: TRX_ADDONS_STORAGE['email_mask'], message: TRX_ADDONS_STORAGE['msg_email_not_val
1934id']} 1935 } 1936 ); 1937 } 1938 var error = trx_addons_form_validate(form, comments_args); 1939 return !error; 1940 } 1941 1942 1943 // Show "on scroll" blocks 1944 //------------------------------------ 1945 if ( $show_on_scroll.length > 0 ) { 1946 trx_addons_intersection_observer_add( $show_on_scroll ); 1947 } 1948 1949 1950 // Animations 1951 //------------------------------------ 1952 1953 // Disable animations on mobile 1954 if ( TRX_ADDONS_STORAGE['disable_animation_on_mobile'] && $body.hasClass('ua_mobile') ) { 1955 // jQuery('[data-animation^="animated"]').removeAttr('data-animation'); 1956 jQuery('[data-post-animation^="animated"]').removeAttr('data-post-animation'); 1957 jQuery('[data-hover-animation^="animated"]').removeAttr('data-hover-animation'); 1958 // Update global lists 1959 $animated_elements = jQuery('[data-post-animation^="animated"]:not(.animated)'); 1960 $animated_hover = jQuery('[data-hover-animation^="animated"]:not(.animated)'); 1961 } 1962 1963 // Animate elements after its enter to the viewport 1964 if ( $animated_elements.length > 0 ) { 1965 trx_addons_intersection_observer_add( $animated_elements, function( item, enter ) { 1966 if ( ! item.hasClass('inited_animation') && enter ) { 1967 item.addClass('inited_animation'); 1968 trx_addons_intersection_observer_remove( item ); 1969 var animation = item.data('post-animation'); 1970 if ( ! animation ) animation = item.data('animation'); 1971 setTimeout( function() { 1972 // Add class with animation 1973 item.addClass( animation ); 1974 // Remove attribute 'data-post-animation' to prevent hiding items from 3rd-party plugins 1975 item.removeAttr('data-post-animation'); 1976 // Update global list 1977 $animated_elements = jQuery('[data-post-animation^="animated"]:not(.animated)'); 1978 // Generate action after element is animated 1979 $document.trigger('action.start_item_animation', [item]); 1980 }, 100 * trx_addons_random(0, 10) ); 1981 } 1982 } ); 1983 } 1984 1985 // Animated hover 1986 container 1987 .find('[data-hover-animation^="animated"]') 1988 .closest('.elementor-column,.post_layout_custom') 1989 .each(function() { 1990 var $self = jQuery(this); 1991 if ($self.hasClass('hover-animation-inited')) return; 1992 $self.addClass('hover-animation-inited').hover( 1993 // Mouse in 1994 function(e) { 1995 jQuery(this).find('[data-hover-animation^="animated"]').each(function() { 1996 var obj = jQuery(this); 1997 var animation = obj.data('hover-animation'); 1998 var animation_in = obj.data('animation-in'); 1999 if (animation_in == undefined) animation_in = "none"; 2000 var animation_in_delay = obj.data('animation-in-delay'); 2001 if (animation_in_delay == undefined) animation_in_delay = 0; 2002 var animation_out = obj.data('animation-out'); 2003 if (animation_out == undefined) animation_out = "none"; 2004 if (animation_in != 'none') { 2005 setTimeout(function() { 2006 obj.removeClass(animation + ' ' + animation_out); 2007 obj.addClass(animation + ' ' + animation_in); 2008 }, animation_in_delay); 2009 } 2010 }); 2011 }, 2012 // Mouse out 2013 function(e) { 2014 jQuery(this).find('[data-hover-animation^="animated"]').each(function() { 2015 var obj = jQuery(this); 2016 var animation = obj.data('hover-animation'); 2017 var animation_in = obj.data('animation-in'); 2018 if (animation_in == undefined) animation_in = "none"; 2019 var animation_out = obj.data('animation-out'); 2020 if (animation_out == undefined) animation_out = "none"; 2021 var animation_out_delay = obj.data('animation-out-delay'); 2022 if (animation_out_delay == undefined) animation_out_delay = 0; 2023 if (animation_out != 'none') { 2024 setTimeout(function() { 2025 obj.removeClass(animation + ' ' + animation_in); 2026 obj.addClass(animation + ' ' + animation_out); 2027 }, animation_out_delay); 2028 } 2029 }); 2030 } 2031 ); 2032 }); 2033 2034 2035 // Init Parallax controller 2036 //----------------------------------- 2037 if ( typeof ScrollMagic != 'undefined' ) { 2038 if ( parallax_controller === null ) { 2039 parallax_controller = new ScrollMagic.Controller( { 2040 globalSceneOptions: { 2041 triggerHook: "onEnter", 2042 duration: "200%" 2043 } 2044 } ); 2045 } 2046 // Build Parallax scenes 2047 $parallax_wrap.each( function() { 2048 var $self = jQuery( this ), 2049 id = $self.attr( 'id' ),
2050 speed = $self.data( 'parallax' ) ? Number( $self.data( 'parallax' ) ) : 0; 2051 if ( speed !== 0 && ! $self.hasClass( 'parallax_inited' ) ) { 2052 $self.addClass( 'parallax_inited' ); 2053 if ( ! id ) { 2054 id = 'sc_parallax_wrap_' + trx_addons_get_unique_id(); 2055 $self.attr( 'id', id ); 2056 } 2057 var selector = '#' + id + ( $self.find( '> .wp-caption' ).length > 0 ? '>.wp-caption' : '' ) + '>img'; 2058 new ScrollMagic 2059 .Scene( { triggerElement: '#' + id } ) 2060 .setTween( selector, { y: speed + "%", ease: Linear.easeNone } ) 2061 .addTo( parallax_controller ); 2062 } 2063 }); 2064 } 2065 2066 2067 // Other settings 2068 //------------------------------------ 2069 2070 // Scroll to top button 2071 if ( ! $scroll_to_top.hasClass('inited') ) { 2072 $scroll_to_top 2073 .addClass('inited') 2074 .on( 'click', function(e) { 2075 jQuery('html,body').animate( { 2076 scrollTop: 0 2077 }, 'slow' ); 2078 e.preventDefault(); 2079 return false; 2080 } ); 2081 // Scroll progress 2082 if ( $scroll_progress.length ) { 2083 $document.on( 'action.scroll_trx_addons', function() { 2084 var prc = trx_addons_document_height() > trx_addons_window_height() ? Math.min(100, Math.max(0, trx_addons_window_scroll_top() / ( trx_addons_document_height() - trx_addons_window_height() ) * 100)) : 100; 2085 if ( $scroll_progress.hasClass('trx_addons_scroll_progress_type_vertical') ) { 2086 $scroll_progress.height(prc+'%'); 2087 } else if ( $scroll_progress.hasClass('trx_addons_scroll_progress_type_horizontal') ) { 2088 $scroll_progress.width(prc+'%'); 2089 } else if ( $scroll_progress.hasClass('trx_addons_scroll_progress_type_box') || $scroll_progress.hasClass('trx_addons_scroll_progress_type_round') ) { 2090 var $bar = $scroll_progress.find('.trx_addons_scroll_progress_bar'); 2091 if ( $bar.length === 0 ) { 2092 $scroll_progress.append( '<svg viewBox="0 0 50 50">' 2093 + ( $scroll_progress.hasClass('trx_addons_scroll_progress_type_round') 2094 ? '<circle class="trx_addons_scroll_progress_bar" cx="25" cy="25" r="22"></circle>' 2095 : '<rect class="trx_addons_scroll_progress_bar" x="3" y="3" width="44" height="44"></rect>' 2096 ) 2097 + '</svg>' ); 2098 $bar = $scroll_progress.find('.trx_addons_scroll_progress_bar'); 2099 } 2100 var bar_max = parseFloat( $bar.css('stroke-dasharray') ); 2101 $bar.css( 'stroke-dashoffset', '' + Math.min( 1, 1 - prc / 100 ) * bar_max ); 2102 } 2103 } ); 2104 } 2105 } 2106 2107 } // trx_addons_ready_actions 2108 2109 2110 // Scroll actions 2111 //============================================== 2112 2113 // Do actions when page scrolled 2114 window.trx_addons_scroll_actions = function() { 2115 // Add class to 'body' if scroll_top > 0 2116 if ( trx_addons_window_scroll_top() > 0 ) { 2117 if ( ! $body.hasClass( 'trx_addons_page_scrolled' ) ) { 2118 $body.addClass( 'trx_addons_page_scrolled' ); 2119 } 2120 } else if ( $body.hasClass( 'trx_addons_page_scrolled' ) ) { 2121 $body.removeClass( 'trx_addons_page_scrolled' ); 2122 } 2123 // Scroll to top button show/hide 2124 if ( $scroll_to_top.length > 0 ) { 2125 if ( trx_addons_window_scroll_top() > 100 ) { 2126 if ( ! $scroll_to_top.hasClass( 'show' ) ) { 2127 $scroll_to_top.addClass('show'); 2128 $body.addClass( 'trx_addons_scroll_to_top_show' ); 2129 } 2130 } else { 2131 if ( $scroll_to_top.hasClass( 'show' ) ) { 2132 $scroll_to_top.removeClass('show'); 2133 $body.removeClass( 'trx_addons_scroll_to_top_show' ); 2134 } 2135 } 2136 } 2137 2138 // Display scroll progress 2139 if ( ['top', 'bottom', 'fixed'].indexOf( TRX_ADDONS_STORAGE['scroll_progress'] ) >= 0 ) { 2140 trx_addons_show_scroll_progress(); 2141 } 2142 2143 // Show "on scroll" blocks 2144 $show_on_scroll.each( function() { 2145 var item = jQuery(this); 2146 if ( item.hasClass( 'trx_addons_in_viewport' ) ){ 2147 if ( item.offset().top < trx_addons_window_scroll_top() + trx_addons_window_height() * 0.75 ) { 2148 item.removeClass( 'trx_addons_show_on_scroll' ).addClass( 'trx_addons_showed_on_scroll' ); 2149 trx_addons_intersection_observer_remove( item ); 2150 // Update list of elements 2151 $show_on_scroll = jQuery('.trx_addons_show_on_scroll'); 2152 } 2153 } 2154 } ); 2155 2156 // Call theme/plugins specific action (if exists) 2157 //---------------------------------------------- 2158 $document.trigger('action.before_scroll_trx_addons'); 2159 $document.trigger('action.scroll_trx_addons'); 2160 $document.trigger('action.after_scroll_trx_addons'); 2161 2162 // Set flag about scroll actions are finished 2163 TRX_ADDONS_STORAGE['scroll_busy'] = false;
2164 }; 2165 2166 2167 // Display scroll progress 2168 function trx_addons_show_scroll_progress() { 2169 if ( TRX_ADDONS_STORAGE['scroll_progress_status'] == undefined ) { 2170 $body.append('<div class="scroll_progress_wrap scroll_progress_'+TRX_ADDONS_STORAGE['scroll_progress']+'"><span class="scroll_progress_status"></span></div>'); 2171 TRX_ADDONS_STORAGE['scroll_progress_status'] = jQuery( '.scroll_progress_wrap .scroll_progress_status' ); 2172 trx_addons_get_scroll_posts(); 2173 // Animate to relative page part on click 2174 TRX_ADDONS_STORAGE['scroll_progress_status'].on('click', function(e) { 2175 var prc = e.pageX / jQuery(this).parent().width(); 2176 if ( TRX_ADDONS_STORAGE['scroll_posts'] != undefined && TRX_ADDONS_STORAGE['scroll_posts'].length > 0 ) { 2177 var cur_post = trx_addons_detect_current_scroll_post(), 2178 pt = cur_post.data('post-top'), 2179 ph = cur_post.data('post-height'); 2180 trx_addons_document_animate_to( Math.round( ph * prc + pt - wh / 2 ) ); 2181 } else { 2182 trx_addons_document_animate_to( Math.round( ( trx_addons_document_height() - trx_addons_window_height() ) * prc ) ); 2183 } 2184 e.preventDefault(); 2185 return false; 2186 }); 2187 } 2188 var st = trx_addons_window_scroll_top(), 2189 wh = trx_addons_window_height(), 2190 new_width = '0%'; 2191 if ( TRX_ADDONS_STORAGE['scroll_posts'] !== undefined && TRX_ADDONS_STORAGE['scroll_posts'].length > 0 ) { 2192 var cur_post = trx_addons_detect_current_scroll_post(), 2193 pt = cur_post.data('post-top'), 2194 ph = cur_post.data('post-height'); 2195 new_width = ( st < 10 ? 0 : Math.min( 100, Math.round( ( st + wh / 2 - pt ) * 100 / ph ) ) ) + '%'; 2196 TRX_ADDONS_STORAGE['scroll_progress_status'].width( new_width ); 2197 } else { 2198 new_width = Math.min( 100, Math.round( st * 100 / ( trx_addons_document_height() - wh ) ) ) + '%'; 2199 TRX_ADDONS_STORAGE['scroll_progress_status'].width( new_width ); 2200 } 2201 } 2202 2203 function trx_addons_detect_current_scroll_post() { 2204 var cur_post = false; 2205 TRX_ADDONS_STORAGE['scroll_posts'].each( function() { 2206 var post = jQuery(this), 2207 st = trx_addons_window_scroll_top(), 2208 wh = trx_addons_window_height(), 2209 pt = post.data('post-top'), 2210 ph = post.data('post-height'); 2211 if ( pt < st + wh / 2 ) { 2212 cur_post = post; 2213 } 2214 }); 2215 if ( ! cur_post ) { 2216 cur_post = TRX_ADDONS_STORAGE['scroll_posts'].eq( TRX_ADDONS_STORAGE['scroll_posts'].length - 1 ); 2217 } 2218 return cur_post; 2219 } 2220 2221 $document.on('action.new_post_added', trx_addons_get_scroll_posts); 2222 function trx_addons_get_scroll_posts() { 2223 TRX_ADDONS_STORAGE['scroll_posts'] = ( TRX_ADDONS_STORAGE['scroll_posts'] !== undefined && TRX_ADDONS_STORAGE['scroll_posts'].length > 0 ) 2224 || jQuery('.nav-links-single-scroll').length > 0 2225 ? jQuery('.post_item_single') 2226 : false; 2227 trx_addons_get_scroll_posts_dimensions(); 2228 } 2229 2230 $document.on('action.resize_trx_addons', trx_addons_get_scroll_posts_dimensions); 2231 function trx_addons_get_scroll_posts_dimensions() { 2232 if ( TRX_ADDONS_STORAGE['scroll_posts'] !== undefined && TRX_ADDONS_STORAGE['scroll_posts'].length > 0 ) { 2233 TRX_ADDONS_STORAGE['scroll_posts'].each( function() { 2234 var post = jQuery(this); 2235 post.data('post-height', post.height()) 2236 .data('post-top', post.offset().top); 2237 } ); 2238 } 2239 } 2240 2241 2242 // Fix columns 2243 //--------------------------------------------------------------- 2244 2245 // Fix column only if css sticky behaviour is not used 2246 if ( ! $body.hasClass( 'fixed_blocks_sticky' ) ) { 2247 $document.on('action.resize_trx_addons', trx_addons_fix_column); 2248 $document.on('action.scroll_trx_addons', trx_addons_fix_column); 2249 2250 var trx_addons_fix_column = function (e, cont) { 2251 2252 if ( $fixed_columns.length === 0 ) { 2253 return; 2254 } 2255 2256 var force = e.namespace == 'resize_trx_addons'; 2257 2258 $fixed_columns.each(function() { 2259 var col = jQuery(this), 2260 row = col.parent(); 2261 2262 // Exit if non-standard responsive is used for this columns 2263 if ( col.attr('class').indexOf('vc_col-lg-') != -1 || col.attr('class').indexOf('vc_col-md-') != -1 ) { 2264 return; 2265 2266 // Unfix on mobile layout (all columns are fullwidth) 2267 } else if ( trx_addons_window_width() < TRX_ADDONS_STORAGE['mobile_breakpoint_fixedcolumns_off'] ) { 2268 var old_style = col.data('old_style'); 2269 if (old_style !== undefined) { 2270 col.attr('style', old_style).removeAttr('data-old_style'); 2271 } 2272 2273 } else { 2274 2275 var col_height = col.outerHeight(); 2276 var row_height = row.outerHeight(); 2277 var row_top = row.offset().top; 2278 2279 // If column shorter then content and page scrolled below the content's top 2280 if (col_height < row_height && trx_addons_window_scroll_top() + trx_addons_fixed_rows_height() > row_top) { 2281 2282 var col_init = { 2283 'position': 'undefined', 2284 'top': 'auto', 2285 'bottom' : 'auto' 2286 }; 2287 2288 if (typeof TRX_ADDONS_STORAGE['scroll_offset_last'] == 'undefined') { 2289 TRX_ADDONS_STORAGE['col_top_last'] = row_top; 2290 TRX_ADDONS_STORAGE['scroll_offset_last'] = trx_addons_window_scroll_top(); 2291 TRX_ADDONS_STORAGE['scroll_dir_last'] = 1; 2292 } 2293 var scroll_dir = trx_addons_window_scroll_top() - TRX_ADDONS_STORAGE['scroll_offset_last']; 2294 scroll_dir = scroll_dir == 0 2295 ? TRX_ADDONS_STORAGE['scroll_dir_last'] 2296 : ( scroll_dir > 0 ? 1 : -1 ); 2297 2298 var col_big = col_height + 30 >= trx_addons_window_height() - trx_addons_fixed_rows_height(), 2299 col_top = col.offset().top; 2300 2301 if (col_top < 0) { 2302 col_top = TRX_ADDONS_STORAGE['col_top_last']; 2303 } 2304 2305 2306 // If column height greater then window height 2307 if (col_big) { 2308 2309 // If change scrolling dir 2310 if (scroll_dir != TRX_ADDONS_STORAGE['scroll_dir_last'] && col.css('position') == 'fixed') {
2311 col_init.top = col_top - row_top; 2312 col_init.position = 'absolute'; 2313 2314 // If scrolling down 2315 } else if (scroll_dir > 0) { 2316 if (trx_addons_window_scroll_top() + trx_addons_window_height() >= row_top + row_height + 30) { 2317 col_init.bottom = 0; 2318 col_init.position = 'absolute'; 2319 } else if (trx_addons_window_scroll_top() + trx_addons_window_height() >= (col.css('position') == 'absolute' ? col_top : row_top) + col_height + 30) { 2320 col_init.bottom = 30; 2321 col_init.position = 'fixed'; 2322 } 2323 2324 // If scrolling up 2325 } else { 2326 if (trx_addons_window_scroll_top() + trx_addons_fixed_rows_height() <= col_top) { 2327 col_init.top = trx_addons_fixed_rows_height(); 2328 col_init.position = 'fixed'; 2329 } 2330 } 2331 2332 // If column height less then window height 2333 } else { 2334 if (trx_addons_window_scroll_top() + trx_addons_fixed_rows_height() >= row_top + row_height - col_height) { 2335 col_init.bottom = 0; 2336 col_init.position = 'absolute'; 2337 } else { 2338 col_init.top = trx_addons_fixed_rows_height(); 2339 col_init.position = 'fixed'; 2340 } 2341 } 2342 2343 if (force && col_init.position == 'undefined' && col.css('position') == 'absolute') { 2344 col_init.position = 'absolute'; 2345 if (col.css('top') != 'auto') { 2346 col_init.top = col.css('top'); 2347 } else { 2348 col_init.bottom = col.css('bottom'); 2349 } 2350 } 2351 2352 if (col_init.position != 'undefined') { 2353 // Insert placeholder before this column 2354 var style = col.attr('style'); 2355 if ( ! style ) style = ''; 2356 if ( ! col.prev().hasClass('sc_column_fixed_placeholder') ) { 2357 col.css(col_init); 2358 TRX_ADDONS_STORAGE['scroll_dir_last'] = 0; 2359 col.before('<div class="sc_column_fixed_placeholder '+col.attr('class').replace('sc_column_fixed', '')+'"' 2360 + (col.data('col') ? ' data-col="' + col.data('col') + '"' : '') 2361 + '></div>'); 2362 } 2363 // Detect horizontal position 2364 col_init.left = col_init.position == 'fixed' ? col.prev().offset().left : col.prev().position().left; 2365 col_init.width = col.prev().width() + parseFloat(col.prev().css('paddingLeft')) + parseFloat(col.prev().css('paddingRight')); 2366 // Set position 2367 if ( force 2368 || col.css('position') != col_init.position 2369 || TRX_ADDONS_STORAGE['scroll_dir_last'] != scroll_dir 2370 || col.width() != col_init.width 2371 ) { 2372 if (col.data('old_style') === undefined) { 2373 col.attr('data-old_style', style); 2374 } 2375 col.css(col_init); 2376 } 2377 } 2378 2379 TRX_ADDONS_STORAGE['col_top_last'] = col_top; 2380 TRX_ADDONS_STORAGE['scroll_offset_last'] = trx_addons_window_scroll_top(); 2381 TRX_ADDONS_STORAGE['scroll_dir_last'] = scroll_dir; 2382 2383 } else { 2384 2385 // Unfix when page scrolling to top 2386 var old_style = col.data('old_style'); 2387 if (old_style !== undefined) { 2388 col.attr('style', old_style).removeAttr('data-old_style'); 2389 if ( col.prev().hasClass('sc_column_fixed_placeholder') ) { 2390 col.prev().remove(); 2391 } 2392 } 2393 } 2394 } 2395 }); 2396 }; 2397 } 2398 2399 // Stack sections 2400 $document.on('action.resize_trx_addons', trx_addons_stack_section); 2401 $document.on('action.scroll_trx_addons', trx_addons_stack_section); 2402 function trx_addons_stack_section(e, cont) { 2403 2404 if ( $stack_sections.length === 0 ) return; 2405 2406 var force = e.namespace == 'resize_trx_addons', 2407 fixed_rows_height = ! $body.hasClass( 'header_position_over' ) ? trx_addons_fixed_rows_height() : 0, 2408 wso = trx_addons_window_scroll_top() + fixed_rows_height; 2409 2410 $stack_sections.each( function( idx ) { 2411 2412 var row = jQuery(this), 2413 row_holder = false, 2414 row_height = 0, 2415 row_top = 0, 2416 use_sticky = $body.hasClass( 'fixed_blocks_sticky' ) && row.hasClass('sc_stack_section_effect_slide'); 2417 2418 // Unfix on mobile layout (all columns are fullwidth) 2419 if ( trx_addons_window_width() < TRX_ADDONS_STORAGE['mobile_breakpoint_stacksections_off'] ) { 2420 2421 if ( row.hasClass('sc_stack_section_fixed') ) { 2422 row.removeClass('sc_stack_section_fixed').prev().remove(); 2423 if ( ! use_sticky ) row.css( { top: row.data('old-top') } ); 2424 } 2425 2426 } else { 2427 2428 // If section is fixed 2429 if ( row.hasClass('sc_stack_section_fixed') ) { 2430 row_holder = row.prev(); 2431 row_height = use_sticky ? row.outerHeight() : row_holder.outerHeight(); 2432 row_top = row_holder.offset().top; 2433 // Unfix row 2434 if ( row_top > wso ) { 2435 row.removeClass('sc_stack_section_fixed'); 2436 if ( ! use_sticky ) { 2437 row.css( { top: row.data('old-top') } ); 2438 } 2439 if ( row.hasClass( 'sc_stack_section_effect_fade' ) ) { 2440 row.css( { 'opacity': 0 } ); 2441 } 2442 row_holder.remove(); 2443 2444 // Set holder height 2445 } else { 2446 if ( force ) { 2447 row_height = row.outerHeight(); 2448 if ( ! use_sticky ) { 2449 row_holder.height(row_height); 2450 row.css( { top: fixed_rows_height + 'px !important' } ); 2451 } 2452 } 2453 if ( row.hasClass( 'sc_stack_section_effect_fade' ) ) { 2454 if ( wso - row_top <= row_height ) { 2455 row.css( { 'opacity': Math.max(0, Math.min( 1, ( wso - row_top ) / row_height ) ) } ); 2456 } else { 2457 row.css( { 'opacity': 1 } ); 2458 } 2459 } 2460 } 2461 2462 // If section is not fixed 2463 } else { 2464 row_top = row.offset().top; 2465 if ( row_top <= wso ) { 2466 if ( ! use_sticky ) { 2467 row_height = row.outerHeight(); 2468 row 2469 .data( 'old-top', row.css('top') ) 2470 .css( { top: fixed_rows_height + 'px'} ); 2471 } 2472 var gap = row.parent().css( 'gap' ); 2473 if ( gap && gap != '0px' && gap != '0' ) { 2474 gap = gap.split(' ')[0].replace('px', ''); 2475 } else { 2476 gap = 0; 2477 } 2478 row 2479 .before( '<div class="sc_stack_section_placeholder"' 2480 + ( ! use_sticky 2481 ? ' style="height:'+row_height+'px;"' 2482 : ( gap > 0 2483 ? ' style="margin-bottom: -' + gap + 'px;"' 2484 : '' 2485 ) 2486 ) 2487 + '></div>' 2488 ) 2489 .addClass('sc_stack_section_fixed'); 2490 } 2491 } 2492 } 2493 2494 } ); 2495 } 2496 2497 // Add zoom effect to the stack sections 2498 function trx_addons_stack_section_zoom() { 2499 $stack_sections.each( function() { 2500 var targetElement = jQuery(this), 2501 zoom = targetElement.hasClass( 'sc_stack_section_zoom_on' ), 2502 transparency = targetElement.hasClass( 'sc_stack_section_transparency_on' ), 2503 blur = targetElement.hasClass( 'sc_stack_section_blur_on' ), 2504 offset = targetElement.data('stack-section-effect-start-offset') || 75; 2505 if ( ! zoom && ! transparency && ! blur ) { 2506 return; 2507 } 2508 var triggerElement = targetElement.next(); 2509 if ( ! triggerElement.length || ( triggerElement.hasClass( 'sc_stack_section_on' ) && ! triggerElement.hasClass( 'sc_stack_section_effect_slide' ) ) ) { 2510 return; 2511 } 2512 // Register Scroll Trigger library 2513 if ( typeof ScrollTrigger == 'undefined' ) { 2514 return; 2515 } 2516 if ( ! TRX_ADDONS_STORAGE['GSAP_Plugin_ScrollTrigger'] ) { 2517 TRX_ADDONS_STORAGE['GSAP_Plugin_ScrollTrigger'] = true; 2518 gsap.registerPlugin( ScrollTrigger ); 2519 } 2520 var timeline = triggerElement.data( 'stack-section-timeline' ) ? triggerElement.data( 'stack-section-timeline' ) : null; 2521 // Reinit a timeline if already inited (for example, after sliders or masonry are inited - a page content shift down) 2522 if ( timeline ) { 2523 timeline.kill(); 2524 } 2525 // Init a timeline 2526 timeline = gsap.timeline( { 2527 scrollTrigger: { 2528 trigger: triggerElement, 2529 start: "top " + offset + "%", 2530 end: "top top", 2531 scrub: 0 2532 } 2533 } ); 2534 var duration = targetElement.data('stack-section-effect-duration'); 2535 if ( duration === undefined ) { 2536 duration = 0.001; 2537 } 2538 duration = Math.max( 0.001, duration ); // Don't take effect with a scrollTrigger (css transition-duration is used instead) and if duration is less than 1 ms 2539 var val = '', 2540 from = {}, 2541 to = { duration: duration }; 2542 if ( zoom ) { 2543 val = targetElement.data('stack-section-zoom-value'); 2544 if ( val == undefined || val == '' ) val = "0.8"; 2545 from.scale = "1"; 2546 to.scale = val; 2547 } 2548 if ( transparency ) { 2549 val = targetElement.data('stack-section-transparency-value'); 2550 if ( val == undefined || val == '' ) val = "0"; 2551 from.opacity = "1"; 2552 to.opacity = val; 2553 } 2554 if ( blur ) { 2555 val = targetElement.data('stack-section-blur-value'); 2556 if ( val == undefined || val == '' ) val = "10"; 2557 from.filter = "blur(0px)"; 2558 to.filter = "blur(" + val + "px)"; 2559 } 2560 timeline.fromTo( targetElement, from, to ); 2561 triggerElement.data( 'stack-section-timeline', timeline ); 2562 } ); 2563 } 2564 if ( $stack_sections.length && window.gsap ) { 2565 trx_addons_stack_section_zoom(); 2566 $document.on( 'action.resize_trx_addons', trx_addons_stack_section_zoom ); 2567 } 2568 2569 // Menu handlers 2570 var $menuContainers = jQuery( '.trx-addons-nav-menu, .sc_layouts_menu_nav' ); 2571 2572 // Smooth scroll to sections on click on menu links with inner hash 2573 // $menuContainers.on( 'click', 'a[href*="#"]:not(a[href="#"])', function( e ) { 2574 // var $link = jQuery( this ); 2575 // // Get hash from the link 2576 // if ( $link.attr( 'href' ) && $link.attr( 'href' ).indexOf( '#' ) > 0 && trx_addons_is_local_link( $link.attr( 'href' ) ) ) { 2577 // var hash = $link.attr( 'href' ).split( '#' )[1]; 2578 // if ( hash && hash.length > 0 ) { 2579 // // Find section with this id 2580 // var $section = jQuery( '#' + hash ); 2581 // if ( $section.length > 0 ) { 2582 // e.preventDefault(); 2583 // trx_addons_document_animate_to( $section ); 2584 // return false;
2585 // } 2586 // } 2587 // } 2588 // } ); 2589 2590 // Select an active menu item based on the section in the middle of the viewport 2591 var trx_addons_set_active_menu_items = trx_addons_throttle( function() { 2592 const screenMiddle = trx_addons_window_scroll_top() + Math.floor( trx_addons_window_height() / 2 ); 2593 let $lastValidSection = null; // Last valid section the top of which is above the middle of the viewport 2594 let $lastValidSectionMenuLink = null; // Corresponding menu link for the last valid section 2595 2596 // Check all sections with id 2597 $sections_with_id.each( function() { 2598 const $section = jQuery( this ); 2599 const sectionTop = $section.offset().top; 2600 const sectionId = $section.attr('id'); 2601 2602 // Check if the section has an item in the menu 2603 const $menuLink = $menuContainers.find( 'a[href$="#' + sectionId + '"]' ).filter( function() { 2604 // Exclude links that are not from the current page 2605 return trx_addons_is_local_link( jQuery(this).attr('href') ); 2606 } ); 2607 2608 // If the section's top is above the middle of the viewport and it has a menu link 2609 if ( sectionTop <= screenMiddle && $menuLink.length ) { 2610 if ( $lastValidSection && $lastValidSection.length && $lastValidSection.data( 'menu-active' ) ) { 2611 $lastValidSection.data( 'menu-active', false ); // Mark previous section as inactive 2612 clearActiveClasses( $lastValidSection.attr('id') ); // Clear the menu active classes for the previous section 2613 } 2614 $lastValidSection = $section; 2615 $lastValidSectionMenuLink = $menuLink; 2616 } else if ( $section.data( 'menu-active' ) ) { 2617 $section.data( 'menu-active', false ); // Mark section as inactive 2618 clearActiveClasses( $section.attr('id') ); // Clear the menu active classes for the previous section 2619 } 2620 } ); 2621 2622 // Activate the last valid section 2623 if ( $lastValidSection && $lastValidSection.length && ! $lastValidSection.data( 'menu-active' ) ) { 2624 setActiveMenuItem( $lastValidSectionMenuLink, $lastValidSection ); 2625 } 2626 2627 // Clear active classes from all menu items 2628 function clearActiveClasses( id ) { 2629 if ( id ) { 2630 $menuContainers.find( 'a[href$="#' + id + '"]' ).parents( 'li' ).removeClass( 'current-menu-item current-menu-ancestor current-menu-parent trx-addons-active-item' ); 2631 } else { 2632 $menuContainers.find('li').removeClass( 'current-menu-item current-menu-ancestor current-menu-parent trx-addons-active-item' ); 2633 } 2634 } 2635 2636 // Set the active menu item based on the section ID 2637 function setActiveMenuItem( $menuLink, $section ) { 2638 // Add classes to the menu item and its ancestors 2639 $menuLink.each( function() { 2640 clearActiveClasses(); 2641 jQuery(this) 2642 .closest('li').addClass('current-menu-item trx-addons-active-item') 2643 .parents('li').each( function( index ) { 2644 const $parent = jQuery(this); 2645 if ( index === 0 ) { 2646 // The immediate parent gets both classes 2647 $parent.addClass('current-menu-ancestor current-menu-parent'); 2648 } else { 2649 // Other parents get only ancestor 2650 $parent.addClass('current-menu-ancestor'); 2651 } 2652 } ); 2653 } ); 2654 // Mark section as active 2655 $section.data( 'menu-active', true ); 2656 } 2657 }, 200 ); 2658 2659 $document.on('action.resize_trx_addons', trx_addons_set_active_menu_items ); 2660 $document.on('action.scroll_trx_addons', trx_addons_set_active_menu_items ); 2661 2662 2663 // Resize actions 2664 //============================================== 2665 2666 // Do actions when window is resized 2667 window.trx_addons_resize_actions = function(cont) { 2668 2669 // Check touch device 2670 if ( trx_addons_browser_is_touch() ) { 2671 if ( ! $body.hasClass( 'ua_touch' ) ) { 2672 $body.addClass( 'ua_touch' ); 2673 } 2674 } else { 2675 if ( $body.hasClass( 'ua_touch' ) ) { 2676 $body.removeClass( 'ua_touch' ); 2677 } 2678 } 2679 2680 if (cont===undefined) cont = $body; 2681 2682 // Call theme/plugins specific action (if exists) 2683 $document.trigger('action.before_resize_trx_addons', [cont] ); 2684 $document.trigger('action.resize_trx_addons', [cont] ); 2685 $document.trigger('action.after_resize_trx_addons', [cont] ); 2686 }; 2687 2688 // Fit video frames to document width 2689 $document.on('action.resize_trx_addons', trx_addons_resize_video); 2690 function trx_addons_resize_video(e, cont) { 2691 // Resize tag 'video' 2692 if ( $video_tags.length > 0 ) { 2693 $video_tags.each(function() { 2694 var $self = jQuery(this), 2695 classes = $self.attr( 'class' ); 2696 // If item now invisible or has a other resize handler or it's a video in the Revolution Slider 2697 if ( ( ! TRX_ADDONS_STORAGE['resize_tag_video'] && $self.parents('.mejs-mediaelement').length === 0 ) 2698 || $self.hasClass( 'trx_addons_noresize' ) 2699 || classes.indexOf( '_resize' ) > 0 2700 || classes.indexOf( '_noresize' ) > 0 2701 || $self.hasClass( 'sr7-media' ) 2702 || $self.parent().is( 'rs-bgvideo' ) 2703 || $self.parents( 'rs-slide,div:hidden,section:hidden,article:hidden' ).length > 0 2704 ) { 2705 return; 2706 } 2707 var video = $self.addClass('trx_addons_resize').eq(0); 2708 var ratio = (video.data('ratio') !== undefined ? video.data('ratio').split(':') : [16,9]); 2709 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 2710 var mejs_cont = video.parents('.mejs-video').eq(0); 2711 var mfp_cont = video.parents( '.mfp-content' ).eq(0); 2712 var w_attr = video.data('width'); 2713 var h_attr = video.data('height'); 2714 if (!w_attr || !h_attr) { 2715 w_attr = video.attr('width'); 2716 h_attr = video.attr('height'); 2717 if ((!w_attr || !h_attr) && mejs_cont.length > 0) {
2718 w_attr = Math.ceil( mejs_cont.width() ); 2719 h_attr = Math.ceil( mejs_cont.height() ); 2720 } 2721 if (!w_attr || !h_attr) return; 2722 video.data({'width': w_attr, 'height': h_attr}); 2723 } 2724 var percent = (''+w_attr).slice(-1) == '%'; 2725 w_attr = parseInt( w_attr, 10 ); 2726 h_attr = parseInt( h_attr, 10 ); 2727 var par = mejs_cont.length > 0 ? mejs_cont.parents('.post_video,.post_featured').eq(0) : video.parents('.post_video,.post_featured').eq(0); 2728 if ( ! par.length ) { 2729 par = mejs_cont.length > 0 ? mejs_cont.parents('div,section,article').eq(0) : video.parents('div,section,article').eq(0); 2730 } 2731 var w_real = Math.ceil( Math.min( percent ? 10000 : w_attr, par.width() ) ); 2732 if ( mfp_cont.length > 0 ) { 2733 w_real = Math.max( Math.ceil( mfp_cont.width() ), w_real ); 2734 } 2735 var h_real = Math.ceil( percent ? w_real/ratio : w_real/w_attr*h_attr ); 2736 if ( parseInt( video.attr('data-last-width'), 10) == w_real ) { 2737 return; 2738 } 2739 if ( percent ) { 2740 video.height( h_real ); 2741 } else if ( video.parents('.wp-video-playlist').length > 0 ) { 2742 if ( mejs_cont.length === 0 ) { 2743 video.attr({'width': w_real, 'height': h_real}); 2744 } 2745 } else { 2746 video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'}); 2747 // If a height of the video is less than h_real - a max-height is applied, recalculate the width 2748 var h_video = video.height(); 2749 if ( h_video < h_real ) { 2750 w_real = Math.ceil( w_real * h_video / h_real ); 2751 h_real = h_video; 2752 video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'}); 2753 } 2754 // Set dimensions for Media Elements player 2755 if (mejs_cont.length > 0) { 2756 trx_addons_set_mejs_player_dimensions(video, w_real, h_real); 2757 } 2758 } 2759 video.attr('data-last-width', w_real); 2760 }); 2761 } 2762 2763 // Resize tag 'iframe' 2764 if ( TRX_ADDONS_STORAGE['resize_tag_iframe'] && $iframe_tags.length > 0 ) { 2765 $iframe_tags.each(function() { 2766 var $self = jQuery(this); 2767 // If item now invisible or it's a video in the Revolution Slider or video is in the fullscreen mode 2768 if ( $self.addClass('trx_addons_resize').parents('div:hidden,section:hidden,article:hidden').length > 0 2769 || $self.hasClass('trx_addons_noresize') 2770 || $self.parent().is( 'rs-bgvideo' ) 2771 || $self.parents( 'rs-slide' ).length > 0 2772 || document.fullscreenElement 2773 || document.mozFullScreenElement 2774 || document.webkitFullscreenElement 2775 || document.msFullscreenElement 2776 ) { 2777 return; 2778 } 2779 var iframe = $self.eq(0), 2780 iframe_src = iframe.attr('src') ? iframe.attr('src') : iframe.data('src'); 2781 if (iframe_src === undefined || iframe_src.indexOf('soundcloud') > 0) return; 2782 var w_attr = iframe.attr('width'); 2783 var h_attr = iframe.attr('height'); 2784 if ( ! w_attr || ! h_attr || w_attr <= trx_addons_apply_filters( 'trx_addons_filter_noresize_iframe_width', 325 ) ) { 2785 return; 2786 } 2787 var ratio = iframe.data('ratio') !== undefined 2788 ? iframe.data('ratio').split(':') 2789 : ( iframe.parent().data('ratio') !== undefined 2790 ? iframe.parent().data('ratio').split(':') 2791 : ( iframe.find('[data-ratio]').length>0 2792 ? iframe.find('[data-ratio]').data('ratio').split(':') 2793 : [w_attr, h_attr] 2794 ) 2795 ); 2796 ratio = ratio.length != 2 || ratio[0] === 0 || ratio[1] === 0 ? 16 / 9 : ratio[0] / ratio[1]; 2797 var percent = ( '' + w_attr ).slice(-1) == '%'; 2798 w_attr = parseInt( w_attr, 10 ); 2799 h_attr = parseInt( h_attr, 10 ); 2800 var par = iframe.parents( '.post_video,.post_featured' ).eq(0); 2801 if ( ! par.length ) { 2802 par = iframe.parents( '.mfp-content' ).eq(0); 2803 if ( ! par.length ) { 2804 par = iframe.parents( 'div,section,article' ).eq(0); 2805 } 2806 } 2807 var contains = iframe.data('contains-in-parent')=='1' || iframe.hasClass('contains-in-parent'), 2808 nostretch = iframe.data('no-stretch-to-parent')=='1' || iframe.hasClass('no-stretch-to-parent'),
2809 pw = Math.ceil( par.width() ), 2810 ph = Math.ceil( par.height() ), 2811 w_real = nostretch ? Math.min( w_attr, pw ) : pw, 2812 h_real = Math.ceil( percent ? w_real/ratio : w_real/w_attr*h_attr ); 2813 if ( contains && par.css('position') == 'absolute' && h_real > ph ) { 2814 h_real = ph; 2815 w_real = Math.ceil( percent ? h_real*ratio : h_real*w_attr/h_attr ); 2816 } 2817 if ( parseInt(iframe.attr('data-last-width'), 10) == w_real ) return; 2818 iframe.css({'width': w_real+'px', 'height': h_real+'px'}); 2819 iframe.attr('data-last-width', w_real); 2820 }); 2821 } 2822 } // trx_addons_resize_video 2823 2824 2825 // Set Media Elements player dimensions 2826 function trx_addons_set_mejs_player_dimensions(video, w, h) { 2827 if (mejs) { 2828 for (var pl in mejs.players) { 2829 if (mejs.players[pl].media.src == video.attr('src')) { 2830 if (mejs.players[pl].media.setVideoSize) { 2831 mejs.players[pl].media.setVideoSize(w, h); 2832 } else if (mejs.players[pl].media.setSize) { 2833 mejs.players[pl].media.setSize(w, h); 2834 } 2835 mejs.players[pl].setPlayerSize(w, h); 2836 mejs.players[pl].setControlsSize(); 2837 } 2838 } 2839 } 2840 } 2841 2842 2843 // Autoplay video from YouTube 2844 //--------------------------------- 2845 var initAPI = false; 2846 var initEvents = false; 2847 var process = false; 2848 var players = []; 2849 var attrs = []; 2850 var oldAPI = window.onYouTubeIframeAPIReady; 2851 var YTdeferred = jQuery.Deferred(); 2852 2853 // Detect if element is in viewport 2854 jQuery.fn.isInViewport = function() { 2855 var $self = jQuery(this); 2856 var $panel = $self.data( 'sc-panel-thumb' ); 2857 if ( ! $panel ) { 2858 $panel = $self.parents('.sc_panel_thumb'); 2859 $self.data( 'sc-panel-thumb', $panel ); 2860 } 2861 var rez = trx_addons_apply_filters( 'trx_addons_filter_element_in_viewport', $panel.length === 0 || $panel.hasClass('sc_panel_thumb_active'), $self ); 2862 if ( rez ) { 2863 var elementTop = $self.offset().top; 2864 var elementBottom = elementTop + $self.outerHeight(); 2865 var viewportTop = trx_addons_window_scroll_top(); 2866 var viewportBottom = viewportTop + trx_addons_window_height(); 2867 rez = elementTop >= viewportTop && elementTop <= viewportBottom 2868 || 2869 elementBottom >= viewportTop && elementBottom <= viewportBottom; 2870 } 2871 return rez; 2872 }; 2873 2874 function embedYoutubeAPI() { 2875 if ( ! initAPI ) { 2876 var tag = document.createElement('script'); 2877 tag.src = 'https://www.youtube.com/iframe_api'; 2878 var firstScriptTag = document.getElementsByTagName('script')[0]; 2879 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 2880 initAPI = true; 2881 } 2882 } 2883 2884 window.onYouTubePlayerAPIReady = function() { 2885 if ( oldAPI && typeof oldAPI == 'function' ) oldAPI(); 2886 YTdeferred.resolve(window.YT); 2887 }; 2888 2889 function initYoutubePlayer() { 2890 if (process) return; 2891 process = true; 2892 // Load Youtube API 2893 if ( $video_autoplay_yt.length ) { 2894 embedYoutubeAPI(); 2895 } 2896 2897 if ( ! initAPI ) { 2898 process = false; 2899 return; 2900 } 2901 2902 if ( typeof YTdeferred != 'undefined' ) { 2903 YTdeferred.done( function(YT) { 2904 $video_autoplay_yt.each( function() { 2905 var $self = jQuery(this); 2906 if ( $self.parents('.sc_layouts_submenu:not(.layouts_inited):not(:visible)').length ) return; 2907 2908 var $frame = $self.parents('.video_frame').eq(0), 2909 $wrap = $self.parents('.with_video_autoplay').eq(0), 2910 $sticky = $self.parents('.trx_addons_video_sticky_inner').eq(0), 2911 isInit = $wrap.hasClass('video_autoplay_inited'), 2912 isInView = $wrap.isInViewport(), 2913 id = ! isInit ? trx_addons_get_unique_id() : $wrap.attr('data-uid'); 2914 2915 if ( ! isInit ) { 2916 $self.attr( 'id', id ); 2917 $wrap 2918 .addClass('video_autoplay_inited') 2919 .attr('data-uid', id); 2920 var videoID = $wrap.data('video-id'); 2921 if ( ! videoID ) { 2922 var src = ( $self.data('src') ? $self.data('src') : $self.attr('src') ).split('?'); 2923 videoID = src[0].substring( src[0].indexOf('/embed/') + 7 ); 2924 $wrap.data('video-id', videoID); 2925 } 2926 if ( ! videoID ) return; 2927 $frame.append( 2928 '<span class="video_frame_overlay"></span>' 2929 + '<span class="video_frame_controls">' 2930 + '<a class="video_frame_control_stop video_frame_link" href="https://youtube.com/watch?v='+videoI
2930D+'" target="_blank"></a>' 2931 + '<span class="video_frame_control_volume video_frame_control_volume_mute"></span>' 2932 + '<span class="video_frame_control_state video_frame_control_state_' 2933 + ( $self.attr( 'allow' ) && $self.attr( 'allow' ).indexOf( 'autoplay' ) >= 0 ? 'pause' : 'play' ) 2934 + '"></span>' 2935 + '</span>' 2936 ); 2937 2938 // Play/Pause video on enter/leave viewport 2939 trx_addons_intersection_observer_add( $wrap, function( item, enter ) { 2940 initYoutubePlayer(); 2941 } ); 2942 2943 // Play/Pause video 2944 $frame.find('.video_frame_control_state').on('click', function() { 2945 var $self = jQuery(this); 2946 $self.toggleClass('video_frame_control_state_play video_frame_control_state_pause'); 2947 if ( $self.hasClass('video_frame_control_state_play') ) { 2948 $self.removeClass('video_frame_control_state_upause'); 2949 if ( typeof players[id].playVideo == 'function' ) players[id].playVideo(); 2950 } else { 2951 $self.addClass('video_frame_control_state_upause'); 2952 if ( typeof players[id].pauseVideo == 'function' ) players[id].pauseVideo(); 2953 } 2954 } ); 2955 2956 // Stop video (on go to Youtube) 2957 $frame.find('.video_frame_control_stop').on('click', function() { 2958 var $self = jQuery(this); 2959 $self.siblings('.video_frame_control_state').removeClass('video_frame_control_state_play').addClass('video_frame_control_state_pause'); 2960 $self.addClass('video_frame_control_state_upause'); 2961 if ( typeof players[id].pauseVideo == 'function' ) players[id].pauseVideo(); 2962 } ); 2963 2964 // Mute/Unmute video 2965 $frame.find('.video_frame_control_volume').on('click', function() { 2966 var $self = jQuery(this); 2967 $self.toggleClass('video_frame_control_volume_mute video_frame_control_volume_unmute'); 2968 if ( $self.hasClass('video_frame_control_volume_unmute') ) { 2969 if ( typeof players[id].unMute == 'function' ) players[id].unMute(); 2970 } else { 2971 if ( typeof players[id].mute == 'function' ) players[id].mute(); 2972 } 2973 } ); 2974 2975 attrs[id] = { 2976 'videoId': videoID, 2977 'startSeconds': $self.data('video-start') || trx_addons_apply_filters( 'trx_addons_filter_youtube_autoplay_start_seconds', -1 ), 2978 'suggestedQuality': 'hd720' 2979 }; 2980 if ( $self.data('video-end') ) { 2981 attrs[id]['endSeconds'] = $self.data('video-end'); 2982 } 2983 players[id] = new YT.Player( this, { 2984 playerVars: { 2985 autoplay: 0, 2986 autohide: 1, 2987 modestbranding: 1, 2988 rel: 0, 2989 showinfo: 0, 2990 controls: 0, 2991 disablekb: 1, 2992 enablejsapi: 1, 2993 iv_load_policy: 3, 2994 playsinline: 1, 2995 loop: 1 2996 }, 2997 events: { 2998 'onReady': function onReady(e) { 2999 //players[id].loadVideoById( attrs[id] ); 3000 players[id].mute(); 3001 }, 3002 'onStateChange': function onStateChange(e) { 3003 if (e.data === 1) { 3004 $wrap.addClass('video_autoplay_started'); 3005 } else if (e.data === 0) { 3006 if ( attrs[id].startSeconds >= 0 ) { 3007 players[id].seekTo(attrs[id].startSeconds); 3008 } 3009 } 3010 } 3011 } 3012 } ); 3013 // Save a reference to the player object in the frame's data store 3014 // to allow 3rd party scripts to control the video programmatically 3015 $frame.data('video-player', players[id]); 3016 } 3017 // FadeIn video 3018 if ( isInit && isInView && ! $frame.hasClass('.video_frame_visible') ) { 3019 setTimeout( function() { 3020 $frame.fadeTo( 500, 1.0, function() { 3021 $frame.addClass('video_frame_visible'); 3022 }); 3023 }, trx_addons_apply_filters( 'trx_addons_filter_video_frame_timeout', 0 ) ); 3024 } 3025 // Play/Pause on window scroll 3026 var control = $wrap.find('.video_frame_control_state'); 3027 if ( isInit && typeof players[id].playVideo == 'function' && ! control.hasClass('video_frame_control_state_upause') && $sticky.length === 0 ) { 3028 if ( isInView && control.hasClass('video_frame_control_state_pause') ) { 3029 control.removeClass('video_frame_control_state_pause').addClass('video_frame_control_state_play'); 3030 players[id].playVideo(); 3031 } 3032 if ( ! isInView && control.hasClass('video_frame_control_state_play') ) { 3033 control.removeClass('video_frame_control_state_play').addClass('video_frame_control_state_pause'); 3034 players[id].pauseVideo(); 3035 } 3036 } 3037 } ); 3038 3039 } ); 3040 } 3041 3042 process = false;
3043 3044 } // initYoutubePlayer 3045 3046 initYoutubePlayer(); 3047 3048 // Init hidden and loaded elements 3049 if ( ! initEvents ) { 3050 initEvents = true; 3051 $document.on( 'action.init_hidden_elements action.got_ajax_response action.after_show_submenu action.after_hide_submenu', trx_addons_debounce( function( e ) { 3052 initYoutubePlayer(); 3053 }, 50 ) ); 3054 $document.on( 'action.start_item_animation', function() { 3055 setTimeout( function() { 3056 initYoutubePlayer(); 3057 }, 10 ); 3058 } ); 3059 } 3060 3061 ready_busy = false; 3062 3063 } ); // document.ready 3064 3065 3066 // Global functions 3067 //------------------------------------- 3068 3069 // Paint arc on canvas with digits (used in the shortcodes and reviews) 3070 window.trx_addons_draw_arc_on_canvas = function(item, value) { 3071 3072 var canvas = item.find('canvas'); 3073 if (canvas.length === 0) return; 3074 3075 var digits = canvas.next(); 3076 var brd = parseInt(digits.css('border-top-width'), 10); 3077 var w = Math.ceil(digits.width()+2*brd); 3078 3079 var needRepaint = false; 3080 if (canvas.attr('width') != w) { 3081 needRepaint = true; 3082 canvas.attr({ 3083 'width': w, 3084 'height': w 3085 }); 3086 } 3087 3088 if (item.data('old-value') == value && !needRepaint) return; 3089 item.data('old-value', value); 3090 3091 var percent = value * 100 / canvas.data('max-value'); 3092 var angle = 360 * percent / 100; 3093 var Ar = angle * Math.PI / 180; 3094 3095 var canvas_dom = canvas.get(0); 3096 var context = canvas_dom.getContext('2d'); 3097 var r = (w - brd) / 2; 3098 var cx = w / 2; 3099 var cy = w / 2; 3100 3101 context.beginPath(); 3102 context.clearRect(0, 0, w, w); 3103 context.arc(cx, cy, r, 0, Ar, false); 3104 context.imageSmoothingEnabled= true; 3105 context.lineWidth = brd;
3106 context.strokeStyle = canvas.data('color'); 3107 context.stroke(); 3108 }; 3109 3110})();
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.