1(function($, cw){ 2$(document).ready(function() { 3 window.accept_auto_update = false; // sorry! 4 5 $('.cw-component-listashore').bind('cw-reinit-package-selectbuttons', function(){ 6 $('.cw-package-list-calendar-container #duration', this).selectbuttons({ 7 numberButtons: 5, 8 defaultText: '+' 9 }); 10 }); 11 var $component = $('.cw-component-packagedetails'); 12 var $calendar = $('.cw-package-calendar'); 13 var first = true; 14 15 // init all the different selectbuttons 16 $component.bind("cw-reinit-package-selectbuttons", function(){ 17 cw_update_pos_in_room_max_guests(); 18 }); 19 20 cw_update_pos_in_room_max_guests(); 21 22 $('body') 23 .on('change', '.cw-change-premise', function() { 24 window.location.href = $(this).data('change-url').replace(/__PREMISE/, $(this).val()); 25 }); 26 27 // handler for vertical selectbuttons for room selection 28 $component 29 .on('change', '.passengertype-qty', function(e) { 30 var pt = $(this).data('passengertype'); 31 var show = parseInt($(this).val(), 10) > 0; 32 $('.cw-room-spec-cont', $component).each(function() { 33 if(show) { 34 $('.cw-passenger-type-'+pt, this).show(); 35 } else { 36 $('.cw-passenger-type-'+pt, this).hide(); 37 } 38 39 if(pt == 'infant') { 40 if(show) { 41 $('.cw-passenger-type-infant_wo_bed', this).show(); 42 } else { 43 $('.cw-passenger-type-infant_wo_bed', this).hide(); 44 } 45 } 46 });
47 $('.cw-choices-hot').trigger('cw-room-update'); 48 }) 49 .on('change', '.cw-room-categories-selector', function(e){ 50 var ctg_code = $(this).val(); 51 var room_cont = $(this).closest('.cw-choices'); 52 $('.cw-room-spec-cont :input', room_cont).prop('disabled', true); // disable inputs to hidden room spec 53 $('.cw-pax-qty-row .cw-selectbuttons').each(function() { 54 update_possible_lodging_pax($('.passengertype-qty', this), true); 55 }); 56 $('.cw-room-spec-cont', room_cont).filter(':visible').slideUp(); // show selected room spec 57 $('.cw-room-spec-cont-'+ctg_code +' :input', room_cont).prop('disabled', false); // enable inputs to hidden room spec 58 $('.cw-room-spec-cont-'+ctg_code, room_cont).slideDown(function() { 59 $('.cw-pax-qty-row .cw-selectbuttons').each(function() { 60 update_possible_lodging_pax($('.passengertype-qty', this), true); 61 }); 62 }); 63 $('.cw-choices-hot').trigger('cw-room-update'); 64 }) 65 .on('change', '.cw-passenger-type-qty', function(){ 66 cw_update_pos_in_room_max_guests($(this).closest('.cw-room-spec-cont')); 67 }) 68 69 .on('change', '.cw-passenger-type-adult-count', function() { 70 var spec_qty_cont = $('input.cw-premise-passengertype-adult-qty', $(this).closest('.cw-choices')); 71 var spec_qty = $(this).val(); 72 spec_qty_cont.val(spec_qty);
73 $('.cw-choices-hot').trigger('cw-room-update'); 74 }) 75 76 .on('change', '.cw-package-meals .cw-ctg', function(e){ 77 var cont = $(this).closest('.cw-package-meals'); 78 var details_conts = $('.cw-ctg-details-cont', cont); 79 details_conts.hide(); 80 $('input,select', details_conts).prop('disabled', true); 81 var ctg_details_cont = $('.cw-ctg-details-cont-' + $(this).val(), cont); 82 $('input,select', ctg_details_cont).prop('disabled', false); 83 ctg_details_cont.show(); 84 }) 85 .on('change', '.cw-package-meals .cw-ctg-copy-to', function(){ 86 var cont = $(this).hasClass('cw-ctg') ? 87 $('.cw-ctg-details-cont-' + $(this).val(), $(this).closest('.cw-package-meals')) : 88 $(this).closest('.cw-ctg-details-cont'); 89 var curval = $(this).val(); 90 $('.cw-ctg-copy-from-' + $(this).data('cw-ctg-copy-to'), cont).each(function(){ 91 $(this).val( curval ); 92 }); 93 }) 94 .on('cw-room-update', '.cw-choices-hot', function(e, UpdateNumIfPos){ 95 var room_ctg = $('.cw-room-categories-selector', this).val(); 96 97 if( '' == room_ctg ){ 98 $('.cw-room-warning', this).hide(); 99 } else { 100 var room_ctg_info = $('.cw-room-categories-selector option', this).filter(':selected'); 101 var min = parseInt(room_ctg_info.data('cw-min-guests'), 10); 102 var max = parseInt(room_ctg_info.data('cw-max-guests'), 10); 103 104 var max_per_type = {}; 105 $('.cw-choose-spec .passengertype-qty', $component).each(function(){ 106 var paxtype = $(this).data('passengertype'); 107 var n = parseInt($(this).val(), 10); 108 if( !isNaN(n) && '' != paxtype ){ 109 if( undefined === max_per_type[paxtype] ){ 110 max_per_type[paxtype] = n; 111 } 112 113 } 114 }); 115 var altered = false; 116 if( true === UpdateNumIfPos && !$(this).data('cw-room-update-in-progress') ){ 117 $('select.cw-passenger-type-qty', this).filter(':enabled').each(function(){ 118 var n = parseInt($(this).val(), 10); 119 if( isNaN(n) ){ 120 n = 0; 121 $(this).val(n); 122 log('setting to zero as not a number: ' + $(this).val()); 123 altered = true; 124 } 125 if( $('option[value="' + n + '"]', this).filter(':enabled').length == 0 ){ 126 var fixed = false; 127 for( var i = 1; i < n; i++ ){ 128 if( $('option[value="' + (n-i) + '"]', this).filter(':enabled').length ){ 129 $(this).val(n-i); 130 log('setting to ' + (n-i) + ' to fix pos (2nd attempt)'); 131 altered = true; 132 fixed = true; 133 break; 134 } 135 } 136 if( !fixed ){ 137 var paxtype = $(this).data('cw-passenger-type'); 138 var max_for_type = undefined === max_per_type[paxtype] ? 0 : max_per_type[paxtype]; 139 for( var i = 1; i < 5 && n+1 <= max_for_type; i++ ){ 140 if( $('option[value="' + (n+i) + '"]', this).filter(':enabled').length ){ 141 $(this).val(n+i); 142 log('setting to ' + (n+i) + ' to fix pos (2nd attempt)'); 143 altered = true; 144 fixed = true; 145 break; 146 } 147 } 148 } 149 } 150 }); 151 } 152 var _this = this; 153 var recalc_num_guests = function(){ 154 var num_guests = 0; 155 $('select.cw-passenger-type-qty', _this).not('.cw-passenger-type-infant_wo_bed-count').filter(':enabled').each(function(){ 156 var n = parseInt($(this).val(), 10); 157 if( !isNaN(n) ){ 158 num_guests += n; 159 } 160 }); 161 return num_guests; 162 }; 163 var num_guests = recalc_num_guests(); 164 165 if( isNaN(min) || min < 1 || min <= num_guests ){ 166 //log( 'min OK: ' + min + ' <= ' + num_guests ); 167 //$('.cw-room-warning-too-few', this).hide(); 168 } else { 169 if( true === UpdateNumIfPos && !$(this).data('cw-room-update-in-progress') ){ 170 $(this).data('cw-room-update-in-progress', true); 171 var num_more_req = min - num_guests; 172 $('select.cw-passenger-type-qty', this).filter(':enabled').each(function(){ 173 var n = parseInt($(this).val(), 10); 174 if( !isNaN(n) ){ 175 var paxtype = $(this).data('cw-passenger-type'); 176 var max_for_type = undefined === max_per_type[paxtype] ? 0 : max_per_type[paxtype]; 177 for(var i = 0; i < num_more_req && n + num_more_req - i <= max_for_type; i++){ 178 if( $('option[value="' + (n + num_more_req - i) + '"]', this).filter(':enabled').length ){ 179 $(this).val(n + num_more_req - i); 180 //log_o('Setting to fix min: ' + (n + num_more_req - i), $('option[value="' + (n + num_more_req - i) + '"]', this).filter(':enabled')); 181 altered = true; 182 break; 183 } 184 } 185 num_guests = recalc_num_guests(); 186 num_more_req = min - num_guests; 187 if( num_more_req < 1 ){ 188 return false;
189 } 190 } 191 }); 192 } 193 } 194 if( isNaN(max) || max < 1 || max >= num_guests ){ 195 //$('.cw-room-warning-too-many', this).hide(); 196 } else { 197 if( true === UpdateNumIfPos && !$(this).data('cw-room-update-in-progress') ){ 198 $(this).data('cw-room-update-in-progress', true); 199 var num_less_req = num_guests - max; 200 $('select.cw-passenger-type-qty', this).filter(':enabled').each(function(){ 201 var n = parseInt($(this).val(), 10); 202 if( !isNaN(n) ){ 203 for(var i = 0; i < num_less_req; i++){ 204 if( $('option[value="' + (n - num_less_req + i) + '"]', this).filter(':enabled').length ){ 205 $(this).val(n - num_less_req + i); 206 //log_o('Setting to fix max: ' + (n - num_less_req + i), $('option[value="' + (n - num_less_req + i) + '"]', this).filter(':enabled')); 207 altered = true; 208 break; 209 } 210 } 211 num_guests = recalc_num_guests(); 212 num_less_req = num_guests - max; 213 if( num_less_req < 1 ){ 214 return false; 215 } 216 } 217 }); 218 } 219 } 220 221 num_guests = recalc_num_guests(); 222 if( isNaN(min) || min < 1 || min <= num_guests ){ 223 //$('.cw-room-warning-too-few', this).hide(); 224 } else { 225 //log('min not OK: ' + min + ' > ' + num_guests); 226 $('.cw-room-warning-too-few .cw-room-warning-num', this).text(min); 227 $('.cw-room-warning-too-few', this).show().find('button').on('click', function(){ 228 window.accept_auto_update = true;
229 jQuery('.cw-choices-hot').trigger('cw-room-update', [window.accept_auto_update]); 230 window.accept_auto_update = false; 231 $(this).parent().hide(); 232 return false; 233 }); 234 } 235 if( isNaN(max) || max < 1 || max >= num_guests ){ 236 $('.cw-room-warning-too-many', this).hide(); 237 } else { 238 //log('max not OK: ' + max + ' < ' + num_guests); 239 $('.cw-room-warning-too-many .cw-room-warning-num', this).text(max); 240 $('.cw-room-warning-too-many', this).show().find('button').on('click', function(){ 241 window.accept_auto_update = true; 242 jQuery('.cw-choices-hot').trigger('cw-room-update', [window.accept_auto_update]); 243 window.accept_auto_update = false; 244 $(this).parent().hide(); 245 return false; 246 }); 247 } 248 249 $(this).data('cw-room-update-in-progress', false); 250 } 251 }); 252 253 $('.cw-car-ctg', $component).data('cw-package-skip-update', true).change().data('cw-package-skip-update', false); 254 $('.cw-package-meals .cw-ctg', $component).change(); 255 $('.cw-package-meals .cw-ctg-copy-to', $component).change(); 256 257 $('.cw-room-categories-selector', $component).trigger('change'); 258 $('.passengertype-qty', $('.cw-choose-spec')).addClass('exclude-from-cabin-validation'); 259 260}); 261})(jQuery, CarresWeb); 262 263function cw_update_pos_in_room_max_guests_child(container){ 264 if( undefined === container || '' == container ){ 265 container = 'body'; 266 } 267 var rooms = jQuery(container).hasClass('cw-room-spec-cont') ? jQuery(container) : jQuery('.cw-room-spec-cont', container); 268 rooms.each(function(){ 269 var room_cont = jQuery(this); 270 var max_num = parseInt(jQuery('.cw-room-hiddeninfo', room_cont).data('cw-max-pax'), 10); 271 if( isNaN(max_num) || 1 > max_num ){ 272 jQuery('.cw-maxinroomexceeeded', room_cont).removeClass('cw-maxinroomexceeeded').prop('disabled', false); 273 } else { 274 var num_remaining = max_num; 275 jQuery('.cw-passenger-type', room_cont).each(function(){ 276 if(!jQuery(this).hasClass('cw-passenger-type cw-passenger-type-infant_wo_bed')) { 277 return; 278 } 279 280 var num_here = parseInt(jQuery('.cw-passenger-type-qty', this).val(), 10); 281 var num_here_changed = false; 282 if( isNaN(num_here) || 0 > num_here ){ 283 num_here = 0; 284 num_here_changed = true; 285 } else if( num_here > num_remaining ){ 286 num_here = num_remaining; 287 num_here_changed = true; 288 289 } 290 if( num_here_changed ){ 291 var num_here_btn = jQuery('.cw-passenger-type-qty', this).val(num_here).trigger('change'); 292 //if( num_here_btn.length > 0 ){ 293 // num_here_btn.click(); 294 // return false; // click will trigger new cw-selctbutton-pressed so exit this loop and let the new one handle it 295 //} 296 } 297 298 jQuery('.cw-passenger-type-qty option', this).each(function() { 299 var val = parseInt(jQuery(this).val(), 10); 300 if(val > num_remaining) { 301 jQuery(this).prop('disabled', true).hide(); 302 } else { 303 jQuery(this).prop('disabled', false).show(); 304 } 305 }); 306 307 if(!jQuery(this).hasClass('cw-passenger-type cw-passenger-type-infant_wo_bed')) { 308 jQuery('select option[value="1"]', this).prop('disabled', false).show(); 309 } 310 311 var to_disable = jQuery('.cw-selectbutton-btn', this).not(':disabled:not(.cw-maxinroomexceeeded)').filter(function(){ 312 var val = parseInt(jQuery(this).val(), 10); 313 return !isNaN(val) && val > num_remaining; 314 }); 315 to_disable.addClass('cw-maxinroomexceeeded').prop('disabled', true); 316 var to_enable = jQuery('.cw-selectbutton-btn.cw-maxinroomexceeeded', this).filter(function(){ 317 var val = parseInt(jQuery(this).val(), 10); 318 return !isNaN(val) && val <= num_remaining; 319 }); 320 to_enable.removeClass('cw-maxinroomexceeeded').prop('disabled', false); 321 num_remaining -= num_here; 322 323 }); 324 if( 1 > num_remaining ){ 325 room_cont.addClass('cw-room-full'); 326 } else { 327 room_cont.removeClass('cw-room-full'); 328 } 329 } 330 }); 331} 332function cw_package_run_before_update(component){
333 jQuery('.cw-choices-hot').trigger('cw-room-update', [window.accept_auto_update]); 334 jQuery('.cw-package-meals .cw-ctg-copy-to', component).data('cw-package-skip-update', true).change().data('cw-package-skip-update', false); 335 jQuery('.cw-car-ctg', component).each(function(){ 336 var cont = jQuery(this).closest('.cw-package-order-row-input'); 337 if( '' == jQuery(this).val() ){ 338 jQuery('.cw-car-qty', cont).each(function(){ 339 var qty = parseInt(jQuery(this).val(), 10); 340 if( !isNaN(qty) && qty > 0 ){ 341 jQuery(this).data('cw-saved-val', qty); 342 } 343 jQuery(this).val(0); 344 }); 345 } else { 346 jQuery('.cw-car-qty', cont).each(function(){ 347 var qty = parseInt(jQuery(this).val(), 10); 348 var saved_qty = parseInt(jQuery(this).data('cw-saved-val'), 10); 349 if( (isNaN(qty) || qty < 1) && (!isNaN(saved_qty) && saved_qty > 0) ){ 350 jQuery(this).val(saved_qty); 351 } 352 }); 353 } 354 355 }); 356}
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.