option_nature = (in_array($option_nature, $check_nature)) ? $option_nature : 'radio'; parent::__construct( $manager, $id, $args ); } /** * Loads the jQuery UI Button script and custom scripts/styles. * * @since 1.0.0 * @access public * @return void */ public function enqueue(){ //wp_enqueue_script( 'jquery-ui-button' ); wp_enqueue_style( 'dg-customizer-imageoptions-control-css', dglib_directory_uri('assets/parts/controls/css/dg-customizer-imageoptions-control.min.css'), array(), '1.0.0' ); wp_enqueue_script('dg-customizer-imageoptions-control-js', dglib_directory_uri('assets/parts/controls/js/dg-customizer-imageoptions-control.min.js'), array('jquery-ui-button'), '1.0.0', false ); } /** * Add custom JSON parameters to use in the JS template. * * @since 1.0.0 * @access public * @return void */ public function to_json(){ parent::to_json(); // We need to make sure we have the correct image URL. foreach ( $this->choices as $value => $args ) $this->choices[ $value ]['url'] = esc_url( sprintf( $args['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ) ); $this->json['choices'] = $this->choices; $this->json['link'] = $this->get_link(); $this->json['value'] = $this->value(); $this->json['id'] = $this->id; $this->json['option_nature'] = $this->option_nature; } /** * Underscore JS template to handle the control's output. * * @since 1.0.0 * @access public * @return void */ public function content_template() { ?> <# if ( data.label ) { #> {{ data.label }} <# } #> <# if ( data.description ) { #> {{{ data.description }}} <# } #>
<# for ( key in data.choices ) { #> <# if(data.option_nature=='radio') { #> <# var is_checked = ( key == data.value) ? 'checked="checked"' : 'radiofalse'; #> <# }else{ #> <# var imageoption_value = data.value.replace(/"/g,'"'); #> <# var imageoption_value = (imageoption_value) ? imageoption_value : '[]'; #> <# var is_checked = ( _.contains(JSON.parse(imageoption_value), key) ) ? 'checked="checked"' : ''; #> <# } #>
{{{ data.link }}}<# } #> />
<# } #> <# if(data.option_nature=='checkbox') { #> <# } #>