1/* ========================================================================== 2 tapahtumakalenteri.js 3========================================================================== */ 4 5(function($) { 6 7 // Event grid AJAX 8 function document_to_dom_object(data) { 9 return $($.trim(String(data) 10 .replace(/<\!DOCTYPE[^>]*>/i, '') 11 .replace(/<(html|head|body|title|meta|script)([\s\>])/gi, '<div class="document-$1"$2') 12 .replace(/<\/(html|head|body|title|meta|script)\>/gi, '</div>'))); 13 } 14 15 function supports_history_api() { 16 return !!(window.history && history.pushState); 17 } 18 19 $('#events-search-submit').click(function(e) { 20 e.preventDefault(); 21 $('#events-search-form').submit(); 22 }); 23 24 $(".sf-input-select").change(function(e) { 25 e.preventDefault(); 26 $('#events-search-form').submit(); 27 }); 28 29 $('#events-search-form-input').keyup(function(e) { 30 if (!$(this).val()) { 31 $('#empty-events-search').removeClass('show'); 32 } else { 33 $('#empty-events-search').addClass('show'); 34 } 35 }); 36 $('#events-search-form-input').trigger('keyup'); 37 38 // add class to even rows for styling 39 var partio_events_even_rows_class = function() { 40 var i = 1; 41 42 $('#events-search-results-content').find('.event-item').each(function() { 43 if (i % 2 === 0) { 44 $(this).addClass('even'); 45 } 46 47 i++; 48 }); 49 }; 50 51 partio_events_even_rows_class(); 52 53 function partio_events_ajax_to(url) { 54 55 $('#events-search-results').addClass('loading'); 56 console.log($('#events-search-results')); 57 var $destination = $('#events-search-results-content'); 58 59 $.ajax({ 60 url: url, 61 success: function(data, textStatus, jqXHR) { 62 63 // Prepare 64 var $data = document_to_dom_object(data); 65 var $dataBody = $data.find('.document-body:first'); 66 var $dataContent = $dataBody.find('#events-search-results-content'); 67 68 // Fetch the content 69 contentHtml = $dataContent.html() || $data.html(); 70 if (!contentHtml) { 71 document.location.href = url; 72 return false; 73 } 74 75 // Update the content 76 $destination.html(contentHtml); 77 $('#events-search-results').removeClass('loading'); 78 $('#events-search-results').addClass('has-content'); 79 80 partio_events_even_rows_class(); 81 82 // replace state 83 if (supports_history_api()) { 84 window.history.replaceState(url, '', url); 85 } 86 87 }, 88 error: function(jqXHR, textStatus, errorThrown) { 89 document.location.href = url; 90 return false; 91 } 92 93 }); // end ajax 94 } 95 96 $('#events-search-form').submit(function(e) { 97 e.preventDefault(); 98 var $form = $('#events-search-form'); 99 var url = $form.attr('action') + '?' + $form.serialize(); 100 partio_events_ajax_to(url); 101 }); 102 103 // Events search - load more 104 $('#page').on('click', '#events-search-load-more a', function(e) { 105 e.preventDefault(); 106 var $destination = $('.events-search-results-list').filter(':last'); 107 $('#events-search-load-more').addClass('loading'); 108 109 var url = $(this).attr('href'); 110 $(this).blur(); 111 $.ajax({ 112 url: url, 113 success: function(data, textStatus, jqXHR) { 114 115 // Prepare 116 var $data = document_to_dom_object(data); 117 var $dataBody = $data.find('.document-body:first'); 118 var $content = $dataBody.find('.events-search-results-list').filter(':first').addClass('entrance newpage'); 119 120 // insert more items 121 $content.insertAfter($destination); 122 123 // remove duplicate month dividers 124 var found = {}; 125 126 $('#events-search-results-content').find('[data-month]').each(function() { 127 var $this = $(this); 128 129 if (found[$this.data('month')]) { 130 $this.remove(); 131 } else { 132 found[$this.data('month')] = true; 133 } 134 }); 135 136 // re-apply even row classes after inserting new items 137 partio_events_even_rows_class(); 138 139 setTimeout(function() { 140 $('.events-search-results-list').removeClass('entrance'); 141 }, 250); 142 143 // manipulate load more button 144 if ($dataBody.find('#events-search-load-more').length) { 145 var new_href = $dataBody.find('#events-search-load-more a').attr('href'); 146 $('#events-search-load-more a').attr('href', new_href); 147 $('#events-search-load-more').removeClass('loading'); 148 } 149 150 }, 151 error: function(jqXHR, textStatus, errorThrown) { 152 document.location.href = url; 153 return false;
154 } 155 }); // end ajax 156 }); 157 158 159 160 $(".sf-input-select").select2({ 161 closeOnSelect: false, 162 }); 163 164 $("#page").on('click', '.select2-container', function(event) { 165 $(this).find('.select2-search__field').focus(); 166 }); 167 168 $("body").on('click', '.select2-results__option', function(event) { 169 var search_id = $(this).parent('.select2-results__options').attr('id'); 170 $('textarea[aria-controls=' + search_id + ']').focus(); 171 }); 172 173 $("#page").on('click focusin focus', '.select2-search__field', function(event) { 174 event.stopPropagation(); 175 }); 176 177 $('.select2-search__field').each(function() { 178 $(this).attr('placeholder', ''); 179 }); 180 181 $('.select2-selection--multiple').each(function() { 182 var placeholder_text = $(this).parent().parent().parent().find('.sf-input-select').data('placeholder'); 183 var span = $('<span />').text(placeholder_text).addClass('sf-placeholder'); 184 185 $(this).prepend(span); 186 187 if ($(this).find('.select2-selection__rendered').children('.select2-selection__choice').length > 0) { 188 span.addClass('sf-placeholder--hidden'); 189 } 190 191 }); 192 193 $('#page').on('DOMSubtreeModified', '.select2-selection--multiple .select2-selection__rendered', function() { 194 console.log('changed'); 195 var placeholder = $(this).parent().find('.sf-placeholder'); 196 197 if ($(this).children('.select2-selection__choice').length > 0) { 198 placeholder.addClass('sf-placeholder--hidden'); 199 } else { 200 placeholder.removeClass('sf-placeholder--hidden'); 201 } 202 }); 203 204 205 $(".js-datepicker").datepicker({ 206 dateFormat: "d.m.yy", 207 showOtherMonths: true, 208 beforeShow: function(input, inst) { 209 setTimeout(function() { 210 inst.dpDiv.css({ 211 top: $(".js-datepicker").offset().top + 35, 212 left: $(".js-datepicker").offset().left 213 }); 214 }, 0); 215 } 216 }); 217 218})(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.