1(function($){ 2 "use strict"; 3 4 var chariti_display = 'desktop'; 5 if( typeof(window.matchMedia) == 'function' ){ 6 $(window).on('resize chariti-set-display', function(){ 7 if( window.matchMedia('(max-width: 419px)').matches ){ 8 chariti_display = 'mobile-portrait'; 9 }else if( window.matchMedia('(max-width: 767px)').matches ){ 10 chariti_display = 'mobile-landscape' 11 }else if( window.matchMedia('(max-width: 959px)').matches ){ 12 chariti_display = 'tablet' 13 }else{ 14 chariti_display = 'desktop'; 15 } 16 }); 17 $(window).trigger('chariti-set-display'); 18 }else{ 19 $(window).on('resize chariti-set-display', function(){ 20 if( $(window).innerWidth() <= 419 ){ 21 chariti_display = 'mobile-portrait'; 22 }else if( $(window).innerWidth() <= 767 ){ 23 chariti_display = 'mobile-landscape' 24 }else if( $(window).innerWidth() <= 959 ){ 25 chariti_display = 'tablet' 26 }else{ 27 chariti_display = 'desktop'; 28 } 29 }); 30 $(window).trigger('chariti-set-display'); 31 } 32 33 // ref : http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ 34 // ensure 1 is fired 35 var chariti_debounce = function(func, threshold, execAsap){ 36 37 var timeout; 38 39 return function debounced(){ 40 41 var obj = this, args = arguments; 42 43 function delayed(){ 44 if( !execAsap ){ 45 func.apply(obj, args); 46 } 47 timeout = null; 48 }; 49 50 if( timeout ){ 51 clearTimeout(timeout); 52 }else if( execAsap ){ 53 func.apply(obj, args); 54 } 55 timeout = setTimeout(delayed, threshold); 56 }; 57 } 58 59 // reduce the event occurance 60 var chariti_throttling = function(func, threshold){ 61 62 var timeout; 63 64 return function throttled(){ 65 var obj = this, args = arguments; 66 67 function delayed(){ 68 func.apply(obj, args); 69 timeout = null; 70 }; 71 72 if( !timeout ){ 73 timeout = setTimeout(delayed, threshold); 74 } 75 }; 76 } 77 78 ///////////////////////// 79 // menu handle function 80 ///////////////////////// 81 var chariti_sf_menu = function( menu ){ 82 83 if( menu.length == 0 ) return; 84 85 this.main_menu = menu; 86 87 this.slide_bar = this.main_menu.children('.chariti-navigation-slide-bar'); 88 this.slide_bar_val = { width: 0, left: 0 }; 89 this.slide_bar_offset = '15'; 90 if( this.slide_bar.attr('data-size-offset') ){ 91 this.slide_bar_offset = parseInt(this.slide_bar.attr('data-size-offset')); 92 } 93 94 this.slide_bar_width = 0; 95 if( this.slide_bar.attr('data-width') ){ 96 this.slide_bar_width = parseInt(this.slide_bar.attr('data-width')); 97 } 98 99 this.current_menu = this.main_menu.children('.sf-menu').children('.current-menu-item, .current-menu-ancestor').children('a'); 100 101 this.init(); 102 103 } // chariti_sf_menu 104 105 chariti_sf_menu.prototype = { 106 107 init: function(){ 108 109 var t = this; 110 111 // sf menu mod 112 t.sf_menu_mod(); 113 114 // init superfish menu 115 if(typeof($.fn.superfish) == 'function'){ 116 t.main_menu.superfish({ delay: 400, speed: 'fast' }); 117 118 t.sf_menu_position(); 119 $(window).resize(chariti_debounce(function(){ 120 t.sf_menu_position(); 121 }, 300)); 122 } 123 124 // init the slidebar 125 if( t.slide_bar.length > 0 ){ 126 t.init_slidebar(); 127 } 128 129 }, // init 130 131 sf_menu_mod: function(){ 132 133 // create the mega menu script 134 this.main_menu.find('.sf-mega > ul').each(function(){ 135 var mega_content = $('<div></div>'); 136 var mega_row = $('<div class="sf-mega-section-wrap" ></div>'); 137 var mega_column_size = 0; 138 139 $(this).children('li').each(function(){ 140 var column_size = parseInt($(this).attr('data-size')); 141 if( mega_column_size + column_size <= 60 ){ 142 mega_column_size += column_size; 143 }else{ 144 mega_column_size = column_size; 145 mega_content.append(mega_row); 146 mega_row = $('<div class="sf-mega-section-wrap" ></div>'); 147 } 148 149 mega_row.append( $('<div class="sf-mega-section" ></div>') 150 .addClass('chariti-column-' + column_size) 151 .html( $('<div class="sf-mega-section-inner" ></div>') 152 .addClass($(this).attr('class')) 153 .attr('id', $(this).attr('id')) 154 .html($(this).html()) 155 ) 156 ); 157 }); 158 159 mega_content.append(mega_row); 160 $(this).replaceWith(mega_content.html()); 161 }); 162 163 }, // sf_menu_mod 164 165 sf_menu_position: function(){ 166 167 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 168 169 // submenu of normal menu 170 var body_wrapper = $('.chariti-body-wrapper'); 171 var sub_normal_menu = this.main_menu.find('.sf-menu > li.chariti-normal-menu .sub-menu'); 172 173 sub_normal_menu.css({display: 'block'}
173).removeClass('sub-menu-right sub-menu-left'); 174 sub_normal_menu.each(function(){ 175 if( $(this).offset().left + $(this).width() > body_wrapper.outerWidth() ){ 176 $(this).addClass('sub-menu-right'); 177 }else if( $(this).offset().left < 0 ){ 178 $(this).addClass('sub-menu-left'); 179 } 180 }); 181 sub_normal_menu.css({display: 'none'}); 182 183 // submenu of mega menu 184 this.main_menu.find('.sf-menu > li.chariti-mega-menu .sf-mega').each(function(){ 185 if( !$(this).hasClass('sf-mega-full') ){ 186 187 $(this).css({ display: 'block' }); 188 189 // set the position 190 $(this).css({ right: '', 'margin-left': -(($(this).width() - $(this).parent().outerWidth()) / 2) }); 191 192 // if exceed the screen 193 if( $(this).offset().left + $(this).width() > $(window).width() ){ 194 $(this).css({ right: 0, 'margin-left': '' }); 195 } 196 197 $(this).css({ display: 'none' }); 198 } 199 200 }); 201 202 }, // sf_menu_position 203 204 init_slidebar: function(){ 205 206 var t = this; 207 208 t.init_slidebar_pos(); 209 $(window).load(function(){ t.init_slidebar_pos(); }); 210 211 // animate slidebar 212 t.main_menu.children('.sf-menu').children('li').on({ 213 mouseenter: function(){ 214 var nav_element = $(this).children('a'); 215 216 if( nav_element.length > 0 ){ 217 218 if( t.slide_bar_width > 0 ){ 219 var sbw = t.slide_bar_width; 220 if( t.slide_bar.hasClass('chariti-left') ){ 221 var sbl = nav_element.position().left - t.slide_bar_offset; 222 }else{ 223 var sbl = nav_element.position().left + ((nav_element.outerWidth() - sbw)/2) - t.slide_bar_offset; 224 } 225 }else{ 226 var sbw = nav_element.outerWidth() + (2 * t.slide_bar_offset); 227 var sbl = nav_element.position().left - t.slide_bar_offset; 228 } 229 230 t.slide_bar.animate({ width: sbw, left: sbl }, { queue: false, duration: 250 }); 231 } 232 }, 233 mouseleave: function(){ 234 t.slide_bar.animate({ width: t.slide_bar_val.width, left: t.slide_bar_val.left }, { queue: false, duration: 250 }); 235 } 236 }); 237 238 // window resize event 239 $(window).on('resize', function(){ t.init_slidebar_pos(); }); 240 $(window).on('chariti-navigation-slider-bar-init', function(){ 241 t.current_menu = t.main_menu.children('.sf-menu').children('.current-menu-item, .current-menu-ancestor').children('a'); 242 t.animate_slidebar_pos(); 243 }); 244 $(window).on('chariti-navigation-slider-bar-animate', function(){ t.animate_slidebar_pos(); }); 245 246 }, // init_slidebar 247 248 init_slidebar_pos: function(){ 249 250 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 251 252 var t = this; 253 254 if( t.current_menu.length > 0 ){ 255 if( t.slide_bar_width > 0 ){ 256 var sbw = t.slide_bar_width; 257 if( t.slide_bar.hasClass('chariti-left') ){ 258 var sbl = t.current_menu.position().left - t.slide_bar_offset; 259 }else{ 260 var sbl = t.current_menu.position().left + ((t.current_menu.outerWidth() - sbw)/2) - t.slide_bar_offset; 261 } 262 }else{ 263 var sbw = t.current_menu.outerWidth() + (2 * t.slide_bar_offset); 264 var sbl = t.current_menu.position().left - t.slide_bar_offset; 265 } 266 t.slide_bar_val = { width: sbw, left: sbl }; 267 }else{ 268 t.slide_bar_val = { width: 0 } 269 270 var first_child = t.main_menu.children('ul').children('li:first-child'); 271 if( typeof(first_child.position()) != 'undefined' ){ 272 t.slide_bar_val.left = first_child.position().left; 273 }else{ 274 t.slide_bar_val.left = 0; 275 } 276 } 277 t.slide_bar.css({ width: t.slide_bar_val.width, left: t.slide_bar_val.left, display: 'block' }); 278 279 }, // set_slidebar_pos 280 animate_slidebar_pos: function(){ 281 282 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 283 284 var t = this; 285 286 if( t.current_menu.length > 0 ){ 287 if( t.slide_bar_width > 0 ){ 288 var sbw = t.slide_bar_width; 289 if( t.slide_bar.hasClass('chariti-left') ){ 290 var sbl = t.current_menu.position().left - t.slide_bar_offset; 291 }else{ 292 var sbl = t.current_menu.position().left + ((t.current_menu.outerWidth() - sbw)/2) - t.slide_bar_offset; 293 } 294 }else{ 295 var sbw = t.current_menu.outerWidth() + (2 * t.slide_bar_offset); 296 var sbl = t.current_menu.position().left - t.slide_bar_offset; 297 } 298 t.slide_bar_val = { width: sbw, left: sbl }; 299 }else{ 300 t.slide_bar_val = { width: 0 } 301 302 var first_child = t.main_menu.children('ul').children('li:first-child'); 303 if( typeof(first_child.position()) != 'undefined' ){ 304 t.slide_bar_val.left = first_child.position().left; 305 }else{ 306 t.slide_bar_val.left = 0; 307 } 308 } 309 t.slide_bar.animate({ width: t.slide_bar_val.width, left: t.slide_bar_val.left }, { queue: false, duration: 250 }); 310 311 } // set_slidebar_pos 312 313 }; // chariti_sf_menu.prototype 314 315 ///////////////////////// 316 // mobile menu 317 ///////////////////////// 318 $.fn.chariti_mobile_menu = function( args ){ 319 320 var menu_button = $(this).siblings('.chariti-mm-menu-button'); 321 var options = { 322 navbar: { title: '<span class="mmenu-custom-close" ></span>' }, 323 extensions: [ 'pagedim-black' ], 324 325 }; 326 var extensions = { 327 offCanvas: { pageNodetype: '.chariti-body-outer-wrapper' } 328 }; 329 330 // remove the wrap for submenu 331 $(this).find('a[href="#"]').each(function(){ 332 var content = $(this).html(); 333 $('<span class="chariti-mm-menu-blank" ></span>').html(content).insertBefore($(this)); 334 $(this).remove(); 335 }); 336
337 if( $(this).attr('data-slide') ){ 338 var html_class = 'chariti-mmenu-' + $(this).attr('data-slide'); 339 $('html').addClass(html_class); 340 341 options.offCanvas = { position : $(this).attr('data-slide') }; 342 } 343 344 $(this).mmenu(options, extensions); 345 346 var menu_api = $(this).data('mmenu'); 347 $(this).find('a').not('.mm-next, .mm-prev').on('click', function(){ 348 menu_api.close(); 349 }); 350 $(this).find('.mmenu-custom-close').on('click', function(){ 351 menu_api.close(); 352 }); 353 $(window).resize(function(){ 354 menu_api.close(); 355 }); 356 357 // add class active to button 358 menu_api.bind('open', function($panel){ 359 menu_button.addClass('chariti-active'); 360 }); 361 menu_api.bind('close', function($panel){ 362 menu_button.removeClass('chariti-active'); 363 }); 364 365 } 366 367 ///////////////////////// 368 // overlay menu 369 ///////////////////////// 370 var chariti_overlay_menu = function( menu ){ 371 372 this.menu = menu; 373 this.menu_button = menu.children('.chariti-overlay-menu-icon'); 374 this.menu_content = menu.children('.chariti-overlay-menu-content'); 375 this.menu_close = this.menu_content.children('.chariti-overlay-menu-close'); 376 377 this.init(); 378 } 379 chariti_overlay_menu.prototype = { 380 381 init: function(){ 382 383 var t = this; 384 385 // add transition delay for each menu 386 var delay_count = 0; 387 t.menu_content.appendTo('body'); 388 t.menu_content.find('ul.menu > li').each(function(){ 389 $(this).css('transition-delay', (delay_count * 150) + 'ms'); 390 391 delay_count++; 392 }); 393 394 // bind the menu button 395 t.menu_button.on('click', function(){ 396 $(this).addClass('chariti-active'); 397 398 t.menu_content.fadeIn(200, function(){ 399 $(this).addClass('chariti-active'); 400 }); 401 402 return false; 403 }); 404 405 // bind the menu close button 406 t.menu_close.on('click', function(){ 407 t.menu_button.removeClass('chariti-active'); 408 409 t.menu_content.fadeOut(400, function(){ 410 $(this).removeClass('chariti-active'); 411 }); 412 t.menu_content.find('.sub-menu').slideUp(200).removeClass('chariti-active'); 413 414 return false; 415 }); 416 417 // menu item click 418 t.menu_content.find('a').on('click', function(e){ 419 var sub_menu = $(this).siblings('.sub-menu'); 420 if( sub_menu.length > 0 ){ 421 if( !sub_menu.hasClass('chariti-active') ){ 422 var prev_active = sub_menu.closest('li').siblings().find('.sub-menu.chariti-active'); 423 if( prev_active.length > 0 ){ 424 prev_active.removeClass('chariti-active').slideUp(150); 425 sub_menu.delay(150).slideDown(400, 'easeOutQuart').addClass('chariti-active'); 426 }else{ 427 sub_menu.slideDown(400, 'easeOutQuart').addClass('chariti-active'); 428 } 429 430 $(this).addClass('chariti-no-preload'); 431 return false; 432 }else{ 433 $(this).removeClass('chariti-no-preload'); 434 } 435 }else{ 436 t.menu_close.trigger('click'); 437 } 438 }); 439 440 } 441 442 }; // chariti_overlay_menu.prototype 443 444 ///////////////////////// 445 // header side navigation 446 ///////////////////////// 447 var chariti_header_side_nav = function( side_nav ){ 448 449 if( side_nav.length == 0 ) return; 450 451 this.prev_scroll = 0; 452 453 this.side_nav = side_nav; 454 this.side_nav_content = side_nav.children(); 455 456 this.init(); 457 458 } // chariti_header_side_nav 459 460 chariti_header_side_nav.prototype = { 461 462 init: function(){ 463 464 var t = this; 465 466 t.init_nav_bar_element(); 467 468 $(window).resize(function(){ 469 t.init_nav_bar_element(); 470 }); 471 472 $(window).scroll(function(){ 473 474 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 475 476 // if content longer than screen height 477 if( t.side_nav.hasClass('chariti-allow-slide') ){ 478 479 var admin_bar_height = parseInt($('html').css('margin-top')); 480 var scroll_down = ($(window).scrollTop() > t.prev_scroll); 481 t.prev_scroll = $(window).scrollTop(); 482 483 // if scroll down 484 if( scroll_down ){ 485 486 if( !t.side_nav.hasClass('chariti-fix-bottom') ){ 487 if( t.side_nav.hasClass('chariti-fix-top') ){ 488 t.side_nav.css('top', t.side_nav.offset().top); 489 t.side_nav.removeClass('chariti-fix-top'); 490 491 }else if( $(window).height() + $(window).scrollTop() > t.side_nav_content.offset().top + t.side_nav_content.outerHeight() ){ 492 if( !t.side_nav.hasClass('chariti-fix-bottom') ){ 493 t.side_nav.addClass('chariti-fix-bottom'); 494 t.side_nav.css('top', ''); 495 } 496 } 497 } 498 499 // if scroll up 500 }else{ 501 502 if( !t.side_nav.hasClass('chariti-fix-top') ){ 503 if( t.side_nav.hasClass('chariti-fix-bottom') ){ 504 var top_pos = $(window).scrollTop() + ($(window).height() - admin_bar_height) - t.side_nav_content.outerHeight(); 505 t.side_nav.css('top', top_pos); 506 t.side_nav.removeClass('chariti-fix-bottom'); 507 508 }else if( $(window).scrollTop() + admin_bar_height < t.side_nav_content.offset().top ){ 509 if( !t.side_nav.hasClass('chariti-fix-top') ){ 510 t.side_nav.addClass('chariti-fix-top'); 511 t.side_nav.css('top', ''); 512 } 513 } 514 } 515 516 } 517 518 } 519 }); 520 521 }, 522 523 init_nav_bar_element: function(){ 524 525 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 526 527 var t = this; 528 var middle_pos = t.side_nav_content.children('.chariti-pos-middle').addClass('chariti-active'); 529 var bottom_pos = t.side_nav_content.children('.chariti-pos-bottom').addClass('chariti-active'); 530 531 // remove all additional space 532 t.side_nav_content.children('.chariti-pre-spaces').remove(); 533 534 // add class depends on the screen size/content 535 if( $(window).height() < t.side_nav_content.height() ){ 536 t.side_nav.addClass('chariti-allow-slide'); 537 }else{
538 t.side_nav.removeClass('chariti-allow-slide chariti-fix-top chariti-fix-bottom').css('top', ''); 539 540 // set the middle position 541 if( t.side_nav.hasClass('chariti-style-middle') ){ 542 middle_pos.each(function(){ 543 var top_padding = parseInt($(this).css('padding-top')); 544 var prespace = ((t.side_nav.height() - (t.side_nav_content.height() - top_padding)) / 2) - top_padding; 545 546 if( prespace > 0 ){ 547 $('<div class="chariti-pre-spaces" ></div>').css('height', prespace).insertBefore($(this)); 548 } 549 }); 550 } 551 552 // set the bottom position 553 bottom_pos.each(function(){ 554 var prespace = t.side_nav.height() - t.side_nav_content.height(); 555 556 if( prespace > 0 ){ 557 $('<div class="chariti-pre-spaces" ></div>').css('height', prespace).insertBefore($(this)); 558 } 559 }); 560 561 } 562 } 563 564 }; // chariti_sf_menu.prototype 565 566 ///////////////////////// 567 // anchoring 568 ///////////////////////// 569 570 var chariti_anchor = function(){ 571 572 this.anchor_link = $('a[href*="#"]').not('[href="#"]').filter(function(){ 573 574 // for mm-menu plugin 575 if( $(this).is('.chariti-mm-menu-button, .mm-next, .mm-prev, .mm-title, .gdlr-core-ilightbox') ){ 576 return false; 577 } 578 579 // for additional plugins 580 if( $(this).is('.fbx-btn-transition') ){ 581 return false; 582 } 583 584 // for woocommerce 585 if( $(this).parent('.description_tab, .reviews_tab').length || $(this).not('[class^="chariti"]').closest('.woocommerce').length ){ 586 if( !$(this).closest('.menu-item').length ){ 587 return false; 588 } 589 } 590 591 return true; 592 }); 593 594 if( this.anchor_link.length ){ 595 this.menu_anchor = $('#chariti-main-menu, #chariti-bullet-anchor, #frmaster-content-navigation-item-outer'); 596 this.home_anchor = this.menu_anchor.find('ul.sf-menu > li.current-menu-item > a, ul.sf-menu > li.current-menu-ancestor > a, .chariti-bullet-anchor-link.current-menu-item, .frmaster-content-navigation-tab.frmaster-active'); 597 this.init(); 598 } 599 } 600 chariti_anchor.prototype = { 601 602 init: function(){ 603 604 var t = this; 605 606 t.animate_anchor(); 607 t.scroll_section(); 608 609 // init bullet anchor height 610 t.menu_anchor.filter('#chariti-bullet-anchor').each(function(){ 611 $(this).css('margin-top', - t.menu_anchor.height() / 2).addClass('chariti-init'); 612 }); 613 614 // initialize if the page hash exists 615 // wait for all element to initialize ( eg. flexslider ) 616 var url_hash = window.location.hash; 617 if( url_hash ){ 618 setTimeout(function(){ 619 620 var current_menu = t.menu_anchor.find('a[href*="' + url_hash + '"]'); 621 if( !current_menu.is('.current-menu-item, .current-menu-ancestor') ){ 622 current_menu.addClass('current-menu-item').siblings().removeClass('current-menu-item current-menu-ancestor'); 623 624 $(window).trigger('chariti-navigation-slider-bar-init'); 625 } 626 627 t.scroll_to(url_hash, false, 300); 628 }, 500); 629 } 630 631 }, 632 633 animate_anchor: function(){ 634 635 var t = this; 636 637 // home anchor 638 t.home_anchor.on('click', function(){ 639 640 if( window.location.href == this.href ){ 641 $('html, body').animate({ scrollTop: 0 }, { duration: 1500, easing: 'easeOutQuart' }); 642 return false; 643 } 644 645 }); 646 647 // normal anchor 648 t.anchor_link.on('click', function() { 649 if( location.hostname == this.hostname && location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') ){ 650 651 if( $(this).closest('#chariti-main-menu').length ){ 652 $(this).parent().addClass('current-menu-item').siblings().removeClass('current-menu-item'); 653 $(window).trigger('chariti-navigation-slider-bar-init'); 654 } 655 return t.scroll_to(this.hash, true); 656 } 657 }); 658 659 }, // animate anchor 660 661 scroll_to: function( hash, redirect, duration ){ 662 663 // start scrolling 664 if( hash == '#chariti-top-anchor' ){ 665 var scroll_position = 0; 666 }else{ 667 668 var target = $(hash); 669 670 if( target.length ){ 671 var scroll_position = target.offset().top; 672 } 673 } 674 675 if( typeof(scroll_position) != 'undefined' ){ 676 677 // offset for wordpress admin bar 678 scroll_position = scroll_position - parseInt($('html').css('margin-top')); 679 680 // offset for fixed nav bar 681 if( chariti_display == 'mobile-portrait' || chariti_display == 'mobile-landscape' ){ 682 scroll_position = scroll_position - 75; 683 }else if( typeof(window.chariti_anchor_offset) != 'undefined' && !isNaN(window.chariti_anchor_offset) ){ 684 scroll_position = scroll_position - parseInt(window.chariti_anchor_offset); 685 } 686 687 if( scroll_position < 0 ) scroll_position = 0; 688 689 $('html').addClass('chariti-anchor-animated'); 690 $('html, body').animate({ scrollTop: scroll_position }, { duration: 1500, easing: 'easeOutQuart', queue: false, complete: function(){ 691 $('html').removeClass('chariti-anchor-animated'); 692 $(window).trigger('scroll'); 693 }}); 694 695 return false; 696 697 }else if( redirect ){ 698 699 window.location.href = $('body').attr('data-home-url') + hash; 700 701 return false; 702 } 703 704 }, // scroll to 705 706 scroll_section: function(){ 707 708 var t = this; 709 710 // have anchor in anchor menu 711 var menu_link_anchor = this.menu_anchor.find('a[href*="#"]').not('[href="#"]'); 712 if( !menu_link_anchor.length ){ return; } 713 714 // get anchor section 715 var home_anchor_section = $('#chariti-page-wrapper'); 716 var anchor_section = home_anchor_section.find('div[id], section[id]'); 717 if( !anchor_section.length ){ return; } 718 719 // add data for faster query 720 menu_link_anchor.each(function(){ 721 if( $(this).closest('.sub-menu').length == 0 && $(this.hash).length ){ 722 $(this).attr('data-anchor', this.hash); 723 } 724 }); 725 726 // check section on scroll event 727 $(window).scroll(function(){ 728 729 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 730 731 if( $('html').hasClass('chariti-anchor-animated') ){ 732 return; 733 } 734 735 if( t.home_anchor.length && $(window).scrollTop() <= home_anchor_section.offset().top ){ 736 737 t.home_anchor.each(function(){ 738 if( $(this).hasClass('frmaster-content-navigation-tab') ){ 739 $(this).addClass('frmaster-active').siblings().removeClass('frmaster-active'); 740 }else if( $(this).hasClass('chariti-bullet-anchor-link') ){ 741 $(this).addClass('current-menu-item').siblings().removeClass('current-menu-item'); 742 $(this).parent('.chariti-bullet-anchor').attr('data-anchor-section', 'chariti-home'); 743 }else if( !$(this).parent('.current-menu-item, .current-menu-ancestor').length ){ 744 $(this).parent().addClass('current-menu-item').siblings().removeClass('current-menu-item current-menu-ancestor');
745 $(window).trigger('chariti-navigation-slider-bar-init'); 746 } 747 }); 748 749 }else{ 750 var section_position = $(window).scrollTop() + ($(window).height() / 2); 751 752 anchor_section.each(function(){ 753 if( $(this).css('display') == 'none' || $(this).closest('.frmaster-tour-booking-bar-wrap').length || $(this).is('#frmaster-page-wrapper') ) return; 754 755 var top_offset_pos = $(this).offset().top; 756 757 if( (section_position > top_offset_pos) && (section_position < top_offset_pos + $(this).outerHeight()) ){ 758 var section_id = $(this).attr('id'); 759 menu_link_anchor.filter('[data-anchor="#' + section_id + '"]').each(function(){ 760 if( $(this).hasClass('frmaster-content-navigation-tab') ){ 761 $(this).addClass('frmaster-active').siblings().removeClass('frmaster-active'); 762 $(this).closest('#frmaster-content-navigation-item-outer').trigger('frmaster-change'); 763 }else if( $(this).hasClass('chariti-bullet-anchor-link') ){ 764 $(this).addClass('current-menu-item').siblings().removeClass('current-menu-item'); 765 $(this).parent('.chariti-bullet-anchor').attr('data-anchor-section', section_id); 766 }else if( $(this).parent('li.menu-item').length && !$(this).parent('li.menu-item').is('.current-menu-item, .current-menu-ancestor') ){ 767 $(this).parent('li.menu-item').addClass('current-menu-item').siblings().removeClass('current-menu-item current-menu-ancestor'); 768 $(window).trigger('chariti-navigation-slider-bar-init'); 769 } 770 }); 771 772 return false; 773 } 774 775 }); 776 } 777 778 }); 779 780 } // scroll section 781 782 }; 783 784 var chariti_sticky_navigation = function(){ 785 786 var t = this; 787 788 // get navigation 789 t.sticky_nav = $('.chariti-with-sticky-navigation .chariti-sticky-navigation'); 790 t.mobile_menu = $('#chariti-mobile-header'); 791 792 // set the anchor offset 793 if( t.sticky_nav.hasClass('chariti-sticky-navigation-height') ){ 794 window.chariti_anchor_offset = t.sticky_nav.outerHeight(); 795 $(window).resize(function(){ 796 window.chariti_anchor_offset = t.sticky_nav.outerHeight(); 797 }); 798 }else if( t.sticky_nav.attr('data-navigation-offset') ){ 799 window.chariti_anchor_offset = parseInt(t.sticky_nav.attr('data-navigation-offset')); 800 }else if( t.sticky_nav.length ){ 801 window.chariti_anchor_offset = 75; 802 } 803 804 // init the sticky navigation 805 if( t.sticky_nav.length ){ 806 t.init(); 807 } 808 809 if( t.mobile_menu.hasClass('chariti-sticky-mobile-navigation') ){ 810 t.style_mobile_slide(); 811 $(window).trigger('chariti-set-sticky-mobile-navigation'); 812 } 813 814 } 815 chariti_sticky_navigation.prototype = { 816 817 init: function(){ 818 819 var t = this; 820 821 if( t.sticky_nav.hasClass('chariti-style-fixed') ){ 822 t.style_fixed(); 823 }else if( t.sticky_nav.hasClass('chariti-style-slide') ){ 824 t.style_slide(); 825 } 826 827 $(window).trigger('chariti-set-sticky-navigation'); 828 }, 829 830 style_fixed: function(){ 831 832 var t = this; 833 var placeholder = $('<div class="chariti-sticky-menu-placeholder" ></div>'); 834 835 $(window).on('scroll chariti-set-sticky-navigation', function(){ 836 837 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ) return; 838 839 var page_offset = parseInt($('html').css('margin-top')); 840 841 if( !t.sticky_nav.hasClass('chariti-fixed-navigation') ){ 842 843 if( $(window).scrollTop() + page_offset > t.sticky_nav.offset().top ){ 844 if( !t.sticky_nav.hasClass('chariti-without-placeholder') ){ 845 placeholder.height(t.sticky_nav.outerHeight()); 846 } 847 placeholder.insertAfter(t.sticky_nav); 848 $('body').append(t.sticky_nav); 849 t.sticky_nav.addClass('chariti-fixed-navigation'); 850 851 setTimeout(function(){ t.sticky_nav.addClass('chariti-animate-fixed-navigation'); }, 10); 852 setTimeout(function(){ 853 t.sticky_nav.css('height', ''); 854 $(window).trigger('chariti-navigation-slider-bar-animate'); 855 }, 200); 856 } 857 }else{ 858 859 if( $(window).scrollTop() + page_offset <= placeholder.offset().top ){ 860 if( !t.sticky_nav.hasClass('chariti-without-placeholder') ){ 861 t.sticky_nav.height(placeholder.height()); 862 } 863 t.sticky_nav.insertBefore(placeholder); 864 t.sticky_nav.removeClass('chariti-fixed-navigation'); 865 placeholder.remove(); 866 867 setTimeout(function(){ t.sticky_nav.removeClass('chariti-animate-fixed-navigation'); }, 10); 868 setTimeout(function(){ 869 t.sticky_nav.css('height', '');
870 $(window).trigger('chariti-navigation-slider-bar-animate'); 871 }, 200); 872 } 873 } 874 }); 875 876 }, // style_fixed 877 878 style_slide: function(){ 879 880 var t = this; 881 var placeholder = $('<div class="chariti-sticky-menu-placeholder" ></div>'); 882 883 $(window).on('scroll chariti-set-sticky-navigation', function(){ 884 885 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ){ return; } 886 887 var page_offset = parseInt($('html').css('margin-top')); 888 889 if( !t.sticky_nav.hasClass('chariti-fixed-navigation') ){ 890 891 if( $(window).scrollTop() + page_offset > t.sticky_nav.offset().top + t.sticky_nav.outerHeight() + 200 ){ 892 893 if( !t.sticky_nav.hasClass('chariti-without-placeholder') ){ 894 placeholder.height(t.sticky_nav.outerHeight()); 895 } 896 placeholder.insertAfter(t.sticky_nav); 897 t.sticky_nav.css('display', 'none'); 898 899 $('body').append(t.sticky_nav); 900 t.sticky_nav.addClass('chariti-fixed-navigation chariti-animate-fixed-navigation'); 901 t.sticky_nav.slideDown(200); 902 $(window).trigger('chariti-navigation-slider-bar-animate'); 903 } 904 }else{ 905 906 if( $(window).scrollTop() + page_offset <= placeholder.offset().top + placeholder.height() + 200 ){ 907 var clone = t.sticky_nav.clone(); 908 clone.insertAfter(t.sticky_nav); 909 clone.slideUp(200, function(){ $(this).remove(); }); 910 911 t.sticky_nav.insertBefore(placeholder); 912 placeholder.remove(); 913 t.sticky_nav.removeClass('chariti-fixed-navigation chariti-animate-fixed-navigation'); 914 t.sticky_nav.css('display', 'block'); 915 916 $(window).trigger('chariti-navigation-slider-bar-animate'); 917 } 918 } 919 }); 920 921 }, // style_slide 922 923 style_mobile_slide: function(){ 924 925 var t = this; 926 var placeholder = $('<div class="chariti-sticky-mobile-placeholder" ></div>'); 927 928 $(window).on('scroll chariti-set-sticky-mobile-navigation', function(){ 929 930 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' || chariti_display == 'tablet' ){ 931 932 var page_offset = parseInt($('html').css('margin-top')); 933 934 if( !t.mobile_menu.hasClass('chariti-fixed-navigation') ){ 935 if( $(window).scrollTop() + page_offset > t.mobile_menu.offset().top + t.mobile_menu.outerHeight() + 200 ){ 936 placeholder.height(t.mobile_menu.outerHeight()).insertAfter(t.mobile_menu); 937 $('body').append(t.mobile_menu); 938 t.mobile_menu.addClass('chariti-fixed-navigation'); 939 t.mobile_menu.css('display', 'none').slideDown(200); 940 } 941 }else{ 942 if( $(window).scrollTop() + page_offset <= placeholder.offset().top + placeholder.height() + 200 ){ 943 var clone = t.mobile_menu.clone(); 944 clone.insertAfter(t.mobile_menu); 945 clone.slideUp(200, function(){ $(this).remove(); }); 946 947 t.mobile_menu.insertBefore(placeholder); 948 placeholder.remove(); 949 t.mobile_menu.removeClass('chariti-fixed-navigation'); 950 t.mobile_menu.css('display', 'block'); 951 } 952 } 953 } 954 955 }); 956 957 }, // style_slide 958 959 }; 960 961 var chariti_font_resize = function(){ 962 963 this.heading_font = $('h1, h2, h3, h4, h5, h6'); 964 965 this.init(); 966 967 } 968 chariti_font_resize.prototype = { 969 970 init: function(){ 971 972 var t = this; 973 974 t.resize(); 975 $(window).on('resize', chariti_throttling(function(){ 976 t.resize(); 977 }, 100)); 978 979 }, 980 981 resize: function(){ 982 983 var t = this; 984 985 if( chariti_display == 'mobile-landscape' || chariti_display == 'mobile-portrait' ){ 986 987 t.heading_font.each(function(){ 988 if( parseInt($(this).css('font-size')) > 40 ){ 989 if( !$(this).attr('data-orig-font') ){ 990 $(this).attr('data-orig-font', $(this).css('font-size')); 991 } 992 993 $(this).css('font-size', '40px'); 994 } 995 }); 996 997 // return font to normal 998 }else{ 999 1000 t.heading_font.filter('[data-orig-font]').each(function(){ 1001 $(this).css('font-size', $(this).attr('data-orig-font')); 1002 }); 1003 1004 } 1005 } 1006 1007 }; 1008 1009 // frmaster lightbox 1010 function chariti_lightbox( content ){ 1011 1012 var lightbox_wrap = $('<div class="chariti-lightbox-wrapper" ></div>').hide(); 1013 var lightbox_content_wrap = $('<div class="chariti-lightbox-content-cell" ></div>'); 1014 lightbox_wrap.append(lightbox_content_wrap); 1015 lightbox_content_wrap.wrap($('<div class="chariti-lightbox-content-row" ></div>')); 1016 1017 lightbox_content_wrap.append(content); 1018 1019 var scrollPos = $(window).scrollTop(); 1020 $('html').addClass('chariti-lightbox-on'); 1021 $('body').append(lightbox_wrap); 1022 lightbox_wrap.fadeIn(300); 1023 1024 // do a lightbox action 1025 lightbox_wrap.on('click', '.chariti-lightbox-close', function(){ 1026 $('html').removeClass('chariti-lightbox-on'); 1027 $(window).scrollTop(scrollPos); 1028 lightbox_wrap.fadeOut(300, function(){ 1029 $(this).remove(); 1030 }); 1031 }); 1032 1033 } // chariti_lightbox 1034 1035 //////////////////////////////// 1036 // starting running the script 1037 //////////////////////////////// 1038 $(document).ready(function(){ 1039 1040 // resize font on mobile 1041 new chariti_font_resize(); 1042 1043 // init main navigation menu 1044 $('#chariti-main-menu, #chariti-right-menu, #chariti-mobile-menu, #chariti-top-bar-menu').each(function(){ 1045 if( $(this).hasClass('chariti-overlay-menu') ){ 1046 new chariti_overlay_menu( $(this) ); 1047 }else if( $(this).hasClass('chariti-mm-menu-wrap') ){ 1048 $(this).chariti_mobile_menu(); 1049 }else{ 1050 new chariti_sf_menu( $(this) ); 1051 } 1052 }); 1053 1054 $('#chariti-top-search, #chariti-mobile-top-search').each(function(){ 1055 1056 var search_wrap = $(this).siblings('.chariti-top-search-wrap'); 1057 search_wrap.appendTo('body'); 1058
1059 // bind click button 1060 $(this).on('click', function(){ 1061 search_wrap.fadeIn(200, function(){ 1062 $(this).addClass('chariti-active'); 1063 }); 1064 }); 1065 1066 // bind close button 1067 search_wrap.find('.chariti-top-search-close').on('click', function(){ 1068 search_wrap.fadeOut(200, function(){ 1069 $(this).addClass('chariti-active'); 1070 }); 1071 }); 1072 1073 // bind search button 1074 search_wrap.find('.search-submit').on('click', function(){ 1075 if( search_wrap.find('.search-field').val().length == 0 ){ 1076 return false; 1077 } 1078 }); 1079 }); 1080 1081 $('#chariti-main-menu-cart, #chariti-mobile-menu-cart').each(function(){ 1082 1083 $(this).on({ 1084 mouseenter: function(){ 1085 $(this).addClass('chariti-active chariti-animating'); 1086 }, 1087 mouseleave: function(){ 1088 var menu_cart = $(this); 1089 menu_cart.removeClass('chariti-active'); 1090 setTimeout(function(){ 1091 menu_cart.removeClass('chariti-animating'); 1092 }, 400) 1093 } 1094 }); 1095 }); 1096 1097 // woocommerce top bar cart 1098 $('body').on('added_to_cart', function(){ 1099 $.ajax({ 1100 type: 'POST', 1101 url: wc_add_to_cart_params.ajax_url, 1102 data: { 'action': 'top_bar_woocommerce_cart' }, 1103 dataType: 'json', 1104 error: function(jqXHR, textStatus, errorThrown){ 1105 console.log(jqXHR, textStatus, errorThrown); 1106 }, 1107 success: function(data){ 1108 if( typeof(data['title']) != 'undefined' ){ 1109 $('.chariti-top-cart-title').replaceWith(data['title']); 1110 } 1111 if( typeof(data['cart-items']) != 'undefined' ){ 1112 $('.chariti-top-cart-item-wrap').replaceWith(data['cart-items']); 1113 } 1114 } 1115 }); 1116 }); 1117 1118 // chariti 1119 $('#chariti-dropdown-chariti-flag').hover(function(){ 1120 $(this).children('.chariti-dropdown-chariti-list').fadeIn(200); 1121 }, function(){ 1122 $(this).children('.chariti-dropdown-chariti-list').fadeOut(200); 1123 }); 1124 1125 // additional space for header transparent 1126 $('.chariti-header-boxed-wrap, .chariti-header-background-transparent, .chariti-navigation-bar-wrap.chariti-style-transparent').each(function(){ 1127 var header_transparent = $(this); 1128 var header_transparent_sub = $('.chariti-header-transparent-substitute'); 1129 1130 header_transparent_sub.height(header_transparent.outerHeight()); 1131 $(window).on('load resize', function(){ 1132 header_transparent_sub.height(header_transparent.outerHeight()); 1133 }); 1134 }); 1135 1136 // full screen for 404 not found 1137 $('body.error404, body.search-no-results').each(function(){ 1138 1139 var wrap = $(this).find('#chariti-full-no-header-wrap'); 1140 var body_wrap_offset = parseInt($(this).children('.chariti-body-outer-wrapper').children('.chariti-body-wrapper').css('margin-bottom')); 1141 1142 var padding = ($(window).height() - wrap.offset().top - wrap.outerHeight() - body_wrap_offset) / 2; 1143 if( padding > 0 ){ 1144 wrap.css({ 'padding-top': padding, 'padding-bottom': padding }); 1145 } 1146 1147 $(window).on('load resize', function(){ 1148 wrap.css({ 'padding-top': 0, 'padding-bottom': 0 }); 1149 padding = ($(window).height() - wrap.offset().top - wrap.outerHeight() - body_wrap_offset) / 2; 1150 if( padding > 0 ){ 1151 wrap.css({ 'padding-top': padding, 'padding-bottom': padding }); 1152 } 1153 }); 1154 }); 1155 1156 // back to top button 1157 var back_to_top = $('#chariti-footer-back-to-top-button'); 1158 if( back_to_top.length ){ 1159 $(window).on('scroll', function(){ 1160 if( $(window).scrollTop() > 300 ){ 1161 back_to_top.addClass('chariti-scrolled'); 1162 }else{ 1163 back_to_top.removeClass('chariti-scrolled'); 1164 } 1165 }); 1166 } 1167 1168 // page preload 1169 $('body').children('#chariti-page-preload').each(function(){ 1170 var page_preload = $(this); 1171 var animation_time = parseInt(page_preload.attr('data-animation-time')); 1172 1173 $('a[href]').not('[href^="#"], [target="_blank"], .gdlr-core-js, .strip, .sf-with-ul, .remove, .ajax_add_to_cart').on('click', function(e){ 1174 if( e.which != 1 || $(this).hasClass('chariti-no-preload') || e.ctrlKey ) return; 1175 1176 if( window.location.href != this.href ){ 1177 page_preload.addClass('chariti-out').fadeIn(animation_time); 1178 } 1179 }); 1180 1181 $(window).load(function(){ 1182 page_preload.fadeOut(animation_time); 1183 }); 1184 }); 1185 1186 // single nav style 2 sync height 1187 $('body.chariti-blog-style-2 .chariti-single-nav-area').each(function(){ 1188 var max_height; 1189 var single_nav_2 = $(this).children();
1190 1191 max_height = 0; 1192 single_nav_2.css('min-height', '0px'); 1193 single_nav_2.each(function(){ 1194 if( max_height < $(this).outerHeight() ){ 1195 max_height = $(this).outerHeight(); 1196 } 1197 }); 1198 single_nav_2.css('min-height', max_height); 1199 1200 $(window).resize(function(){ 1201 max_height = 0; 1202 single_nav_2.css('min-height', '0px'); 1203 single_nav_2.each(function(){ 1204 if( max_height < $(this).outerHeight() ){ 1205 max_height = $(this).outerHeight(); 1206 } 1207 }); 1208 single_nav_2.css('min-height', max_height); 1209 }); 1210 }); 1211 1212 // lightbox popup 1213 $('[data-chariti-lb]').click(function(){ 1214 var lb_content = $(this).siblings('[data-chariti-lb-id="' + $(this).attr('data-chariti-lb') + '"]'); 1215 chariti_lightbox(lb_content.clone()); 1216 }); 1217 1218 }); 1219 1220 // fix back button for preload 1221 $(window).on('pageshow', function(event) { 1222 if( event.originalEvent.persisted ){ 1223 $('body').children('#chariti-page-preload').each(function(){ 1224 $(this).fadeOut(400); 1225 }); 1226 } 1227 }); 1228 1229 $(window).load(function(){ 1230
1231 // fixed footer 1232 $('#chariti-fixed-footer').each(function(){ 1233 var fixed_footer = $(this); 1234 var placeholder = $('<div class="chariti-fixed-footer-placeholder" ></div>'); 1235 1236 placeholder.insertBefore(fixed_footer); 1237 placeholder.height(fixed_footer.outerHeight()); 1238 $('body').css('min-height', $(window).height() - parseInt($('html').css('margin-top'))); // for safari 1239 $(window).resize(function(){ 1240 placeholder.height(fixed_footer.outerHeight()); 1241 $('body').css('min-height', $(window).height() - parseInt($('html').css('margin-top'))); 1242 }); 1243 }); 1244 1245 // side navigation bar 1246 new chariti_header_side_nav( $('#chariti-header-side-nav') ); 1247 1248 // sticky navigation 1249 if( !$('body').is('.single-cause') ){ 1250 new chariti_sticky_navigation(); 1251 } 1252 1253 // anchoring 1254 new chariti_anchor(); 1255 1256 }); 1257 1258})(jQuery);
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.