Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. $wp_customize->add_setting( 'boxed_body_border_width', array(
  2. 'default' => '0',
  3. 'transport' => 'postMessage',
  4. 'sanitize_callback' => 'mytheme_sanitize_integer',
  5. ) );
  6. $wp_customize->add_control(new Slider_Control( $wp_customize, 'boxed_body_border_width', array(
  7. 'label' => esc_html__( 'Boxed Body Border Width (px)', 'mytheme' ),
  8. 'section' => 'section_general',
  9. ) ) );
  10.  
  11. /**
  12. * Slider custom control
  13. *
  14. * @package WordPress
  15. * @subpackage inc/customizer
  16. * @version 1.0.0
  17. * @author dingo_d
  18. * @license https://www.gnu.org/licenses/gpl-3.0.txt GNU/GPLv3
  19. * @since 1.0.0
  20. */
  21. class Slider_Control extends WP_Customize_Control {
  22. /**
  23. * Control type
  24. *
  25. * @var string
  26. */
  27. public $type = 'slider_control';
  28. /**
  29. * Control scripts and styles enqueue
  30. *
  31. * @since 1.0.0
  32. */
  33. public function enqueue() {
  34. wp_enqueue_script( 'custom_controls', UTTER_TEMPPATH . '/inc/customizer/js/custom-controls.js', array( 'jquery', 'jquery-ui-slider' ), UTTER_THEME_VERSION, true );
  35. wp_enqueue_style( 'custom_controls_css', UTTER_TEMPPATH . '/inc/customizer/css/custom-controls.css' );
  36. }
  37. /**
  38. * Control method
  39. *
  40. * @since 1.0.0
  41. */
  42. public function render_content() {
  43. ?>
  44. <div class="slider_control">
  45. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?><span class="slider_value"><?php echo esc_attr( $this->value() ); ?></span></span>
  46. <p><?php echo esc_html( $this->description ); ?></p>
  47. <input class="slider_input" type="text" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" data-customize-setting-link="<?php echo esc_attr( $this->id ); ?>" />
  48. <div class="slider-range"></div>
  49. </div>
  50. <?php
  51. }
  52. }
  53.  
  54. /********* Slider Custom control ***********/
  55. $('.slider-range').slider({
  56. range: "min",
  57. value: 0,
  58. step: 1,
  59. min: 0,
  60. max: 100,
  61. slide: function(event, ui) {
  62. var $this = $(this);
  63. $this.parent().find('.slider_input').attr('value', ui.value);
  64. $this.parent().find('.slider_value').html(ui.value)
  65. .trigger('change');
  66. }
  67. });
  68.  
  69. /* Slider */
  70. .slider_value{
  71. margin-left: 20px;
  72. }
  73.  
  74. .ui-slider {
  75. position: relative;
  76. text-align: left;
  77. margin-top: 20px;
  78. background: #ddd;
  79. border-radius: 2px;
  80. }
  81. .ui-slider .ui-slider-handle {
  82. position: absolute;
  83. z-index: 2;
  84. width: 1.2em;
  85. height: 1.2em;
  86. cursor: default;
  87. border: 1px solid #ccc;
  88. background: #fff;
  89. border-radius: 5px;
  90. -ms-touch-action: none;
  91. touch-action: none;
  92. }
  93. .ui-slider .ui-slider-range {
  94. position: absolute;
  95. z-index: 1;
  96. font-size: .7em;
  97. display: block;
  98. border: 0;
  99. background-position: 0 0;
  100. }
  101.  
  102. /* support: IE8 - See #6727 */
  103. .ui-slider.ui-state-disabled .ui-slider-handle,
  104. .ui-slider.ui-state-disabled .ui-slider-range {
  105. filter: inherit;
  106. }
  107.  
  108. .ui-slider-horizontal {
  109. height: .8em;
  110. }
  111. .ui-slider-horizontal .ui-slider-handle {
  112. top: -.3em;
  113. margin-left: -.6em;
  114. }
  115. .ui-slider-horizontal .ui-slider-range {
  116. top: 0;
  117. height: 100%;
  118. }
  119. .ui-slider-horizontal .ui-slider-range-min {
  120. left: 0;
  121. }
  122. .ui-slider-horizontal .ui-slider-range-max {
  123. right: 0;
  124. }
  125.  
  126. .ui-slider-vertical {
  127. width: .8em;
  128. height: 100px;
  129. }
  130. .ui-slider-vertical .ui-slider-handle {
  131. left: -.3em;
  132. margin-left: 0;
  133. margin-bottom: -.6em;
  134. }
  135. .ui-slider-vertical .ui-slider-range {
  136. left: 0;
  137. width: 100%;
  138. }
  139. .ui-slider-vertical .ui-slider-range-min {
  140. bottom: 0;
  141. }
  142. .ui-slider-vertical .ui-slider-range-max {
  143. top: 0;
  144. }
  145.  
  146. function mytheme_dynamic_css_targets( value ) {
  147. var css_styles_targets = '<style id="customizer_dynamic_color_css_' + value + '" type="text/css"></style>';
  148. if ( ! $( '#customizer_dynamic_color_css_' + value ).length) {
  149. $( '#mytheme_main_css-inline-css' ).after( css_styles_targets );
  150. }
  151. }
  152.  
  153. // Boxed Body Border width
  154. wp.customize( 'boxed_body_border_width', function(value) {
  155. value.bind(function(newval) {
  156. mytheme_dynamic_css_targets( 'boxed_body_border_width' );
  157. var width = '.boxed_body_wrapper{border-right-width: ' + newval + '; border-left-width: ' + newval + ';}';
  158. $( '#customizer_dynamic_color_css_boxed_body_border_width' ).text( width );
  159.  
  160. });
  161. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement