Guest User

init js

a guest
Nov 28th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.32 KB | None | 0 0
  1. /* global jQuery:false */
  2. /* global NIOBE_STORAGE:false */
  3.  
  4. jQuery(document).ready(function() {
  5. "use strict";
  6.  
  7. var theme_init_counter = 0;
  8.  
  9. niobe_init_actions();
  10.  
  11. // Theme init actions
  12. function niobe_init_actions() {
  13.  
  14. if (NIOBE_STORAGE['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length==0 && theme_init_counter++ < 30) {
  15. setTimeout(niobe_init_actions, 200);
  16. return;
  17. }
  18.  
  19. // Check fullheight elements
  20. jQuery(document).on('action.init_hidden_elements', niobe_stretch_height);
  21. jQuery(document).on('action.init_shortcodes', niobe_stretch_height);
  22. jQuery(document).on('action.sc_layouts_row_fixed_off', niobe_stretch_height);
  23. jQuery(document).on('action.sc_layouts_row_fixed_on', niobe_stretch_height);
  24.  
  25. // Add resize on VC action vc-full-width-row
  26. // But we emulate 'action.resize_vc_row_start' and 'action.resize_vc_row_end'
  27. // to correct resize sliders and video inside 'boxed' pages
  28. var vc_resize = false;
  29. jQuery(document).on('action.resize_vc_row_start', function(e, el) {
  30. vc_resize = true;
  31. niobe_resize_actions(el);
  32. });
  33.  
  34. // Resize handlers
  35. jQuery(window).resize(function() {
  36. if (!vc_resize) {
  37. niobe_resize_actions();
  38. }
  39. });
  40.  
  41. // Scroll handlers
  42. jQuery(window).scroll(function() {
  43. niobe_scroll_actions();
  44. });
  45.  
  46. // First call to init core actions
  47. niobe_ready_actions();
  48. niobe_resize_actions();
  49. niobe_scroll_actions();
  50.  
  51. // Wait for logo load
  52. if (jQuery('body').hasClass('menu_style_side') && !niobe_check_images_complete(jQuery('.menu_side_wrap .sc_layouts_logo'))) {
  53. setTimeout(function() {
  54. niobe_stretch_sidemenu();
  55. }, 500);
  56. }
  57. // Hack for MailChimp - use our scroll to form, because his method damage layouts in the Chrome
  58. if (window.mc4wp_forms_config && window.mc4wp_forms_config.submitted_form && window.mc4wp_forms_config.submitted_form.element_id) {
  59. trx_addons_document_animate_to(window.mc4wp_forms_config.submitted_form.element_id);
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66. // Theme first load actions
  67. //==============================================
  68. function niobe_ready_actions() {
  69.  
  70. // Add scheme class and js support
  71. //------------------------------------
  72. document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/,'js');
  73. if (document.documentElement.className.indexOf(NIOBE_STORAGE['site_scheme'])==-1)
  74. document.documentElement.className += ' ' + NIOBE_STORAGE['site_scheme'];
  75.  
  76. // Init background video
  77. //------------------------------------
  78. // Use Bideo to play local video
  79. if (NIOBE_STORAGE['background_video'] && jQuery('.top_panel.with_bg_video').length > 0 && window.Bideo) {
  80. // Waiting 10ms after mejs init
  81. setTimeout(function() {
  82. jQuery('.top_panel.with_bg_video').prepend('<video id="background_video" loop muted></video>');
  83. var bv = new Bideo();
  84. bv.init({
  85. // Video element
  86. videoEl: document.querySelector('#background_video'),
  87.  
  88. // Container element
  89. container: document.querySelector('.top_panel'),
  90.  
  91. // Resize
  92. resize: true,
  93.  
  94. // autoplay: false,
  95.  
  96. isMobile: window.matchMedia('(max-width: 768px)').matches,
  97.  
  98. playButton: document.querySelector('#background_video_play'),
  99. pauseButton: document.querySelector('#background_video_pause'),
  100.  
  101. // Array of objects containing the src and type
  102. // of different video formats to add
  103. // For example:
  104. // src: [
  105. // { src: 'night.mp4', type: 'video/mp4' }
  106. // { src: 'night.webm', type: 'video/webm;codecs="vp8, vorbis"' }
  107. // ]
  108. src: [
  109. {
  110. src: NIOBE_STORAGE['background_video'],
  111. type: 'video/'+niobe_get_file_ext(NIOBE_STORAGE['background_video'])
  112. }
  113. ],
  114.  
  115. // What to do once video loads (initial frame)
  116. onLoad: function () {
  117. //document.querySelector('#background_video_cover').style.display = 'none';
  118. }
  119. });
  120. }, 10);
  121.  
  122. // Use Tubular to play video from Youtube
  123. } else if (jQuery.fn.tubular) {
  124. jQuery('div#background_video').each(function() {
  125. var youtube_code = jQuery(this).data('youtube-code');
  126. if (youtube_code) {
  127. jQuery(this).tubular({videoId: youtube_code});
  128. jQuery('#tubular-player').appendTo(jQuery(this)).show();
  129. jQuery('#tubular-container,#tubular-shield').remove();
  130. }
  131. });
  132. }
  133.  
  134. // Tabs
  135. //------------------------------------
  136. if (jQuery('.niobe_tabs:not(.inited)').length > 0 && jQuery.ui && jQuery.ui.tabs) {
  137. jQuery('.niobe_tabs:not(.inited)').each(function () {
  138. // Get initially opened tab
  139. var init = jQuery(this).data('active');
  140. if (isNaN(init)) {
  141. init = 0;
  142. var active = jQuery(this).find('> ul > li[data-active="true"]').eq(0);
  143. if (active.length > 0) {
  144. init = active.index();
  145. if (isNaN(init) || init < 0) init = 0;
  146. }
  147. } else {
  148. init = Math.max(0, init);
  149. }
  150. // Init tabs
  151. jQuery(this).addClass('inited').tabs({
  152. active: init,
  153. show: {
  154. effect: 'fadeIn',
  155. duration: 300
  156. },
  157. hide: {
  158. effect: 'fadeOut',
  159. duration: 300
  160. },
  161. create: function( event, ui ) {
  162. if (ui.panel.length > 0) jQuery(document).trigger('action.init_hidden_elements', [ui.panel]);
  163. },
  164. activate: function( event, ui ) {
  165. if (ui.newPanel.length > 0) jQuery(document).trigger('action.init_hidden_elements', [ui.newPanel]);
  166. }
  167. });
  168. });
  169. }
  170. // AJAX loader for the tabs
  171. jQuery('.niobe_tabs_ajax').on( "tabsbeforeactivate", function( event, ui ) {
  172. if (ui.newPanel.data('need-content')) niobe_tabs_ajax_content_loader(ui.newPanel, 1, ui.oldPanel);
  173. });
  174. // AJAX loader for the pages in the tabs
  175. jQuery('.niobe_tabs_ajax').on( "click", '.nav-links a', function(e) {
  176. var panel = jQuery(this).parents('.niobe_tabs_content');
  177. var page = 1;
  178. var href = jQuery(this).attr('href');
  179. var pos = -1;
  180. if ((pos = href.lastIndexOf('/page/')) != -1 ) {
  181. page = Number(href.substr(pos+6).replace("/", ""));
  182. if (!isNaN(page)) page = Math.max(1, page);
  183. }
  184. niobe_tabs_ajax_content_loader(panel, page);
  185. e.preventDefault();
  186. return false;
  187. });
  188.  
  189. // Menu
  190. //----------------------------------------------
  191.  
  192. // Add TOC in the side menu
  193. if (jQuery('.menu_side_inner').length > 0 && jQuery('#toc_menu').length > 0)
  194. jQuery('#toc_menu').appendTo('.menu_side_inner');
  195.  
  196. // Open/Close side menu
  197. jQuery('.menu_side_button').on('click', function(e){
  198. jQuery(this).parent().toggleClass('opened');
  199. e.preventDefault();
  200. return false;
  201. });
  202.  
  203. // Add images to the menu items with classes image-xxx
  204. jQuery('.sc_layouts_menu li[class*="image-"]').each(function() {
  205. var classes = jQuery(this).attr('class').split(' ');
  206. var icon = '';
  207. for (var i=0; i < classes.length; i++) {
  208. if (classes[i].indexOf('image-') >= 0) {
  209. icon = classes[i].replace('image-', '');
  210. break;
  211. }
  212. }
  213. if (icon) jQuery(this).find('>a').css('background-image', 'url('+NIOBE_STORAGE['theme_url']+'/trx_addons/css/icons.png/'+icon+'.png');
  214. });
  215.  
  216. // Add arrows to the mobile menu
  217. jQuery('.menu_mobile .menu-item-has-children > a').append('<span class="open_child_menu"></span>');
  218.  
  219. // Open/Close mobile menu
  220. jQuery('.sc_layouts_menu_mobile_button > a,.menu_mobile_button,.menu_mobile_description').on('click', function(e) {
  221. if (jQuery(this).parent().hasClass('sc_layouts_menu_mobile_button_burger') && jQuery(this).next().hasClass('sc_layouts_menu_popup')) return;
  222. jQuery('.menu_mobile_overlay').fadeIn();
  223. jQuery('.menu_mobile').addClass('opened');
  224. jQuery(document).trigger('action.stop_wheel_handlers');
  225. e.preventDefault();
  226. return false;
  227. });
  228. jQuery(document).on('keypress', function(e) {
  229. if (e.keyCode == 27) {
  230. if (jQuery('.menu_mobile.opened').length == 1) {
  231. jQuery('.menu_mobile_overlay').fadeOut();
  232. jQuery('.menu_mobile').removeClass('opened');
  233. jQuery(document).trigger('action.start_wheel_handlers');
  234. e.preventDefault();
  235. return false;
  236. }
  237. }
  238. });;
  239. jQuery('.menu_mobile_close, .menu_mobile_overlay').on('click', function(e){
  240. jQuery('.menu_mobile_overlay').fadeOut();
  241. jQuery('.menu_mobile').removeClass('opened');
  242. jQuery(document).trigger('action.start_wheel_handlers');
  243. e.preventDefault();
  244. return false;
  245. });
  246.  
  247. // Open/Close mobile submenu
  248. jQuery('.menu_mobile').on('click', 'li a, li a .open_child_menu', function(e) {
  249. var $a = jQuery(this).hasClass('open_child_menu') ? jQuery(this).parent() : jQuery(this);
  250. if ($a.parent().hasClass('menu-item-has-children')) {
  251. if ($a.attr('href')=='#' || jQuery(this).hasClass('open_child_menu')) {
  252. if ($a.siblings('ul:visible').length > 0)
  253. $a.siblings('ul').slideUp().parent().removeClass('opened');
  254. else {
  255. jQuery(this).parents('li').siblings('li').find('ul:visible').slideUp().parent().removeClass('opened');
  256. $a.siblings('ul').slideDown().parent().addClass('opened');
  257. }
  258. }
  259. }
  260. if (!jQuery(this).hasClass('open_child_menu') && niobe_is_local_link($a.attr('href')))
  261. jQuery('.menu_mobile_close').trigger('click');
  262. if (jQuery(this).hasClass('open_child_menu') || $a.attr('href')=='#') {
  263. e.preventDefault();
  264. return false;
  265. }
  266. });
  267.  
  268. if (!NIOBE_STORAGE['trx_addons_exist'] || jQuery('.top_panel.top_panel_default .sc_layouts_menu_default').length > 0) {
  269. // Init superfish menus
  270. niobe_init_sfmenu('.sc_layouts_menu:not(.inited) > ul:not(.inited)');
  271. // Show menu
  272. jQuery('.sc_layouts_menu:not(.inited)').each(function() {
  273. if (jQuery(this).find('>ul.inited').length == 1) jQuery(this).addClass('inited');
  274. });
  275. // Generate 'scroll' event after the menu is showed
  276. jQuery(window).trigger('scroll');
  277. }
  278.  
  279.  
  280. // Forms
  281. //----------------------------------------------
  282.  
  283. // Wrap select with .select_container
  284. jQuery('select:not(.esg-sorting-select):not([class*="trx_addons_attrib_"])').each(function() {
  285. var s = jQuery(this);
  286. if (s.css('display') != 'none'
  287. && !s.next().hasClass('select2')
  288. && !s.hasClass('select2-hidden-accessible'))
  289. s.wrap('<div class="select_container"></div>');
  290. });
  291.  
  292. // Comment form
  293. jQuery("form#commentform").submit(function(e) {
  294. var rez = niobe_comments_validate(jQuery(this));
  295. if (!rez)
  296. e.preventDefault();
  297. return rez;
  298. });
  299.  
  300. jQuery("form").on('keypress', '.error_field', function() {
  301. if (jQuery(this).val() != '')
  302. jQuery(this).removeClass('error_field');
  303. });
  304.  
  305.  
  306. // Blocks with stretch width
  307. //----------------------------------------------
  308. // Action to prepare stretch blocks in the third-party plugins
  309. jQuery(document).trigger('action.prepare_stretch_width');
  310. // Wrap stretch blocks
  311. jQuery('.trx-stretch-width').wrap('<div class="trx-stretch-width-wrap"></div>');
  312. jQuery('.trx-stretch-width').after('<div class="trx-stretch-width-original"></div>');
  313. niobe_stretch_width();
  314.  
  315.  
  316. // Pagination
  317. //------------------------------------
  318.  
  319. // Load more
  320. jQuery('.nav-links-more a').on('click', function(e) {
  321. if (NIOBE_STORAGE['load_more_link_busy']) return;
  322. NIOBE_STORAGE['load_more_link_busy'] = true;
  323. var more = jQuery(this);
  324. var page = Number(more.data('page'));
  325. var max_page = Number(more.data('max-page'));
  326. if (page >= max_page) {
  327. more.parent().hide();
  328. return;
  329. }
  330. more.parent().addClass('loading');
  331. var panel = more.parents('.niobe_tabs_content');
  332. if (panel.length == 0) { // Load simple page content
  333. jQuery.get(location.href, {
  334. paged: page+1
  335. }).done(function(response) {
  336. // Get inline styles and add to the page styles
  337. var selector = 'niobe-inline-styles-inline-css';
  338. var p1 = response.indexOf(selector);
  339. if (p1 < 0) {
  340. selector = 'trx_addons-inline-styles-inline-css';
  341. p1 = response.indexOf(selector);
  342. }
  343. if (p1 > 0) {
  344. p1 = response.indexOf('>', p1) + 1;
  345. var p2 = response.indexOf('</style>', p1);
  346. var inline_css_add = response.substring(p1, p2);
  347. var inline_css = jQuery('#'+selector);
  348. if (inline_css.length == 0)
  349. jQuery('body').append('<style id="'+selector+'" type="text/css">' + inline_css_add + '</style>');
  350. else
  351. inline_css.append(inline_css_add);
  352. }
  353. // Get new posts and append to the .posts_container
  354. niobe_loadmore_add_items(jQuery('.content .posts_container').eq(0),
  355. jQuery(response).find('.content .posts_container > article,'
  356. +'.content .posts_container > div[class*="column-"],'
  357. +'.content .posts_container > .masonry_item')
  358. );
  359. });
  360. } else { // Load tab's panel content
  361. jQuery.post(NIOBE_STORAGE['ajax_url'], {
  362. nonce: NIOBE_STORAGE['ajax_nonce'],
  363. action: 'niobe_ajax_get_posts',
  364. blog_template: panel.data('blog-template'),
  365. blog_style: panel.data('blog-style'),
  366. posts_per_page: panel.data('posts-per-page'),
  367. cat: panel.data('cat'),
  368. parent_cat: panel.data('parent-cat'),
  369. post_type: panel.data('post-type'),
  370. taxonomy: panel.data('taxonomy'),
  371. page: page+1
  372. }).done(function(response) {
  373. var rez = {};
  374. try {
  375. rez = JSON.parse(response);
  376. } catch (e) {
  377. rez = { error: NIOBE_STORAGE['strings']['ajax_error'] };
  378. console.log(response);
  379. }
  380. if (rez.error !== '') {
  381. panel.html('<div class="niobe_error">'+rez.error+'</div>');
  382. } else {
  383. niobe_loadmore_add_items(panel.find('.posts_container'), jQuery(rez.data).find('article'));
  384. }
  385. });
  386. }
  387. // Append items to the container
  388. function niobe_loadmore_add_items(container, items) {
  389. if (container.length > 0 && items.length > 0) {
  390. container.append(items);
  391. if (container.hasClass('portfolio_wrap') || container.hasClass('masonry_wrap')) {
  392. container.masonry( 'appended', items ).masonry();
  393. if (container.hasClass('gallery_wrap')) {
  394. NIOBE_STORAGE['GalleryFx'][container.attr('id')].appendItems();
  395. }
  396. }
  397. more.data('page', page+1).parent().removeClass('loading');
  398. // Remove TOC if exists (rebuild on init_shortcodes)
  399. jQuery('#toc_menu').remove();
  400. // Trigger actions to init new elements
  401. NIOBE_STORAGE['init_all_mediaelements'] = true;
  402. jQuery(document).trigger('action.init_shortcodes', [container.parent()]);
  403. jQuery(document).trigger('action.init_hidden_elements', [container.parent()]);
  404. }
  405. if (page+1 >= max_page)
  406. more.parent().hide();
  407. else
  408. NIOBE_STORAGE['load_more_link_busy'] = false;
  409. // Fire 'window.scroll' after clearing busy state
  410. jQuery(window).trigger('scroll');
  411. }
  412. e.preventDefault();
  413. return false;
  414. });
  415.  
  416.  
  417. // Checkbox with "I agree..."
  418. if (jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited),#wpmtst-form input[type="checkbox"]:not(.inited),input[type="checkbox"][name="AGREE_TO_TERMS"]:not(.inited)').length > 0) {
  419. jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited),#wpmtst-form input[type="checkbox"]:not(.inited),input[type="checkbox"][name="AGREE_TO_TERMS"]:not(.inited)')
  420. .addClass('inited')
  421. .on('change', function(e) {
  422. if (jQuery(this).get(0).checked)
  423. jQuery(this).parents('form').find('button,input[type="submit"]').removeAttr('disabled');
  424. else
  425. jQuery(this).parents('form').find('button,input[type="submit"]').attr('disabled', 'disabled');
  426. }).trigger('change');
  427. }
  428.  
  429. // CF7 checkboxes - add class to correct check/uncheck pseudoelement when input at right side of the label
  430. jQuery( '.wpcf7-checkbox > .wpcf7-list-item > .wpcf7-list-item-label,.wpcf7-radio > .wpcf7-list-item > .wpcf7-list-item-label,.wpcf7-wpgdprc > .wpcf7-list-item > .wpcf7-list-item-label' ).on(
  431. 'click', function() {
  432. var chk = jQuery( this ).siblings( 'input[type="checkbox"],input[type="radio"]' );
  433. if (chk.attr( 'type' ) == 'radio') {
  434. jQuery( this ).parents( '.wpcf7-radio' )
  435. .find( '.wpcf7-list-item-label' ).removeClass( 'wpcf7-list-item-checked' )
  436. .find( 'input[type="radio"]' ).each(
  437. function(){
  438. this.checked = false;
  439. }
  440. );
  441. }
  442. if (chk.length > 0) {
  443. chk.get( 0 ).checked = chk.get( 0 ).checked ? false : true;
  444. jQuery( this ).toggleClass( 'wpcf7-list-item-checked', chk.get( 0 ).checked );
  445. chk.trigger('change');
  446. }
  447. }
  448. );
  449.  
  450. // Infinite scroll
  451. jQuery(document).on('action.scroll_niobe', function(e) {
  452. if (NIOBE_STORAGE['load_more_link_busy']) return;
  453. var container = jQuery('.content > .posts_container').eq(0);
  454. var inf = jQuery('.nav-links-infinite');
  455. if (inf.length == 0) return;
  456. if (container.offset().top + container.height() < jQuery(window).scrollTop() + jQuery(window).height()*1.5)
  457. inf.find('a').trigger('click');
  458. });
  459.  
  460.  
  461. // Other settings
  462. //------------------------------------
  463.  
  464. jQuery(document).trigger('action.ready_niobe');
  465.  
  466. // Init post format specific scripts
  467. jQuery(document).on('action.init_hidden_elements', niobe_init_post_formats);
  468.  
  469. // Init hidden elements (if exists)
  470. jQuery(document).trigger('action.init_hidden_elements', [jQuery('body').eq(0)]);
  471.  
  472. } //end ready
  473.  
  474.  
  475.  
  476.  
  477. // Scroll actions
  478. //==============================================
  479.  
  480. // Do actions when page scrolled
  481. function niobe_scroll_actions() {
  482.  
  483. var scroll_offset = jQuery(window).scrollTop();
  484. var adminbar_height = Math.max(0, jQuery('#wpadminbar').height());
  485.  
  486. // Call theme/plugins specific action (if exists)
  487. //----------------------------------------------
  488. jQuery(document).trigger('action.scroll_niobe');
  489.  
  490. // Fix/unfix sidebar
  491. // niobe_fix_sidebar();
  492.  
  493. // Shift top and footer panels when header position equal to 'Under content'
  494. if (jQuery('body').hasClass('header_position_under') && !niobe_browser_is_mobile()) {
  495. var delta = 50;
  496. var adminbar = jQuery('#wpadminbar');
  497. var adminbar_height = adminbar.length == 0 && adminbar.css('position') == 'fixed' ? 0 : adminbar.height();
  498. var header = jQuery('.top_panel');
  499. var header_height = header.height();
  500. var mask = header.find('.top_panel_mask');
  501. if (mask.length==0) {
  502. header.append('<div class="top_panel_mask"></div>');
  503. mask = header.find('.top_panel_mask');
  504. }
  505. if (scroll_offset > adminbar_height) {
  506. var offset = scroll_offset - adminbar_height;
  507. if (offset <= header_height) {
  508. var mask_opacity = Math.max(0, Math.min(0.8, (offset-delta)/header_height));
  509. // Don't shift header with Revolution slider in Chrome
  510. if ( !(/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) || header.find('.slider_engine_revo').length == 0 )
  511. header.css('top', Math.round(offset/1.2)+'px');
  512. mask.css({
  513. 'opacity': mask_opacity,
  514. 'display': offset==0 ? 'none' : 'block'
  515. });
  516. } else if (parseInt(header.css('top')) != 0) {
  517. header.css('top', Math.round(offset/1.2)+'px');
  518. }
  519. } else if (parseInt(header.css('top')) != 0 || mask.css('display')!='none') {
  520. header.css('top', '0px');
  521. mask.css({
  522. 'opacity': 0,
  523. 'display': 'none'
  524. });
  525. }
  526. var footer = jQuery('.footer_wrap');
  527. var footer_height = Math.min(footer.height(), jQuery(window).height());
  528. var footer_visible = (scroll_offset + jQuery(window).height()) - (header.outerHeight() + jQuery('.page_content_wrap').outerHeight());
  529. if (footer_visible > 0) {
  530. mask = footer.find('.top_panel_mask');
  531. if (mask.length==0) {
  532. footer.append('<div class="top_panel_mask"></div>');
  533. mask = footer.find('.top_panel_mask');
  534. }
  535. if (footer_visible <= footer_height) {
  536. var mask_opacity = Math.max(0, Math.min(0.8, (footer_height - footer_visible)/footer_height));
  537. // Don't shift header with Revolution slider in Chrome
  538. if ( !(/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) || footer.find('.slider_engine_revo').length == 0 )
  539. footer.css('top', -Math.round((footer_height - footer_visible)/1.2)+'px');
  540. mask.css({
  541. 'opacity': mask_opacity,
  542. 'display': footer_height - footer_visible <= 0 ? 'none' : 'block'
  543. });
  544. } else if (parseInt(footer.css('top')) != 0 || mask.css('display')!='none') {
  545. footer.css('top', 0);
  546. mask.css({
  547. 'opacity': 0,
  548. 'display': 'none'
  549. });
  550. }
  551. }
  552. }
  553. }
  554.  
  555.  
  556. // Resize actions
  557. //==============================================
  558.  
  559. // Do actions when page scrolled
  560. function niobe_resize_actions(cont) {
  561. niobe_check_layout();
  562. // niobe_fix_sidebar();
  563. niobe_fix_footer();
  564. niobe_stretch_width(cont);
  565. niobe_stretch_height(null, cont);
  566. niobe_stretch_bg_video();
  567. niobe_resize_video( cont );
  568. niobe_vc_row_fullwidth_to_boxed(cont);
  569. if (NIOBE_STORAGE['menu_side_stretch']) niobe_stretch_sidemenu();
  570.  
  571. // Call theme/plugins specific action (if exists)
  572. //----------------------------------------------
  573. jQuery(document).trigger('action.resize_niobe', [cont]);
  574. }
  575.  
  576. // Stretch sidemenu (if present)
  577. function niobe_stretch_sidemenu() {
  578. var toc_items = jQuery('.menu_side_wrap.menu_side_icons .toc_menu_item');
  579. if (toc_items.length < 5) return;
  580. var toc_items_height = jQuery(window).height()
  581. - niobe_fixed_rows_height(true, false)
  582. - jQuery('.menu_side_wrap .sc_layouts_logo').outerHeight()
  583. - toc_items.length;
  584. var th = Math.floor(toc_items_height / toc_items.length);
  585. var th_add = toc_items_height - th*toc_items.length;
  586. toc_items.find(".toc_menu_description,.toc_menu_icon").css({
  587. 'height': th+'px',
  588. 'lineHeight': th+'px'
  589. });
  590. toc_items.eq(0).find(".toc_menu_description,.toc_menu_icon").css({
  591. 'height': (th+th_add)+'px',
  592. 'lineHeight': (th+th_add)+'px'
  593. });
  594. }
  595.  
  596. // Check for mobile layout
  597. function niobe_check_layout() {
  598. var resize = true;
  599. if (jQuery('body').hasClass('no_layout')) {
  600. jQuery('body').removeClass('no_layout');
  601. resize = false;
  602. }
  603. var w = window.innerWidth;
  604. if (w == undefined)
  605. w = jQuery(window).width()+(jQuery(window).height() < jQuery(document).height() || jQuery(window).scrollTop() > 0 ? 16 : 0);
  606. if (NIOBE_STORAGE['mobile_layout_width'] >= w) {
  607. if (!jQuery('body').hasClass('mobile_layout')) {
  608. jQuery('body').removeClass('desktop_layout').addClass('mobile_layout');
  609. if (resize) jQuery(window).trigger('resize');
  610. }
  611. } else {
  612. if (!jQuery('body').hasClass('desktop_layout')) {
  613. jQuery('body').removeClass('mobile_layout').addClass('desktop_layout');
  614. jQuery('.menu_mobile').removeClass('opened');
  615. jQuery('.menu_mobile_overlay').hide();
  616. if (resize) jQuery(window).trigger('resize');
  617. }
  618. }
  619. if (NIOBE_STORAGE['mobile_device'] || niobe_browser_is_mobile())
  620. jQuery('body').addClass('mobile_device');
  621. }
  622.  
  623. // Stretch area to full window width
  624. function niobe_stretch_width(cont) {
  625. if (cont===undefined) cont = jQuery('body');
  626. cont.find('.trx-stretch-width').each(function() {
  627. var $el = jQuery(this);
  628. var $el_cont = $el.parents('.page_wrap');
  629. var $el_cont_offset = 0;
  630. if ($el_cont.length == 0)
  631. $el_cont = jQuery(window);
  632. else
  633. $el_cont_offset = $el_cont.offset().left;
  634. var $el_full = $el.next('.trx-stretch-width-original');
  635. var el_margin_left = parseInt( $el.css( 'margin-left' ), 10 );
  636. var el_margin_right = parseInt( $el.css( 'margin-right' ), 10 );
  637. var offset = $el_cont_offset - $el_full.offset().left - el_margin_left;
  638. var width = $el_cont.width();
  639. if (!$el.hasClass('inited')) {
  640. $el.addClass('inited invisible');
  641. $el.css({
  642. 'position': 'relative',
  643. 'box-sizing': 'border-box'
  644. });
  645. }
  646. $el.css({
  647. 'left': offset,
  648. 'width': $el_cont.width()
  649. });
  650. if ( !$el.hasClass('trx-stretch-content') ) {
  651. var padding = Math.max(0, -1*offset);
  652. var paddingRight = Math.max(0, width - padding - $el_full.width() + el_margin_left + el_margin_right);
  653. $el.css( { 'padding-left': padding + 'px', 'padding-right': paddingRight + 'px' } );
  654. }
  655. $el.removeClass('invisible');
  656. });
  657. }
  658.  
  659. // Stretch area to the full window height
  660. function niobe_stretch_height(e, cont) {
  661. if (cont===undefined) cont = jQuery('body');
  662. cont.find('.niobe-full-height').each(function () {
  663. var fullheight_item = jQuery(this);
  664. // If item now invisible
  665. if (jQuery(this).parents('div:hidden,section:hidden,article:hidden').length > 0) {
  666. return;
  667. }
  668. var fullheight_row = jQuery(this).parents('.vc_row-o-full-height');
  669. if (fullheight_row.length > 0)
  670. fullheight_item.height(fullheight_row.height());
  671. else {
  672. var fh = niobe_fixed_rows_height();
  673. var wh = jQuery(window).width() >= 960
  674. ? jQuery(window).height() - fh
  675. : 'auto';
  676. if (wh > 0) {
  677. if (fullheight_item.data('display') != fullheight_item.css('display'))
  678. fullheight_item.css('display', fullheight_item.data('display'));
  679. fullheight_item.css('height', wh);
  680. } else if (wh=='auto' && fullheight_item.css('height')!='auto') {
  681. if (fullheight_item.data('display')==undefined)
  682. fullheight_item.attr('data-display', fullheight_item.css('display'));
  683. fullheight_item.css({'height': wh, 'display': 'block'});
  684. }
  685. }
  686. });
  687. }
  688.  
  689. // Stretch background video
  690. function niobe_stretch_bg_video() {
  691. var video_wrap = jQuery('div#background_video,.tourmaster-background-video');
  692. if (video_wrap.length == 0) return;
  693. var cont = video_wrap.hasClass('tourmaster-background-video') ? video_wrap.parent() : video_wrap,
  694. w = cont.width(),
  695. h = cont.height(),
  696. video = video_wrap.find('>iframe,>video');
  697. if (w/h < 16/9)
  698. w = h/9*16;
  699. else
  700. h = w/16*9;
  701. video
  702. .attr({'width': w, 'height': h})
  703. .css({'width': w, 'height': h});
  704. }
  705.  
  706. // Recalculate width of the vc_row[data-vc-full-width="true"] when content boxed or menu_style=='left|right'
  707. function niobe_vc_row_fullwidth_to_boxed(cont) {
  708. if (true || jQuery('body').hasClass('body_style_boxed') || jQuery('body').hasClass('menu_style_side')) {
  709. if (cont === undefined || !cont.hasClass('.vc_row') || !cont.data('vc-full-width'))
  710. cont = jQuery('.vc_row[data-vc-full-width="true"]');
  711. var width_content = jQuery('.page_wrap').width();
  712. var content_wrap = jQuery('.page_content_wrap .content_wrap');
  713. if (content_wrap.length == 0) content_wrap = jQuery('.page_content_wrap .content');
  714. if (content_wrap.length == 0) return;
  715. var width_content_wrap = content_wrap.width();
  716. var indent = ( width_content - width_content_wrap ) / 2;
  717. var rtl = jQuery('html').attr('dir') == 'rtl';
  718. cont.each( function() {
  719. var mrg = parseInt(jQuery(this).css('marginLeft'));
  720. var stretch_content = jQuery(this).attr('data-vc-stretch-content');
  721. var in_content = jQuery(this).parents('.content_wrap').length > 0;
  722. jQuery(this).css({
  723. 'width': width_content,
  724. 'left': rtl ? 'auto' : (in_content ? -indent : 0) - mrg,
  725. 'right': !rtl ? 'auto' : (in_content ? -indent : 0) - mrg,
  726. 'padding-left': stretch_content ? 0 : indent + mrg,
  727. 'padding-right': stretch_content ? 0 : indent + mrg
  728. });
  729. });
  730. }
  731. }
  732.  
  733. // Fix/unfix footer
  734. function niobe_fix_footer() {
  735. if (jQuery('body').hasClass('header_position_under') && !niobe_browser_is_mobile()) {
  736. var ft = jQuery('.footer_wrap');
  737. if (ft.length > 0) {
  738. var ft_height = ft.outerHeight(false),
  739. pc = jQuery('.page_content_wrap'),
  740. pc_offset = pc.offset().top,
  741. pc_height = pc.height();
  742. if (pc_offset + pc_height + ft_height < jQuery(window).height()) {
  743. if (ft.css('position')!='absolute') {
  744. ft.css({
  745. 'position': 'absolute',
  746. 'left': 0,
  747. 'bottom': 0,
  748. 'width' :'100%'
  749. });
  750. }
  751. } else {
  752. if (ft.css('position')!='relative') {
  753. ft.css({
  754. 'position': 'relative',
  755. 'left': 'auto',
  756. 'bottom': 'auto'
  757. });
  758. }
  759. }
  760. }
  761. }
  762. }
  763.  
  764.  
  765. // Fix/unfix sidebar
  766. function niobe_fix_sidebar() {
  767. var sb = jQuery('.sidebar');
  768. var content = sb.siblings('.content');
  769. if (sb.length > 0) {
  770.  
  771. // Unfix when sidebar is under content
  772. if (content.css('float') == 'none') {
  773.  
  774. var old_style = sb.data('old_style');
  775. if (old_style !== undefined) sb.attr('style', old_style).removeAttr('data-old_style');
  776.  
  777. } else {
  778.  
  779. var sb_height = sb.outerHeight();
  780. var content_height = content.outerHeight();
  781. var content_top = content.offset().top;
  782. var scroll_offset = jQuery(window).scrollTop();
  783.  
  784. var top_panel_fixed_height = niobe_fixed_rows_height();
  785.  
  786. // If sidebar shorter then content and page scrolled below the content's top
  787. if (sb_height < content_height && scroll_offset + top_panel_fixed_height > content_top) {
  788.  
  789. var sb_init = {
  790. 'position': 'undefined',
  791. 'float': 'none',
  792. 'top': 'auto',
  793. 'bottom' : 'auto'
  794. };
  795.  
  796. if (typeof NIOBE_STORAGE['scroll_offset_last'] == 'undefined') {
  797. NIOBE_STORAGE['sb_top_last'] = content_top;
  798. NIOBE_STORAGE['scroll_offset_last'] = scroll_offset;
  799. NIOBE_STORAGE['scroll_dir_last'] = 1;
  800. }
  801. var scroll_dir = scroll_offset - NIOBE_STORAGE['scroll_offset_last'];
  802. if (scroll_dir == 0)
  803. scroll_dir = NIOBE_STORAGE['scroll_dir_last'];
  804. else
  805. scroll_dir = scroll_dir > 0 ? 1 : -1;
  806.  
  807. var sb_big = sb_height + 30 >= jQuery(window).height() - top_panel_fixed_height,
  808. sb_top = sb.offset().top;
  809.  
  810. if (sb_top < 0) sb_top = NIOBE_STORAGE['sb_top_last'];
  811.  
  812. // If sidebar height greater then window height
  813. if (sb_big) {
  814.  
  815. // If change scrolling dir
  816. if (scroll_dir != NIOBE_STORAGE['scroll_dir_last'] && sb.css('position') == 'fixed') {
  817. sb_init.top = sb_top - content_top;
  818. sb_init.position = 'absolute';
  819.  
  820. // If scrolling down
  821. } else if (scroll_dir > 0) {
  822. if (scroll_offset + jQuery(window).height() >= content_top + content_height + 30) {
  823. sb_init.bottom = 0;
  824. sb_init.position = 'absolute';
  825. } else if (scroll_offset + jQuery(window).height() >= (sb.css('position') == 'absolute' ? sb_top : content_top) + sb_height + 30) {
  826.  
  827. sb_init.bottom = 30;
  828. sb_init.position = 'fixed';
  829. }
  830.  
  831. // If scrolling up
  832. } else {
  833. if (scroll_offset + top_panel_fixed_height <= sb_top) {
  834. sb_init.top = top_panel_fixed_height;
  835. sb_init.position = 'fixed';
  836. }
  837. }
  838.  
  839. // If sidebar height less then window height
  840. } else {
  841. if (scroll_offset + top_panel_fixed_height >= content_top + content_height - sb_height) {
  842. sb_init.bottom = 0;
  843. sb_init.position = 'absolute';
  844. } else {
  845. sb_init.top = top_panel_fixed_height;
  846. sb_init.position = 'fixed';
  847. }
  848. }
  849.  
  850. if (sb_init.position != 'undefined') {
  851. // Detect horizontal position when resize
  852. var pos = 0;
  853. if (sb_init.position == 'fixed' || (!jQuery('body').hasClass('body_style_wide') && !jQuery('body').hasClass('body_style_boxed'))) {
  854. var sb_parent = sb.parent();
  855. pos = sb_parent.position();
  856. pos = pos.left + Math.max(0, parseInt(sb_parent.css('paddingLeft'), 10))
  857. + Math.max(0, parseInt(sb_parent.css('marginLeft'), 10))
  858. + (jQuery('body').hasClass('menu_style_right')
  859. ? Math.max(0, parseInt(jQuery('body').css('marginRight'), 10))
  860. : 0);
  861. }
  862. if (sb.hasClass('right')) sb_init.right = pos;
  863. else sb_init.left = pos;
  864.  
  865. // Set position
  866. if (sb.css('position') != sb_init.position || NIOBE_STORAGE['scroll_dir_last'] != scroll_dir) {
  867. if (sb.data('old_style') === undefined) {
  868. var style = sb.attr('style');
  869. if (!style) style = '';
  870. sb.attr('data-old_style', style);
  871. }
  872. sb.css(sb_init);
  873. }
  874. }
  875.  
  876. NIOBE_STORAGE['sb_top_last'] = sb_top;
  877. NIOBE_STORAGE['scroll_offset_last'] = scroll_offset;
  878. NIOBE_STORAGE['scroll_dir_last'] = scroll_dir;
  879.  
  880. } else {
  881.  
  882. // Unfix when page scrolling to top
  883. var old_style = sb.data('old_style');
  884. if (old_style !== undefined)
  885. sb.attr('style', old_style).removeAttr('data-old_style');
  886.  
  887. }
  888. }
  889. }
  890. }
  891.  
  892.  
  893.  
  894.  
  895.  
  896. // Navigation
  897. //==============================================
  898.  
  899. // Init Superfish menu
  900. function niobe_init_sfmenu(selector) {
  901. jQuery(selector).show().each(function() {
  902. var animation_in = jQuery(this).parent().data('animation_in');
  903. if (animation_in == undefined) animation_in = "none";
  904. var animation_out = jQuery(this).parent().data('animation_out');
  905. if (animation_out == undefined) animation_out = "none";
  906. jQuery(this).addClass('inited').superfish({
  907. delay: 500,
  908. animation: {
  909. opacity: 'show'
  910. },
  911. animationOut: {
  912. opacity: 'hide'
  913. },
  914. speed: animation_in!='none' ? 500 : 200,
  915. speedOut: animation_out!='none' ? 500 : 200,
  916. autoArrows: false,
  917. dropShadows: false,
  918. onBeforeShow: function(ul) {
  919. if (jQuery(this).parents("ul").length > 1){
  920. var w = jQuery('.page_wrap').width();
  921. var par_offset = jQuery(this).parents("ul").offset().left;
  922. var par_width = jQuery(this).parents("ul").outerWidth();
  923. var ul_width = jQuery(this).outerWidth();
  924. if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0)
  925. jQuery(this).addClass('submenu_left');
  926. else
  927. jQuery(this).removeClass('submenu_left');
  928. }
  929. if (animation_in!='none') {
  930. jQuery(this).removeClass('animated fast '+animation_out);
  931. jQuery(this).addClass('animated fast '+animation_in);
  932. }
  933. },
  934. onBeforeHide: function(ul) {
  935. if (animation_out!='none') {
  936. jQuery(this).removeClass('animated fast '+animation_in);
  937. jQuery(this).addClass('animated fast '+animation_out);
  938. }
  939. }
  940. });
  941. });
  942. }
  943.  
  944.  
  945.  
  946.  
  947. // Post formats init
  948. //=====================================================
  949.  
  950. function niobe_init_post_formats(e, cont) {
  951.  
  952. // MediaElement init
  953. niobe_init_media_elements(cont);
  954.  
  955. // Video play button
  956. cont.find('.format-video .post_featured.with_thumb .post_video_hover:not(.inited)')
  957. .addClass('inited')
  958. .on('click', function(e) {
  959. jQuery(this).parents('.post_featured')
  960. .addClass('post_video_play')
  961. .find('.post_video').html(jQuery(this).data('video'));
  962. jQuery(window).trigger('resize');
  963. e.preventDefault();
  964. return false;
  965. });
  966. }
  967.  
  968.  
  969. function niobe_init_media_elements(cont) {
  970. if (NIOBE_STORAGE['use_mediaelements'] && cont.find('audio:not(.inited),video:not(.inited)').length > 0) {
  971. if (window.mejs) {
  972. if (window.mejs.MepDefaults) window.mejs.MepDefaults.enableAutosize = true;
  973. if (window.mejs.MediaElementDefaults) window.mejs.MediaElementDefaults.enableAutosize = true;
  974. cont.find('audio:not(.inited),video:not(.inited)').each(function() {
  975. // If item now invisible
  976. if (jQuery(this).parents('div:hidden,section:hidden,article:hidden').length > 0) {
  977. return;
  978. }
  979. if (jQuery(this).parents('.mejs-mediaelement').length == 0
  980. && jQuery( this ).parents( '.wp-block-video' ).length == 0
  981. && ! jQuery( this ).hasClass( 'wp-block-cover__video-background' )
  982. && (NIOBE_STORAGE['init_all_mediaelements']
  983. || (!jQuery(this).hasClass('wp-audio-shortcode')
  984. && !jQuery(this).hasClass('wp-video-shortcode')
  985. && !jQuery(this).parent().hasClass('wp-playlist')))) {
  986. var media_tag = jQuery(this);
  987. var settings = {
  988. enableAutosize: true,
  989. videoWidth: -1, // if set, overrides <video width>
  990. videoHeight: -1, // if set, overrides <video height>
  991. audioWidth: '100%', // width of audio player
  992. audioHeight: 30, // height of audio player
  993. success: function(mejs) {
  994. var autoplay, loop;
  995. if ( 'flash' === mejs.pluginType ) {
  996. autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
  997. loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
  998. autoplay && mejs.addEventListener( 'canplay', function () {
  999. mejs.play();
  1000. }, false );
  1001. loop && mejs.addEventListener( 'ended', function () {
  1002. mejs.play();
  1003. }, false );
  1004. }
  1005. }
  1006. };
  1007. jQuery(this).mediaelementplayer(settings);
  1008. }
  1009. });
  1010. } else
  1011. setTimeout(function() { niobe_init_media_elements(cont); }, 400);
  1012. }
  1013. }
  1014.  
  1015.  
  1016. // Fit video frames to document width
  1017. function niobe_resize_video(cont) {
  1018. if (cont === undefined) {
  1019. cont = jQuery( 'body' );
  1020. }
  1021. cont.find( 'video' ).each(
  1022. function() {
  1023. // If item now invisible
  1024. if (jQuery( this ).hasClass( 'trx_addons_resize' ) || jQuery( this ).parents( 'div:hidden,section:hidden,article:hidden' ).length > 0) {
  1025. return;
  1026. }
  1027. var video = jQuery( this ).addClass( 'niobe_resize' ).eq( 0 );
  1028. var ratio = (video.data( 'ratio' ) !== undefined ? video.data( 'ratio' ).split( ':' ) : [16,9]);
  1029. ratio = ratio.length != 2 || ratio[0] == 0 || ratio[1] == 0 ? 16 / 9 : ratio[0] / ratio[1];
  1030. var mejs_cont = video.parents( '.mejs-video' ).eq(0);
  1031. var w_attr = video.data( 'width' );
  1032. var h_attr = video.data( 'height' );
  1033. if ( ! w_attr || ! h_attr) {
  1034. w_attr = video.attr( 'width' );
  1035. h_attr = video.attr( 'height' );
  1036. if ( ! w_attr || ! h_attr) {
  1037. return;
  1038. }
  1039. video.data( {'width': w_attr, 'height': h_attr} );
  1040. }
  1041. var percent = ('' + w_attr).substr( -1 ) == '%';
  1042. w_attr = parseInt( w_attr, 10 );
  1043. h_attr = parseInt( h_attr, 10 );
  1044. var w_real = Math.round(
  1045. mejs_cont.length > 0
  1046. ? Math.min( percent ? 10000 : w_attr, mejs_cont.parents( 'div,article' ).eq(0).width() )
  1047. : Math.min( percent ? 10000 : w_attr, video.parents( 'div,article' ).eq(0).width() )
  1048. ),
  1049. h_real = Math.round( percent ? w_real / ratio : w_real / w_attr * h_attr );
  1050. if (parseInt( video.attr( 'data-last-width' ), 10 ) == w_real) {
  1051. return;
  1052. }
  1053. if (percent) {
  1054. video.height( h_real );
  1055. } else if (video.parents( '.wp-video-playlist' ).length > 0) {
  1056. if (mejs_cont.length === 0) {
  1057. video.attr( {'width': w_real, 'height': h_real} );
  1058. }
  1059. } else {
  1060. video.attr( {'width': w_real, 'height': h_real} ).css( {'width': w_real + 'px', 'height': h_real + 'px'} );
  1061. if (mejs_cont.length > 0) {
  1062. niobe_set_mejs_player_dimensions( video, w_real, h_real );
  1063. }
  1064. }
  1065. video.attr( 'data-last-width', w_real );
  1066. }
  1067. );
  1068. cont.find( '.video_frame iframe' ).each(
  1069. function() {
  1070. // If item now invisible
  1071. if (jQuery( this ).hasClass( 'trx_addons_resize' ) || jQuery( this ).addClass( 'niobe_resize' ).parents( 'div:hidden,section:hidden,article:hidden' ).length > 0) {
  1072. return;
  1073. }
  1074. var iframe = jQuery( this ).eq( 0 );
  1075. if (iframe.attr( 'src' ).indexOf( 'soundcloud' ) > 0) {
  1076. return;
  1077. }
  1078. var ratio = (iframe.data( 'ratio' ) !== undefined
  1079. ? iframe.data( 'ratio' ).split( ':' )
  1080. : (iframe.parent().data( 'ratio' ) !== undefined
  1081. ? iframe.parent().data( 'ratio' ).split( ':' )
  1082. : (iframe.find( '[data-ratio]' ).length > 0
  1083. ? iframe.find( '[data-ratio]' ).data( 'ratio' ).split( ':' )
  1084. : [16,9]
  1085. )
  1086. )
  1087. );
  1088. ratio = ratio.length != 2 || ratio[0] == 0 || ratio[1] == 0 ? 16 / 9 : ratio[0] / ratio[1];
  1089. var w_attr = iframe.attr( 'width' );
  1090. var h_attr = iframe.attr( 'height' );
  1091. if ( ! w_attr || ! h_attr) {
  1092. return;
  1093. }
  1094. var percent = ('' + w_attr).substr( -1 ) == '%';
  1095. w_attr = parseInt( w_attr, 10 );
  1096. h_attr = parseInt( h_attr, 10 );
  1097. var par = iframe.parents( 'div,section' ).eq(0),
  1098. pw = par.width(),
  1099. ph = par.height(),
  1100. w_real = pw,
  1101. h_real = Math.round( percent ? w_real / ratio : w_real / w_attr * h_attr );
  1102. if (par.css( 'position' ) == 'absolute' && h_real > ph) {
  1103. h_real = ph;
  1104. w_real = Math.round( percent ? h_real * ratio : h_real * w_attr / h_attr )
  1105. }
  1106. if (parseInt( iframe.attr( 'data-last-width' ), 10 ) == w_real) {
  1107. return;
  1108. }
  1109. iframe.css( {'width': w_real + 'px', 'height': h_real + 'px'} );
  1110. iframe.attr( 'data-last-width', w_real );
  1111. }
  1112. );
  1113. }
  1114.  
  1115. // Set Media Elements player dimensions
  1116. function niobe_set_mejs_player_dimensions(video, w, h) {
  1117. if (mejs) {
  1118. for (var pl in mejs.players) {
  1119. if (mejs.players[pl].media.src == video.attr( 'src' )) {
  1120. if (mejs.players[pl].media.setVideoSize) {
  1121. mejs.players[pl].media.setVideoSize( w, h );
  1122. } else if (mejs.players[pl].media.setSize) {
  1123. mejs.players[pl].media.setSize( w, h );
  1124. }
  1125. mejs.players[pl].setPlayerSize( w, h );
  1126. mejs.players[pl].setControlsSize();
  1127. }
  1128. }
  1129. }
  1130. }
  1131.  
  1132.  
  1133.  
  1134. // Load the tab's content
  1135. function laundrycity_tabs_ajax_content_loader(panel, page, oldPanel) {
  1136. "use strict";
  1137. if (panel.html().replace(/\s/g, '')=='') {
  1138. var height = oldPanel === undefined ? panel.height() : oldPanel.height();
  1139. if (isNaN(height) || height < 100) height = 100;
  1140. panel.html('<div class="niobe_tab_holder" style="min-height:'+height+'px;"></div>');
  1141. } else
  1142. panel.find('> *').addClass('niobe_tab_content_remove');
  1143. panel.data('need-content', false).addClass('niobe_loading');
  1144. jQuery.post(NIOBE_STORAGE['ajax_url'], {
  1145. nonce: NIOBE_STORAGE['ajax_nonce'],
  1146. action: 'niobe_ajax_get_posts',
  1147. blog_template: panel.data('blog-template'),
  1148. blog_style: panel.data('blog-style'),
  1149. posts_per_page: panel.data('posts-per-page'),
  1150. cat: panel.data('cat'),
  1151. parent_cat: panel.data('parent-cat'),
  1152. post_type: panel.data('post-type'),
  1153. taxonomy: panel.data('taxonomy'),
  1154. page: page
  1155. }).done(function(response) {
  1156. panel.removeClass('niobe_loading');
  1157. var rez = {};
  1158. try {
  1159. rez = JSON.parse(response);
  1160. } catch (e) {
  1161. rez = { error: NIOBE_STORAGE['strings']['ajax_error'] };
  1162. console.log(response);
  1163. }
  1164. if (rez.error !== '') {
  1165. panel.html('<div class="niobe_error">'+rez.error+'</div>');
  1166. } else {
  1167. panel.prepend(rez.data).fadeIn(function() {
  1168. jQuery(document).trigger('action.init_shortcodes', [panel]);
  1169. jQuery(document).trigger('action.init_hidden_elements', [panel]);
  1170. jQuery(window).trigger('scroll');
  1171. setTimeout(function() {
  1172. panel.find('.niobe_tab_holder,.niobe_tab_content_remove').remove();
  1173. jQuery(window).trigger('scroll');
  1174. }, 600);
  1175. });
  1176. }
  1177. });
  1178. }
  1179.  
  1180.  
  1181. // Forms validation
  1182. //-------------------------------------------------------
  1183.  
  1184. // Comments form
  1185. function niobe_comments_validate(form) {
  1186. form.find('input').removeClass('error_field');
  1187. var comments_args = {
  1188. error_message_text: NIOBE_STORAGE['strings']['error_global'], // Global error message text (if don't write in checked field)
  1189. error_message_show: true, // Display or not error message
  1190. error_message_time: 4000, // Error message display time
  1191. error_message_class: 'niobe_messagebox niobe_messagebox_style_error', // Class appended to error message block
  1192. error_fields_class: 'error_field', // Class appended to error fields
  1193. exit_after_first_error: false, // Cancel validation and exit after first error
  1194. rules: [
  1195. {
  1196. field: 'comment',
  1197. min_length: { value: 1, message: NIOBE_STORAGE['strings']['text_empty'] },
  1198. max_length: { value: NIOBE_STORAGE['comment_maxlength'], message: NIOBE_STORAGE['strings']['text_long']}
  1199. }
  1200. ]
  1201. };
  1202. if (form.find('.comments_author input[aria-required="true"]').length > 0) {
  1203. comments_args.rules.push(
  1204. {
  1205. field: 'author',
  1206. min_length: { value: 1, message: NIOBE_STORAGE['strings']['name_empty']},
  1207. max_length: { value: 60, message: NIOBE_STORAGE['strings']['name_long']}
  1208. }
  1209. );
  1210. }
  1211. if (form.find('.comments_email input[aria-required="true"]').length > 0) {
  1212. comments_args.rules.push(
  1213. {
  1214. field: 'email',
  1215. min_length: { value: 1, message: NIOBE_STORAGE['strings']['email_empty']},
  1216. max_length: { value: 60, message: NIOBE_STORAGE['strings']['email_long']},
  1217. mask: { value: NIOBE_STORAGE['email_mask'], message: NIOBE_STORAGE['strings']['email_not_valid']}
  1218. }
  1219. );
  1220. }
  1221. var error = niobe_form_validate(form, comments_args);
  1222. return !error;
  1223. }
  1224.  
  1225. });
Add Comment
Please, Sign In to add comment