pen-backend.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ;( function() {
  2. jQuery( document ).ready(
  3. function( $ ) {
  4. if ( $( '#pen_configuration' ).length ) {
  5. var pen_has_AreYouSure = typeof areYouSure;
  6. if ( pen_has_AreYouSure !== 'undefined' && pen_has_AreYouSure !== undefined && pen_has_AreYouSure !== null ) {
  7. $( '#pen_configuration' ).areYouSure( { message: pen_backend_js.text.unsaved_changes } );
  8. }
  9. } else {
  10. var $post_meta = $( '#pen_post_meta' );
  11. $( '#pen_post_meta_hint' ).hide();
  12. $( '#pen_meta_box h2' ).prepend( '<span class="pen_only">' + pen_backend_js.text.pen_theme + '</span>' )
  13. .find( '.pen_only' ).attr( 'title', $( '#pen_post_meta_hint' ).text() );
  14. $post_meta.find( '.postbox select' ).each(
  15. function() {
  16. var $select = $( this );
  17. pen_post_meta_select( $select );
  18. $select.on(
  19. 'change',
  20. function() {
  21. pen_post_meta_select( $select );
  22. $select.closest( '.pen_post_meta_container' ).slideDown( 'fast' ).removeClass( 'closed' ).attr( 'aria-expanded', true )
  23. .closest( '.pen_post_meta_options' ).removeClass( 'closed' );
  24. }
  25. );
  26. }
  27. );
  28. function pen_post_meta_select( $select ) {
  29. var id = $select.attr( 'id' ),
  30. value_current = $select.val();
  31. if ( $( '#apply_' + id ).length ) {
  32. var value_new = $( '#apply_' + id ).val();
  33. if ( value_new != value_current ) {
  34. var $option = $( '#apply_' + id );
  35. $option.prop( 'disabled', false )
  36. .closest( 'tr' ).find( '.button' ).removeClass( 'disabled' );
  37. }
  38. }
  39. if ( value_current === 'no' ) {
  40. $select.parent().addClass( 'pen_post_meta_disable' ).removeClass( 'pen_post_meta_enable' );
  41. if ( id === 'pen_content_thumbnail_display_override' || id === 'pen_list_thumbnail_display_override' ) {
  42. $select.closest( '.pen_wrap' ).siblings( '.pen_wrap' ).filter( ':not(:first-of-type)' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  43. if ( id === 'pen_list_thumbnail_display_override' ) {
  44. $( '#pen_list_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  45. }
  46. if ( id === 'pen_content_thumbnail_display_override' ) {
  47. $( '#pen_content_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  48. }
  49. } else if ( id === 'pen_content_header_display_override' ) {
  50. $( '#pen_content_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  51. } else if ( id === 'pen_list_header_display_override' ) {
  52. $( '#pen_list_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  53. } else if ( id === 'pen_content_header_alignment_override' ) {
  54. $( '#pen_content_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  55. } else if ( id === 'pen_list_post_header_alignment_override' ) {
  56. $( '#pen_list_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  57. }
  58. } else if ( value_current === 'yes' || value_current != 'default' ) {
  59. $select.parent().removeClass( 'pen_post_meta_disable' ).addClass( 'pen_post_meta_enable' );
  60. if ( id === 'pen_content_thumbnail_display_override' || id === 'pen_list_thumbnail_display_override' ) {
  61. $select.closest( '.pen_wrap' ).siblings( '.pen_wrap' ).filter( ':not(:first-of-type)' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  62. if ( id === 'pen_list_thumbnail_display_override' ) {
  63. $( '#pen_list_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  64. }
  65. if ( id === 'pen_content_thumbnail_display_override' ) {
  66. $( '#pen_content_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  67. }
  68. } else if ( id === 'pen_content_header_display_override' ) {
  69. $( '#pen_content_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  70. } else if ( id === 'pen_list_header_display_override' ) {
  71. $( '#pen_list_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  72. } else if ( id === 'pen_content_header_alignment_override' ) {
  73. $( '#pen_content_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  74. } else if ( id === 'pen_list_post_header_alignment_override' ) {
  75. $( '#pen_list_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 0.3 }, { queue: false, duration: 300 } );
  76. }
  77. } else {
  78. $select.parent().removeClass( 'pen_post_meta_enable pen_post_meta_disable' );
  79. if ( id === 'pen_content_thumbnail_display_override' || id === 'pen_list_thumbnail_display_override' ) {
  80. $select.closest( '.pen_wrap' ).siblings( '.pen_wrap' ).filter( ':not(:first-of-type)' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  81. if ( id === 'pen_list_thumbnail_display_override' ) {
  82. $( '#pen_list_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  83. }
  84. if ( id === 'pen_content_thumbnail_display_override' ) {
  85. $( '#pen_content_thumbnail_animation_reveal_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  86. }
  87. } else if ( id === 'pen_content_header_display_override' ) {
  88. $( '#pen_content_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  89. } else if ( id === 'pen_list_header_display_override' ) {
  90. $( '#pen_list_title_display_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  91. } else if ( id === 'pen_content_header_alignment_override' ) {
  92. $( '#pen_content_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  93. } else if ( id === 'pen_list_post_header_alignment_override' ) {
  94. $( '#pen_list_title_alignment_override' ).closest( '.pen_wrap' ).animate( { opacity: 1 }, { queue: false, duration: 300 } );
  95. }
  96. }
  97. }
  98. $post_meta.find( '.pen_sidebars input' ).each(
  99. function() {
  100. var $checkbox = $( this );
  101. pen_post_meta_sidebars( $checkbox );
  102. $checkbox.on(
  103. 'change',
  104. function() {
  105. pen_post_meta_sidebars( $checkbox );
  106. $checkbox.closest( '.pen_post_meta_container' ).slideDown( 'fast' ).removeClass( 'closed' ).attr( 'aria-expanded', true )
  107. .closest( '.pen_post_meta_options' ).removeClass( 'closed' );
  108. }
  109. );
  110. }
  111. );
  112. function pen_post_meta_sidebars( $checkbox ) {
  113. var $option = $( '#apply_' + $checkbox.attr( 'id' ) ),
  114. $button = $option.closest( 'tr' ).find( '.button' );
  115. if ( $checkbox.is( ':checked' ) ) {
  116. $checkbox.parent().addClass( 'pen_post_meta_disable' );
  117. $option.prop( 'disabled', true ).removeAttr( 'checked' ).prop( 'checked', false ).trigger( 'change' );
  118. $button.addClass( 'disabled' );
  119. } else {
  120. $checkbox.parent().removeClass( 'pen_post_meta_disable' );
  121. $option.prop( 'disabled', false );
  122. $button.removeClass( 'disabled' );
  123. }
  124. }
  125. $post_meta.find( 'h3' ).each(
  126. function() {
  127. var $h3 = $( this ),
  128. $container = $h3.next( '.pen_post_meta_container' );
  129. $h3.append( '<button type="button" class="handlediv button-link"><span class="screen-reader-text">' + pen_backend_js.text.toggle + '</span><span class="toggle-indicator" aria-hidden="true"></span></button>' );
  130. if ( ! $container.find( '.pen_post_meta_enable,.pen_post_meta_disable' ).length ) {
  131. $container.slideUp( 'fast' ).addClass( 'closed' ).attr( 'aria-expanded', false )
  132. .closest( '.pen_post_meta_options' ).addClass( 'closed' );
  133. }
  134. $h3.on(
  135. 'click',
  136. function() {
  137. var $container = $( this ).closest( '.pen_post_meta_options' ).find( '.pen_post_meta_container' );
  138. pen_options_expanded( $container );
  139. }
  140. );
  141. }
  142. );
  143. function pen_options_expanded( $container ) {
  144. if ( $container.hasClass( 'closed' ) ) {
  145. $container.slideDown( 'fast' ).removeClass( 'closed' ).closest( '.pen_post_meta_options' ).removeClass( 'closed' )
  146. .prev( 'h3' ).find( '.handlediv' ).attr( 'aria-expanded', 'true' );
  147. } else {
  148. $container.slideUp( 'fast' ).addClass( 'closed' ).closest( '.pen_post_meta_options' ).addClass( 'closed' )
  149. .prev( 'h3' ).find( '.handlediv' ).attr( 'aria-expanded', 'false' );
  150. }
  151. }
  152. }
  153. }
  154. );
  155. } )( jQuery );