1/** 2 * @requires jQuery 2, CbUx, moment.js 3 * @param {type} $ 4 * @returns {undefined} 5 */ 6/* Detect mobile Devices */ 7var userAgent = navigator.userAgent || navigator.vendor || window.opera; 8 9var lastDay = null; 10var lastMonth = null; 11var initDatepicker = true; 12var oldDataEvent = []; 13var infiniteScrollEnabled = false; 14 15mobileAndTabletcheck = function () { 16 // Windows Phone must come first because its UA also contains "Android" 17 if (/windows phone/i.test(userAgent) || /android/i.test(userAgent) || (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream)) { 18 console.log(true); 19 return true; 20 } 21 return false; 22}; 23CbEventSearch = { 24 conf: { 25 event_api_url: ENV.link_root + '/event.json', 26 autocomplete_api_url: ENV.link_root + '/autocomplete.json?item=Cb3TcityTregionTcountry', 27 renderResults: function (data, append) { 28 if (append) { 29 data.EventOveriew = oldDataEvent.concat(data.EventOverview); 30 } else { 31 oldDataEvent = data.EventOverview; 32 } 33 34 $('#emptyResultsToInsert').hide(); 35 if(data.EventOverview.length === 0) { 36 $('#load-more-events-button').hide(); 37 } else if(infiniteScrollEnabled === false) { 38 $('#load-more-events-button').show(); 39 } 40 41 $.each(data.EventOverview, function (index, item) { 42 if (item.DateMonth !== lastMonth) { 43 44 lastMonth = item.DateMonth; 45 lastDay = item.DateDay; 46 item.IsNextMonth = true; 47 item.IsNextDay = true; 48 } else if (item.DateDay !== lastDay) { 49 50 lastDay = item.DateDay; 51 item.IsNextMonth = false; 52 item.IsNextDay = true; 53 } else { 54 55 item.IsNextMonth = false; 56 item.IsNextDay = false; 57 } 58 }); 59 var sortedData = []; 60 var sortedDayArray = []; 61 function sortDayArray() { 62 console.log(sortedDayArray); 63 if (sortedDayArray.length <= 2) { 64 /** if day counts 2 or less events we doesnt sort the array**/ 65 /** push every element of day array to sortedData **/ 66 sortedData = sortedData.concat(sortedDayArray); 67 } else { 68 var leftArray = []; 69 var rightArray = []; 70 /** sort events into left or right array **/ 71 $.each(sortedDayArray, function (index, item) { 72 if (item.Position === "left") { 73 leftArray.push(item); 74 } else { 75 rightArray.push(item); 76 } 77 }); 78 /** if one of left or right array is empty, we doesnt sort **/ 79 if (leftArray.length && rightArray.length) { 80 /** Oh, we really have to sort the events **/ 81 var dayLength = leftArray.length + rightArray.length; 82 var sorted = []; 83 for (var i = 0; i < dayLength; i++) { 84 if (i % 2 == 0) { 85 if (leftArray.length) { 86 sorted.push(leftArray.shift()); 87 } else if (rightArray.length) { 88 sorted.push(rightArray.shift()); 89 } 90 } else { 91 if (rightArray.length) { 92 sorted.push(rightArray.shift()); 93 } else if (leftArray.length) { 94 sorted.push(leftArray.shift()); 95 } 96 } 97 } 98 $.each(sorted, function (index, item) { 99 if (!index) { 100 item.IsNextDay = true; 101 } else { 102 item.IsNextDay = false;
103 item.IsNextMonth = false; 104 } 105 }); 106 107 sortedData = sortedData.concat(sorted); 108 ; 109 } else { 110 var mergedSides = leftArray.concat(rightArray); 111 sortedData = sortedData.concat(mergedSides); 112 } 113 } 114 } 115 ; 116 117 /** sort by days algorithm **/ 118 for (var i = 0; i < data.EventOverview.length; i++) { 119 console.log(i); 120 var item = data.EventOverview[i]; 121 122 if (Object.keys(item).length) { 123 if (!sortedDayArray.length && item.IsNextDay) { 124 sortedDayArray.push(item); 125 sortDayArray(); 126 sortedDayArray = []; 127 } else if (sortedDayArray.length && item.IsNextDay) { 128 sortDayArray(); 129 sortedDayArray = []; 130 sortedDayArray.push(item); 131 } else { 132 /** add item to day array **/ 133 sortedDayArray.push(item); 134 } 135 } 136 } 137 sortDayArray(); 138 data.EventOverview = sortedData; 139 console.log(sortedData); 140 var html = ''; 141 142 if (append) { 143 CbEventSearch.result_container.innerHTML += Mustache.render(document.getElementById('CbEventSearch-template').innerHTML, data) 144 } else { 145 // Results overview string 146 if (data.Pager && data.Pager.IsFirstPage) { 147// var count_results = document.querySelector('#result-feedback .count-results') 148// count_results.innerHTML = data.Pager.NbResults; 149// var area_name = data.CityName || data.RegionName; 150 /** 151 html += '<p>Found ' + data.Pager.NbResults + ' results ' + (area_name ? ' in ' + area_name : '') 152 if (data.Count && data.Count.Date) 153 html += ' [' + data.Count.Date + ' date results] ' 154 if (data.Count && data.Count.All) 155 html += ' [' + data.Count.All + ' all results] ' 156 157 html += '</p>' 158 **/ 159 } 160 CbEventSearch.result_container.innerHTML = html + Mustache.render(document.getElementById('CbEventSearch-template').innerHTML, data); 161 /** Cookie Listener **/ 162 CbEventSearch.cookieLastEvent(); 163 } 164 /* no results found */ 165 if (!CbEventSearch.result_container.innerHTML.length) { 166 CbEventSearch.result_container.innerHTML = $("#emptyResultsToInsert").html(); 167// if (!CbEventSearch.GET('city_range') || CbEventSearch.GET('city_range') == 200) { 168 $(".no_result_city_range").hide(); 169// } else { 170// $(".no_result_city_range").show(); 171// } 172// if (!CbEventSearch.GET('category')) { 173 $(".no_result_category").hide(); 174// } else { 175// $(".no_result_category").show(); 176// } 177 } 178 179 $('.reset_link').unbind('click').on('click', function () { 180 window.location = window.location.href.split("?")[0]; 181 }); 182 183 var calendarCarousel = function() { 184 $('.carousel').not($('.slick-initialized')).slick({ 185 dots: true, 186 arrows: false, 187 infinite: false, 188 centerMode: false, 189 speed: 800, 190 variableWidth: true, 191 slidesToShow: 1, 192 slidesToScroll: 1, 193 autoplaySpeed: 3000, 194 responsive: [ 195 { 196 breakpoint: 768, 197 settings: { 198 slidesToShow: 1, 199 slidesToScroll: 1, 200 } 201 } 202 ] 203 }); 204 $('.toggle-carousel').each(function () { 205 $(this).unbind('click'); 206 $(this).click(function (evt) { 207 $(this).closest($('.cal__event')).find($('.carousel-container')).toggleClass('open-carousel'); 208 $(this).closest($('.cal__event')).find($('.carousel')).each(function (event, slick) { 209 $(this).slick('slickSetOption', {autoplay: true}, true) 210 }) 211 evt.stopPropagation(); 212 evt.preventDefault(); 213 }) 214 }) 215 } 216 217 calendarCarousel(); 218 }, 219 city_ranges: [10, 25, 50, 100] 220 }, 221 loading: false, 222 paging_block: 1, 223 buttons: {}, 224 default_city_range: 5, 225 default_city_parent_range: 3, 226 default_category_system: '', 227 form_data: {}, 228 init: function () { 229 230 CbEventSearch.form = document.getElementById('CbEventSearch-form') 231 if (!CbEventSearch.form) 232 return 233 234 CbEventSearch.result_container = document.getElementById('CbEventSearch-result-container') 235 236 CbEventSearch.formal_select_input = document.getElementById('CbEventSearch-formal-select-input'); 237 CbEventSearch.location_select_input = document.getElementById('CbEventSearch-location-select-input'); 238 CbEventSearch.status_type_select_input = document.getElementById('CbEventSearch-status-type-select-input'); 239 240// CbEventSearch.query_input = document.querySelector('[name="q"]') 241// CbEventSearch.query_search_icon = document.querySelector('.searchfield__submit'); 242 CbEventSearch.search_icon = document.getElementById('CbEventSearch-search-icon'); 243 // TODO: Make this more transparent in code 244 CbEventSearch.geo_elements = document.querySelectorAll('.city-region-search-container, .locate-me-wrapper, #CbEventSearch-form') 245 CbEventSearch.geo_search_input = document.querySelector('[name="city_region_search"]') 246 247 CbEventSearch.geo_search_display = document.querySelectorAll('.show-location-name') 248 249 CbEventSearch.geo_lat_input = document.querySelector('[name="geo_lat"]') 250 CbEventSearch.geo_long_input = document.querySelector('[name="geo_long"]') 251 CbEventSearch.category_input = document.querySelector('[name="category"]'); 252 CbEventSearch.date_input = document.querySelector('[name="date"]'); 253 CbEventSearch.locate_me_button = document.querySelectorAll('.CbEventSearch-locate-me-button') 254 CbEventSearch.reset_location_button = document.getElementById('CbEventSearch-reset-location-button') 255 CbEventSearch.city_range_input = document.querySelector('[name="city_range"]') 256 CbEventSearch.city_range_parent_input = document.querySelector('[name="city_range_parent"]') 257 CbEventSearch.showrange = document.querySelector('.show-range'); 258 259 CbEventSearch.form.submit = CbEventSearch.submit 260 261 // Load data for input elements like eg. categories 262 CbEventSearch.loadInputOptions() 263 264 // Attach handlers to form elements 265 CbEventSearch.initForm() 266 267 // Check if GET parameters are in the url, 268 // if so we set the form values accordingly 269 if (window.location.search) { 270 CbEventSearch.setFormValues(CbEventSearch.form, CbEventSearch.GET()) 271 } 272 273 // set date for mobile month datepicker 274 initDatepicker = true; 275 $('div.date_month').datepick('setDate', $('input[name="date"]').val()); 276 initDatepicker = false;
277 278 // Form request 279 CbEventSearch.form.submit() 280 281 282 CbEventSearch.geoAsCollapsibleTogglerToo(); 283 CbEventSearch.clickOnMobileLocationName(); 284 285 CbEventSearch.onWindowLoadAndResize(); 286 CbEventSearch.isMobileDeviceClass(); 287 CbEventSearch.interceptEnterKey(); 288 CbEventSearch.cookieLastSearch(); 289 CbEventSearch.noResultButtonHandling(); 290 CbEventSearch.resetSearchToDefault(); 291 CbEventSearch.handleMeineOperFilter(); 292 if (mobileAndTabletcheck()) { 293 CbEventSearch.handleMobileFocusOnInput(); 294 } 295 $(".searchfield__submit").on("click", function () { 296 CbEventSearch.paging_block = 0; 297 CbEventSearch.form.submit(); 298 }); 299 300 $('#load-more-events-button').on('click', function() { 301 $('#load-more-events-button').hide(); 302 infiniteScrollEnabled = true; 303 $(window).trigger('scroll'); 304 }); 305 306 }, 307 handleMeineOperFilter: function () { 308 var oldWindowWidth = $(window).width(); 309 var subSearchInner = $(".sub-search-row-inner"); 310 $(window).on("load resize", function () { 311 thisWidth = $(this).width(); 312 if (thisWidth >= 768) { 313 $(".sub-search-row-inner, .more-filter-button").removeClass("hide-elems"); 314 subSearchInner.addClass("filter-visible"); 315 } else { 316 if (oldWindowWidth >= 768) { 317 subSearchInner.removeClass("filter-visible"); 318 } 319 } 320 oldWindowWidth = thisWidth; 321 }); 322 $(".more-filter-button").click(function () { 323 $(this).toggleClass("filter-visible"); 324 $(".sub-search-row-inner").toggleClass("filter-visible"); 325 }); 326 327 function valInSelectbox(select_pure) { 328 setTimeout(function () { 329 if (select_pure.find('.select-pure__option--selected').length) { 330 console.log(select_pure); 331 select_pure.addClass("not-all-selected"); 332 } else { 333 select_pure.removeClass("not-all-selected"); 334 } 335 }, 1000); 336 } 337 setTimeout(function () { 338 valInSelectbox($("#CbEventSearch-status-type-select-input")); 339 valInSelectbox($("#CbEventSearch-formal-select-input")); 340 valInSelectbox($("#CbEventSearch-location-select-input")); 341 }, 5000); 342 // if value selected on selectboxes 343 $("#CbEventSearch-form").on("click", ".select-pure__option", function () { 344 valInSelectbox($(this).parents(".autocomplete-select")); 345 console.log("click"); 346 }); 347 348 $(window).on("scroll", function () { 349 var pos = 50 - $(this).scrollTop(); 350 if (pos < 0) { 351 pos = 0; 352 } 353 $(".big-filter-container").css("top", pos + "px"); 354 if ($(window).width() <= 768) { 355 if ($(this).scrollTop() < 100) { 356 $(".sub-search-row-inner, .more-filter-button").removeClass("hide-elems"); 357 } else { 358 $(".more-filter-button.filter-visible .mf-container").click(); 359 $(".sub-search-row-inner, .more-filter-button").addClass("hide-elems"); 360 361 362 } 363 } 364 365 }); 366 367 // position of selectboxes in datepicker 368 function setSelectWidth(_this) { 369 370 _this.width(_this.find("option:selected").text().length * 12); 371 372 } 373 $(".datepick-month-year").each(function () { 374 setSelectWidth($(this)); 375 }); 376 $("body").on('click', function () { 377 if ($(".datepick-month-year").length > 2) { 378 $(".datepick-month-year").each(function () { 379 setSelectWidth($(this)); 380 }); 381 } 382 }); 383 $(".datepicker-container").on('click', function () { 384 $(".datepick-month-year").each(function () { 385 setSelectWidth($(this)); 386 }); 387 }); 388 $("body").on("change", ".datepick-month-year", function () { 389 setSelectWidth($(this)); 390 }); 391 392 $(".datepicker-container.open .over-after-date-closer").on("click", function () { 393 $(this).parent().click(); 394 }); 395 396 397 }, 398 handleMobileFocusOnInput: function () { 399 $(CbEventSearch.geo_search_input, CbEventSearch.category_input, CbEventSearch.date_input).on("focus", function () { 400 $("html, body").animate({ 401 scrollTop: $(this).offset().top 402 }, 500); 403 }); 404 $(CbEventSearch.date_input).attr("readonly", "readonly"); 405 }, 406 resetSearchToDefault: function () { 407 408 409// $("#CbEventSearch-form, #CbEventSearch-result-container").on("click", ".reset_link", function () { 410// 411// var today = new Date(); 412// var dateString = today.getDate() < 10 ? "0" + today.getDate() : today.getDate(); 413// dateString = dateString + "." + today.getMonth() + 1 + "." + today.getFullYear(); 414// CbEventSearch.setFormValues(CbEventSearch.form, { 415// // TODO: Check city_range / range differencies 416// city_range_parent: CbEventSearch.default_city_parent_range, 417// city_range: CbEventSearch.default_city_range, 418// range: '', 419// geo_city: '', 420// geo_lat: '', 421// geo_lng: '', 422// city_region_search: '', 423// id_city_region_search: '', 424// q: '', 425// p: 1, 426// date: dateString, 427// category: '', 428// location: '', 429// status_type: '' 430// }) 431// CbEventSearch.category_input.value = ''; 432// $(".select-pure__options .select-pure__option--selected").removeClass("select-pure__option--selected"); 433// $(".select-pure__option:first-child").addClass("select-pure__option--selected"); 434// $(".select-pure__label").html($(".select-pure__option:first-child").text()); 435// CbEventSearch.submit(); 436// }); 437 }, 438 noResultButtonHandling: function () { 439 $("#CbEventSearch-result-container").on("click", ".no_result_category, .no_result_city_range", function () { 440 if ($(this).hasClass("no_result_category")) { 441 CbEventSearch.category_input.value = ''; 442 $(".select-pure__options .select-pure__option--selected").removeClass("select-pure__option--selected"); 443 $(".select-pure__option:first-child").addClass("select-pure__option--selected"); 444 $(".select-pure__label").html($(".select-pure__option:first-child").text()); 445 } 446 CbEventSearch.submit(); 447 }); 448 }, 449 cookieLastEvent: function () { 450 if ($.cookie("lastEventUrl") !== undefined) { 451 $(".event").ready(function () { 452 var lastEvent; 453 var findLastEvent = function () { 454 lastEvent = $(".event .event-info-wrapper .title").find("[href='" + $.cookie("lastEventUrl") + "']"); 455 if (lastEvent.length) { 456 $("html, body").animate({ 457 scrollTop: lastEvent.offset().top - 150 458 }, 2000); 459 } else { 460 /** scroll down till user can see the last Event 461 console.log("scrollDown"); 462 $("html, body").animate({ 463 scrollTop:$(document).height() 464 }, 2000, function(){ 465 setTimeout(function(){ 466 CbEventSearch.cookieLastEvent(); 467 }, 1500); 468 }); 469 **/ 470 } 471 }; 472 findLastEvent(); 473 }); 474 } 475 }, 476 cookieLastSearch: function () { 477 $("#CbEventSearch-result-container").on("click", ".event .event-info-wrapper .title a", function (e) { 478 $.cookie("lastEventUrl", $(this).attr("href")); 479 }); 480 481 482 483 }, 484 interceptEnterKey: function () { 485 $(CbEventSearch.form).on("keyup keypress", function (e) { 486 var key_code = e.key_code || e.which 487 if (key_code === 13) { 488 e.preventDefault() 489 if ($(CbEventSearch.geo_search_input).hasClass("__AC_validated") || 490 ($("#CbEventSearch-form:not([class*=located]
490)").length && !$(CbEventSearch.geo_search_input).val().length)) { 491 CbEventSearch.submit(); 492 } 493 return false 494 } 495 }); 496 }, 497 isMobileDeviceClass: function () { 498 if (mobileAndTabletcheck()) { 499 $(CbEventSearch.form).addClass("isMobileDevice"); 500 } 501 if (/iPad|iPhone|iPod/.test(userAgent)) { 502 $(CbEventSearch.form).addClass("isApple"); 503 } 504 }, 505 506 categoryDatepickerArrowHandling: function () { 507 //TODO vanillaJS and rotate Arrows 508 $('body').on('DOMNodeInserted', '.datepick-popup', function () { 509 $("#CbEventSearch-form .datepicker-container").addClass("open"); 510 }); 511 $('body').on('DOMNodeRemoved', '.datepick-popup', function () { 512 $("#CbEventSearch-form .datepicker-container").removeClass("open"); 513 }); 514 515 $('body').on('click', '#CbEventSearch-formal-select-input', function (e) { 516 e.preventDefault(); 517 if (!$(this).children(".select-pure__select").hasClass("select-pure__select--opened")) { 518 $(CbEventSearch.formal_select_input).addClass("open"); 519 } else { 520 $(CbEventSearch.formal_select_input).removeClass("open"); 521 } 522 }); 523 }, 524 /*TODO OPTIMIZE */ 525 onWindowLoadAndResize: function () { 526 var attributeObj = $(".searchfield__input").parent(".searchfield-inner"); 527 $(window).on("resize load", function () { 528 /* Handle query inputfield placeholder for mobile devices */ 529 if ($(window).width() < 768) { 530 $(".searchfield__input").attr("placeholder", $(attributeObj).attr("mobile-placeholder")); 531 } else { 532 $(".searchfield__input").attr("placeholder", $(attributeObj).attr("desktop-placeholder")); 533 } 534 }); 535 }, 536 clickOnMobileLocationName: function () { 537 $('.show-location-name.mobile, #CbEventSearch-location-display .location_search_default').on("click", function () { 538 539 if (!$('.collapsible--noscroll').hasClass("open")) { 540 $(".collapsible-toggler").click(); 541 $(CbEventSearch.geo_search_input).focus(); 542 } 543 }); 544 }, 545 geoAsCollapsibleTogglerToo: function () { 546 //TODO vanillaJS 547 $("#CbEventSearch-location-display span:not(.location_search_located), #CbEventSearch-location-display span:not(.location_search_located)").on("click", function () { 548 //if sub search form is closed 549 if (!$(".top-form-part").hasClass("open")) { 550 $(".collapsible-toggler").click(); 551 $(CbEventSearch.geo_search_input).focus(); 552 } 553 }); 554 }, 555 /** Display city names and geoinformation on the input field **/ 556 handleGeoInputInit: function () { 557 558 }, 559 setGeoDisplay: function (value) { 560 561 }, 562 toggleGeoInputDisplay: function (reseted) { 563 564 }, 565 isGeoSearch: function (fields) { 566 return (fields.geo_lat || 567 fields.geo_lang || 568 fields.id_city_region_search || 569 fields.city_region_search || 570 fields.geo_city) 571 }, 572 loadResults: function (renderMethod, append) { 573 574 var append = append 575 576 CbEventSearch.loading = true 577 CbUx.showLoader() 578 579 // Get form values and make a virtual redirect 580 var form_data = CbEventSearch.formValues(CbEventSearch.form) 581 582 // Assign form_data for later use 583 CbEventSearch.form_data = CbEventSearch.cloneObject(form_data) 584 585 // Add pagination info 586 form_data.p = CbEventSearch.paging_block 587 588 // Set default city range 589 if (CbEventSearch.isGeoSearch(form_data) && !form_data.city_range) { 590 CbEventSearch.city_range_input.value = CbEventSearch.default_city_range 591 form_data.city_range = CbEventSearch.city_range_input.value 592 } 593 594 //add location 595 form_data.location = $('input[name="location"]').val(); 596 console.log(form_data); 597 598 $.ajax({ 599 type: 'GET', 600 dataType: "json", 601 url: CbEventSearch.conf.event_api_url, 602 data: form_data 603 }).done(function (data) { 604 605 CbEventSearch.loading = false 606 607 renderMethod(data, append) 608 609 if (data.Pager && data.Pager.NbResults > 0 && !data.Pager.IsLastPage) { 610 window.onscroll = function () { 611 if (CbEventSearch.loading || infiniteScrollEnabled === false) 612 return 613 if (document.body.clientHeight - (window.pageYOffset + window.innerHeight) < (window.innerHeight / 2)) { 614 CbEventSearch.paging_block += 1 615 // Load results but append them 616 CbEventSearch.loadResults(CbEventSearch.conf.renderResults, true); 617 } 618 } 619 } else { 620 window.onscroll = function () {} 621 } 622 623 }).fail( 624 CbUx.ajaxErrorEvent 625 ).always( 626 CbUx.hideLoader 627 ) 628 629 // Remove page indicator in url if page is 1 630 if (form_data.p == 1) 631 delete form_data.p 632 633 // Enable disable additional fields for geo search 634 CbEventSearch.toggleAdditionalGeoInputs(form_data) 635
636 // Do not show city_range in url if no range search is present 637 if (CbEventSearch.isGeoSearch(form_data)) { 638 639 // Remove id_city and geo_city 640 if (form_data.geo_lat && form_data.geo_long && form_data.id_city_region_search.indexOf('city') === -1) { 641 delete form_data.city_region_search 642 delete form_data.id_city_region_search 643 delete form_data.geo_city 644 // If its a region search we hide the city range select input 645 } else if (form_data.id_city_region_search && form_data.id_city_region_search.indexOf('region') !== -1) { 646 // alert('region search') 647 CbEventSearch.toggleCityRangeInput(false) 648 } 649 650 } else { 651 delete form_data.range 652 delete form_data.city_range 653 delete form_data.city_range_parent 654 // form_data.city_range = CbEventSearch.default_city_range 655 } 656 // Remove the date if its the current date 657 // if (CbEventSearch.GET('date') && CbEventSearch.GET('date') == moment().format('DD.MM.YYYY')) 658 // delete form_data.date 659 660 var url = location.pathname + CbEventSearch.objectToGETUrl(form_data) 661 history.pushState({url: url}, null, url); 662 663 664 /** Cookie Handling **/ 665 if ($.cookie('lastEventSearch') !== undefined) { 666 if (!window.location.href.includes($.cookie('lastEventSearch'))) { 667 $.removeCookie('lastEventUrl'); 668 } 669 } 670 //var splitUrl = window.location.href.split("&p="); 671 $.cookie('lastEventSearch', window.location.href); 672 673 674 675 }, 676 // If the current search is containing geo data we show or hide 677 // additional inputs like range or clearing of the geo data 678 toggleAdditionalGeoInputs: function (form_data) { 679 680 // Enable Geo Search 681 if (this.isGeoSearch(form_data)) { 682 CbEventSearch.toggleResetLoctionButton(true) 683 CbEventSearch.toggleCityRangeInput(true) 684 } else { 685 CbEventSearch.toggleResetLoctionButton(false) 686 CbEventSearch.toggleCityRangeInput(false) 687 } 688 }, 689 toggleResetLoctionButton: function (show) { 690 691 }, 692 toggleCityRangeInput: function (show) { 693 if (!this.city_range_parent_input) 694 return 695 if (show) { 696 $(".show-range-wrapper").removeClass("disabled_input"); 697 this.city_range_parent_input.classList.remove('disabled_input') 698 this.city_range_parent_input.disabled = false 699 } else { 700 $(".show-range-wrapper").addClass("disabled_input"); 701 this.city_range_parent_input.classList.add('disabled_input') 702 this.city_range_parent_input.disabled = true 703 } 704 }, 705 switchCategorySystem: function () { 706 CbEventSearch.setFormValues(CbEventSearch.form, {category: ''}) 707 CbEventSearch.paging_block = 0; 708 CbEventSearch.form.submit() 709 // Reload is needed here in order to initialize the category system again 710 location.reload() 711 }, 712 // Retrieve additional form input options from the server 713 loadInputOptions: function () { 714 715 // Do not load additional inputs with pureselect or category_system if 716 // no formal select is present 717 if (!CbEventSearch.formal_select_input) 718 return 719 720// var category_system = CbEventSearch.GET('category_system') || CbEventSearch.default_category_system 721 722 // Request EventCategories class in class.event_handler.php get() with "m" for method 723 $.ajax({ 724 type: 'GET', 725 dataType: "json", 726 url: CbEventSearch.conf.event_api_url, 727 data: { 728 // If no category_system from GET is available the 729 // $config[default_cb_cat_system] will be used 730 m: 'EventCategories' 731 732 } 733 }).done(function (options) { 734 735 // console.log('CAT SYSTEM: ' + category_system) 736 // console.log(options) 737 738 var content_select_config = { 739 autocomplete: false, 740 onChange: function (value) { 741 742 var inputs = document.getElementsByClassName('select-pure__autocomplete') 743 for (var i = 0, input; input = inputs[i]; i++) { 744 input.value = '' 745 CbEventSearch.pureCategorySelect._boundSortOptions({target: input}) 746 } 747 748 document.querySelector('input[name="category"]').value = value 749 CbEventSearch.paging_block = 0; 750 CbEventSearch.form.submit() 751 }, 752 options: options 753 } 754 755 // Show pureselect search box only if we have more 756 // than 11 Items in the categories overview 757 if (options.length > 20) { 758 content_select_config.autocomplete = true 759 } 760 761 // Set 762 content_select_config.value = CbEventSearch.GET('category') ? CbEventSearch.GET('category') : '' 763 CbEventSearch.pureCategorySelect = new SelectPure(CbEventSearch.formal_select_input, content_select_config) 764 765 }).fail( 766 // CbUx.ajaxErrorEvent 767 ).always( 768 // CbUx.hideLoader 769 ) 770 771 // Request EventCategories class in class.event_handler.php get() with "m" for method 772 $.ajax({ 773 type: 'GET', 774 dataType: "json", 775 url: CbEventSearch.conf.event_api_url, 776 data: { 777 // If no category_system from GET is available the 778 // $config[default_cb_cat_system] will be used 779 m: 'EventLocations' 780 781 } 782 }).done(function (options) { 783 784 // console.log('CAT SYSTEM: ' + category_system) 785 // console.log(options) 786 787 var content_select_config = { 788 autocomplete: false, 789 onChange: function (value) { 790 791 var inputs = document.getElementsByClassName('select-pure__autocomplete') 792 for (var i = 0, input; input = inputs[i]; i++) { 793 input.value = '' 794 CbEventSearch.pureLocationSelect._boundSortOptions({target: input}) 795 } 796 797 document.querySelector('input[name="location"]').value = value 798 CbEventSearch.paging_block = 0; 799 CbEventSearch.form.submit() 800 }, 801 options: options 802 } 803 804 // Show pureselect search box only if we have more 805 // than 11 Items in the categories overview 806 if (options.length > 20) { 807 content_select_config.autocomplete = true 808 } 809 810 // Set 811 content_select_config.value = CbEventSearch.GET('location') ? CbEventSearch.GET('location') : '' 812 CbEventSearch.pureLocationSelect = new SelectPure(CbEventSearch.location_select_input, content_select_config); 813 }).fail( 814 // CbUx.ajaxErrorEvent 815 ).always( 816 // CbUx.hideLoader 817 ) 818 819 820 // Request EventCategories class in class.event_handler.php get() with "m" for method 821 $.ajax({ 822 type: 'GET', 823 dataType: "json", 824 url: CbEventSearch.conf.event_api_url, 825 data: { 826 // If no category_system from GET is available the 827 // $config[default_cb_cat_system] will be used 828 m: 'EventStatusTypes' 829 830 } 831 }).done(function (options) { 832 833 // console.log('CAT SYSTEM: ' + category_system) 834 // console.log(options) 835 836 var content_select_config = { 837 autocomplete: false, 838 onChange: function (value) { 839 840 var inputs = document.getElementsByClassName('select-pure__autocomplete') 841 for (var i = 0, input; input = inputs[i]; i++) { 842 input.value = '' 843 CbEventSearch.pureContentCategorySelect._boundSortOptions({target: input}) 844 } 845 846 document.querySelector('input[name="status_type"]').value = value 847 CbEventSearch.paging_block = 0; 848 CbEventSearch.form.submit() 849 }, 850 options: options 851 } 852 853 // Show pureselect search box only if we have more 854 // than 11 Items in the categories overview 855 if (options.length > 20) { 856 content_select_config.autocomplete = true 857 } 858 859 // Set 860 content_select_config.value = CbEventSearch.GET('status_type') ? CbEventSearch.GET('status_type') : '' 861 CbEventSearch.pureContentCategorySelect = new SelectPure(CbEventSearch.status_type_select_input, content_select_config); 862 863 }).fail( 864 // CbUx.ajaxErrorEvent 865 ).always( 866 // CbUx.hideLoader 867 ) 868 869 }, 870 submit: function (e) { 871 872 if (e) { 873 alert('submit') 874 e.preventDefault() 875 } 876 877 if (CbEventSearch.loading) 878 return false 879 880 // Reset pagination 881 882 if (CbEventSearch.paging_block === 0) { 883 CbEventSearch.paging_block = 1; 884 } else { 885 var p_param = parseInt(CbEventSearch.GET('p')); 886 CbEventSearch.paging_block = p_param ? p_param : 1; 887 } 888 889 890 CbEventSearch.loadResults(function (data) { 891 892 if (CbEventSearch.isGeoSearch(CbEventSearch.form_data)) { 893 if (data.Pager && data.Pager.NbResults == 0) { 894 if (CbEventSearch.city_range_input) { 895 console.log("submit:" + CbEventSearch.city_range_input.value); 896 var current_range_index = CbEventSearch.conf.city_ranges.indexOf(parseInt(CbEventSearch.city_range_input.value)) 897 if (current_range_index > -1 && current_range_index < CbEventSearch.conf.city_ranges.length - 1) { 898 CbEventSearch.city_range_input.value = CbEventSearch.conf.city_ranges[current_range_index + 1] 899 CbEventSearch.form.submit() 900 return 901 } 902 } 903 } 904 905 } 906 CbEventSearch.conf.renderResults(data) 907 }) 908 return false 909 }, 910 initForm: function () { 911 lastDay = null; 912 lastMonth = null; 913 914 $(document).ready(function () { 915 CbEventSearch.categoryDatepickerArrowHandling(); 916 917 918 919 }); 920 921 // Assign onclick handers if available 922 if (CbEventSearch.locate_me_button) { 923 /* Make locate me button interactive 924 $(CbEventSearch.locate_me_button).on("click", function(){ 925 }); 926 */ 927 // Make reset of search 928 929 930 } 931 932 // datepicker 933 var date_input = $('input[name="date"]') 934 date_input.val(moment().format('DD.MM.YYYY')) 935 var date_input_month = $('div.date_month') 936 937// var array = ["1","2","3"] 938 939 date_input_month.datepick({ 940 showOnFocus: false, 941 onSelect: function () { 942 }, 943 onChangeMonthYear: function (year, month) { 944 if (initDatepicker === false) { 945 var monthString = parseInt(month) < 10 ? '0' + month : month 946 date_input.val('01.' + monthString + '.' + year); 947 CbEventSearch.paging_block = 0; 948 CbEventSearch.form.submit(); 949 } else { 950 initDatepicker = false;
951 } 952 953 } 954 }); 955 956 var timelineDatepicker = null; 957 958 date_input.datepick({ 959 onSelect: function (dates) { 960 timelineDatepicker.scrollToDate($('input[name="date"]').val()); 961 initDatepicker = true; 962 date_input_month.datepick('setDate', dates[0]); 963 initDatepicker = false; 964 CbEventSearch.paging_block = 0; 965 CbEventSearch.form.submit(); 966 }, 967 onDate: function (date, current) { 968// console.log(array.indexOf('' + date.getDate())); 969// if(array.indexOf('' + date.getDate()) == -1) { 970 return {selectable: true}; 971// } else { 972// return {selectable: false, dateClass: 'date-disabled'}; 973// } 974 } 975 }); 976 977 978 // CALENDAR TIMELINE start 979 function selectedDateCallbackTestFunction(date) { 980 $('input[name="date"]').val(date); 981 CbEventSearch.form.submit(); 982 } 983 984 if ($('#timeline-datepicker').length === 1) { 985 timelineDatepicker = new TimelineDatepicker( 986 $('#timeline-datepicker'), 987 selectedDateCallbackTestFunction 988 ); 989 990 setTimeout(function () { 991 timelineDatepicker.scrollToDate($('input[name="date"]').val()); 992 }, 1000); 993 } 994 // CALENDAR TIMELINE end 995 996 // Initialize autocomplete 997 if (CbEventSearch.geo_search_input) { 998 var jform = $(CbEventSearch.form) 999 $(CbEventSearch.geo_search_input, jform).autoComplete({ 1000 requestUrl: CbEventSearch.conf.autocomplete_api_url, 1001 putIdInto: 'input[name=id_city_region_search]', 1002 customCallbackFinal: function () { 1003 1004 CbEventSearch.setFormValues(CbEventSearch.form, { 1005 geo_city: '', 1006 geo_lat: '', 1007 geo_lng: '' 1008 }) 1009 CbEventSearch.form.submit() 1010 // Remove Geo search styling 1011 CbEventSearch.toggleGeoInputDisplay(false) 1012 // alert(CbEventSearch.geo_search_input.value) 1013 CbEventSearch.setGeoDisplay(CbEventSearch.geo_search_input.value) 1014 } 1015 }) 1016 } 1017 }, 1018 // Fill form with according values and check for select fillers 1019 setFormValues: function (form, values) { 1020 1021 var var_separator = '.' 1022 1023 // Set a value of an element 1024 function _setValue(element, value) { 1025 if (value === null) 1026 return 1027 // Set radio and checkboxes right 1028 if (element.type == 'radio' || element.type == 'checkbox') { 1029 if (element.type == 'radio' && element.value == value.toString()) { 1030 element.checked = true 1031 } else if (element.type == 'checkbox') { 1032 element.checked = parseInt(value) ? true : false 1033 } 1034 // Default (input type text or select for example) 1035 1036 } else 1037 element.value = value 1038 } 1039 1040 if (typeof form == 'string') 1041 form = document.querySelector(form) 1042 if (!values) 1043 values = {} 1044 // if (!form.onsubmit) form.onsubmit = function() { return false; } 1045 for (var i = 0, element, p; element = form.elements[i]; i++) { 1046 if (element.type == 'search' || element.type == 'text' || element.type == 'range' || element.type == 'checkbox' || element.type == 'hidden' || element.type == 'radio' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA') { 1047 var value = null 1048 p = element.name || element.id 1049 // Check if id contains [], if so we replace it for now, 1050 // is used in checkboxes for example 1051 if (p.indexOf('[') > 0) 1052 p = p.replace('[', '').replace(']', '') 1053 p = p.split(var_separator) 1054 switch (p.length) { 1055 // Set value.name 1056 case 1: 1057 if (typeof values[p[0]] != 'undefined') 1058 value = values[p[0]]; 1059 break 1060 // Set value.name.subname 1061 case 2: 1062 if (typeof values[p[0]] != 'undefined' && typeof values[p[0]][p[1]] != 'undefined') 1063 value = values[p[0]][p[1]]; 1064 break 1065 // Set value.name.subname.subsubname 1066 case 3: 1067 if (typeof values[p[0]] != 'undefined' && typeof values[p[0]][p[1]] != 'undefined' && typeof values[p[0]][p[1]][p[2]] != 'undefined') 1068 value = values[p[0]][p[1]][p[2]]; 1069 break 1070 } 1071 _setValue(element, value) 1072 } 1073 } 1074 }, 1075 GET: function (key, string) { 1076 var query = string || window.location.search.substring(1), 1077 result = {}, 1078 vars = query.split('&'), 1079 pair 1080 1081 for (var i = 0; i < vars.length; i++) { 1082 pair = vars[i].split('=') 1083 if (pair[0]) { 1084 // console.log('DECODED: ' + pair[1]) 1085 pair[1] = decodeURIComponent(pair[1]).replace('+', ' ', 'g') 1086 if (key === pair[0]) 1087 return pair[1] 1088 if (typeof result[pair[0]] == 'undefined') { 1089 result[pair[0]] = pair[1] 1090 } else { 1091 if (typeof result[pair[0]] == 'object') 1092 result[pair[0]].push(pair[1]) 1093 else 1094 result[pair[0]] = [result[pair[0]], pair[1]] 1095 } 1096 } 1097 } 1098 if (key) 1099 return null 1100 return result 1101 }, 1102 // Clone an object instead of referencing 1103 cloneObject: function (o) { 1104 var n = {} 1105 for (var i in o) 1106 n[i] = (typeof o[i] == 'object') ? CbEventSearch.cloneObject(o[i]) : o[i] 1107 return n 1108 }, 1109 // Get all values of a given form 1110 formValues: function (form, skip_empty) { 1111 1112 var var_separator = '.' 1113 1114 if (typeof form == 'string') 1115 form = document.querySelector(form) 1116 1117 var values = {}, 1118 set_value 1119 1120 // if (!form.onsubmit) form.onsubmit = function() { return false; } 1121 for (var i = 0, value, p, element; element = form.elements[i]; i++) { 1122 set_value = true 1123 is_array = false
1124 p = (element.name || element.id) 1125 if (p) { 1126 // Check if id contains [], if so we replace it for now, 1127 // is used in checkboxes for example 1128 if (p.indexOf('[') > 0) { 1129 is_array = true 1130 p = p.replace('[', '').replace(']', ''); 1131 p_split = p.split(var_separator) 1132 if (typeof values[p_split[0]] == 'undefined') 1133 values[p_split[0]] = [] 1134 } 1135 if (element.type == 'radio') { 1136 if (element.checked) 1137 value = element.value 1138 else 1139 set_value = false 1140 } else if (element.type == 'checkbox') { 1141 if (element.value && element.value != 'on' && element.value != '0' && element.value != '1') 1142 value = element.checked ? element.value : '' 1143 else 1144 value = element.checked ? 1 : 0 1145 } else 1146 value = element.value 1147 1148 if (set_value) { 1149 p = p.split(var_separator) 1150 switch (p.length) { 1151 case 1: 1152 if (!value && skip_empty) 1153 break 1154 if (is_array) 1155 values[p[0]].push(value) 1156 else 1157 values[p[0]] = value 1158 break 1159 case 2: 1160 if (typeof values[p[0]] == 'undefined') 1161 values[p[0]] = {} 1162 values[p[0]][p[1]] = value 1163 break 1164 case 3: 1165 if (typeof values[p[0]] == 'undefined') 1166 values[p[0]] = {} 1167 if (typeof values[p[0]][p[1]] == 'undefined') 1168 values[p[0]][p[1]] = {} 1169 values[p[0]][p[1]][p[2]] = value 1170 break 1171 } 1172 } 1173 } 1174 } 1175 return values 1176 }, 1177 // Take an object with key value pairs and create a get url from it, eg {foo:bar,x:y} becomes ?foo=bar&x=z 1178 // If include_empty is set, also empty values will be sent 1179 objectToGETUrl: function (o, include_empty) { 1180 var s = '?' 1181 for (var p in o) { 1182 if (include_empty || o[p]) 1183 s += encodeURIComponent(p) + '=' + encodeURIComponent(o[p]) + '&' 1184 } 1185 return s.slice(0, -1) 1186 } 1187} 1188 1189$(document).ready(function () { 1190 if($('#CbEventSearch-form').length !== 0) { 1191 CbEventSearch.init(); 1192 } 1193});
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.