1/** 2 * Init scripts 3 * 4 * @package WordPress 5 * @subpackage ThemeREX Addons 6 * @since v1.0 7 */ 8 9/* global jQuery:false */ 10/* global TRX_ADDONS_STORAGE:false */ 11 12jQuery(document).ready(function() { 13 "use strict"; 14 TRX_ADDONS_STORAGE['vc_init_counter'] = 0; 15 trx_addons_init_actions(); 16}); 17 18jQuery(window).on('beforeunload', function() { 19 "use strict"; 20 // Show preloader 21 if (jQuery.browser && !jQuery.browser.safari) jQuery('#page_preloader').css({display: 'block', opacity: 0}).animate({opacity:0.8}, 300); 22}); 23 24 25// Init actions 26function trx_addons_init_actions() { 27 "use strict"; 28 29 if (TRX_ADDONS_STORAGE['vc_edit_mode'] > 0 && jQuery('.vc_empty-placeholder').length==0 && TRX_ADDONS_STORAGE['vc_init_counter']++ < 30) { 30 setTimeout(trx_addons_init_actions, 200); 31 return; 32 } 33 34 // Hide preloader 35 jQuery('#page_preloader').animate({opacity:0}, 800, function() { 36 jQuery(this).css( {display: 'none'} ); 37 }); 38 39 // Check for Retina display 40 if (trx_addons_is_retina()) { 41 trx_addons_set_cookie('trx_addons_is_retina', 1, 365); 42 } 43 44 45 // Add ready actions to the hidden elements actions 46 jQuery(document).on('action.init_hidden_elements', trx_addons_ready_actions); 47 48 // Init core actions 49 trx_addons_ready_actions(); 50 trx_addons_resize_actions(); 51 trx_addons_scroll_actions(); 52 53 // Resize handlers 54 jQuery(window).resize(function() { 55 "use strict"; 56 trx_addons_resize_actions(); 57 }); 58 59 // Add resize on VC action vc-full-width-row 60 jQuery(document).on('vc-full-width-row', function(e, el) { 61 trx_addons_resize_actions(); 62 }); 63 64 // Scroll handlers 65 jQuery(window).scroll(function() { 66 "use strict"; 67 trx_addons_scroll_actions(); 68 }); 69} 70 71 72 73// Page first load actions 74//============================================== 75function trx_addons_ready_actions(e, container) { 76 "use strict"; 77 78 if (arguments.length < 2) var container = jQuery('body'); 79 80 // Tabs 81 //------------------------------------ 82 if (container.find('.trx_addons_tabs:not(.inited)').length > 0 && jQuery.ui && jQuery.ui.tabs) { 83 container.find('.trx_addons_tabs:not(.inited)').each(function () { 84 "use strict"; 85 // Get initially opened tab 86 var init = jQuery(this).data('active'); 87 if (isNaN(init)) { 88 init = 0; 89 var active = jQuery(this).find('> ul > li[data-active="true"]').eq(0); 90 if (active.length > 0) { 91 init = active.index(); 92 if (isNaN(init) || init < 0) init = 0; 93 } 94 } else { 95 init = Math.max(0, init); 96 } 97 // Get disabled tabs 98 var disabled = []; 99 jQuery(this).find('> ul > li[data-disabled="true"]').each(function() { 100 "use strict"; 101 disabled.push(jQuery(this).index()); 102 }); 103 // Init tabs 104 jQuery(this).addClass('inited').tabs({ 105 active: init, 106 disabled: disabled, 107 show: { 108 effect: 'fadeIn', 109 duration: 300 110 }, 111 hide: { 112 effect: 'fadeOut', 113 duration: 300 114 }, 115 create: function( event, ui ) { 116 if (ui.panel.length > 0) jQuery(document).trigger('action.init_hidden_elements', [ui.panel]); 117 }, 118 activate: function( event, ui ) { 119 if (ui.newPanel.length > 0) jQuery(document).trigger('action.init_hidden_elements', [ui.newPanel]);
120 } 121 }); 122 }); 123 } 124 125 126 // Accordion 127 //------------------------------------ 128 if (container.find('.trx_addons_accordion:not(.inited)').length > 0 && jQuery.ui && jQuery.ui.accordion) { 129 container.find('.trx_addons_accordion:not(.inited)').each(function () { 130 "use strict"; 131 // Get headers selector 132 var accordion = jQuery(this); 133 var headers = accordion.data('headers'); 134 if (headers===undefined) headers = 'h5'; 135 // Get height style 136 var height_style = accordion.data('height-style'); 137 if (height_style===undefined) height_style = 'content'; 138 // Get initially opened tab 139 var init = accordion.data('active'); 140 var active = false; 141 if (isNaN(init)) { 142 init = 0; 143 var active = accordion.find(headers+'[data-active="true"]').eq(0); 144 if (active.length > 0) { 145 while (!active.parent().hasClass('trx_addons_accordion')) { 146 active = active.parent(); 147 } 148 init = active.index(); 149 if (isNaN(init) || init < 0) init = 0; 150 } 151 } else { 152 init = Math.max(0, init); 153 } 154 // Init accordion 155 accordion.addClass('inited').accordion({ 156 active: init, 157 header: headers, 158 heightStyle: height_style, 159 create: function( event, ui ) { 160 if (ui.panel.length > 0) { 161 jQuery(document).trigger('action.init_hidden_elements', [ui.panel]); 162 } else if (active !== false && active.length > 0) { 163 // If headers and panels wrapped into div 164 active.find('>'+headers).trigger('click'); 165 } 166 }, 167 activate: function( event, ui ) { 168 if (ui.newPanel.length > 0) jQuery(document).trigger('action.init_hidden_elements', [ui.newPanel]);
169 } 170 }); 171 }); 172 } 173 174 175 // Sliders 176 //---------------------------------------------- 177 jQuery(document).trigger('action.init_sliders', [container]); 178 179 180 // Shortcodes 181 //---------------------------------------------- 182 jQuery(document).trigger('action.init_shortcodes', [container]); 183 184 185 // Video player 186 //---------------------------------------------- 187 if (container.find('.trx_addons_video_player.with_cover .video_hover:not(.inited)').length > 0) { 188 container.find('.trx_addons_video_player.with_cover .video_hover:not(.inited)') 189 .addClass('inited') 190 .on('click', function(e) { 191 "use strict"; 192 193 jQuery(this).parents('.trx_addons_video_player') 194 .addClass('video_play') 195 .find('.video_embed').html(jQuery(this).data('video')); 196 197 // If video in the slide 198 var slider = jQuery(this).parents('.slider_swiper'); 199 if (slider.length > 0) { 200 var id = slider.attr('id'); 201 TRX_ADDONS_STORAGE['swipers'][id].stopAutoplay(); 202 } 203 204 jQuery(window).trigger('resize'); 205 e.preventDefault(); 206 return false; 207 }); 208 } 209 210 211 // Popups 212 //---------------------------------------------- 213 if (TRX_ADDONS_STORAGE['popup_engine'] == 'pretty') { 214 // Display lightbox on click on the image 215 container.find("a[href$='jpg']:not(.inited),a[href$='jpeg']:not(.inited),a[href$='png']:not(.inited),a[href$='gif']:not(.inited)").attr('rel', 'prettyPhoto[slideshow]'); 216 var images = container.find("a[rel*='prettyPhoto']:not(.inited):not(.esgbox):not([data-rel*='pretty']):not([rel*='magnific']):not([data-rel*='magnific'])").addClass('inited'); 217 try { 218 images.prettyPhoto({ 219 social_tools: '', 220 theme: 'facebook', 221 deeplinking: false 222 }); 223 } catch (e) {}; 224 } else if (TRX_ADDONS_STORAGE['popup_engine']=='magnific') { 225 // Display lightbox on click on the image 226 container.find("a[href$='jpg']:not(.inited),a[href$='jpeg']:not(.inited),a[href$='png']:not(.inited),a[href$='gif']:not(.inited)").attr('rel', 'magnific'); 227 var images = container.find("a[rel*='magnific']:not(.inited):not(.esgbox):not(.prettyphoto):not([rel*='pretty']):not([data-rel*='pretty'])").addClass('inited'); 228 try { 229 images.magnificPopup({ 230 type: 'image', 231 mainClass: 'mfp-img-mobile', 232 closeOnContentClick: true, 233 closeBtnInside: true, 234 fixedContentPos: true, 235 midClick: true, 236 //removalDelay: 500, 237 preloader: true, 238 tLoading: TRX_ADDONS_STORAGE['msg_magnific_loading'], 239 gallery:{ 240 enabled: true 241 }, 242 image: { 243 tError: TRX_ADDONS_STORAGE['msg_magnific_error'], 244 verticalFit: true 245 }, 246 zoom: { 247 enabled: true, 248 duration: 300, 249 easing: 'ease-in-out', 250 opener: function(openerElement) { 251 // openerElement is the element on which popup was initialized, in this case its <a> tag 252 // you don't need to add "opener" option if this code matches your needs, it's defailt one. 253 if (!openerElement.is('img')) { 254 if (openerElement.parents('.trx_addons_hover').find('img').length > 0) 255 openerElement = openerElement.parents('.trx_addons_hover').find('img'); 256 else if (openerElement.siblings('img').length > 0) 257 openerElement = openerElement.siblings('img'); 258 else if (openerElement.parent().parent().find('img').length > 0) 259 openerElement = openerElement.parent().parent().find('img'); 260 } 261 return openerElement; 262 } 263 }, 264 callbacks: { 265 beforeClose: function(){ 266 jQuery('.mfp-figure figcaption').hide(); 267 jQuery('.mfp-figure .mfp-arrow').hide(); 268 } 269 } 270 }); 271 } catch (e) {}; 272 273 // Display lightbox on click on the popup link 274 container.find(".trx_addons_popup_link:not(.inited)").addClass('inited').magnificPopup({ 275 type: 'inline', 276 focus: 'input', 277 closeBtnInside: true 278 }); 279 } 280 281 282 // Likes counter 283 //--------------------------------------------- 284 if (container.find('.post_counters_likes:not(.inited),.comment_counters_likes:not(.inited)').length > 0) { 285 container.find('.post_counters_likes:not(.inited),.comment_counters_likes:not(.inited)') 286 .addClass('inited') 287 .on('click', function(e) { 288 "use strict"; 289 var button = jQuery(this); 290 var inc = button.hasClass('enabled') ? 1 : -1; 291 var post_id = button.hasClass('post_counters_likes') ? button.data('postid') : button.data('commentid'); 292 var cookie_likes = trx_addons_get_cookie(button.hasClass('post_counters_likes') ? 'trx_addons_likes' : 'trx_addons_comment_likes'); 293 if (cookie_likes === undefined || cookie_likes===null) cookie_likes = ''; 294 jQuery.post(TRX_ADDONS_STORAGE['ajax_url'], { 295 action: button.hasClass('post_counters_likes') ? 'post_counter' : 'comment_counter', 296 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 297 post_id: post_id, 298 likes: inc 299 }).done(function(response) { 300 "use strict"; 301 var rez = {}; 302 try { 303 rez = JSON.parse(response); 304 } catch (e) { 305 rez = { error: TRX_ADDONS_STORAGE['msg_ajax_error'] }; 306 console.log(response); 307 } 308 if (rez.error === '') { 309 var counter = rez.counter; 310 if (inc == 1) { 311 var title = button.data('title-dislike'); 312 button.removeClass('enabled trx_addons_icon-heart-empty').addClass('disabled trx_addons_icon-heart'); 313 cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ','; 314 } else { 315 var title = button.data('title-like'); 316 button.removeClass('disabled trx_addons_icon-heart').addClass('enabled trx_addons_icon-heart-empty'); 317 cookie_likes = cookie_likes.replace(','+post_id+',', ','); 318 }
319 button.data('likes', counter).attr('title', title).find(button.hasClass('post_counters_likes') ? '.post_counters_number' : '.comment_counters_number').html(counter); 320 trx_addons_set_cookie(button.hasClass('post_counters_likes') ? 'trx_addons_likes' : 'trx_addons_comment_likes', cookie_likes, 365); 321 } else { 322 alert(TRX_ADDONS_STORAGE['msg_error_like']); 323 } 324 }); 325 e.preventDefault(); 326 return false; 327 }); 328 } 329 330 331 // Socials share 332 //---------------------------------------------- 333 if (container.find('.socials_share .socials_caption:not(.inited)').length > 0) { 334 container.find('.socials_share .socials_caption:not(.inited)').each(function() { 335 "use strict"; 336 jQuery(this).addClass('inited').on('click', function(e) { 337 "use strict"; 338 jQuery(this).siblings('.social_items').fadeToggle(); 339 e.preventDefault(); 340 return false; 341 }); 342 }); 343 } 344 if (container.find('.socials_share .social_items:not(.inited)').length > 0) { 345 container.find('.socials_share .social_items:not(.inited)').each(function() { 346 "use strict"; 347 jQuery(this).addClass('inited').on('click', '.social_item_popup > a.social_icons', function(e) { 348 "use strict"; 349 var url = jQuery(this).data('link'); 350 window.open(url, '_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=480, height=400, toolbar=0, status=0'); 351 e.preventDefault(); 352 return false; 353 }); 354 }); 355 } 356 357 358 // Widgets decoration 359 //---------------------------------------------- 360 361 // Decorate nested lists in widgets and side panels 362 container.find('.widget ul > li').each(function() { 363 "use strict"; 364 if (jQuery(this).find('ul').length > 0) { 365 jQuery(this).addClass('has_children'); 366 } 367 }); 368 369 // Archive widget decoration 370 container.find('.widget_archive a:not(.inited)').addClass('inited').each(function() { 371 "use strict"; 372 var val = jQuery(this).html().split(' '); 373 if (val.length > 1) { 374 val[val.length-1] = '<span>' + val[val.length-1] + '</span>'; 375 jQuery(this).html(val.join(' ')) 376 } 377 }); 378 379 380 // Menu 381 //---------------------------------------------- 382 383 // Prepare menus (if menu cache is used) 384 if (TRX_ADDONS_STORAGE['menu_cache']) { 385 // Mark the current menu item and its parent items in the cached menus 386 var href = window.location.href; 387 for (var menu in TRX_ADDONS_STORAGE['menu_cache']) { 388 menu = jQuery(TRX_ADDONS_STORAGE['menu_cache'][menu]); 389 if (menu.length==0) continue; 390 menu.find('li').removeClass('current-menu-ancestor current-menu-parent current-menu-item'); 391 menu.find('a[href="'+href+'"]').each(function(idx) { 392 var li = jQuery(this).parent(); 393 li.addClass('current-menu-item'); 394 if (li.hasClass('menu-item-object-page')) li.addClass('current_page_item'); 395 var cnt = 0; 396 while ((li = li.parents('li')).length > 0) { 397 cnt++; 398 li.addClass('current-menu-ancestor'+(cnt==1 ? ' current-menu-parent' : '')); 399 } 400 }); 401 } 402 } 403 404 405 // Other settings 406 //------------------------------------ 407 408 // Scroll to top button 409 container.find('.trx_addons_scroll_to_top:not(.inited)').addClass('inited').on('click', function(e) { 410 "use strict"; 411 jQuery('html,body').animate({ 412 scrollTop: 0 413 }, 'slow'); 414 e.preventDefault(); 415 return false; 416 }); 417 418} //end ready 419 420 421 422 423// Scroll actions 424//============================================== 425 426// Do actions when page scrolled 427function trx_addons_scroll_actions() { 428 "use strict"; 429 430 var scroll_offset = jQuery(window).scrollTop(); 431 var scroll_to_top_button = jQuery('.trx_addons_scroll_to_top'); 432 var adminbar_height = Math.max(0, jQuery('#wpadminbar').height()); 433 434 // Scroll to top button show/hide 435 if (scroll_to_top_button.length > 0) { 436 if (scroll_offset > 100) 437 scroll_to_top_button.addClass('show'); 438 else 439 scroll_to_top_button.removeClass('show'); 440 } 441 442 // Scroll actions for animated elements 443 jQuery('[data-animation^="animated"]:not(.animated)').each(function() { 444 "use strict"; 445 if (jQuery(this).offset().top < scroll_offset + jQuery(window).height()) 446 jQuery(this).addClass(jQuery(this).data('animation')); 447 }); 448} 449 450 451 452// Resize actions 453//============================================== 454 455// Do actions when page scrolled 456function trx_addons_resize_actions(cont) { 457 "use strict"; 458 if (window.trx_addons_resize_sliders) trx_addons_resize_sliders(cont); 459 trx_addons_resize_video(cont); 460} 461 462 463 464// Fit video frames to document width 465function trx_addons_resize_video(cont) { 466 if (cont===undefined) cont = jQuery('body'); 467 cont.find('video').each(function() { 468 "use strict"; 469 var video = jQuery(this).eq(0); 470 var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]); 471 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 472 var mejs_cont = video.parents('.mejs-video'); 473 var w_attr = video.data('width'); 474 var h_attr = video.data('height'); 475 if (!w_attr || !h_attr) { 476 w_attr = video.attr('width'); 477 h_attr = video.attr('height'); 478 if (!w_attr || !h_attr) return;
479 video.data({'width': w_attr, 'height': h_attr}); 480 } 481 var percent = (''+w_attr).substr(-1)=='%'; 482 w_attr = parseInt(w_attr); 483 h_attr = parseInt(h_attr); 484 var w_real = Math.round(mejs_cont.length > 0 ? Math.min(percent ? 10000 : w_attr, mejs_cont.parents('div,article').width()) : video.width()), 485 h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr); 486 if (parseInt(video.attr('data-last-width'))==w_real) return; 487 if (mejs_cont.length > 0 && mejs) { 488 trx_addons_set_mejs_player_dimensions(video, w_real, h_real); 489 } 490 if (percent) { 491 video.height(h_real); 492 } else { 493 video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'}); 494 } 495 video.attr('data-last-width', w_real); 496 }); 497 cont.find('.video_frame iframe').each(function() { 498 "use strict"; 499 var iframe = jQuery(this).eq(0); 500 if (iframe.attr('src').indexOf('soundcloud')>0) return; 501 var ratio = (iframe.data('ratio')!=undefined 502 ? iframe.data('ratio').split(':') 503 : (iframe.parent().data('ratio')!=undefined 504 ? iframe.parent().data('ratio').split(':') 505 : (iframe.find('[data-ratio]').length>0 506 ? iframe.find('[data-ratio]').data('ratio').split(':') 507 : [16,9] 508 ) 509 ) 510 ); 511 ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1]; 512 var w_attr = iframe.attr('width'); 513 var h_attr = iframe.attr('height'); 514 if (!w_attr || !h_attr) { 515 return; 516 } 517 var percent = (''+w_attr).substr(-1)=='%'; 518 w_attr = parseInt(w_attr); 519 h_attr = parseInt(h_attr); 520 var pw = iframe.parent().width(), 521 ph = iframe.parent().height(), 522 w_real = pw, 523 h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr); 524 if (iframe.parent().css('position') == 'absolute' && h_real > ph) { 525 h_real = ph; 526 w_real = Math.round(percent ? h_real*ratio : h_real*w_attr/h_attr) 527 } 528 if (parseInt(iframe.attr('data-last-width'))==w_real) return; 529 iframe.css({'width': w_real+'px', 'height': h_real+'px'}); 530 iframe.attr('data-last-width', w_real); 531 }); 532} 533 534 535// Set Media Elements player dimensions 536function trx_addons_set_mejs_player_dimensions(video, w, h) { 537 "use strict"; 538 if (mejs) { 539 for (var pl in mejs.players) { 540 if (mejs.players[pl].media.src == video.attr('src')) { 541 if (mejs.players[pl].media.setVideoSize) { 542 mejs.players[pl].media.setVideoSize(w, h); 543 } 544 mejs.players[pl].setPlayerSize(w, h); 545 mejs.players[pl].setControlsSize(); 546 } 547 } 548 } 549}
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.