pen-customize-main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Theme Customizer enhancements for a better user experience.
  3. *
  4. * @package Pen
  5. */
  6. ;( function( $ ) {
  7. wp.customize.bind(
  8. 'ready',
  9. function() {
  10. var pen_customize_url_home = wp.customize.settings.url.home;
  11. if ( pen_customize_js.preset_preview ) {
  12. pen_customize_url_home += '?pen_preview_color=' + pen_customize_js.preset_color + '&pen_preview_font=' + pen_customize_js.preset_font;
  13. /*
  14. * If the user wanted to save the preset there has to be no need to
  15. * change anything to have the "Publish" button enabled.
  16. */
  17. wp.customize.state( 'saved' ).set( false );
  18. }
  19. wp.customize.previewer.previewUrl.set( pen_customize_url_home );
  20. var _query = wp.customize.previewer.query;
  21. wp.customize.previewer.query = function () {
  22. var query = _query.call( this );
  23. if ( pen_customize_js.preset_preview ) {
  24. query.pen_preview_color = pen_customize_js.preset_color;
  25. query.pen_preview_font = pen_customize_js.preset_font;
  26. }
  27. return query;
  28. };
  29. var sections = [
  30. 'pen_section_colors_header,#pen_header',
  31. 'pen_section_colors_navigation,#pen_navigation',
  32. 'pen_section_colors_search,#pen_search',
  33. 'pen_section_colors_content,#primary',
  34. 'pen_section_colors_list,#primary',
  35. 'pen_section_colors_bottom,#pen_bottom',
  36. 'pen_section_colors_footer,#pen_footer',
  37. 'pen_section_typography_header,#pen_header',
  38. 'pen_section_typography_footer,#pen_footer',
  39. 'pen_section_typography_navigation,#pen_navigation',
  40. 'pen_section_header_general,#pen_header',
  41. 'title_tagline,#pen_header',
  42. 'pen_section_header_search,#pen_header',
  43. 'pen_section_header_navigation,#pen_navigation',
  44. 'pen_section_content,#primary',
  45. 'pen_section_layout,#primary',
  46. 'pen_section_list,#primary',
  47. 'pen_section_layout,#primary',
  48. 'pen_section_background_image_navigation,#pen_navigation',
  49. 'pen_section_background_image_search,#pen_search',
  50. 'pen_section_background_image_bottom,#pen_bottom',
  51. 'pen_section_background_image_footer,#pen_footer',
  52. 'pen_section_footer,#pen_footer'
  53. ];
  54. for ( i = 0; i < sections.length; i++ ) {
  55. var data = sections[ i ].split( ',' ),
  56. section_id = data[0],
  57. selector = data[1];
  58. pen_section_change( section_id, selector );
  59. }
  60. function pen_section_change( section_id, html_id ) {
  61. wp.customize.section(
  62. section_id,
  63. function( section ) {
  64. section.expanded.bind(
  65. function( is_expanding ) {
  66. if ( is_expanding ) {
  67. wp.customize.previewer.send( 'pen_section_change', { selector: html_id } );
  68. }
  69. }
  70. );
  71. }
  72. );
  73. }
  74. wp.customize.previewer.bind(
  75. 'pen_switch_section',
  76. function( data ) {
  77. if ( data.type === 'section' ) {
  78. var $container = wp.customize.section( data.target );
  79. }
  80. if ( data.type === 'panel' ) {
  81. var $container = wp.customize.panel( data.target );
  82. }
  83. if ( $container !== 'undefined' && $container !== undefined && $container !== null ) {
  84. $container.focus();
  85. } else {
  86. console.log( 'Not found: ' + data.target );
  87. }
  88. }
  89. );
  90. wp.customize.section(
  91. 'static_front_page',
  92. function( section ) {
  93. pen_switch_to_front( section );
  94. }
  95. );
  96. wp.customize.section(
  97. 'pen_section_front_sidebars',
  98. function( section ) {
  99. pen_switch_to_front( section );
  100. }
  101. );
  102. function pen_switch_to_front( section ) {
  103. var previous_url,
  104. clear_previous_url = function() {
  105. previous_url = null;
  106. },
  107. preview_url_value = wp.customize.previewer.previewUrl;
  108. section.expanded.bind(
  109. function( is_expanded ) {
  110. var url;
  111. if ( is_expanded ) {
  112. url = wp.customize.settings.url.home;
  113. previous_url = preview_url_value.get();
  114. preview_url_value.set( url );
  115. preview_url_value.bind( clear_previous_url );
  116. } else {
  117. preview_url_value.unbind( clear_previous_url );
  118. if ( previous_url ) {
  119. preview_url_value.set( previous_url );
  120. }
  121. }
  122. }
  123. );
  124. }
  125. $( '#customize-info .accordion-section-title' ).append( '<p><a href="' + pen_customize_js.support_url + '" title="' + pen_customize_js.text.support_description + '" class="button" target="_blank">' + pen_customize_js.text.support_text + '</a></p>' );
  126. $( "li[id^=accordion-panel-pen_]" ).add( $( "li[id^=accordion-section-pen_]" ) )
  127. .children( '.accordion-section-title' )
  128. .prepend( '<span style="background:#7f7f7f;border-radius:300px;color:#fff;box-shadow:1px 1px 3px rgba(0,0,0,0.75) inset;cursor:help;display:inline-block;font-size:smaller;font-weight:bold;margin:0 5px 0 0;padding-left:5px;padding-right:5px;text-shadow:1px 1px 3px rgba(0,0,0,0.5)" title="' + pen_customize_js.text.theme_specific + '">' + pen_customize_js.text.pen_theme + '</span>' );
  129. }
  130. );
  131. } )( jQuery );