intergalactic-2.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ( function( $ ) {
  2. var $window = $( window );
  3. /*
  4. * Toggle slide menu
  5. */
  6. function slideControl() {
  7. $( '.menu-toggle' ).on( 'click', function( e ) {
  8. e.preventDefault();
  9. $( '.slide-menu' ).toggleClass( 'expanded' ).resize();
  10. $( 'body' ).toggleClass( 'sidebar-open' );
  11. $( this ).toggleClass( 'toggle-on' );
  12. } );
  13. }
  14. /*
  15. * Close slide menu with escape key
  16. */
  17. $( document ).keyup( function( e ) {
  18. if ( e.keyCode === 27 && $( '.slide-menu' ).hasClass( 'expanded' ) ) {
  19. $( 'body' ).removeClass( 'sidebar-open' );
  20. $( '.menu-toggle' ).removeClass( 'toggle-on' );
  21. $( '.slide-menu' ).removeClass( 'expanded' );
  22. }
  23. } );
  24. /*
  25. * Wrap tiled gallery
  26. */
  27. function galleryWrapper() {
  28. $( '.entry-content' ).find( '.tiled-gallery' ).each( function() {
  29. if ( ! $( this ).hasClass( 'gallery-wrapped' ) ) {
  30. $( this ).wrap( '<div class="tiled-gallery-wrapper"></div>' );
  31. $( this ).addClass( 'gallery-wrapped' );
  32. $( this ).resize();
  33. }
  34. } );
  35. }
  36. /*
  37. * Add extra class to large images
  38. */
  39. function outdentImages() {
  40. $( '.entry-content img' ).each( function() {
  41. var img = $( this ),
  42. caption = $( this ).closest( 'figure' ),
  43. new_img = new Image();
  44. new_img.src = img.attr('src');
  45. var img_width = new_img.width;
  46. if ( img_width >= 1000 && $( this ).parents( '[class^="wp-block-"]').length === 0 ) {
  47. $( this ).addClass( 'size-big' );
  48. $( this ).parents( 'p' ).addClass( 'size-big-wrapper' );
  49. if ( $.trim( $( this ).parents( 'p' ).text() ) != '' ) {
  50. $( this ).parents( 'p' ).contents().filter( 'a, img' ).wrap( '<span class="size-big-wrapper" />' );
  51. $( this ).parents( 'p' ).removeClass( 'size-big-wrapper' );
  52. }
  53. }
  54. if ( caption.hasClass( 'wp-caption' ) && img_width >= 1000 ) {
  55. $( this ).removeClass( 'size-big' );
  56. caption.addClass( 'caption-big' );
  57. }
  58. } );
  59. }
  60. /*
  61. * Manage full-screen featured images
  62. */
  63. function fullScreenImages() {
  64. var $entryBackground = $( '.entry-background' ),
  65. singleThumbnail = $( 'body' ).hasClass( 'single-thumbnail' );
  66. if ( ! singleThumbnail ) {
  67. return;
  68. }
  69. if ( 768 < $window.width() ) {
  70. $entryBackground.height( $window.height() + 'px' );
  71. } else {
  72. $entryBackground.height( 'auto' );
  73. }
  74. $( 'html, .single.single-thumbnail' ).height( 'auto' );
  75. }
  76. //After DOM is ready
  77. $( document ).ready( function() {
  78. slideControl();
  79. fullScreenImages();
  80. } );
  81. // After page loads
  82. $window.load( function() {
  83. galleryWrapper();
  84. outdentImages();
  85. } );
  86. // On window resize
  87. $window.on( 'resize', function() {
  88. fullScreenImages();
  89. });
  90. // After infinite scroll loads
  91. $window.on( 'post-load', function() {
  92. galleryWrapper();
  93. outdentImages();
  94. } );
  95. } )( jQuery );