1SitePlannerFrontendModulesWorldMap = { 2 /** 3 * @param {Object} config 4 */ 5 init: function(config) { 6 var me = this; 7 8 this.resultsOpened = false; 9 this.detailOpened = false; 10 this.currentRegionTagId = null; 11 this.currentRegionTitle = null; 12 this.page = 1; 13 this.holder = config.container; 14 this.settings = config.settings; 15 this.moduleItemId = config.moduleItemId; 16 17 this.mapContainer = this.holder.find('.map-container'); 18 this.resultsPopup = this.holder.find('.results-popup'); 19 this.resultsPopupClose = this.resultsPopup.find('.close-button'); 20 this.resultsPopupItemsContainer = this.resultsPopup.find('.items'); 21 this.mapPins = this.holder.find('.region-overlay'); 22 23 this.detailPopup = this.holder.find('.detail-popup'); 24 this.detailPopupClose = this.detailPopup.find('.close-button'); 25 this.detailPopupContent = this.detailPopup.find('.detail-content'); 26 27 this.contentTypeLabel = config.contentTypeLabel; 28 this.contentTypeLabelPlural = config.contentTypeLabelPlural; 29 30 this.activeFilters = []; 31 32 this.holder.find('.filter-tag input[type=checkbox]').change(function (event) { 33 var id = $(this).attr('id').replace('tag-', ''); 34 35 if(event.target.checked) { 36 me.activeFilters.push(id); 37 $(this).parent().addClass('checked'); 38 } else { 39 me.activeFilters.splice( $.inArray(id, me.activeFilters), 1 ); 40 $(this).parent().removeClass('checked'); 41 } 42 43 if(me.resultsOpened) { 44 me.closeResultsPopup(); 45 } 46 47 if(me.detailOpened) { 48 me.closeDetailPopup(); 49 } 50 51 me.holder.find('.filter').removeClass('visible'); 52 53 me.getCounts(); 54 }); 55 56 57 this.getCounts(); 58 59 this.holder.find('.filter-title').on('click', function(event, a, b) { 60 $(this).parent().siblings().removeClass('visible'); 61 $(this).parent().toggleClass('visible'); 62 }); 63 64 this.mapPins.on('click', function(event, a, b) { 65 if(parseInt($(this).find('.count .number').text()) > 0) { 66 me.openResultsPopup($(this).data('tag-id'), $(this).find('.title').text()); 67 } 68 }); 69 70 this.resultsPopupClose.on('click', function(event, a, b) { 71 me.closeResultsPopup(); 72 }); 73 this.resultsPopup.find('.prev-page').on('click', function(event, a, b) { 74 me.prevPage(); 75 }); 76 this.resultsPopup.find('.next-page').on('click', function(event, a, b) { 77 me.nextPage(); 78 }); 79 80 this.detailPopupClose.on('click', function(event, a, b) { 81 me.closeDetailPopup(); 82 }); 83 }, 84 85 getCounts: function() { 86 var me = this; 87 88 $.ajax({ 89 type: 'POST', 90 url: SS.route('SitePlanner', 'SitePlannerModules', 'worldMapGetCounts', null), 91 data: { 92 'module_item_id': this.moduleItemId, 93 'filters': this.activeFilters 94 }, 95 beforeSend: function () { 96 me.holder.addClass('loading'); 97 }, 98 complete: function () { 99 me.holder.removeClass('loading'); 100 }, 101 success: function (response) { 102 me.updateMapCounts(response.regionCounts); 103 me.updateFilterCounts(response.filterCounts); 104 } 105 }); 106 }, 107 108 updateMapCounts: function (counts) { 109 var me = this; 110 111 $.each(counts, function (regionName, count) { 112 var regionOverlayEl = me.holder.find('.region-overlay.' + regionName.replace('region_', '').replace('_', '-')); 113 114 if(parseInt(count) > 0) { 115 var countEl = regionOverlayEl.find('.count span.number'); 116 var labelEl = regionOverlayEl.find('.count span.count-label'); 117 118 countEl.text(count); 119 120 if(count === 1) { 121 labelEl.text(me.contentTypeLabel); 122 } else { 123 labelEl.text(me.contentTypeLabelPlural); 124 } 125 126 regionOverlayEl.removeClass('hidden'); 127 } else { 128 regionOverlayEl.addClass('hidden'); 129 } 130 }); 131 }, 132 133 updateFilterCounts: function(counts) { 134 var me = this; 135 136 $.each(counts, function (tagId, count) { 137 var labelCountEl = me.holder.find('#tag-count-' + tagId); 138 var filterTagEl = labelCountEl.parents('.filter-tag'); 139 140 if (count === 0 && me.settings['hide_empty_filters'] && parseInt(me.settings['hide_empty_filters'])) { 141 // Hide the filter 142 filterTagEl.addClass('zero-count').hide(); 143 } else { 144 filterTagEl.removeClass('zero-count').show(); 145 labelCountEl.text(' (' + count + ')'); 146 } 147 }); 148 149 // Check if all tags in a category were hidden, and hide the category 150 $.each(this.holder.find('.filter'), function (index, filter) { 151 var visibleTagFilters = $(filter).find('.filter-tag:not(.zero-count)'); 152 153 if(visibleTagFilters.length === 0) { 154 $(filter).hide(); 155 } else { 156 $(filter).show(); 157 } 158 }) 159 160 isMobile = typeof window.matchMedia !== 'undefined' && $.isFunction(window.matchMedia) && window.matchMedia("(max-width: 900px)").matches; 161 162 if(!isMobile) { 163 this.truncateFilters(); 164 } 165 }, 166 167 truncateFilters: function() { 168 var countIfMoreThen = 7; 169 170 $.each(this.holder.find('.filter-tags'), function (index, module) { 171 var $tagGroup = $(this); 172 var $tagGroupItems = $tagGroup.find('.filter-tag:not(.zero-count) label'); 173 var checkedItems = $tagGroupItems.filter('.checked').length; 174 175 if (checkedItems > countIfMoreThen) { 176 countIfMoreThen = checkedItems; 177 } 178 179 if ($tagGroupItems.length > countIfMoreThen) { 180 // Place checked tags first in the list 181 $.each($tagGroupItems, function (index, tag) { 182 if ($(this).hasClass('checked')) { 183 $(this).parent().prependTo($tagGroup); 184 } 185 }); 186 // Re read all group tag items 187 $tagGroupItems = $tagGroup.find('label'); 188 189 // Delete Show more if present 190 $tagGroup.closest('.filter').find('.show_more').remove(); 191 // Create the Show more link 192 var $showMore = $('<a/>').attr('href', '#').html(__d('site_planner','See more')).addClass('show_more').appendTo($tagGroup.closest('.filter')); 193 $tagGroupItems.filter(':gt(' + (countIfMoreThen - 1) + ')').hide(); 194 $tagGroup.data('collapsed', true); 195 196 // register show more link listeners 197 $showMore.on('click', function (event) { 198 event.preventDefault(); 199 if ($tagGroup.data('collapsed')) { 200 $tagGroupItems.filter(':gt(' + (countIfMoreThen - 1) + ')').slideDown(200); 201 $tagGroup.data('collapsed', false); 202 $showMore.html(__d('site_planner','See less')); 203 } else { 204 $tagGroupItems.filter(':gt(' + (countIfMoreThen - 1) + ')').slide
204Up(200); 205 $tagGroup.data('collapsed', true); 206 $showMore.html(__d('site_planner','See more')); 207 } 208 }); 209 } 210 }); 211 }, 212 213 closeResultsPopup: function() { 214 this.resultsPopup.removeClass('visible'); 215 216 this.mapContainer.removeClass('popup-open'); 217 218 this.resultsOpened = false; 219 this.page = 1; 220 }, 221 222 openResultsPopup: function(regionTagId, title) { 223 var me = this; 224 225 this.currentRegionTagId = regionTagId; 226 this.currentRegionTitle = title; 227 228 $.ajax({ 229 type: 'POST', 230 url: SS.route('SitePlanner', 'SitePlannerModules', 'worldMapGetItems', null), 231 data: { 232 'page': this.page, 233 'module_item_id': this.moduleItemId, 234 'filters': this.activeFilters.concat(regionTagId) 235 }, 236 beforeSend: function () { 237 me.holder.addClass('loading'); 238 }, 239 complete: function () { 240 me.holder.removeClass('loading'); 241 }, 242 success: function (response) { 243 me.resultsPopupItemsContainer.html(''); 244 245 if(response.renderedItems && response.renderedItems.length > 0) { 246 me.resultsPopupItemsContainer.html(response.renderedItems.join(' ')); 247 } 248 249 if(response.items && response.items.length > 0) { 250 $.each(response.items, function (index, item) { 251 if(item['_link_'] && item['_link_'].length > 0) { 252 me.resultsPopupItemsContainer.find('a[href="' + item['_link_'] + '"]').click(function (event) { 253 event.preventDefault(); 254 me.openDetailPopup(item['ContentItem']['id']); 255 }); 256 } 257 }); 258 } 259 260 me.togglePagination(response.total); 261 262 me.resultsPopup.find('.subtitle .count').text(response.total); 263 264 var label = me.resultsPopup.find('.subtitle .label'); 265 if(response.total === 1) { 266 label.text(me.contentTypeLabel.toUpperCase()); 267 } else { 268 label.text(me.contentTypeLabelPlural.toUpperCase()); 269 } 270 271 me.resultsPopup.find('.title').text(title); 272 273 me.resultsPopup.addClass('visible'); 274 275 me.mapContainer.addClass('popup-open'); 276 277 me.scrollToTop(); 278 279 me.resultsOpened = true; 280 } 281 }); 282 }, 283 284 openDetailPopup: function (contentItemId) { 285 var me = this; 286 287 $.ajax({ 288 type: 'POST', 289 url: SS.route('SitePlanner', 'SitePlannerModules', 'worldMapGetDetail', null), 290 data: { 291 'content_item_id': contentItemId, 292 'module_item_id': this.moduleItemId 293 }, 294 beforeSend: function () { 295 me.holder.addClass('loading'); 296 }, 297 complete: function () { 298 me.holder.removeClass('loading'); 299 }, 300 success: function (response) { 301 if(response.renderedItem && response.renderedItem.length > 0) { 302 me.detailPopupContent.html(response.renderedItem); 303 304 me.resultsPopup.css({ 305 position: 'absolute', 306 zIndex: -1 307 }); 308 309 me.detailPopup.addClass('visible'); 310 311 me.mapContainer.addClass('detail-popup-open'); 312 313 me.scrollToTop(); 314 315 me.detailOpened = true; 316 } 317 } 318 }); 319 }, 320 321 closeDetailPopup: function() { 322 this.resultsPopup.css({ 323 position: 'relative', 324 zIndex: 'auto' 325 }); 326 327 this.detailPopup.removeClass('visible'); 328 this.mapContainer.removeClass('detail-popup-open'); 329 this.detailOpened = false;
330 }, 331 332 togglePagination: function (total) { 333 this.holder.find('.prev-page, .next-page').removeClass('visible'); 334 335 var pages = Math.ceil(total / 6); 336 337 if(this.page > 1 && pages > 1) { 338 this.holder.find('.prev-page').addClass('visible'); 339 } 340 341 if(this.page < pages) { 342 this.holder.find('.next-page').addClass('visible'); 343 } 344 345 if(pages > 1) { 346 this.holder.find('.pagination .current-page').text(this.page); 347 this.holder.find('.pagination .total-pages').text(pages); 348 349 this.holder.find('.pagination').addClass('visible'); 350 } else { 351 this.holder.find('.pagination').removeClass('visible'); 352 } 353 }, 354 355 prevPage: function () { 356 this.page--; 357 this.openResultsPopup(this.currentRegionTagId, this.currentRegionTitle); 358 }, 359 360 nextPage: function () { 361 this.page++; 362 this.openResultsPopup(this.currentRegionTagId, this.currentRegionTitle); 363 }, 364 365 scrollToTop: function () { 366 if (typeof window.matchMedia !== 'undefined' && $.isFunction(window.matchMedia) && window.matchMedia("(min-width: 900px)").matches) { 367 return; 368 } 369 370 var destination = this.holder.offset().top; 371 var headerEl = $('.tpl-section-header'); 372 373 if(headerEl.length) { 374 destination = destination - headerEl.outerHeight(); 375 } 376 377 $("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, 500); 378 } 379};
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.