customizer-controls.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Customizer controls
  3. *
  4. * @package Astra
  5. */
  6. ( function( $ ) {
  7. /* Internal shorthand */
  8. var api = wp.customize;
  9. /**
  10. * Helper class for the main Customizer interface.
  11. *
  12. * @since 1.0.0
  13. * @class ASTCustomizer
  14. */
  15. ASTCustomizer = {
  16. controls : {},
  17. /**
  18. * Initializes our custom logic for the Customizer.
  19. *
  20. * @since 1.0.0
  21. * @method init
  22. */
  23. init: function()
  24. {
  25. ASTCustomizer._initToggles();
  26. },
  27. /**
  28. * Initializes the logic for showing and hiding controls
  29. * when a setting changes.
  30. *
  31. * @since 1.0.0
  32. * @access private
  33. * @method _initToggles
  34. */
  35. _initToggles: function()
  36. {
  37. // Trigger the Adv Tab Click trigger.
  38. ASTControlTrigger.triggerHook( 'astra-toggle-control', api );
  39. // Loop through each setting.
  40. $.each( ASTCustomizerToggles, function( settingId, toggles ) {
  41. // Get the setting object.
  42. api( settingId, function( setting ) {
  43. // Loop though the toggles for the setting.
  44. $.each( toggles, function( i, toggle ) {
  45. // Loop through the controls for the toggle.
  46. $.each( toggle.controls, function( k, controlId ) {
  47. // Get the control object.
  48. api.control( controlId, function( control ) {
  49. // Define the visibility callback.
  50. var visibility = function( to ) {
  51. control.container.toggle( toggle.callback( to ) );
  52. };
  53. // Init visibility.
  54. visibility( setting.get() );
  55. // Bind the visibility callback to the setting.
  56. setting.bind( visibility );
  57. });
  58. });
  59. });
  60. });
  61. });
  62. }
  63. };
  64. $( function() { ASTCustomizer.init(); } );
  65. })( jQuery );
  66. ( function( api ) {
  67. // Extends our custom astra-pro section.
  68. api.sectionConstructor['astra-pro'] = api.Section.extend( {
  69. // No events for this type of section.
  70. attachEvents: function () {},
  71. // Always make the section active.
  72. isContextuallyActive: function () {
  73. return true;
  74. }
  75. } );
  76. } )( wp.customize );