layout.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* jshint esnext:true */
  2. import { toggle } from './helpers';
  3. var layout = ( api, $ ) => {
  4. 'use strict';
  5. api( 'vamtam_theme[full-width-header]', value => {
  6. value.bind( to => {
  7. $( '.header-maybe-limit-wrapper' ).toggleClass( 'limit-wrapper', to );
  8. } );
  9. } );
  10. api( 'vamtam_theme[sticky-header]', value => {
  11. value.bind( to => {
  12. requestAnimationFrame( function() {
  13. document.body.classList.toggle( 'sticky-header', +to );
  14. document.body.classList.remove( 'had-sticky-header' );
  15. window.VAMTAM.stickyHeader.rebuild();
  16. } );
  17. } );
  18. } );
  19. api( 'vamtam_theme[enable-header-search]', value => {
  20. value.bind( to => {
  21. toggle( $( 'header.main-header .search-wrapper' ), + to );
  22. } );
  23. } );
  24. api( 'vamtam_theme[show-empty-header-cart]', value => {
  25. value.bind( to => {
  26. document.querySelector( '.cart-dropdown' ).classList.toggle( 'show-if-empty', + to );
  27. $( 'body' ).trigger( 'wc_fragments_refreshed' );
  28. } );
  29. } );
  30. api( 'vamtam_theme[one-page-footer]', value => {
  31. value.bind( to => {
  32. toggle( $( '.footer-wrapper' ), to );
  33. setTimeout( function() {
  34. window.VAMTAM.resizeElements();
  35. }, 50 );
  36. } );
  37. } );
  38. api( 'vamtam_theme[page-title-layout]', value => {
  39. value.bind( to => {
  40. var header = $( 'header.page-header' );
  41. var line = header.find( '.page-header-line' );
  42. header
  43. .removeClass( 'layout-centered layout-one-row-left layout-one-row-right layout-left-align layout-right-align' )
  44. .addClass( 'layout-' + to );
  45. if ( to.match( /one-row-/ ) ) {
  46. line.appendTo( header.find( 'h1' ) );
  47. } else {
  48. line.appendTo( header );
  49. }
  50. } );
  51. } );
  52. };
  53. export default layout;