| @@ -507,9 +507,9 @@ | ||
| 507 | 507 | $options['sanitize'] = false; |
| 508 | 508 | $data = $options ? json_encode($options) : '{}'; |
| 509 | 509 | JFactory::getDocument()->addScriptDeclaration( |
| 510 | 510 | <<<JS |
| 511 | -jQuery(document).ready(function() { | |
| 511 | +jQuery(function() { | |
| 512 | 512 | jQuery('$selector').popover($data); |
| 513 | 513 | }); |
| 514 | 514 | JS |
| 515 | 515 | ); |
| @@ -703,28 +703,34 @@ | ||
| 703 | 703 | return JLanguage::getKnownLanguages(); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
| 707 | - * Returns the HTML code to display the radio buttons for Yes-No. | |
| 708 | - * | |
| 709 | - * @return string The HTML code to render the radio buttons. | |
| 707 | + * Returns the HTML code to display a toggle button in iOS style through a checkbox element. | |
| 708 | + * | |
| 709 | + * @param string $name the checkbox element name. | |
| 710 | + * @param string $label_yes label for the checked status. | |
| 711 | + * @param string $label_no label for the un-checked status. | |
| 712 | + * @param string $cur_value the default checkbox value state. | |
| 713 | + * @param string $yes_value the checkbox value when checked. | |
| 714 | + * @param string $no_value the checkbox value when un-checked (unsupported). | |
| 715 | + * @param string $onclick optional onclick attribute to fire a JS callback. | |
| 716 | + * @param array $class_list optional list of additional CSS classes to add ('blue', 'orange', 'red', 'gold', 'purple'). | |
| 717 | + * | |
| 718 | + * | |
| 719 | + * @return string The HTML code to render the radio buttons. | |
| 720 | + * | |
| 721 | + * @since 1.16.9 (J) - 1.6.9 (WP) introduced argument $class_list. | |
| 710 | 722 | */ |
| 711 | - public function printYesNoButtons($name, $label_yes, $label_no, $cur_value = '1', $yes_value = '1', $no_value = '0', $onclick = '') | |
| 723 | + public function printYesNoButtons($name, $label_yes, $label_no, $cur_value = '1', $yes_value = '1', $no_value = '0', $onclick = '', $class_list = []) | |
| 712 | 724 | { |
| 713 | 725 | $html = ''; |
| 714 | - $id_yes = $name . '-on'; | |
| 715 | - $id_no = $name . '-off'; | |
| 716 | - | |
| 726 | + | |
| 717 | 727 | /** |
| 718 | - * @deprecated since 1.3.0 | |
| 728 | + * Normalize ID attribute for checkbox. | |
| 719 | 729 | * |
| 720 | - $html = '<div class="switch-field"> | |
| 721 | - <input type="radio" id="'.$id_yes.'" name="'.$name.'" value="'.$yes_value.'"'.($cur_value === $yes_value ? ' checked="checked"' : '').'/> | |
| 722 | - <label for="'.$id_yes.'" class="button-yes">'.$label_yes.'</label> | |
| 723 | - <input type="radio" id="'.$id_no.'" name="'.$name.'" value="'.$no_value.'"'.($cur_value === $no_value ? ' checked="checked"' : '').'/> | |
| 724 | - <label for="'.$id_no.'" class="button-no">'.$label_no.'</label> | |
| 725 | - </div>'; | |
| 726 | - */ | |
| 730 | + * @since 1.8.8 | |
| 731 | + */ | |
| 732 | + $id_yes = preg_replace("/[^a-z0-9_]+/", '-', $name . '-on'); | |
| 727 | 733 | |
| 728 | 734 | /** |
| 729 | 735 | * New toggle button in iOS style. |
| 730 | 736 | * |
| @@ -730,9 +736,9 @@ | ||
| 730 | 736 | * |
| 731 | 737 | * @since 1.3.0 |
| 732 | 738 | */ |
| 733 | 739 | $show_labels = ($label_yes != JText::translate('JYES') && $label_yes != JText::translate('VBYES')); |
| 734 | - $html = '<span class="vik-iostoggle-wrap vbo-iostoggle-wrap"> | |
| 740 | + $html = '<span class="vik-iostoggle-wrap vbo-iostoggle-wrap' . ($class_list ? ' ' . implode(' ', $class_list) : '') . '"> | |
| 735 | 741 | <input type="checkbox" name="' . $name . '" class="vik-iostoggle-elem vbo-iostoggle-elem" id="' . $id_yes . '" value="' . $yes_value . '"' . (!empty($onclick) ? ' onclick="' . $onclick . '"' : '') . ($cur_value === $yes_value ? ' checked' : '').'> |
| 736 | 742 | <label for="' . $id_yes . '">' . ($show_labels ? '<span class="vik-iostoggle-lbls vbo-iostoggle-lbls" data-on="' . addslashes($label_yes) . '" data-off="' . addslashes($label_no) . '"></span>' : '') . '</label> |
| 737 | 743 | </span>'; |
| 738 | 744 | |
| @@ -810,8 +816,14 @@ | ||
| 810 | 816 | * the form containing the input field gets submitted. It should |
| 811 | 817 | * be set to true when the form does not get submitted. |
| 812 | 818 | */ |
| 813 | 819 | 'fullNumberOnBlur' => false, |
| 820 | + /** | |
| 821 | + * Allow to dispatch an event to transport the selected country data. | |
| 822 | + * | |
| 823 | + * @since 1.18.8 (J) - 1.8.8 (WP) | |
| 824 | + */ | |
| 825 | + 'countryDataEvent' => null, | |
| 814 | 826 | ); |
| 815 | 827 | |
| 816 | 828 | // merge config object with user's specified properties |
| 817 | 829 | $final_opts = array_merge($default_opts, $opts); |
| @@ -817,10 +829,13 @@ | ||
| 817 | 829 | $final_opts = array_merge($default_opts, $opts); |
| 818 | 830 | $data = json_encode($final_opts); |
| 819 | 831 | |
| 820 | 832 | // apply set full number on blur |
| 821 | - $full_number_on_blur = (int)$final_opts['fullNumberOnBlur']; | |
| 833 | + $full_number_on_blur = (int) $final_opts['fullNumberOnBlur']; | |
| 822 | 834 | |
| 835 | + // check if an event should be dispatched with the selected country data | |
| 836 | + $countryDataEvent = $final_opts['countryDataEvent'] ? json_encode($final_opts['countryDataEvent']) : 0; | |
| 837 | + | |
| 823 | 838 | $document = JFactory::getDocument(); |
| 824 | 839 | |
| 825 | 840 | if ($load_assets) { |
| 826 | 841 | $document->addStyleSheet(VBO_SITE_URI . 'resources/intlTelInput.css'); |
| @@ -839,8 +854,14 @@ | ||
| 839 | 854 | if ($full_number_on_blur) { |
| 840 | 855 | jQuery('#$selector').val(cur_phone); |
| 841 | 856 | } else { |
| 842 | 857 | jQuery('#$selector').intlTelInput('setNumber', cur_phone); |
| 858 | + } | |
| 859 | + if ($countryDataEvent && typeof VBOCore !== 'undefined') { | |
| 860 | + let countryData = jQuery('#$selector').intlTelInput('getSelectedCountryData'); | |
| 861 | + if (countryData && countryData?.iso2) { | |
| 862 | + VBOCore.emitEvent($countryDataEvent, countryData); | |
| 863 | + } | |
| 843 | 864 | } |
| 844 | 865 | }); |
| 845 | 866 | jQuery('#$selector').closest('form').on('submit', function() { |
| 846 | 867 | // always make sure the input field contains the complete phone number |