id = $id;
$this->param = $param;
}
public function init(): string {
return $this->create();
}
private function create(): string {
$id = $this->id;
$param = $this->param;
$count = ! empty( $param['item']['type'] ) ? count( $param['item']['type'] ) : 0;
if ( $count === 0 ) {
return false;
}
$wrapper = $this->wrapper( $id, $param );
$menu = $wrapper;
$menu .= $this->button( $param );
$menu .= '
';
$menu .= $this->elements( $count, $param );
$menu .= '
'; // close menu tags
return $menu;
}
private function wrapper( $id, $param ): string {
$position = isset( $param['position'] ) ? ' ' . $param['position'] : ' -left';
$shape = isset( $param['shapes'] ) ? ' ' . $param['shapes'] : ' -circle';
$size = isset( $param['size'] ) ? ' ' . $param['size'] : ' -size-md';
$shadow = ! empty( $param['shadow'] ) ? ' -shadowless' : ' -shadow';
$animation = isset( $param['animation'] ) ? ' ' . $param['animation'] : '';
$open_menu = ! empty( $param['open_menu'] ) ? ' -active' : '';
$menu_add_classes = $position . $shape . $size . $shadow . $animation . $open_menu;
$action = '';
$action_type = ! empty( $param['action'] ) ? $param['action'] : '';
if ( $action_type === 'scroll_show' ) {
$action = ' data-behavior="showScroll:' . absint( $param['scroll'] ) . '"';
$menu_add_classes .= ' -hidden';
} elseif ( $action_type === 'scroll_hide' ) {
$action = ' data-behavior="hideScroll:' . absint( $param['scroll'] ) . '"';
} elseif ( $action_type === 'timer_show' ) {
$action = ' data-behavior="showDelay:' . absint( $param['timer'] ) * 1000 . '"';
$menu_add_classes .= ' -hidden';
} elseif ( $action_type === 'timer_hide' ) {
$action = ' data-behavior="hideDelay:' . absint( $param['timer'] ) * 1000 . '"';
}
if ( ! empty( $param['hide_menus'] ) ) {
$action .= ' data-bubbles-hide="true"';
}
if ( ! empty( $param['close_menus'] ) ) {
$action .= ' data-bubble-toggle="true"';
}
$style = '';
if ( ! empty( $param['zindex'] ) && $param['zindex'] !== '9' ) {
$style .= '--z-index:' . absint( $param['zindex'] ) . ';';
}
if ( ! empty( $param['margin_block'] ) ) {
$style .= '--margin-block:' . esc_attr( $param['margin_block'] ) . 'px;';
}
if ( ! empty( $param['margin_inline'] ) ) {
$style .= '--margin-inline:' . esc_attr( $param['margin_inline'] ) . 'px;';
}
if ( ! empty( $param['label_color'] ) ) {
$style .= '--label-color:' . esc_attr( $param['label_color'] ) . ';';
}
if ( ! empty( $param['label_background_color'] ) ) {
$style .= '--label-background:' . esc_attr( $param['label_background_color'] ) . ';';
}
$style = ! empty( $style ) ? ' style="' . esc_attr( $style ) . '"' : '';
$css = '';
if ( ! empty( $param['mobile_on'] ) ) {
$screen = ! empty( $param['mobile'] ) ? $param['mobile'] : 480;
$css .= '
@media only screen and (max-width: ' . absint( $screen ) . 'px){
#bubble-menu-' . absint( $id ) . ' {
display:none;
}
}';
}
if ( ! empty( $param['desktop_on'] ) ) {
$screen_more = ! empty( $param['desktop'] ) ? $param['desktop'] : 1200;
$css .= '
@media only screen and (min-width: ' . absint( $screen_more ) . 'px){
#bubble-menu-' . absint( $id ) . ' {
display:none;
}
}';
}
if ( ! empty( $css ) ) {
$css = '';
}
return $css . '