| @@ -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 | ); |
| @@ -722,12 +722,17 @@ | ||
| 722 | 722 | */ |
| 723 | 723 | public function printYesNoButtons($name, $label_yes, $label_no, $cur_value = '1', $yes_value = '1', $no_value = '0', $onclick = '', $class_list = []) |
| 724 | 724 | { |
| 725 | 725 | $html = ''; |
| 726 | - $id_yes = $name . '-on'; | |
| 727 | - $id_no = $name . '-off'; | |
| 728 | 726 | |
| 729 | 727 | /** |
| 728 | + * Normalize ID attribute for checkbox. | |
| 729 | + * | |
| 730 | + * @since 1.8.8 | |
| 731 | + */ | |
| 732 | + $id_yes = preg_replace("/[^a-z0-9_]+/", '-', $name . '-on'); | |
| 733 | + | |
| 734 | + /** | |
| 730 | 735 | * New toggle button in iOS style. |
| 731 | 736 | * |
| 732 | 737 | * @since 1.3.0 |
| 733 | 738 | */ |
| @@ -811,8 +816,14 @@ | ||
| 811 | 816 | * the form containing the input field gets submitted. It should |
| 812 | 817 | * be set to true when the form does not get submitted. |
| 813 | 818 | */ |
| 814 | 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, | |
| 815 | 826 | ); |
| 816 | 827 | |
| 817 | 828 | // merge config object with user's specified properties |
| 818 | 829 | $final_opts = array_merge($default_opts, $opts); |
| @@ -818,10 +829,13 @@ | ||
| 818 | 829 | $final_opts = array_merge($default_opts, $opts); |
| 819 | 830 | $data = json_encode($final_opts); |
| 820 | 831 | |
| 821 | 832 | // apply set full number on blur |
| 822 | - $full_number_on_blur = (int)$final_opts['fullNumberOnBlur']; | |
| 833 | + $full_number_on_blur = (int) $final_opts['fullNumberOnBlur']; | |
| 823 | 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 | + | |
| 824 | 838 | $document = JFactory::getDocument(); |
| 825 | 839 | |
| 826 | 840 | if ($load_assets) { |
| 827 | 841 | $document->addStyleSheet(VBO_SITE_URI . 'resources/intlTelInput.css'); |
| @@ -840,8 +854,14 @@ | ||
| 840 | 854 | if ($full_number_on_blur) { |
| 841 | 855 | jQuery('#$selector').val(cur_phone); |
| 842 | 856 | } else { |
| 843 | 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 | + } | |
| 844 | 864 | } |
| 845 | 865 | }); |
| 846 | 866 | jQuery('#$selector').closest('form').on('submit', function() { |
| 847 | 867 | // always make sure the input field contains the complete phone number |