illustratr.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ( function( $ ) {
  2. /*
  3. * Add dropdown toggle that display child menu items.
  4. */
  5. function primary_nav() {
  6. $( '.main-navigation ul .genericon' ).remove();
  7. if( $( window ).width() < 960 ) {
  8. $( '.main-navigation .page_item_has_children > a, .main-navigation .menu-item-has-children > a' ).append( '<span class="genericon genericon-expand" />' );
  9. $( '.main-navigation ul .genericon' ).click( function( event ) {
  10. event.preventDefault();
  11. $( this ).toggleClass( 'genericon-expand' ).toggleClass( 'genericon-collapse' );
  12. $( this ).closest( 'li' ).toggleClass( 'toggle-on' );
  13. $( this ).parent().next( '.children, .sub-menu' ).toggleClass( 'toggle-on' );
  14. } );
  15. }
  16. }
  17. /*
  18. * Add classes to images and captions if image post format.
  19. */
  20. function image_post_format() {
  21. $( '.hentry.format-image img, .portfolio-entry .entry-content img' ).each( function() {
  22. var img = $( this ),
  23. caption = $( this ).closest( 'div' ),
  24. new_img = new Image();
  25. new_img.src = img.attr('src');
  26. var img_width = new_img.width;
  27. if ( img_width >= 1100 ) {
  28. $( this ).addClass( 'image-big' );
  29. $( this ).parents( 'p' ).addClass( 'image-big-wrapper' );
  30. if ( $.trim( $( this ).parents( 'p' ).text() ) != '' ) {
  31. $( this ).parents( 'p' ).contents().filter( 'a, img' ).wrap( '<span class="image-big-wrapper" />' );
  32. $( this ).parents( 'p' ).removeClass( 'image-big-wrapper' );
  33. }
  34. }
  35. if ( caption.hasClass( 'wp-caption' ) && img_width >= 1080 ) {
  36. $( this ).removeClass( 'image-big' );
  37. caption.addClass( 'caption-big' );
  38. }
  39. } );
  40. }
  41. /*
  42. * Remove Flash Fallback from HTML5 Audio in audio post format.
  43. */
  44. function audio_post_format() {
  45. $( '.hentry.format-audio .entry-media audio' ).each( function() {
  46. var audio_id = $( this ).attr( 'id' );
  47. $( this ).next( '#' + audio_id + '-flash' ).remove();
  48. $( this ).parent().siblings( '.entry-content' ).find( '#' + audio_id + '-flash' ).parents( 'span' ).remove();
  49. } );
  50. }
  51. /*
  52. * Remove content if empty.
  53. */
  54. function content() {
  55. $( '.page-content, .hentry:not(.portfolio-entry) .entry-content, .entry-summary, .entry-sharedaddy, .sharedaddy' ).each( function() {
  56. if ( ! $( this ).find( 'iframe' ).length && ! $( this ).find( 'img' ).length && $.trim( $( this ).text() ) === '' ) {
  57. $( this ).remove();
  58. }
  59. } );
  60. }
  61. /*
  62. * Resize entry-thumbnail, entry-gallery, entry-media, video-wrapper (video post format), caption-big and image-big for full width on small screens.
  63. */
  64. function calc() {
  65. $( '.entry-thumbnail, .entry-gallery, .entry-media, .hentry.format-video > .video-wrapper, .caption-big' ).each( function() {
  66. if( $( window ).width() < 768 ) {
  67. $( this ).css( 'width', '100%' ).css( 'width', '+=40px' );
  68. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  69. $( this ).css( 'margin-right', '-20px' );
  70. } else {
  71. $( this ).css( 'margin-left', '-20px' );
  72. }
  73. } else if( $( window ).width() < 960 ) {
  74. $( this ).css( 'width', '100%' ).css( 'width', '+=80px' );
  75. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  76. $( this ).css( 'margin-right', '-40px' );
  77. } else {
  78. $( this ).css( 'margin-left', '-40px' );
  79. }
  80. } else {
  81. $( this ).css( {
  82. 'width': '',
  83. 'margin-right': '',
  84. 'margin-left': ''
  85. } );
  86. }
  87. } );
  88. $( '.caption-big' ).each( function() {
  89. if( $( window ).width() < 960 ) {
  90. $( this ).css( 'max-width', '200%' );
  91. } else {
  92. $( this ).css( 'max-width', '' );
  93. }
  94. } );
  95. $( '.image-big' ).each( function() {
  96. if( $( window ).width() < 768 ) {
  97. $( this ).parents( '.image-big-wrapper' ).css( {
  98. 'display': 'block',
  99. 'width': '100%',
  100. } ).css( 'width', '+=40px' );
  101. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  102. $( this ).parents( '.image-big-wrapper' ).css( 'margin-right', '-20px' );
  103. } else {
  104. $( this ).parents( '.image-big-wrapper' ).css( 'margin-left', '-20px' );
  105. }
  106. } else if( $( window ).width() < 960 ) {
  107. $( this ).parents( '.image-big-wrapper' ).css( {
  108. 'display': 'block',
  109. 'width': '100%',
  110. } ).css( 'width', '+=80px' );
  111. if ( $( 'body' ).hasClass( 'rtl' ) ) {
  112. $( this ).parents( '.image-big-wrapper' ).css( 'margin-right', '-40px' );
  113. } else {
  114. $( this ).parents( '.image-big-wrapper' ).css( 'margin-left', '-40px' );
  115. }
  116. } else {
  117. $( this ).parents( '.image-big-wrapper' ).css( {
  118. 'display': '',
  119. 'width': '',
  120. 'margin-right': '',
  121. 'margin-left': ''
  122. } );
  123. }
  124. } );
  125. }
  126. /*
  127. * Wrap sharedaddy in a div and move it after entry-header for aside, quote and status post format.
  128. */
  129. function sharedaddy() {
  130. $( '.hentry.format-aside .entry-content > .sharedaddy, .hentry.format-quote .entry-content > .sharedaddy, .hentry.format-status .entry-content > .sharedaddy' ).each( function() {
  131. $( this ).wrap( '<div class="entry-sharedaddy" />' );
  132. } );
  133. $( '.entry-sharedaddy' ).each( function() {
  134. $( this ).insertAfter( $( this ).closest( '.hentry' ).find( '.entry-header' ) );
  135. } );
  136. }
  137. /*
  138. * Load all the functions.
  139. */
  140. function load_functions() {
  141. primary_nav();
  142. image_post_format();
  143. audio_post_format();
  144. content();
  145. calc();
  146. sharedaddy();
  147. }
  148. $( window ).load( load_functions ).resize( _.debounce( load_functions, 100 ) );
  149. $( document ).on( 'post-load', load_functions );
  150. } )( jQuery );