admin管理员组文章数量:1126299
I'am creating a Custom Control on Customizer API, I add Multiple Checkbox as my custom type.
When I wanna add a live preview, the jQuery doesn't find the selector that I want.
Here's functions.php code:
function dziri_customizer_settings( $wp_customize ) {
$wp_customize->add_panel( 'dziri_home_panel', array(
'title' => __( 'Home', 'dziri' ),
'priority' => 10
)
);
$wp_customize->add_section( 'dziri_home_products' , array(
'title' => __( 'Home Page Products Tabs', 'dziri' ),
'priority' => 70,
'panel' => 'dziri_home_panel'
)
);
$wp_customize->add_setting( 'home_products' , array(
'default' => array('new-arrivals', 'featured-products', 'onsale-items'),
'transport' => 'postMessage'
)
);
$wp_customize->get_setting( 'home_products' )->transport = 'postMessage';
$wp_customize->add_control( new Dziri_Customize_Control_Checkbox_Multiple( $wp_customize, 'home_products',
array(
'label' => __( 'Product\'s Tabs', 'dziri' ),
'section' => 'dziri_home_products',
'settings' => 'home_products',
'type' => 'checkbox-multiple',
'sanitize_callback' => 'dziri_checkbox_tabs',
'choices' => array(
'new-arrivals' => 'New Arrivals',
'featured-products' => 'Featured Products',
'onsale-items' => 'On Sale Items',
)
)
)
);
class Dziri_Customize_Control_Checkbox_Multiple extends WP_Customize_Control {
public $type = 'checkbox-multiple';
public function render_content() {
if ( empty( $this->choices ) )
return; ?>
<?php if ( !empty( $this->label ) ) : ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php endif; ?>
<?php if ( !empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
<?php $multi_values = !is_array( $this->value() ) ? explode( ',', $this->value() ) : $this->value(); ?>
<ul>
<?php foreach ( $this->choices as $value => $label ) : ?>
<li>
<label>
<input type="checkbox" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $multi_values ) ); ?> data-customize-setting-link="<?php echo esc_attr( $value ); ?>" />
<?php echo esc_html( $label ); ?>
</label>
</li>
<?php endforeach; ?>
</ul>
<input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( implode( ',', $multi_values ) ); ?>" />
<?php
}
}
function dziri_checkbox_tabs( $values ) {
$multi_values = !is_array( $values ) ? explode( ',', $values ) : $values;
return !empty( $multi_values ) ? array_map( 'sanitize_text_field', $multi_values ) : array();
}
function dziri_theme_preview_register() {
wp_enqueue_script( 'dziri-customize-controls', get_template_directory_uri() . '/assets/js/customize-controls.js', array( 'jquery', 'customize-preview' ), _DZIRI_VERSION, true );
}
add_action( 'customize_preview_init', 'dziri_theme_preview_register' );
And here's my customize-controls.js code:
(function($) {
$(window).load(function() {
console.log($('.customize-control-checkbox-multiple input[type="checkbox"]'));
// My Code Here
})
})(jQuery);
When I check the code by inspecting elements, I find that the tag ".customize-control-checkbox-mutiple" exists:
<li id="customize-control-home_products" class="customize-control customize-control-checkbox-multiple">
<span class="customize-control-title">Product's Tabs</span>
<div class="customize-control-notifications-container"></div>
<ul>
<li>
<label>
<input type="checkbox" value="new-arrivals" checked="checked" data-customize-setting-link="new-arrivals">
New Arrivals
</label>
</li>
<li>
<label>
<input type="checkbox" value="featured-products" checked="checked" data-customize-setting-link="featured-products">
Featured Products
</label>
</li>
<li>
<label>
<input type="checkbox" value="onsale-items" checked="checked" data-customize-setting-link="onsale-items">
On Sale Items
</label>
</li>
</ul>
<input type="hidden" data-customize-setting-link="home_products" value="new-arrivals,featured-products,onsale-items">
</li>
And that's what I get as results on the console:
e.<computed> {length: 0, prevObject: ce.fn.init}
But When I console.log on console directly, I get this results:
e.<computed> {0: input, 1: input, 2: input, length: 3, prevObject: ce.fn.init}
Any help, please?
本文标签: phpCan39t find elemnts on the DOM using Custom Control in Customizer API
版权声明:本文标题:php - Can't find elemnts on the DOM using Custom Control in Customizer API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736630850a1945774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论