1var search = new Map([[1,{adults:1, children:0, infants:0}]]); 2var roomIndex = 1; 3 4 5jQuery(document).ready(function (){ 6 //jQuery('#searchData').val('{"1":{"adults":1,"children":1,"infants":1},"2":{"adults":2,"children":2,"infants":5},"3":{"adults":3,"children":0,"infants":0}}') //smazat 7 8 if(jQuery('#searchData').val().length == 0) { 9 jQuery('#searchData').val(JSON.stringify(Object.fromEntries(search))); //na ostrém webu upravit 10 } 11 else { 12 data = jQuery('#searchData').val(); 13 data = JSON.parse(data); 14 15 search = new Map(); 16 for (let room in data) { 17 search.set(Number(room), data[room]); 18 } 19 } 20 21 data = JSON.parse(jQuery('#searchData').val()); 22 23 for (let room in data) { 24 if(room > 1) { 25 addRoomData (); 26 } 27 } 28 29 jQuery('button[data-task="plus"]').click(function() {buttonPlus(this)}); 30 jQuery('button[data-task="minus"]').click(function() {buttonMinus(this)}); 31 jQuery('button[data-task="deleteRoom"]').click(function() {buttonDeleteRoom(this)}); 32 jQuery('button#totalSum').click(function() {jQuery('#searchForm').toggle()}); 33 jQuery('button#addRoom').click(function() {addRoom()}); 34 35 updateSearchData(); 36 37}); 38 39function updateSearchData() { 40 data = jQuery('#searchData').val(); 41 data = JSON.parse(data); 42 43 rooms = jQuery('#rooms > div'); 44 45 for (let room in data) { 46 jQuery('span[data-room="'+ room +'"][data-age="adults"][data-type="count"]').html(data[room].adults +' '+ plural('COM_HOTELS_SEARCH_ADULTS_COUNT', data[room].adults)); 47 48 if(data[room].children > 0) { 49 jQuery('span[data-room="'+ room +'"][data-age="children"][data-type="count"]').html(data[room].children +' '+ plural('COM_HOTELS_SEARCH_CHILDREN_COUNT', data[room].children)); 50 } 51 else { 52 jQuery('span[data-room="'+ room +'"][data-age="children"][data-type="count"]').html(plural('COM_HOTELS_SEARCH_CHILDREN_COUNT', data[room].children)); 53 } 54 55 if(data[room].infants > 0) { 56 jQuery('span[data-room="'+ room +'"][data-age="infants"][data-type="count"]').html(data[room].infants +' '+ plural('COM_HOTELS_SEARCH_INFANTS_COUNT', data[room].infants)); 57 } 58 else { 59 jQuery('span[data-room="'+ room +'"][data-age="infants"][data-type="count"]').html(plural('COM_HOTELS_SEARCH_INFANTS_COUNT', data[room].infants)); 60 } 61 } 62 63 if(rooms.length > 1) { 64 jQuery('#addRoom').html(Joomla.JText._('COM_HOTELS_SEARCH_ADD_ROOM')); 65 } 66 else { 67 jQuery('#rooms > #room_1').find('[data-type="title"]').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS')); 68 jQuery('#rooms > #room_1').find('[data-task="deleteRoom"]').addClass('hidden'); 69 jQuery('#addRoom').html(Joomla.JText._('COM_HOTELS_SEARCH_SET_MANUALLY')); 70 } 71 72 total = totalSum(); 73 jQuery('#totalSum').html(total.text); 74} 75 76function buttonPlus(em) { 77 room = jQuery(em).data('room'); 78 age = jQuery(em).data('age'); 79 80 data = search.get(room); 81 82 switch(age) { 83 case 'adults': 84 data.adults = data.adults + 1; 85 break; 86 87 case 'children': 88 data.children = data.children + 1; 89 break; 90 91 case 'infants': 92 data.infants = data.infants + 1; 93 break; 94 } 95 96 search.set(room, data); 97 jQuery('#searchData').val(JSON.stringify(Object.fromEntries(search))); 98 99 updateSearchData(); 100} 101 102function buttonMinus(em) { 103 room = jQuery(em).data('room'); 104 age = jQuery(em).data('age'); 105 106 data = search.get(room); 107 108 switch(age) { 109 case 'adults': 110 if(data.adults > 1) { 111 data.adults = data.adults - 1; 112 } 113 break; 114 115 case 'children': 116 if(data.children > 0) { 117 data.children = data.children - 1; 118 } 119 break; 120 121 case 'infants': 122 if(data.infants > 0) { 123 data.infants = data.infants - 1; 124 } 125 break; 126 } 127 128 search.set(room, data); 129 jQuery('#searchData').val(JSON.stringify(Object.fromEntries(search))); 130 131 updateSearchData(); 132} 133 134function plural(text, num) { 135 return Joomla.JText._(text + num, Joomla.JText._(text)); 136} 137 138function addRoom() { 139 roomIndex++; 140 141 jQuery('#rooms > #room_1 h3').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS_IN_ROOM') +' 1'); 142 jQuery('#rooms > #room_1').find('[data-task="deleteRoom"]').removeClass('hidden'); 143 144 jQuery('#rooms').append('<div id="room_'+ (roomIndex) +'">'); 145 146 newRoom = jQuery('#room_'+ (roomIndex)); 147 newRoom.slideUp(); 148 149 data = jQuery('#rooms > #room_1').html(); 150 151 newRoom.append(data); 152 newRoom.find('h3').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS_IN_ROOM') +' '+ roomIndex); 153 newRoom.find('[data-room="1"]').each(function() { 154 jQuery(this).attr('data-room', roomIndex); 155 }); 156 157 newRoom.find('button[data-task="plus"]').click(function() {buttonPlus(this)}); 158 newRoom.find('button[data-task="minus"]').click(function() {buttonMinus(this)}); 159 newRoom.find('button[data-task="deleteRoom"]').click(function() {buttonDeleteRoom(this)}); 160 161 search.set(roomIndex,{adults:1, children:0, infants:0}); 162 jQuery('#searchData').val(JSON.stringify(Object.fromEntries(search))); 163 updateSearchData(); 164 newRoom.slideDown(); 165} 166 167function addRoomData() { 168 roomIndex++; 169 170 jQuery('#rooms > #room_1 h3').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS_IN_ROOM') +' 1'); 171 jQuery('#rooms > #room_1').find('[data-task="deleteRoom"]').removeClass('hidden'); 172 173 jQuery('#rooms').append('<div id="room_'+ (roomIndex) +'">'); 174 175 newRoom = jQuery('#room_'+ (roomIndex)); 176 newRoom.slideUp(); 177 178 data = jQuery('#rooms > #room_1').html(); 179 180 newRoom.append(data); 181 newRoom.find('h3').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS_IN_ROOM') +' '+ roomIndex); 182 newRoom.find('[data-room="1"]').each(function() { 183 jQuery(this).attr('data-room', roomIndex); 184 }); 185 186 //newRoom.find('button[data-task="plus"]').click(function() {buttonPlus(this)});
187 //newRoom.find('button[data-task="minus"]').click(function() {buttonMinus(this)}); 188 newRoom.find('button[data-task="deleteRoom"]').click(function() {buttonDeleteRoom(this)}); 189 190 newRoom.slideDown(); 191} 192 193function buttonDeleteRoom(em) { 194 room = jQuery(em).data('room'); 195 196 jQuery('#rooms > #room_'+ room).slideUp('', function() { 197 this.remove() 198 search.delete(room); 199 200 searchTmp = new Map(search); 201 searchTmp.forEach((value, key) => { 202 if(key > room) { 203 console.log(key); 204 jQuery('#room_'+ key).find('[data-type="title"]').html(Joomla.JText._('COM_HOTELS_SEARCH_GUESTS_IN_ROOM') +' '+ (key-1)); 205 206 jQuery('#room_'+ key).find('[data-room="'+ key +'"]').each(function() { 207 jQuery(this).attr('data-room', key-1); 208 }); 209 210 jQuery('#room_'+ key).attr('id', 'room_'+ (key-1)); 211 212 search.set(key - 1, value); 213 search.delete(key); 214 } 215 }); 216 217 jQuery('#searchData').val(JSON.stringify(Object.fromEntries(search))); 218 roomIndex--; 219 updateSearchData(); 220 }); 221} 222 223function totalSum() { 224 var total = {rooms: 0, adults: 0, children: 0, infants: 0, sum: 0, text: ''}; 225 226 total.rooms = search.size; 227 228 search.forEach (function(value, key) { 229 total.adults += value.adults; 230 total.children += value.children; 231 total.infants += value.infants; 232 }) 233 234 total.sum = total.adults + total.children + total.infants; 235 236 if(total.children > 0 || total.infants > 0) { 237 total.text = Joomla.JText._('COM_HOTELS_SEARCH_GUESTS').toLowerCase()+' '+total.sum; 238 } 239 else { 240 total.text = total.adults +' '+ plural('COM_HOTELS_SEARCH_ADULTS_COUNT', total.adults); 241 } 242 243 if(total.rooms > 1) { 244 total.text += ' / '+ plural('COM_HOTELS_SEARCH_ROOMS_COUNT', total.rooms) +' '+total.rooms; 245 } 246 247 return total; 248}
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.