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