script-wpcom.js 773 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * script-wpcom.js
  3. *
  4. * Handles toggling of body class name to help WordPress.com custom colors target color changes at different window sizes.
  5. * The Custom Colors plugin does not support media queries.
  6. */
  7. ( function() {
  8. function checkWidth( init ) {
  9. // If browser is resized, check width again
  10. if ( window.innerWidth > 992 ) {
  11. document.body.classList.add( 'tablet-desktop' );
  12. }
  13. else {
  14. if ( ! init ) {
  15. document.body.classList.remove( 'tablet-desktop' );
  16. }
  17. }
  18. }
  19. function init() {
  20. checkWidth( true );
  21. window.addEventListener( 'resize', function() {
  22. checkWidth( false);
  23. } );
  24. }
  25. // After DOM is ready.
  26. if ( document.readyState !== 'loading' ) {
  27. init();
  28. } else {
  29. document.addEventListener( 'DOMContentLoaded', init );
  30. }
  31. } )();