Skip to content

Instantly share code, notes, and snippets.

@danyj
Created December 22, 2017 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyj/30ec82131c7cebe0c563a52de3411c06 to your computer and use it in GitHub Desktop.
Save danyj/30ec82131c7cebe0c563a52de3411c06 to your computer and use it in GitHub Desktop.
<?php if (!defined('FW')) {
die('Forbidden');
}
class FW_Option_Type_Thzanimation extends FW_Option_Type
{
public function get_type()
{
return 'thz-animation';
}
/**
* @internal
*/
public function _get_backend_width_type()
{
return 'full';
}
/**
* @internal
* {@inheritdoc}
*/
protected function _enqueue_static($id, $option, $data)
{
$uri = get_template_directory_uri() . '/inc/includes/option-types/' . $this->get_type();
wp_enqueue_style(
'fw-option-' . $this->get_type(),
$uri . '/static/css/styles.css',
array(),
fw()->theme->manifest->get_version()
);
}
/**
* @internal
*/
protected function _render($id, $option, $data)
{
return fw_render_view(dirname(__FILE__) . '/view.php', array(
'id' => $id,
'option' => $option,
'data' => $data,
'inner_option' => $this->get_inner_option($option)
));
}
/**
* @internal
*/
protected function _get_value_from_input($option, $input_value)
{
if (!is_array($input_value)) {
return $option['value'];
}
$inner_option = $this->get_inner_option($option);
$value = fw()->backend->option_type($inner_option['type'])->get_value_from_input(
$inner_option,
$input_value
);
return array(
'animate' => $value['picked'],
'effect' => $value['active']['effect'],
'duration' => $value['active']['duration'],
'delay' => $value['active']['delay'],
);
}
/**
* @internal
*/
protected function _get_defaults()
{
return array(
'value' => array(
'animate' => 'inactive',
'effect' => 'thz-anim-fadeIn',
'duration'=> 1000,
'delay' => 0,
),
'addlabel'=>''
);
}
/**
* @param array $set_multikeys array('multi/key', 'value')
* @return array
*/
private function get_inner_option($option)
{
$label = (isset($option['addlabel']) && !empty($option['addlabel'])) ? $option['addlabel'] : esc_html__('Animate', 'creatus');
$desc = (isset($option['adddesc']) && !empty($option['adddesc'])) ? $option['adddesc'] : esc_html__('Add animation to the HTML container', 'creatus');
$help = (isset($option['addhelp']) && !empty($option['addhelp'])) ? $option['addhelp'] :'';
$draw = isset($option['draw']) ? $option['draw'] : false;
return array(
'type' => 'multi-picker',
'label' => false,
'desc' => false,
'picker' => array(
'picked' => array(
'label' => $label,
'desc' => $desc,
'help' => $help,
'type' => 'switch',
'right-choice' => array(
'value' => 'active',
'label' => __('Yes', 'creatus')
),
'left-choice' => array(
'value' => 'inactive',
'label' => __('No', 'creatus')
),
)
),
'choices' => array(
'active' => array(
'effect' => array(
'type' => 'select',
'label' => __('Effect', 'creatus'),
'desc' => esc_html__('Select the animation effect.', 'creatus'),
'choices' => _thz_animations_list( $draw )
),
'duration' => array(
'type' => 'thz-spinner',
'label' => __('Duration', 'creatus'),
'desc' => esc_html__('Set duration in milliseconds. 1000ms = 1s', 'creatus'),
'addon' => 'ms',
'min' => 0,
'max' => 2000,
'step' => 100,
),
'delay' => array(
'type' => 'thz-spinner',
'label' => __('Delay', 'creatus'),
'desc' => esc_html__('Set delay in milliseconds. 1000ms = 1s', 'creatus'),
'addon' => 'ms',
'min' => 0,
'max' => 10000,
'step' => 100,
)
)
),
'show_borders' => false
);
}
}
FW_Option_Type::register('FW_Option_Type_Thzanimation');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment