'VE Column', 'description'=>'Row description', 'icon_class'=>"fa fa-columns", 'container'=>true, 'container_element'=>true,//can contain element directly 'lv'=>2, ); parent::__construct($id_base,$name,$options); } function init(){ $this->support('CssEditor'); } function element($instance,$content=''){ $width=isset($instance['width'])?$instance['width']:'1/1'; $offset = isset($instance['offset'])?$instance['offset']:'0/12'; $font_color=isset($instance['font_color'])?$instance['font_color']:''; $this->css('color',$font_color); $this->addClass($this->get_width_class($width)); if($offset) { if($this->get_width_class($offset,'')){ $this->addClass($this->get_width_class($offset, 've-col-md-offset-')); } } if(isset($instance['class'])){ $this->addClass($instance['class']); } if(empty($content)){ $this->addClass('ve_front_empty'); } echo do_shortcode($content); } function get_width_class($width,$prefix = 've-col-sm-'){ $width=$this->convertWidth($width); if ( preg_match( '/^(\d{1,2})\/12$/', $width, $match ) ) { $w = $prefix.$match[1]; } else { $w = $prefix; switch ( $width ) { case "1/6" : $w .= '2'; break; case "1/4" : $w .= '3'; break; case "1/3" : $w .= '4'; break; case "1/2" : $w .= '6'; break; case "2/3" : $w .= '8'; break; case "3/4" : $w .= '9'; break; case "5/6" : $w .= '10'; break; case "1/1" : $w .= '12'; break; default : $w = $width; } } return $w; } function convertWidth($width) { $width_parts = explode('/',$width); if (count($width_parts) == 1) { $width_parts[1] = '12'; } if ($width_parts[1] != "12") { $width_parts[0] = intval((12 * intval($width_parts[0])) / intval($width_parts[1])); $width_parts[1] = 12; } return "{$width_parts[0]}/{$width_parts[1]}"; } function form($instance,$content=''){ $instance=shortcode_atts(array( 'font_color'=>'', 'class'=>'', 'width'=>'12/12', 'offset' => '0/12' ),$instance); $font_color=$instance['font_color']; $class=esc_attr($instance['class']); $instance["width"] = $this->convertWidth($instance["width"]); ?>