-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathclass-customizer-toggle-control.php
More file actions
85 lines (77 loc) · 2.43 KB
/
class-customizer-toggle-control.php
File metadata and controls
85 lines (77 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class Customizer_Toggle_Control extends \WP_Customize_Control {
public $type = 'ios';
/**
* Enqueue scripts/styles.
*
* @since 3.4.0
*/
public function enqueue() {
wp_enqueue_script( 'customizer-toggle-control', $this->abs_path_to_url( dirname( __FILE__ ) . '/js/customizer-toggle-control.js' ), array( 'jquery' ), rand(), true );
wp_enqueue_style( 'pure-css-toggle-buttons', $this->abs_path_to_url( dirname( __FILE__ ) . '/pure-css-toggle-buttons/pure-css-togle-buttons.css' ), array(), rand() );
$css = '
.disabled-control-title {
color: #a0a5aa;
}
input[type=checkbox].tgl-light:checked + .tgl-btn {
background: #0085ba;
}
input[type=checkbox].tgl-light + .tgl-btn {
background: #a0a5aa;
}
input[type=checkbox].tgl-light + .tgl-btn:after {
background: #f7f7f7;
}
input[type=checkbox].tgl-ios:checked + .tgl-btn {
background: #0085ba;
}
input[type=checkbox].tgl-flat:checked + .tgl-btn {
border: 4px solid #0085ba;
}
input[type=checkbox].tgl-flat:checked + .tgl-btn:after {
background: #0085ba;
}
';
wp_add_inline_style( 'pure-css-toggle-buttons', $css );
}
/**
* Render the control's content.
*
* @author soderlind
* @version 1.2.0
*/
public function render_content() {
?>
<label class="customize-toogle-label">
<div style="display:flex;flex-direction: row;justify-content: flex-start;">
<span class="customize-control-title" style="flex: 2 0 0; vertical-align: middle;"><?php echo esc_html( $this->label ); ?></span>
<input id="cb<?php echo $this->instance_number; ?>" type="checkbox" class="tgl tgl-<?php echo $this->type; ?>" value="<?php echo esc_attr( $this->value() ); ?>"
<?php
$this->link();
checked( $this->value() );
?>
/>
<label for="cb<?php echo $this->instance_number; ?>" class="tgl-btn"></label>
</div>
<?php if ( ! empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
</label>
<?php
}
/**
* Plugin / theme agnostic path to URL
*
* @see https://wordpress.stackexchange.com/a/264870/14546
* @param string $path file path
* @return string URL
*/
private function abs_path_to_url( $path = '' ) {
$url = str_replace(
wp_normalize_path( untrailingslashit( ABSPATH ) ),
site_url(),
wp_normalize_path( $path )
);
return esc_url_raw( $url );
}
}