1(function($) { 2 3 $(document).ready(function() { 4 5 6 $('.listing-wrapper[data-action]').each(function(){ 7 8 var list = $(this); 9 listing_get_items( list ); 10 11 var start_from = parseInt(list.attr('data-start-from')); 12 var max_amount_per_load = parseInt(list.attr('data-max-amount-per-load')); 13 if( max_amount_per_load ) { 14 start_from = parseInt(start_from) + max_amount_per_load; 15 list.attr( 'data-start-from', start_from ); 16 } 17 18 }); 19 20 // Show more 21 $('.listing-container .listing-show-more-button').on('click', function(){ 22 23 var list = $(this).closest('.listing-bottom-wrapper').prev('.listing-wrapper'); 24 var start_from = parseInt(list.attr('data-start-from')); 25 var max_amount_per_load = parseInt(list.attr('data-max-amount-per-load')); 26 var show_more_height = $(this).closest('.listing-show-more-wrapper').outerHeight(); 27 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').css('height', show_more_height); 28 29 $(this).closest('.listing-show-more-wrapper').fadeOut('fast', function(){ 30 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').fadeIn('fast'); 31 32 setTimeout(function(){ 33 listing_get_items( list ); 34 if( max_amount_per_load ) { 35 start_from = parseInt(start_from) + max_amount_per_load; 36 list.attr( 'data-start-from', start_from ); 37 } 38 },300); 39 }); 40 41 }); 42 43 // Dropdown 44 $('.listing-category-select').change(function(){ 45 46 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 47 var selected = $(this).find('option:selected'); 48 var taxonomy = selected.data('taxonomy'); 49 var term = $(this).val(); 50 51 hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term ); 52 53 }); 54 55 // Dropdown with multiselect 56 $('.listing-category-multi-select').on('change', function() { 57 58 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 59 var filters_wrapper = $(this).closest('.listing-container').find('.listing-filters-wrapper'); 60 var selected = $(this).find('option:selected'); 61 var taxonomy = selected.attr('data-taxonomy'); 62 var term = $(this).val(); 63 var label = selected.html(); 64 65 hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term, 'add' ); 66 67 if( filters_wrapper.find('.listing-filter-choice[data-term="' + term + '"][data-taxonomy="' + taxonomy + '"]').length == 0 ) { 68 filters_wrapper.find('.listing-selected-filter-choices').append('<div class="listing-filter-choice button-small" data-term="' + term + '" data-taxonomy="' + taxonomy + '">' + label + '<span class="remove"></span></div>'); 69 } 70 71 $(this).val(''); 72 $(this).trigger('change.select2'); 73 74 filters_wrapper.find('.listing-filters-bottom').removeClass('hidden'); 75 76 }); 77 78 $(document).on('click', '.listing-filter-choice', function() { 79 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 80 var taxonomy = $(this).attr('data-taxonomy'); 81 var term = $(this).attr('data-term'); 82 var wrapper = $(this).closest('.listing-selected-filter-choices'); 83 $(this).closest('.listing-filter-choice').remove(); 84 if( wrapper.children().length == 0 ) wrapper.closest('.listing-filters-bottom').addClass('hidden'); 85 hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term, 'remove' ); 86 }); 87 88 $('.listing-clear-selected-filter-choices').on('click', function() { 89 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 90 $(this).closest('.listing-filters-bottom').find('.listing-selected-filter-choices').html(''); 91 $(this).closest('.listing-filters-bottom').addClass('hidden'); 92 hoyrymoottori_listing_filter_taxonomy( list, null, null, 'remove_all' ); 93 }); 94 95 // Tabs 96 $('.listing-category-tabs-wrapper a').on('click', function() { 97 98 $(this).closest('.tabs').find('.tabs-title').removeClass('is-active'); 99 $(this).closest('.tabs-title').addClass('is-active'); 100 101 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 102 var taxonomy = $(this).data('taxonomy'); 103 var term = $(this).data('term'); 104 105 if( term == 'all' ){ 106 hoyrymoottori_listing_filter_taxonomy( list, null, null, 'remove_all' ); 107 } else { 108 hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term ); 109 } 110 111 }); 112 113 // Buttons 114 $('.listing-category-buttons-wrapper a').on('click', function() { 115 116 $(this).closest('.listing-category-buttons-wrapper').find('a').removeClass('is-active'); 117 $(this).addClass('is-active'); 118 119 var list = $(this).closest('.listing-container').find('.listing-wrapper'); 120 var taxonomy = $(this).data('taxonomy'); 121 var term = $(this).data('term'); 122 123 if( term == 'all' ){ 124 hoyrymoottori_listing_filter_taxonomy( list, null, null, 'remove_all' ); 125 } else { 126 hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term ); 127 } 128 129 130 }); 131 132 function hoyrymoottori_listing_filter_taxonomy( list, taxonomy, term, type = 'replace' ) { 133 134 var max_amount_per_load = parseInt( list.attr('data-max-amount-per-load') ); 135 var taxonomies_and_terms = list.data('taxonomies-and-terms'); 136 137 var update_list = false;
138 139 if( type == 'replace' ) { 140 141 if( term == 'all' || term == '' ) { 142 143 $(taxonomies_and_terms).each(function() { 144 if( this.taxonomy === taxonomy ) { 145 146 this.term_ids = []; 147 hoyrymoottori_update_url_parameters( 'filter_' + taxonomy, 'all' ); 148 149 } 150 }); 151 152 } 153 else { 154 155 $(taxonomies_and_terms).each(function() { 156 if( this.taxonomy === taxonomy ) { 157 158 this.term_ids = [term]; 159 hoyrymoottori_update_url_parameters( 'filter_' + taxonomy, term ); 160 161 } 162 }); 163 164 } 165 166 update_list = true; 167 168 } 169 else if( type == 'add' ) { 170 171 $(taxonomies_and_terms).each(function() { 172 if( this.taxonomy === taxonomy ) { 173 if( this.term_ids.indexOf( parseInt( term ) ) == -1 ) { 174 175 this.term_ids.push( parseInt( term ) ); 176 hoyrymoottori_update_url_parameters( 'filter_' + taxonomy, this.term_ids ); 177 update_list = true; 178 179 } 180 } 181 }); 182 183 } 184 else if( type == 'remove' ) { 185 186 $(taxonomies_and_terms).each(function() { 187 if( this.taxonomy === taxonomy ) { 188 189 index = this.term_ids.indexOf( parseInt( term ) ); 190 191 if( index > -1 ) { 192 193 this.term_ids.splice( index, 1 ); 194 195 if( this.term_ids.length > 0 ) { 196 hoyrymoottori_update_url_parameters( 'filter_' + taxonomy, this.term_ids ); 197 } 198 else { 199 hoyrymoottori_update_url_parameters( 'filter_' + taxonomy, 'all' ); 200 } 201 202 } 203 204 } 205 }); 206 207 update_list = true; 208 209 } 210 else if( type == 'remove_all' ) { 211 212 $(taxonomies_and_terms).each(function() { 213 this.term_ids = []; 214 hoyrymoottori_update_url_parameters( 'filter_' + this.taxonomy, 'all' ); 215 }); 216 217 update_list = true; 218 219 } 220 221 if( update_list ) { 222 223 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').css('height', 300); 224 list.next('.listing-bottom-wrapper').find('.listing-show-more-wrapper').fadeOut('fast'); 225 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').fadeIn('fast'); 226 227 list.fadeOut('fast', function(){ 228 list.html(''); 229 }); 230 231 list.attr( 'data-start-from', 0 ); 232 233 list.attr('data-taxonomies-and-terms', JSON.stringify(taxonomies_and_terms)); 234 235 setTimeout(function(){ 236 listing_get_items( list ); 237 list.fadeIn('slow'); 238 239 if( max_amount_per_load ) { 240 list.attr( 'data-start-from', max_amount_per_load ); 241 } 242 }, 300); 243 244 } 245 246 } 247 248 // Search 249 $('.listing-search-button').on('click', function () { 250 251 var input = $(this).closest('.listing-search-wrapper').find('.listing-search-input'); 252 listing_search( input ); 253 254 }); 255 $('.listing-search-input').keyup(function(e){ 256 257 if(e.keyCode === 13) { 258 listing_search( $(this) ) 259 } 260 261 }); 262 263 function listing_search( input ) { 264 265 var list = input.closest('.listing-container').find('.listing-wrapper'); 266 var search_keywords = input.val(); 267 var max_amount_per_load = parseInt(list.attr('data-max-amount-per-load')); 268 269 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').css('height', 300); 270 list.next('.listing-bottom-wrapper').find('.listing-show-more-wrapper').fadeOut('fast'); 271 list.next('.listing-bottom-wrapper').find('.listing-loader-wrapper').fadeIn('fast'); 272 273 list.fadeOut('fast', function(){ 274 list.html(''); 275 }); 276 277 list.attr( 'data-search', search_keywords ); 278 list.attr( 'data-start-from', 0 ); 279 280 setTimeout(function(){ 281 listing_get_items( list ); 282 list.fadeIn('slow'); 283 284 if( max_amount_per_load ) { 285 list.attr( 'data-start-from', max_amount_per_load ); 286 } 287 },300); 288 289 } 290 291 function listing_get_items( list ) { 292 293 list.closest('.listing-container').addClass('loading'); 294 295 $.ajax({ 296 dataType: "json", 297 type: 'GET', 298 url: hoyrymoottori_resturl + list.attr('data-action'), 299 beforeSend: function ( xhr ) { 300 if ($('body').hasClass('logged-in')) { 301 xhr.setRequestHeader( 'X-WP-Nonce', hoyrymoottori_restnonce ); 302 } 303 }, 304 data: { 305 language_slug: hoyrymoottori_current_language_slug, 306 post_id: list.attr('data-post-id'), 307 user_id: list.attr('data-user-id'), 308 type: list.attr('data-type'), 309 post_type: list.attr('data-post-type'), 310 parent_page_id: list.attr('data-parent-page-id'), 311 orderby: list.attr('data-orderby'), 312 max_amount: list.attr('data-max-amount'), 313 max_amount_per_load: list.attr('data-max-amount-per-load'), 314 manual_items: list.attr('data-manual-items'), 315 custom_items: list.attr('data-custom-items'), 316 show_categories: list.attr('data-show-categories'), 317 show_locations: list.attr('data-show-locations'), 318 show_post_types: list.attr('data-show-post-types'), 319 show_images: list.attr('data-show-images'), 320 show_dates: list.attr('data-show-dates'), 321 show_ingress: list.attr('data-show-ingress'), 322 show_link_texts: list.attr('data-show-link-texts'), 323 link_text: list.attr('data-link-text'), 324 image_cropping: list.attr('data-image-cropping'), 325 start_from: list.attr('data-start-from'), 326 taxonomies_and_terms: list.attr('data-taxonomies-and-terms'), 327 search: list.attr('data-search'), 328 custom_params: list.attr('data-custom-params') 329 } 330 331 }
331).done(function(objData, textStatus, jqXHR) { 332 333 var status = objData.status; 334 var error_message = objData.error_message; 335 var data_returned = objData.data; 336 var post_count = objData.post_count; 337 var load_more = objData.load_more; 338 339 // Everything went well 340 if (status == 'success') { 341 342 list.closest('.listing-container').find('.listing-loader-wrapper').fadeOut('fast').css('display', 'none'); 343 344 if( data_returned != '' ) { 345 346 if (list.find('.grid-container').length > 0) { 347 list.find('.grid-container .grid-x').append(data_returned); 348 Foundation.reInit(list.find('.grid-container')); 349 } 350 else { 351 list.append(data_returned); 352 list.foundation(); 353 } 354 355 } 356 357 var start_from = parseInt( list.attr('data-start-from') ); 358 359 if( post_count < start_from || start_from == 0 ) start_from = post_count; 360 361 list.closest('.listing-container').find('.listing-categories-info-count-total').text( post_count ); 362 list.closest('.listing-container').find('.listing-categories-info-count').text( start_from ); 363 364 if( load_more ) { 365 list.closest('.listing-container').find('.listing-show-more-wrapper').fadeIn('fast').css('display', 'block'); 366 } 367 368 list.closest('.listing-container').removeClass('loading'); 369 370 } 371 else { 372 console.warn(error_message); 373 } 374 375 if( objData.debug ) { 376 console.info( objData.debug ); 377 } 378 379 }).fail(function(jqXHR, textStatus, errorThrown) { 380 381 console.error(errorThrown); 382 console.error(MLHttpRequest); 383 384 }); 385 386 } 387 388 389 }); 390 391})(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.