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