PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | libraries/adapter/html/classes/formbehavior.php +88 -68 1.6.4 → 1.8.16 View file →
@@ -2,9 +2,9 @@
2 2 /**
3 3 * @package VikWP - Libraries
4 4 * @subpackage adapter.html
5 5 * @author E4J s.r.l.
6 - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
6 + * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
7 7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 8 * @link https://vikwp.com
9 9 */
10 10
@@ -28,91 +28,111 @@
28 28 * @return void
29 29 */
30 30 public static function chosen($selector = '.btn-toolbar', $debug = null, $options = array())
31 31 {
32 + // load always select2 plugin
33 + // JHtml::fetch('select2');
34 + JText::script('JGLOBAL_SELECT_AN_OPTION');
35 +
32 36 static $loaded = 0;
33 37
34 38 // register only once
35 - if ($loaded)
39 + if (!$loaded)
36 40 {
37 - return;
38 - }
41 + $loaded = 1;
39 42
40 - $loaded = 1;
43 + /**
44 + * Use select2 rendering only in case of WordPress 5.2 or lower.
45 + * Starting from WordPress 5.3 the dropdowns are rendered properly
46 + * and there is no need to use a different layout.
47 + * Contrarily, we will lose the possibility of searching the options.
48 + *
49 + * @since 10.1.30
50 + */
51 + // $use_select2 = version_compare((new JVersion)->getShortVersion(), '5.3', '<') ? 1 : 0;
52 + $use_select2 = 0;
41 53
42 - $version = new JVersion();
54 + // add support for chosen plugin
55 + JFactory::getDocument()->addScriptDeclaration(
56 +<<<JAVASCRIPT
57 +(function($) {
58 + 'use strict';
43 59
44 - /**
45 - * Use select2 rendering only in case of WordPress 5.2 or lower.
46 - * Starting from WordPress 5.3 the dropdowns are rendered properly
47 - * and there is no need to use a different layout.
48 - * Contrarily, we will lose the possibility of searching the options.
49 - *
50 - * @since 10.1.30
51 - */
52 - // $use_select2 = version_compare($version->getShortVersion(), '5.3', '<') ? 1 : 0;
53 - $use_select2 = 0;
60 + if ($.fn.chosen === undefined) {
61 + $.fn.chosen = function(data) {
62 + // iterate all selected elements
63 + $(this).each(function() {
64 + // check is we have a multiple select
65 + var isMultiple = $(this).prop('multiple');
54 66
55 - // load always select2 plugin
56 - // JHtml::fetch('select2');
57 - JText::script('JGLOBAL_SELECT_AN_OPTION');
67 + if (!$use_select2 && !isMultiple) {
68 + // do not go ahead in case we don't need a custom plugin
69 + // to handle standard dropdowns
70 + return this;
71 + }
58 72
59 - // add support for chosen plugin
60 - JFactory::getDocument()->addScriptDeclaration(
61 -<<<JS
62 -if (jQuery.fn.chosen === undefined) {
63 - jQuery.fn.chosen = function(data) {
64 - // iterate all selected elements
65 - jQuery(this).each(function() {
66 - // check is we have a multiple select
67 - var isMultiple = jQuery(this).prop('multiple');
73 + if (data !== undefined) {
74 + // invoke requested method (e.g. destroy)
75 + $(this).select2(data);
76 + } else {
77 + data = {};
78 + data.width = isMultiple ? 300 : 200;
79 + data.allowClear = $(this).hasClass('required') ? false : true;
80 + data.placeholder = Joomla.JText._('JGLOBAL_SELECT_AN_OPTION');
68 81
69 - if (!$use_select2 && !isMultiple) {
70 - // do not go ahead in case we don't need a custom plugin
71 - // to handle standard dropdowns
72 - return this;
73 - }
82 + var firstOption = $(this).find('option').first();
74 83
75 - if (data !== undefined) {
76 - // invoke requested method (e.g. destroy)
77 - jQuery(this).select2(data);
78 - } else {
79 - data = {};
80 - data.width = isMultiple ? 300 : 200;
81 - data.allowClear = jQuery(this).hasClass('required') ? false : true;
82 - data.placeholder = Joomla.JText._('JGLOBAL_SELECT_AN_OPTION');
84 + // in case we don't have an empty option, unset placeholder
85 + if (!isMultiple && firstOption.length && firstOption.val().length > 0) {
86 + data.allowClear = false;
87 + data.placeholder = null;
88 + }
83 89
84 - var firstOption = jQuery(this).find('option').first();
90 + // turn off search when there are 5 options or less
91 + if ($(this).find('option').length <= 5) {
92 + data.minimumResultsForSearch = -1;
93 + }
85 94
86 - // in case we don't have an empty option, unset placeholder
87 - if (!isMultiple && firstOption.length && firstOption.val().length > 0) {
88 - data.allowClear = false;
89 - data.placeholder = null;
95 + // init select2 plugin
96 + $(this).select2(data);
90 97 }
98 + });
91 99
92 - // turn off search when there are 5 options or less
93 - if (jQuery(this).find('option').length <= 5) {
94 - data.minimumResultsForSearch = -1;
95 - }
100 + return this;
101 + }
102 + }
103 +})(jQuery);
104 +JAVASCRIPT
105 + );
106 + }
96 107
97 - // init select2 plugin
98 - jQuery(this).select2(data);
99 - }
100 - });
108 + static $selectors = [];
101 109
102 - return this;
103 - }
104 -}
110 + /**
111 + * The system is now able to initialize multiple selectors as a result of multiple calls.
112 + *
113 + * @since 10.1.63
114 + */
115 + if (!isset($selectors[$selector])) {
116 + $selectors[$selector] = 1;
105 117
106 -jQuery(document).ready(function() {
107 - jQuery('{$selector}')
108 - .find('select')
109 - .chosen()
110 - .on('chosen:updated', function() {
111 - // refresh select2 value when triggered
112 - // jQuery(this).select2('val', jQuery(this).val());
113 - });
114 -});
115 -JS
116 - );
118 + // init requested selectors
119 + JFactory::getDocument()->addScriptDeclaration(
120 +<<<JAVASCRIPT
121 +(function($) {
122 + 'use strict';
123 +
124 + $(function() {
125 + $('{$selector}')
126 + .find('select')
127 + .chosen()
128 + .on('chosen:updated', function() {
129 + // refresh select2 value when triggered
130 + // $(this).select2('val', $(this).val());
131 + });
132 + });
133 +})(jQuery);
134 +JAVASCRIPT
135 + );
136 + }
117 137 }
118 138 }