fl-theme-builder-header-layout.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. (function($){
  2. /**
  3. * Helper class for header layout logic.
  4. *
  5. * @since 1.0
  6. * @class FLThemeBuilderHeaderLayout
  7. */
  8. FLThemeBuilderHeaderLayout = {
  9. /**
  10. * A reference to the window object for this page.
  11. *
  12. * @since 1.0
  13. * @property {Object} win
  14. */
  15. win : null,
  16. /**
  17. * A reference to the body object for this page.
  18. *
  19. * @since 1.0
  20. * @property {Object} body
  21. */
  22. body : null,
  23. /**
  24. * A reference to the header object for this page.
  25. *
  26. * @since 1.0
  27. * @property {Object} header
  28. */
  29. header : null,
  30. /**
  31. * Whether this header overlays the content or not.
  32. *
  33. * @since 1.0
  34. * @property {Boolean} overlay
  35. */
  36. overlay : false,
  37. /**
  38. * Whether the page has the WP admin bar or not.
  39. *
  40. * @since 1.0
  41. * @property {Boolean} hasAdminBar
  42. */
  43. hasAdminBar : false,
  44. /**
  45. * Breakpoint for when the sticky header should apply.
  46. *
  47. * @since 1.4
  48. * @property {String} stickyOn
  49. */
  50. stickyOn: '',
  51. /**
  52. * A reference of the sticky and shrink header breakpoint.
  53. *
  54. * @since 1.2.5
  55. * @property {Number} breakpointWidth
  56. */
  57. breakpointWidth: 0,
  58. /**
  59. * Initializes header layout logic.
  60. *
  61. * @since 1.0
  62. * @method init
  63. */
  64. init: function()
  65. {
  66. var editing = $( 'html.fl-builder-edit' ).length,
  67. header = $( '.fl-builder-content[data-type=header]' ),
  68. menuModule = header.find( '.fl-module-menu' ),
  69. breakpoint = null;
  70. if ( ! editing && header.length ) {
  71. header.imagesLoaded( $.proxy( function() {
  72. this.win = $( window );
  73. this.body = $( 'body' );
  74. this.header = header.eq( 0 );
  75. this.overlay = !! Number( header.attr( 'data-overlay' ) );
  76. this.hasAdminBar = !! $( 'body.admin-bar' ).length;
  77. this.stickyOn = this.header.data( 'sticky-on' );
  78. breakpoint = this.header.data( 'sticky-breakpoint' );
  79. if ( '' == this.stickyOn ) {
  80. if ( typeof FLBuilderLayoutConfig.breakpoints[ breakpoint ] !== undefined ) {
  81. this.breakpointWidth = FLBuilderLayoutConfig.breakpoints[ breakpoint ];
  82. }
  83. else {
  84. this.breakpointWidth = FLBuilderLayoutConfig.breakpoints.medium;
  85. }
  86. }
  87. if ( Number( header.attr( 'data-sticky' ) ) ) {
  88. this.header.data( 'original-top', this.header.offset().top );
  89. this.win.on( 'resize', $.throttle( 500, $.proxy( this._initSticky, this ) ) );
  90. this._initSticky();
  91. }
  92. }, this ) );
  93. }
  94. },
  95. /**
  96. * Initializes sticky logic for a header.
  97. *
  98. * @since 1.0
  99. * @access private
  100. * @method _initSticky
  101. */
  102. _initSticky: function( e )
  103. {
  104. var header = $('.fl-builder-content[data-type=header]'),
  105. windowSize = this.win.width(),
  106. makeSticky = false;
  107. makeSticky = this._makeWindowSticky( windowSize );
  108. if ( makeSticky || ( this.breakpointWidth > 0 && windowSize >= this.breakpointWidth ) ) {
  109. this.win.on( 'scroll.fl-theme-builder-header-sticky', $.proxy( this._doSticky, this ) );
  110. //
  111. // Check if Event Type is 'resize' then invoke this._doSticky()
  112. // only if the 'fl-theme-builder-header-sticky' class is already present.
  113. //
  114. if ( e && 'resize' === e.type ) {
  115. if ( this.header.hasClass( 'fl-theme-builder-header-sticky' ) ) {
  116. this._doSticky( e );
  117. }
  118. this._adjustStickyHeaderWidth();
  119. }
  120. if ( Number( header.attr( 'data-shrink' ) ) ) {
  121. this.header.data( 'original-height', this.header.outerHeight() );
  122. this.win.on( 'resize', $.throttle( 500, $.proxy( this._initShrink, this ) ) );
  123. this._initShrink();
  124. }
  125. this._initFlyoutMenuFix( e );
  126. } else {
  127. this.win.off( 'scroll.fl-theme-builder-header-sticky' );
  128. this.win.off( 'resize.fl-theme-builder-header-sticky' );
  129. this.header.removeClass( 'fl-theme-builder-header-sticky' );
  130. this.header.removeAttr( 'style' );
  131. this.header.parent().css( 'padding-top', '0' );
  132. }
  133. },
  134. /**
  135. * Check if Header should be sticky at a particular Window size.
  136. *
  137. * @since 1.4
  138. * @access private
  139. * @param widowSize
  140. * @method _makeWindowSticky
  141. */
  142. _makeWindowSticky: function ( windowSize )
  143. {
  144. var makeSticky = false;
  145. switch (this.stickyOn) {
  146. case 'xl':
  147. makeSticky = windowSize > FLBuilderLayoutConfig.breakpoints['large'];
  148. break;
  149. case '': // Default
  150. case 'desktop':
  151. makeSticky = windowSize >= FLBuilderLayoutConfig.breakpoints['medium'];
  152. break;
  153. case 'desktop-medium':
  154. makeSticky = windowSize > FLBuilderLayoutConfig.breakpoints['small'];
  155. break;
  156. case 'large':
  157. makeSticky = windowSize > FLBuilderLayoutConfig.breakpoints['medium'] && windowSize <= FLBuilderLayoutConfig.breakpoints['large'];
  158. break;
  159. case 'large-medium':
  160. makeSticky = windowSize > FLBuilderLayoutConfig.breakpoints['small'] && windowSize <= FLBuilderLayoutConfig.breakpoints['large'];
  161. break;
  162. case 'medium':
  163. makeSticky = ( windowSize <= FLBuilderLayoutConfig.breakpoints['medium'] && windowSize > FLBuilderLayoutConfig.breakpoints['small'] );
  164. break;
  165. case 'medium-mobile':
  166. makeSticky = (windowSize <= FLBuilderLayoutConfig.breakpoints['medium']);
  167. break;
  168. case 'mobile':
  169. makeSticky = (windowSize <= FLBuilderLayoutConfig.breakpoints['small']);
  170. break;
  171. case 'all':
  172. makeSticky = true;
  173. break;
  174. }
  175. return makeSticky;
  176. },
  177. /**
  178. * Sticks the header when the page is scrolled.
  179. *
  180. * @since 1.0
  181. * @access private
  182. * @method _doSticky
  183. */
  184. _doSticky: function( e )
  185. {
  186. var winTop = Math.floor( this.win.scrollTop() ),
  187. headerTop = Math.floor( this.header.data( 'original-top' ) ),
  188. hasStickyClass = this.header.hasClass( 'fl-theme-builder-header-sticky' ),
  189. hasScrolledClass = this.header.hasClass( 'fl-theme-builder-header-scrolled' ),
  190. beforeHeader = this.header.prevAll( '.fl-builder-content' ),
  191. bodyTopPadding = parseInt( jQuery('body').css('padding-top') ),
  192. winBarHeight = $('#wpadminbar').length ? $('#wpadminbar').outerHeight() : 0,
  193. headerHeight = 0;
  194. if ( isNaN( bodyTopPadding ) ) {
  195. bodyTopPadding = 0;
  196. }
  197. if ( this.hasAdminBar && this.win.width() > 600 ) {
  198. winTop += Math.floor( winBarHeight );
  199. }
  200. if ( winTop > headerTop ) {
  201. if ( ! hasStickyClass ) {
  202. if ( e && ( 'scroll' === e.type || 'smartscroll' === e.type ) ) {
  203. this.header.addClass( 'fl-theme-builder-header-sticky' );
  204. if ( this.overlay && beforeHeader.length ) {
  205. this.header.css( 'top', winBarHeight);
  206. }
  207. }
  208. if ( ! this.overlay ) {
  209. this._adjustHeaderHeight();
  210. }
  211. }
  212. }
  213. else if ( hasStickyClass ) {
  214. this.header.removeClass( 'fl-theme-builder-header-sticky' );
  215. this.header.removeAttr( 'style' );
  216. this.header.parent().css( 'padding-top', '0' );
  217. }
  218. this._adjustStickyHeaderWidth();
  219. if ( winTop > headerTop ) {
  220. if ( ! hasScrolledClass ) {
  221. this.header.addClass( 'fl-theme-builder-header-scrolled' );
  222. }
  223. } else if ( hasScrolledClass ) {
  224. this.header.removeClass( 'fl-theme-builder-header-scrolled' );
  225. }
  226. this._flyoutMenuFix( e );
  227. },
  228. /**
  229. * Initializes flyout menu fixes on sticky header.
  230. *
  231. * @since 1.4.1
  232. * @method _initFlyoutMenuFix
  233. */
  234. _initFlyoutMenuFix: function( e ) {
  235. var header = this.header,
  236. menuModule = header.find( '.fl-menu' ),
  237. flyoutMenu = menuModule.find( '.fl-menu-mobile-flyout' ),
  238. isPushMenu = menuModule.hasClass( 'fl-menu-responsive-flyout-push' ) || menuModule.hasClass( 'fl-menu-responsive-flyout-push-opacity' ),
  239. isSticky = header.hasClass( 'fl-theme-builder-header-sticky' ),
  240. isOverlay = menuModule.hasClass( 'fl-menu-responsive-flyout-overlay' ),
  241. flyoutPos = menuModule.hasClass( 'fl-flyout-right' ) ? 'right' : 'left',
  242. flyoutParent = header.parent().is( 'header' ) ? header.parent().parent() : header.parent();
  243. isFullWidth = this.win.width() === header.width(),
  244. flyoutLayout = '',
  245. activePos = 250,
  246. headerPos = 0;
  247. if ( ! flyoutMenu.length ) {
  248. return;
  249. }
  250. if ( this.win.width() > header.parent().width() ) {
  251. headerPos = ( this.win.width() - header.width() ) / 2;
  252. }
  253. if ( isOverlay ) {
  254. activePos = headerPos;
  255. }
  256. else if ( isPushMenu ) {
  257. activePos = activePos + headerPos;
  258. }
  259. flyoutMenu.data( 'activePos', activePos );
  260. if ( isPushMenu ) {
  261. flyoutLayout = 'push-' + flyoutPos;
  262. }
  263. else if ( isOverlay ) {
  264. flyoutLayout = 'overlay-' + flyoutPos;
  265. }
  266. if ( isPushMenu && ! $( 'html' ).hasClass( 'fl-theme-builder-has-flyout-menu' ) ) {
  267. $( 'html' ).addClass( 'fl-theme-builder-has-flyout-menu' );
  268. }
  269. if ( ! flyoutParent.hasClass( 'fl-theme-builder-flyout-menu-' + flyoutLayout ) ) {
  270. flyoutParent.addClass( 'fl-theme-builder-flyout-menu-' + flyoutLayout );
  271. }
  272. if ( ! header.hasClass( 'fl-theme-builder-flyout-menu-overlay' ) && isOverlay ) {
  273. header.addClass( 'fl-theme-builder-flyout-menu-overlay' );
  274. }
  275. if ( ! header.hasClass( 'fl-theme-builder-header-full-width' ) && isFullWidth ) {
  276. header.addClass( 'fl-theme-builder-header-full-width' );
  277. }
  278. else if ( ! isFullWidth ) {
  279. header.removeClass( 'fl-theme-builder-header-full-width' );
  280. }
  281. menuModule.on( 'click', '.fl-menu-mobile-toggle', $.proxy( function( event ){
  282. if ( menuModule.find( '.fl-menu-mobile-toggle.fl-active' ).length ) {
  283. $( 'html' ).addClass( 'fl-theme-builder-flyout-menu-active' );
  284. event.stopImmediatePropagation();
  285. }
  286. else {
  287. $( 'html' ).removeClass( 'fl-theme-builder-flyout-menu-active' );
  288. }
  289. this._flyoutMenuFix( event );
  290. }, this ) );
  291. },
  292. /**
  293. * Fix flyout menu inside the sticky header.
  294. *
  295. * @since 1.4.1
  296. * @method _flyoutMenuFix
  297. */
  298. _flyoutMenuFix: function( e ){
  299. var header = this.header,
  300. menuModule = header.find( '.fl-menu' ),
  301. flyoutMenu = menuModule.find( '.fl-menu-mobile-flyout' ),
  302. isPushMenu = menuModule.hasClass( 'fl-menu-responsive-flyout-push' ) || menuModule.hasClass( 'fl-menu-responsive-flyout-push-opacity' ),
  303. flyoutPos = menuModule.hasClass( 'fl-flyout-right' ) ? 'right' : 'left',
  304. menuOpacity = menuModule.find( '.fl-menu-mobile-opacity' ),
  305. isScroll = 'undefined' !== typeof e && 'scroll' === e.handleObj.type,
  306. activePos = 'undefined' !== typeof flyoutMenu.data( 'activePos' ) ? flyoutMenu.data( 'activePos' ) : 0,
  307. headerPos = ( this.win.width() - header.width() ) / 2,
  308. inactivePos = headerPos > 0 ? activePos + 4 : 254;
  309. if ( ! flyoutMenu.length ) {
  310. return;
  311. }
  312. if ( this.overlay ) {
  313. return;
  314. }
  315. if( $( '.fl-theme-builder-flyout-menu-active' ).length ) {
  316. if ( isScroll && ! flyoutMenu.hasClass( 'fl-menu-disable-transition' ) ) {
  317. flyoutMenu.addClass( 'fl-menu-disable-transition' );
  318. }
  319. if ( header.hasClass( 'fl-theme-builder-header-sticky' ) ) {
  320. if ( ! isScroll ) {
  321. setTimeout( $.proxy( function(){
  322. flyoutMenu.css( flyoutPos, '-' + activePos + 'px' );
  323. }, this ), 1 );
  324. }
  325. else {
  326. flyoutMenu.css( flyoutPos, '-' + activePos + 'px' );
  327. }
  328. }
  329. else {
  330. flyoutMenu.css( flyoutPos, '0px' );
  331. }
  332. }
  333. else {
  334. if ( flyoutMenu.hasClass( 'fl-menu-disable-transition' ) ) {
  335. flyoutMenu.removeClass( 'fl-menu-disable-transition' );
  336. }
  337. if ( header.hasClass( 'fl-theme-builder-flyout-menu-overlay' ) && headerPos > 0 && headerPos < 250 ) {
  338. if ( header.hasClass( 'fl-theme-builder-header-sticky' ) ) {
  339. inactivePos = headerPos + 254;
  340. }
  341. else {
  342. inactivePos = 254;
  343. }
  344. }
  345. if ( e && e.type === 'resize' ) {
  346. inactivePos = headerPos + 254;
  347. }
  348. flyoutMenu.css( flyoutPos, '-' + inactivePos + 'px' );
  349. }
  350. if ( e && menuModule.is('.fl-menu-responsive-flyout-overlay') && $.infinitescroll ) {
  351. e.stopImmediatePropagation();
  352. }
  353. if( menuOpacity.length ) {
  354. if ( header.hasClass( 'fl-theme-builder-header-sticky' ) ) {
  355. if ( '0px' === menuOpacity.css( 'left' ) ) {
  356. menuOpacity.css( 'left', '-' + headerPos + 'px' );
  357. }
  358. }
  359. else {
  360. menuOpacity.css( 'left', '' );
  361. }
  362. }
  363. },
  364. /**
  365. * Adjust sticky header width if BB Theme Boxed Layout is used.
  366. *
  367. * @since 1.4
  368. * @access private
  369. * @method _adjustStickyHeaderWidth
  370. */
  371. _adjustStickyHeaderWidth: function () {
  372. if ( $('body').hasClass( 'fl-fixed-width' ) ) {
  373. var parentWidth = this.header.parent().width();
  374. // Better if this is set in the stylesheet file.
  375. if ( this.win.width() >= 992 ) {
  376. this.header.css({
  377. 'margin': '0 auto',
  378. 'max-width': parentWidth,
  379. });
  380. }
  381. else {
  382. this.header.css({
  383. 'margin': '',
  384. 'max-width': '',
  385. });
  386. }
  387. }
  388. },
  389. /**
  390. * Adjust Sticky Header Height
  391. *
  392. * @since 1.4
  393. * @access private
  394. * @method _adjustHeaderHeight
  395. */
  396. _adjustHeaderHeight: function () {
  397. var beforeHeader = this.header.prevAll('.fl-builder-content'),
  398. beforeHeaderHeight = 0,
  399. beforeHeaderFix = 0,
  400. headerHeight = Math.floor( this.header.outerHeight() ),
  401. bodyTopPadding = parseInt( $( 'body' ).css( 'padding-top' ) ),
  402. wpAdminBarHeight = 0,
  403. totalHeaderHeight = 0;
  404. if ( isNaN( bodyTopPadding ) ) {
  405. bodyTopPadding = 0;
  406. }
  407. if ( beforeHeader.length ) {
  408. $.each( beforeHeader, function() {
  409. beforeHeaderHeight += Math.floor( $(this).outerHeight() );
  410. });
  411. // Subtract this value from the header parent's top padding.
  412. beforeHeaderFix = 2;
  413. }
  414. if ( this.hasAdminBar && this.win.width() <= 600 ) {
  415. wpAdminBarHeight = Math.floor( $('#wpadminbar').outerHeight() );
  416. }
  417. totalHeaderHeight = Math.floor( beforeHeaderHeight + headerHeight);
  418. if ( headerHeight > 0 ) {
  419. var headerParent = this.header.parent(),
  420. headerParentTopPadding = 0;
  421. // If the header's parent container is the BODY tag ignore its top padding.
  422. if ( $( headerParent ).is('body') ) {
  423. headerParentTopPadding = Math.floor( headerHeight - wpAdminBarHeight );
  424. } else {
  425. headerParentTopPadding = Math.floor( headerHeight - bodyTopPadding - wpAdminBarHeight );
  426. }
  427. $( headerParent ).css( 'padding-top', ( headerParentTopPadding - beforeHeaderFix ) + 'px' );
  428. this.header.css({
  429. '-webkit-transform': 'translate(0px, -' + totalHeaderHeight + 'px)',
  430. '-ms-transform': 'translate(0px, -' + totalHeaderHeight + 'px)',
  431. 'transform': 'translate(0px, -' + totalHeaderHeight + 'px)'
  432. });
  433. }
  434. },
  435. /**
  436. * Initializes shrink logic for a header.
  437. *
  438. * @since 1.0
  439. * @access private
  440. * @method _initShrink
  441. */
  442. _initShrink: function( e )
  443. {
  444. if ( this.win.width() >= this.breakpointWidth ) {
  445. this.win.on( 'scroll.fl-theme-builder-header-shrink', $.proxy( this._doShrink, this ) );
  446. this._setImageMaxHeight();
  447. if ( this.win.scrollTop() > 0 ){
  448. this._doShrink();
  449. }
  450. } else {
  451. this.header.parent().css( 'padding-top', '0' );
  452. this.win.off( 'scroll.fl-theme-builder-header-shrink' );
  453. this._removeShrink();
  454. this._removeImageMaxHeight();
  455. }
  456. },
  457. /**
  458. * Shrinks the header when the page is scrolled.
  459. *
  460. * @since 1.0
  461. * @access private
  462. * @method _doShrink
  463. */
  464. _doShrink: function( e )
  465. {
  466. var winTop = this.win.scrollTop(),
  467. headerTop = this.header.data('original-top'),
  468. headerHeight = this.header.data('original-height'),
  469. shrinkImageHeight = this.header.data('shrink-image-height'),
  470. windowSize = this.win.width(),
  471. makeSticky = this._makeWindowSticky( windowSize ),
  472. hasClass = this.header.hasClass( 'fl-theme-builder-header-shrink' );
  473. if ( this.hasAdminBar ) {
  474. winTop += 32;
  475. }
  476. if ( makeSticky && ( winTop > headerTop + headerHeight ) ) {
  477. if ( ! hasClass ) {
  478. this.header.addClass( 'fl-theme-builder-header-shrink' );
  479. // Shrink images but don't include lightbox and menu images.
  480. this.header.find('img').each( function( i ) {
  481. var image = $( this ),
  482. maxMegaMenu = image.closest( '.max-mega-menu' ).length,
  483. imageInLightbox = image.closest( '.fl-button-lightbox-content' ).length,
  484. imageInNavMenu = image.closest( 'li.menu-item' ).length;
  485. if ( ! ( imageInLightbox || imageInNavMenu || maxMegaMenu ) ) {
  486. image.css( 'max-height', shrinkImageHeight );
  487. }
  488. });
  489. this.header.find( '.fl-row-content-wrap' ).each( function() {
  490. var row = $( this );
  491. if ( parseInt( row.css( 'padding-bottom' ) ) > 5 ) {
  492. row.addClass( 'fl-theme-builder-header-shrink-row-bottom' );
  493. }
  494. if ( parseInt( row.css( 'padding-top' ) ) > 5 ) {
  495. row.addClass( 'fl-theme-builder-header-shrink-row-top' );
  496. }
  497. } );
  498. this.header.find( '.fl-module-content' ).each( function() {
  499. var module = $( this );
  500. if ( parseInt( module.css( 'margin-bottom' ) ) > 5 ) {
  501. module.addClass( 'fl-theme-builder-header-shrink-module-bottom' );
  502. }
  503. if ( parseInt( module.css( 'margin-top' ) ) > 5 ) {
  504. module.addClass( 'fl-theme-builder-header-shrink-module-top' );
  505. }
  506. } );
  507. }
  508. } else if (hasClass) {
  509. this.header.find( 'img' ).css( 'max-height', '' );
  510. this._removeShrink();
  511. }
  512. // Fixes Shrink header issue with BB Theme when window is scrolled then resized and back.
  513. if ( 'undefined' === typeof( e ) && $('body').hasClass( 'fl-fixed-width' ) ) {
  514. if ( ! this.overlay ) {
  515. this._adjustHeaderHeight();
  516. }
  517. }
  518. },
  519. /**
  520. * Removes the header shrink effect.
  521. *
  522. * @since 1.0
  523. * @access private
  524. * @method _removeShrink
  525. */
  526. _removeShrink: function()
  527. {
  528. var rows = this.header.find( '.fl-row-content-wrap' ),
  529. modules = this.header.find( '.fl-module-content' );
  530. rows.removeClass( 'fl-theme-builder-header-shrink-row-bottom' );
  531. rows.removeClass( 'fl-theme-builder-header-shrink-row-top' );
  532. modules.removeClass( 'fl-theme-builder-header-shrink-module-bottom' );
  533. modules.removeClass( 'fl-theme-builder-header-shrink-module-top' );
  534. this.header.removeClass( 'fl-theme-builder-header-shrink' );
  535. },
  536. /**
  537. * Adds max height to images in modules for smooth scrolling.
  538. *
  539. * @since 1.1.1
  540. * @access private
  541. * @method _setImageMaxHeight
  542. */
  543. _setImageMaxHeight: function()
  544. {
  545. var head = $( 'head' ),
  546. stylesId = 'fl-header-styles-' + this.header.data( 'post-id' ),
  547. styles = '',
  548. images = this.header.find( '.fl-module-content img' );
  549. if ( $( '#' + stylesId ).length ) {
  550. return;
  551. }
  552. images.each( function( i ) {
  553. var image = $( this ),
  554. height = image.height(),
  555. node = image.closest( '.fl-module' ).data( 'node' ),
  556. className = 'fl-node-' + node + '-img-' + i,
  557. maxMegaMenu = image.closest( '.max-mega-menu' ).length,
  558. imageInLightbox = image.closest( '.fl-button-lightbox-content' ).length,
  559. imageInNavMenu = image.closest( 'li.menu-item' ).length;
  560. if ( ! ( imageInLightbox || imageInNavMenu || maxMegaMenu ) ) {
  561. image.addClass( className );
  562. styles += '.' + className + ' { max-height: ' + ( height ? height : image[0].height ) + 'px }';
  563. }
  564. } );
  565. if ( '' !== styles ) {
  566. head.append( '<style id="' + stylesId + '">' + styles + '</style>' );
  567. }
  568. },
  569. /**
  570. * Removes max height on images in modules for smooth scrolling.
  571. *
  572. * @since 1.1.1
  573. * @access private
  574. * @method _removeImageMaxHeight
  575. */
  576. _removeImageMaxHeight: function()
  577. {
  578. $( '#fl-header-styles-' + this.header.data( 'post-id' ) ).remove();
  579. },
  580. };
  581. $( function() { FLThemeBuilderHeaderLayout.init(); } );
  582. })(jQuery);