Browse Source

[FEATURE] possibility for tooltip for leightbox buttons

experimental
Georgi Hristov 3 years ago
parent
commit
f22957e5d5
1 changed files with 21 additions and 6 deletions
  1. +21
    -6
      modules/Utils/LeightboxPrompt/LeightboxPrompt_0.php

+ 21
- 6
modules/Utils/LeightboxPrompt/LeightboxPrompt_0.php View File

@@ -25,10 +25,13 @@ class Utils_LeightboxPrompt extends Module {
return $this->group;
}

public function add_option($key, $label, $icon, $form=null) {
public function add_option($key, $label, $icon, $form=null, $tooltip=null) {
$key = $key?: 'default';
$this->options[$key] = array('icon'=>$icon, 'form'=>$form, 'label'=>$label);
if ($tooltip && !is_array($tooltip))
$tooltip = [$tooltip];
$this->options[$key] = array('icon'=>$icon, 'form'=>$form, 'label'=>$label, 'tooltip'=>$tooltip);
if (isset($form) && $form->exportValue('submited') && !$form->validate()) $this->open();
}
@@ -53,13 +56,14 @@ class Utils_LeightboxPrompt extends Module {
$buttons = array();
$sections = array();
foreach ($this->options as $option_key=>$option) {
$next_button = array('icon'=>$option['icon'], 'label'=>$option['label']);
$next_button = array('icon'=>$option['icon'], 'label'=>$option['label'], 'tooltip' => $option['tooltip']);
if ($option['form']!==null) $form = $option['form'];
else $form = $this->options[$option_key]['form'] = $this->init_module(Libs_QuickForm::module_name());
if (!empty($params_list)) {
foreach ($params_list as $param_key)
$form->addElement('hidden', $this->group.'_'.$param_key, 'none');
}
$tooltip = $this->button_tooltip_attrs($next_button);
if ($option['form']!==null) {
$option['form']->addElement('button', 'cancel', __('Cancel'), array('id'=>$this->group.'_lp_cancel', 'onclick'=>$this->get_close_leightbox_href_js(!$single_option)));
$option['form']->addElement('submit', 'submit', __('OK'), array('id'=>$this->group.'_lp_submit', 'onclick'=>$this->get_close_leightbox_href_js()));
@@ -69,9 +73,9 @@ class Utils_LeightboxPrompt extends Module {
$th->assign('id', $this->get_instance_id());
$th->display('form');
$form_contents = ob_get_clean();
$next_button['open'] = '<a ' . $this->get_form_show_href($option_key) .'>';
$next_button['open'] = '<a ' . $this->get_form_show_href($option_key) . ' ' . $tooltip . '>';
$sections[] = '<div id="'.$this->group.'_'.$option_key.'_form_section" class="'.$this->group.'_form_section" style="display:none;">'.$form_contents.'</div>';

if ($this->selected_option === $option_key)
$active_option = $option_key; // open this selection if selected_option set
@@ -79,7 +83,7 @@ class Utils_LeightboxPrompt extends Module {
$active_option = $option_key; // open this selection if form submitted but not valid
} else {
$next_button['open'] = '<a href="javascript:void(0);" onmouseup="' . $this->get_close_leightbox_href_js() . $form->get_submit_form_js() . ';">';
$next_button['open'] = '<a href="javascript:void(0);" onmouseup="' . $this->get_close_leightbox_href_js() . $form->get_submit_form_js() . ';" ' . $tooltip . '>';
$form->display();
}
$next_button['close'] = '</a>';
@@ -108,6 +112,17 @@ class Utils_LeightboxPrompt extends Module {
}
}
private function button_tooltip_attrs($button) {
$ret = '';
if ($button['tooltip']) {
if (is_callable($button['tooltip'][0]))
$ret = call_user_func_array([Utils_TooltipCommon::class, 'ajax_open_tag_attrs'], $button['tooltip']);
else
$ret = call_user_func_array([Utils_TooltipCommon::class, 'open_tag_attrs'], $button['tooltip']);
}
return $ret;
}
private function get_single_option() {
if (count($this->options) == 1) {
$option_keys = array_keys($this->options);


Loading…
Cancel
Save