https://psihosensus.eu/wp-content/plugins/bookly-responsive-appoin…/backend/resources/js/dropdown.js
1/** 2 * jQuery booklyDropdown. 3 */ 4(function ($) { 5 let id = 0; 6 let methods = { 7 init: function (options) { 8 let opts = $.extend({}, $.fn.booklyDropdown.defaults, options); 9 10 return this.filter('ul').each(function () { 11 if ($(this).data('booklyDropdown')) { 12 return; 13 } 14 let obj = { 15 $container: $('<div class="bookly-dropdown"/>'), 16 $button: $('<button type="button" class="btn btn-default bookly-dropdown-toggle d-flex align-items-center w-100" data-toggle="bookly-dropdown"/>'), 17 $counter: $('<span class="flex-grow-1 text-left me-1"/>'), 18 $ul: $(this), 19 $selectAll: $('<input type="checkbox" class="custom-control-input"/>').attr('id', 'bookly-js-dropdown-' + (++id)), 20 $groups: $(), 21 $options: [], 22 preselected: [], // initially selected options 23 refresh: function () { 24 let $selected = obj.$options.filter(function (o) { return o.is(':checked') }); 25 obj.$selectAll.prop('checked', false); 26 obj.$groups.prop('checked', false); 27 if ($selected.length === 0) { 28 obj.$counter.text(obj.txtNothingSelected); 29 } else if ($selected.length === obj.$options.length) { 30 obj.$counter.text(obj.txtAllSelected); 31 obj.$selectAll.prop('checked', true); 32 obj.$groups.prop('checked', true); 33 } else { 34 if ($selected.length === 1) { 35 obj.$counter.text($selected[0].next().text()); 36 } else { 37 obj.$counter.text($selected.length + '/' + obj.$options.length); 38 } 39 obj.$groups.each(function () { 40 let $this = $(this); 41 $this.prop('checked', $this.data('group-checkboxes').filter(':not(:checked)').length === 0); 42 }); 43 } 44 } 45 }; 46 // Texts. 47 obj.txtSelectAll = obj.$ul.data('txt-select-all') || opts.txtSelectAll; 48 obj.txtAllSelected = obj.$ul.data('txt-all-selected') || opts.txtAllSelected; 49 obj.txtNothingSelected = obj.$ul.data('txt-nothing-selected') || opts.txtNothingSelected; 50 51 let $content = obj.$button; 52 if (obj.$ul.data('hide-icon') === undefined) { 53 $content.append($('<i class="me-1 fa-fw"/>').addClass(obj.$ul.data('icon-class') || opts.iconClass)); 54 } 55 $content.append(obj.$counter); 56 57 obj.$container 58 .addClass(obj.$ul.data('container-class') || opts.containerClass) 59 .append($content) 60 .append( 61 obj.$ul 62 .addClass('bookly-dropdown-menu bookly-dropdown-menu-' + (obj.$ul.data('align') || opts.align)) 63 // Options (checkboxes). 64 .append($.map(opts.options, function (option) { 65 return $('<li/>') 66 .data({ 67 'input-name': option.inputName || opts.inputsName, 68 'value': option.value || '', 69 'selected': option.selected || false 70 }) 71 .text(option.name) 72 ; 73 })) 74 .find('li') 75 .addClass('bookly-dropdown-item') 76 .wrapInner('<div class="custom-control custom-checkbox ml-4"><label class="custom-control-label"></label></div>') 77 .each(function () { 78 let $li = $(this), 79 $checkbox = $('<input type="checkbox" class="custom-control-input"/>').attr('id', 'bookly-js-dropdown-' + (++id)), 80 $ul = $li.find('ul:first') 81 ; 82 if ($li.is('[data-flatten-if-single]') && obj.$ul.children().length === 1) { 83 $li.replaceWith($ul.children()); 84 return true; 85 } 86 if ($ul.length > 0) { 87 $ul.appendTo($li); 88 $ul.addClass('p-0'); 89 obj.$groups = obj.$groups.add($checkbox); 90 } else { 91 $checkbox 92 .attr('name', $li.data('input-name')) 93 .val($li.data('value')) 94 .prop('checked', !!$li.data('selected')) 95 ; 96 obj.$options.push($checkbox); 97 if ($checkbox.prop('checked')) { 98 obj.preselected.push($checkbox.val()); 99 } 100 } 101 $li.find('label:first').attr('for', $checkbox.attr('id')).before($checkbox); 102 }) 103 .end() 104 // Select all. 105 .prepend( 106 $('<li class="bookly-dropdown-item"/>') 107 .append( 108 $('<div class="custom-control custom-checkbox"/>') 109 .append(obj.$selectAll) 110 .append( 111 $('<label class="custom-control-label"/>') 112 .attr('for', obj.$selectAll.attr('id')) 113 .append(obj.txtSelectAll) 114 ) 115 ) 116 ) 117 // Replace with container. 118 .replaceWith(obj.$container)
119 // Do not close on click. 120 .on('click', function (e) { 121 e.stopPropagation(); 122 }) 123 ) 124 // Events. 125 .on('change', 'input:checkbox', function () { 126 let $this = $(this), 127 checked = this.checked; 128 if ($this.is(obj.$selectAll)) { 129 obj.$options.forEach(function (o) {o.prop('checked', checked);}); 130 opts.onChange.call(obj.$ul, obj.$options.map(function (o) { return o.val(); }), checked, true); 131 } else if ($this.is(obj.$groups)) { 132 $this.data('group-checkboxes').prop('checked', this.checked); 133 opts.onChange.call(obj.$ul, $this.data('group-checkboxes').map(function () { return this.value; }).get(), checked, false); 134 } else { 135 opts.onChange.call(obj.$ul, [this.value], checked, false); 136 } 137 obj.refresh(); 138 }) 139 ; 140 141 // Attach a handler to an event for the container 142 obj.$container.bind('bookly-dropdown.change', function () { 143 opts.onChange.call(obj.$ul, obj.$options.map(function (o) { return o.val(); }), this.checked, false); 144 }); 145 146 // Link group checkboxes with sub-items. 147 obj.$groups.each(function () { 148 let $this = $(this), 149 $checkboxes = $this.closest('li').find('ul input:checkbox') 150 ; 151 $this.data('group-checkboxes', $checkboxes); 152 }); 153 154 obj.refresh(); 155 obj.$ul.data('booklyDropdown', obj); 156 }); 157 }, 158 deselect: function (values) { 159 if (!Array.isArray(values)) { 160 values = [values]; 161 } 162 return this.filter('ul').each(function () { 163 var obj = $(this).data('booklyDropdown'); 164 if (!obj) { 165 return; 166 } 167 obj.$options.forEach(function (o) { 168 if ($.inArray(o.val(), values) > -1) { 169 o.prop('checked', false); 170 } 171 }); 172 obj.refresh(); 173 }); 174 }, 175 deselectAll: function () { 176 return this.filter('ul').each(function () { 177 var obj = $(this).data('booklyDropdown'); 178 if (!obj) { 179 return; 180 } 181 obj.$options.forEach(function (o) {o.prop('checked', false)}); 182 obj.refresh(); 183 }); 184 }, 185 getSelected: function () { 186 var obj = this.filter('ul').data('booklyDropdown'), 187 res = [] 188 ; 189 if (obj) { 190 obj.$options.filter(function (o) { return o.is(':checked') }).forEach(function (o) { 191 res.push(o.val()); 192 }); 193 } 194 195 return res; 196 }, 197 getSelectedAllState: function () { 198 var obj = this.filter('ul').data('booklyDropdown'); 199 return obj.$selectAll.prop('checked'); 200 }, 201 itemsCount: function () { 202 return this.filter('ul').data('booklyDropdown').$options.length; 203 }, 204 getSelectedExt: function () { 205 var obj = this.filter('ul').data('booklyDropdown'), 206 res = [] 207 ; 208 if (obj) { 209 obj.$options.filter(function (o) { return o.is(':checked') }).forEach(function (o) { 210 res.push({value: o.val(), name: o.next('label').text()}); 211 }); 212 } 213 214 return res; 215 }, 216 hide: function () { 217 return this.filter('ul').each(function () { 218 var obj = $(this).data('booklyDropdown'); 219 if (!obj) { 220 return; 221 } 222 obj.$container.hide(); 223 }); 224 }, 225 refresh: function () { 226 return this.filter('ul').each(function () { 227 var obj = $(this).data('booklyDropdown'); 228 if (!obj) { 229 return; 230 } 231 obj.refresh(); 232 }); 233 }, 234 reset: function () { 235 return this.filter('ul').each(function () { 236 var obj = $(this).data('booklyDropdown'); 237 if (!obj) { 238 return; 239 } 240 obj.$options.forEach(function (o) { 241 o.prop('checked', $.inArray(o.val(), obj.preselected) > -1); 242 }); 243 obj.refresh(); 244 }); 245 }, 246 select: function (values) { 247 if (!Array.isArray(values)) { 248 values = [values]; 249 } 250 return this.filter('ul').each(function () { 251 var obj = $(this).data('booklyDropdown'); 252 if (!obj) { 253 return; 254 } 255 obj.$options.forEach(function (o) { 256 if ($.inArray(o.val(), values) > -1) { 257 o.prop('checked', true); 258 } 259 }); 260 obj.refresh(); 261 }); 262 }, 263 selectAll: function () { 264 return this.filter('ul').each(function () { 265 var obj = $(this).data('booklyDropdown'); 266 if (!obj) { 267 return; 268 } 269 obj.$options.forEach(function (o) {o.prop('checked', true)}); 270 obj.refresh(); 271 }); 272 }, 273 setSelected: function (values) { 274 if (!Array.isArray(values)) { 275 values = [values]; 276 } 277 return this.filter('ul').each(function () { 278 var obj = $(this).data('booklyDropdown'); 279 if (!obj) { 280 return; 281 } 282 obj.$options.forEach(function (o) { 283 o.prop('checked', $.inArray(o.val(), values) > -1); 284 }); 285 obj.refresh(); 286 }); 287 }, 288 show: function () { 289 return this.filter('ul').each(function () { 290 var obj = $(this).data('booklyDropdown'); 291 if (!obj) { 292 return; 293 } 294 obj.$container.css('display', ''); 295 }); 296 }, 297 toggle: function () { 298 return this.filter('ul').each(function () { 299 var obj = $(this).data('booklyDropdown'); 300 if (!obj) { 301 return; 302 } 303 obj.$button.booklyDropdown('toggle'); 304 }); 305 } 306 }; 307 308 $.fn.booklyDropdown = function (method) { 309 if (methods[method]) { 310 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 311 } else if (typeof method === 'object' || !method) { 312 return methods.init.apply(this, arguments); 313 } else { 314 $.error('No method ' + method + ' for jQuery.booklyDropdown'); 315 } 316 }; 317 318 $.fn.booklyDropdown.defaults = { 319 align: $('body').hasClass('rtl') ? 'right ' : 'left', 320 containerClass: '', 321 iconClass: 'far fa-user', 322 txtSelectAll: 'All', 323 txtAllSelected: 'All selected', 324 txtNothingSelected: 'Nothing selected', 325 inputsName: '', 326 options: [], 327 onChange: function (values, selected, all) {} 328 }; 329})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.