1class StateMachine_Filtering { 2 constructor(parent) { 3 const self = this; 4 this.statemachine = parent; 5 self.statemachineElement = self.statemachine.parent; 6 self.availableTags = self.statemachineElement.data("available-tags"); 7 this.awake(); 8 setTimeout(function(){ 9 self.start(); 10 },0); 11 } 12 13 awake(){ 14 const self = this; 15 self.masks = self.statemachineElement.find(".dd-bolig-mask, .dd-status-indicator-mask"); 16 } 17 18 start(){ 19 const self = this; 20 } 21 22 23 // FILTERING 24 applyFilters(filters){ 25 const self = this; 26 const isResetting = Object.keys(filters).length === 0 && filters.constructor === Object; 27 if(isResetting){ 28 self.masks.removeClass("dd-filtered-out"); 29 self.statemachineElement.removeClass("dd-is-filtering"); 30 return; 31 } 32 self.statemachineElement.addClass("dd-is-filtering"); 33 self.masks.addClass("dd-filtered-out"); 34 const visibleBoligMasks = self.masks.filter(function(){ 35 return self.isWithinFilters(this, filters); 36 }).removeClass("dd-filtered-out"); 37 } 38 39 isWithinFilters(mask, filters){ 40 const self = this; 41 const maskData = jQuery3_4_1(mask).find(".dd-mask-path"); 42 let flag = true; 43 if("rooms-min" in filters){ 44 const rooms = maskData.data("rooms"); 45 flag = flag && (filters["rooms-min"] <= rooms && rooms <= filters["rooms-max"]); 46 } 47 if("area-min" in filters){ 48 const area = maskData.data("area"); 49 flag = flag && (filters["area-min"] <= area && area <= filters["area-max"]); 50 } 51 if("cost-min" in filters){ 52 const cost = maskData.data("cost"); 53 flag = flag && (filters["cost-min"] <= cost && cost <= filters["cost-max"]); 54 } 55 56 const isExcluded = self.isMaskExcludedBecauseOfTags(maskData, filters) 57 flag = flag && ! isExcluded; 58 return flag; 59 } 60 61 isMaskExcludedBecauseOfTags(maskData, filters){ 62 const self = this; 63 if( ! self.hasAnyCategoryFiltering(filters) ) { 64 return false; // NOT exluded: not filtering on any tags 65 } 66 const tags = maskData.data("tags"); 67 if ( ! tags ) { 68 return true; // Bolig IS excluded: it has no tags 69 } 70 return ! self.hasMatchingKeys(tags, filters); 71 } 72 73 hasAnyCategoryFiltering(filters){ 74 const self = this; 75 return self.hasMatchingKeys( self.availableTags , filters ); 76 } 77 78 hasMatchingKeys(arr, obj) { 79 return arr.some(key => key in obj); 80 } 81}
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.