/wp-content/themes/generatepress/inc/customizer/controls/class-range-control.php

https://github.com/livinglab/openlab · PHP · 209 lines · 133 code · 27 blank · 49 comment · 3 complexity · 949af7a15903c17b4454e49558252bb1 MD5 · raw file

  1. <?php
  2. /**
  3. * The range slider Customizer control.
  4. *
  5. * @package GeneratePress
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit; // Exit if accessed directly.
  9. }
  10. if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'Generate_Range_Slider_Control' ) ) {
  11. /**
  12. * Create a range slider control.
  13. * This control allows you to add responsive settings.
  14. *
  15. * @since 1.3.47
  16. */
  17. class Generate_Range_Slider_Control extends WP_Customize_Control {
  18. /**
  19. * The control type.
  20. *
  21. * @access public
  22. * @var string
  23. */
  24. public $type = 'generatepress-range-slider';
  25. /**
  26. * The control description.
  27. *
  28. * @access public
  29. * @var string
  30. */
  31. public $description = '';
  32. /**
  33. * The control sub-description.
  34. *
  35. * @access public
  36. * @var string
  37. */
  38. public $sub_description = '';
  39. /**
  40. * Refresh the parameters passed to the JavaScript via JSON.
  41. *
  42. * @see WP_Customize_Control::to_json()
  43. */
  44. public function to_json() {
  45. parent::to_json();
  46. $devices = array( 'desktop', 'tablet', 'mobile' );
  47. foreach ( $devices as $device ) {
  48. $this->json['choices'][ $device ]['min'] = ( isset( $this->choices[ $device ]['min'] ) ) ? $this->choices[ $device ]['min'] : '0';
  49. $this->json['choices'][ $device ]['max'] = ( isset( $this->choices[ $device ]['max'] ) ) ? $this->choices[ $device ]['max'] : '100';
  50. $this->json['choices'][ $device ]['step'] = ( isset( $this->choices[ $device ]['step'] ) ) ? $this->choices[ $device ]['step'] : '1';
  51. $this->json['choices'][ $device ]['edit'] = ( isset( $this->choices[ $device ]['edit'] ) ) ? $this->choices[ $device ]['edit'] : false;
  52. $this->json['choices'][ $device ]['unit'] = ( isset( $this->choices[ $device ]['unit'] ) ) ? $this->choices[ $device ]['unit'] : false;
  53. }
  54. foreach ( $this->settings as $setting_key => $setting_id ) {
  55. $this->json[ $setting_key ] = array(
  56. 'link' => $this->get_link( $setting_key ),
  57. 'value' => $this->value( $setting_key ),
  58. 'default' => isset( $setting_id->default ) ? $setting_id->default : '',
  59. );
  60. }
  61. $this->json['desktop_label'] = __( 'Desktop', 'generatepress' );
  62. $this->json['tablet_label'] = __( 'Tablet', 'generatepress' );
  63. $this->json['mobile_label'] = __( 'Mobile', 'generatepress' );
  64. $this->json['reset_label'] = __( 'Reset', 'generatepress' );
  65. $this->json['description'] = $this->description;
  66. $this->json['sub_description'] = $this->sub_description;
  67. }
  68. /**
  69. * Enqueue control related scripts/styles.
  70. *
  71. * @access public
  72. */
  73. public function enqueue() {
  74. wp_enqueue_script(
  75. 'generatepress-range-slider',
  76. trailingslashit( get_template_directory_uri() ) . 'inc/customizer/controls/js/slider-control.js',
  77. array(
  78. 'jquery',
  79. 'customize-base',
  80. 'jquery-ui-slider',
  81. ),
  82. GENERATE_VERSION,
  83. true
  84. );
  85. wp_enqueue_style(
  86. 'generatepress-range-slider-css',
  87. trailingslashit( get_template_directory_uri() ) . 'inc/customizer/controls/css/slider-customizer.css',
  88. array(),
  89. GENERATE_VERSION
  90. );
  91. }
  92. /**
  93. * An Underscore (JS) template for this control's content (but not its container).
  94. *
  95. * Class variables for this control class are available in the `data` JS object;
  96. * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
  97. *
  98. * @see WP_Customize_Control::print_template()
  99. *
  100. * @access protected
  101. */
  102. protected function content_template() {
  103. ?>
  104. <div class="generatepress-range-slider-control">
  105. <div class="gp-range-title-area">
  106. <# if ( data.label || data.description ) { #>
  107. <div class="gp-range-title-info">
  108. <# if ( data.label ) { #>
  109. <span class="customize-control-title">{{{ data.label }}}</span>
  110. <# } #>
  111. <# if ( data.description ) { #>
  112. <p class="description">{{{ data.description }}}</p>
  113. <# } #>
  114. </div>
  115. <# } #>
  116. <div class="gp-range-slider-controls">
  117. <span class="gp-device-controls">
  118. <# if ( 'undefined' !== typeof ( data.desktop ) ) { #>
  119. <span class="generatepress-device-desktop dashicons dashicons-desktop" data-option="desktop" title="{{ data.desktop_label }}"></span>
  120. <# } #>
  121. <# if ( 'undefined' !== typeof (data.tablet) ) { #>
  122. <span class="generatepress-device-tablet dashicons dashicons-tablet" data-option="tablet" title="{{ data.tablet_label }}"></span>
  123. <# } #>
  124. <# if ( 'undefined' !== typeof (data.mobile) ) { #>
  125. <span class="generatepress-device-mobile dashicons dashicons-smartphone" data-option="mobile" title="{{ data.mobile_label }}"></span>
  126. <# } #>
  127. </span>
  128. <span title="{{ data.reset_label }}" class="generatepress-reset dashicons dashicons-image-rotate"></span>
  129. </div>
  130. </div>
  131. <div class="gp-range-slider-areas">
  132. <# if ( 'undefined' !== typeof ( data.desktop ) ) { #>
  133. <label class="range-option-area" data-option="desktop" style="display: none;">
  134. <div class="wrapper <# if ( '' !== data.choices['desktop']['unit'] ) { #>has-unit<# } #>">
  135. <div class="generatepress-slider" data-step="{{ data.choices['desktop']['step'] }}" data-min="{{ data.choices['desktop']['min'] }}" data-max="{{ data.choices['desktop']['max'] }}"></div>
  136. <div class="gp_range_value <# if ( '' == data.choices['desktop']['unit'] && ! data.choices['desktop']['edit'] ) { #>hide-value<# } #>">
  137. <input <# if ( data.choices['desktop']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> type="number" step="{{ data.choices['desktop']['step'] }}" class="desktop-range value" value="{{ data.desktop.value }}" min="{{ data.choices['desktop']['min'] }}" max="{{ data.choices['desktop']['max'] }}" {{{ data.desktop.link }}} data-reset_value="{{ data.desktop.default }}" />
  138. <span <# if ( ! data.choices['desktop']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> class="value">{{ data.desktop.value }}</span>
  139. <# if ( data.choices['desktop']['unit'] ) { #>
  140. <span class="unit">{{ data.choices['desktop']['unit'] }}</span>
  141. <# } #>
  142. </div>
  143. </div>
  144. </label>
  145. <# } #>
  146. <# if ( 'undefined' !== typeof ( data.tablet ) ) { #>
  147. <label class="range-option-area" data-option="tablet" style="display:none">
  148. <div class="wrapper <# if ( '' !== data.choices['tablet']['unit'] ) { #>has-unit<# } #>">
  149. <div class="generatepress-slider" data-step="{{ data.choices['tablet']['step'] }}" data-min="{{ data.choices['tablet']['min'] }}" data-max="{{ data.choices['tablet']['max'] }}"></div>
  150. <div class="gp_range_value <# if ( '' == data.choices['tablet']['unit'] && ! data.choices['desktop']['edit'] ) { #>hide-value<# } #>">
  151. <input <# if ( data.choices['tablet']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> type="number" step="{{ data.choices['tablet']['step'] }}" class="tablet-range value" value="{{ data.tablet.value }}" min="{{ data.choices['tablet']['min'] }}" max="{{ data.choices['tablet']['max'] }}" {{{ data.tablet.link }}} data-reset_value="{{ data.tablet.default }}" />
  152. <span <# if ( ! data.choices['tablet']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> class="value">{{ data.tablet.value }}</span>
  153. <# if ( data.choices['tablet']['unit'] ) { #>
  154. <span class="unit">{{ data.choices['tablet']['unit'] }}</span>
  155. <# } #>
  156. </div>
  157. </div>
  158. </label>
  159. <# } #>
  160. <# if ( 'undefined' !== typeof ( data.mobile ) ) { #>
  161. <label class="range-option-area" data-option="mobile" style="display:none;">
  162. <div class="wrapper <# if ( '' !== data.choices['mobile']['unit'] ) { #>has-unit<# } #>">
  163. <div class="generatepress-slider" data-step="{{ data.choices['mobile']['step'] }}" data-min="{{ data.choices['mobile']['min'] }}" data-max="{{ data.choices['mobile']['max'] }}"></div>
  164. <div class="gp_range_value <# if ( '' == data.choices['mobile']['unit'] && ! data.choices['desktop']['edit'] ) { #>hide-value<# } #>">
  165. <input <# if ( data.choices['mobile']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> type="number" step="{{ data.choices['mobile']['step'] }}" class="mobile-range value" value="{{ data.mobile.value }}" min="{{ data.choices['mobile']['min'] }}" max="{{ data.choices['mobile']['max'] }}" {{{ data.mobile.link }}} data-reset_value="{{ data.mobile.default }}" />
  166. <span <# if ( ! data.choices['mobile']['edit'] ) { #>style="display:inline-block;"<# } else { #>style="display:none;"<# } #> class="value">{{ data.mobile.value }}</span>
  167. <# if ( data.choices['mobile']['unit'] ) { #>
  168. <span class="unit">{{ data.choices['mobile']['unit'] }}</span>
  169. <# } #>
  170. </div>
  171. </div>
  172. </label>
  173. <# } #>
  174. </div>
  175. <# if ( data.sub_description ) { #>
  176. <p class="description sub-description">{{{ data.sub_description }}}</p>
  177. <# } #>
  178. </div>
  179. <?php
  180. }
  181. }
  182. }