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