controls-conditionals.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* jshint esnext:true */
  2. (function($, undefined) {
  3. 'use strict';
  4. var api = wp.customize;
  5. // toggle visibility of some controls based on a setting's value
  6. // @see wp-admin/js/customize-controls.js
  7. $.each({
  8. 'vamtam_theme[header-logo-type]': [
  9. {
  10. controls: [ 'vamtam_theme[custom-header-logo]' ],
  11. callback: function( to ) { return 'image' === to; }
  12. },
  13. ],
  14. 'vamtam_theme[site-layout-type]': [
  15. {
  16. controls: [ 'vamtam_theme[full-width-header]' ],
  17. callback: function( to ) { return 'boxed' !== to; }
  18. },
  19. {
  20. controls: [ 'vamtam_theme[boxed-layout-padding]', ],
  21. callback: function( to ) { return 'boxed' === to; }
  22. },
  23. ],
  24. 'vamtam_theme[header-layout]': [
  25. {
  26. controls: [ 'vamtam_theme[full-width-header]' ],
  27. callback: function( to ) { return 'logo-menu' === to; } // show if header is 'logo-menu'
  28. },
  29. {
  30. controls: [ 'vamtam_theme[sub-header-background]' ],
  31. callback: function( to ) { return 'logo-menu' !== to; } // show if header is not 'logo-menu'
  32. },
  33. ],
  34. 'vamtam_theme[top-bar-layout]': [
  35. {
  36. controls: [
  37. 'vamtam_theme[top-bar-social-lead]',
  38. 'vamtam_theme[top-bar-social-fb]',
  39. 'vamtam_theme[top-bar-social-twitter]',
  40. 'vamtam_theme[top-bar-social-linkedin]',
  41. 'vamtam_theme[top-bar-social-gplus]',
  42. 'vamtam_theme[top-bar-social-flickr]',
  43. 'vamtam_theme[top-bar-social-pinterest]',
  44. 'vamtam_theme[top-bar-social-dribbble]',
  45. 'vamtam_theme[top-bar-social-instagram]',
  46. 'vamtam_theme[top-bar-social-youtube]',
  47. 'vamtam_theme[top-bar-social-vimeo]',
  48. ],
  49. callback: function( to ) {
  50. return [ 'menu-social', 'social-menu', 'social-text', 'text-social' ].indexOf( to ) > -1;
  51. }
  52. },
  53. {
  54. controls: [
  55. 'vamtam_theme[top-bar-text]',
  56. ],
  57. callback: function( to ) {
  58. return [ 'menu-text', 'text-menu', 'social-text', 'text-social', 'fulltext' ].indexOf( to ) > -1;
  59. }
  60. },
  61. ],
  62. }, ( settingId, conditions ) => {
  63. api( settingId, setting => {
  64. $.each( conditions, ( cndi, o ) => {
  65. $.each( o.controls, ( i, controlId ) => {
  66. api.control( controlId, ( control ) => {
  67. var visibility = ( to ) => {
  68. control.container.toggle( o.callback( to ) );
  69. };
  70. visibility( setting.get() );
  71. setting.bind( visibility );
  72. });
  73. });
  74. } );
  75. });
  76. });
  77. })(jQuery);