1/** 2 * @namespace WPGMZA 3 * @module CustomFieldFilterController 4 * @requires WPGMZA 5 */ 6jQuery(function($) { 7 8 /** 9 * This module handles the custom field filtering logic 10 * @constructor 11 */ 12 WPGMZA.CustomFieldFilterController = function(map_id) 13 { 14 var self = this; 15 16 this.map_id = map_id; 17 this.widgets = []; 18 this.ajaxTimeoutID = null; 19 this.ajaxRequest = null; 20 21 // TODO: This will break pagination (page count mismatch) when we integrate pagination for basic styles. I suggest we unify the filtering before doing so 22 this.markerListingCSS = $("<style type='text/css'/>"); 23 $(document.body).append(this.markerListingCSS); 24 25 WPGMZA.CustomFieldFilterController.controllersByMapID[map_id] = this; 26 27 $("[data-wpgmza-filter-widget-class][data-map-id=" + map_id + "]").each(function(index, el) { 28 self.widgets.push( WPGMZA.CustomFieldFilterWidget.createInstance(el) ); 29 30 $(el).on("input change", function(event) { 31 self.onWidgetChanged(event); 32 }); 33 34 if($(el).is(":checkbox")) 35 $(el).on("click", function(event) { 36 self.onWidgetChanged(event); 37 }); 38 }); 39 40 var container = $(".wpgmza-filter-widgets[data-map-id='" + map_id + "']"); 41 $(container).find("button.wpgmza-reset-custom-fields").on("click", function(event) { 42 $(container).find("input:not([type='checkbox']):not([type='radio']), textarea").val(""); 43 $(container).find("input[type='checkbox']").prop("checked", false); 44 //$(container).find("option:selected").prop("selected", false); 45 //$(container).find("option[value='*']").prop("selected", true); 46 $(container).find("select").val(""); 47 self.onWidgetChanged(); 48 }); 49 }; 50 51 WPGMZA.CustomFieldFilterController.AJAX_DELAY = 500; 52 WPGMZA.CustomFieldFilterController.controllersByMapID = {}; 53 WPGMZA.CustomFieldFilterController.dataTablesSourceHTMLByMapID = {}; 54 55 WPGMZA.CustomFieldFilterController.createInstance = function(map_id) 56 { 57 return new WPGMZA.CustomFieldFilterController(map_id); 58 }; 59 60 WPGMZA.CustomFieldFilterController.prototype.getAjaxRequestData = function() { 61 var self = this; 62 63 var result = { 64 url: WPGMZA.ajaxurl, 65 method: "POST", 66 data: { 67 action: "wpgmza_custom_field_filter_get_filtered_marker_ids", 68 map_id: this.map_id, 69 widgetData: [] 70 }, 71 success: function(response, status, xhr) { 72 self.onAjaxResponse(response, status, xhr); 73 } 74 }; 75 76 this.widgets.forEach(function(widget) { 77 result.data.widgetData.push(widget.getAjaxRequestData()); 78 }); 79 80 return result; 81 }; 82 83 WPGMZA.CustomFieldFilterController.prototype.onWidgetChanged = function(event) { 84 var self = this; 85 86 var map = WPGMZA.getMapByID(this.map_id); 87 88 /* 89 * Temporary system to move DataTables back to page 1 before filter application 90 * 91 * We really should rework this into the core classes which manage filtering 92 * 93 * For now, this should hold up most of the time, but because it does not address the root cause, we can't rely on it permanently 94 * 95 * Added:2021-07-27 96 */ 97 if(map.markerListing && map.markerListing.dataTable && map.markerListing.dataTable.dataTable){ 98 map.markerListing.dataTable.dataTable.page(1).draw(); 99 } 100 101 map.markerFilter.update({}, this); 102 }; 103 104 WPGMZA.CustomFieldFilterController.prototype.onAjaxResponse = function(response, status, xhr) { 105 this.lastResponse = response; 106 107 var selectors = []; 108 109 for(var marker_id in marker_array[this.map_id]) 110 { 111 var visible = (response.marker_ids.length == 0 || response.marker_ids.indexOf(marker_id) > -1); 112 marker_array[this.map_id][marker_id].setVisible(visible); 113 114 if(!visible) 115 selectors.push(".wpgmaps_mlist_row[mid='" + marker_id + "']"); 116 } 117 118 if(wpgmaps_localize[this.map_id].order_markers_by && wpgmaps_localize[this.map_id].order_markers_by == 2) 119 { 120 wpgmza_update_data_table( 121 WPGMZA.CustomFieldFilterController.dataTablesSourceHTMLByMapID[this.map_id], 122 this.map_id 123 ); 124 } 125 else 126 { 127 this.markerListingCSS.html( selectors.join(", ") + "{ display: none; }" ); 128 129 var container; 130 if(this.currAdvancedTableHTML) 131 container = $("#wpgmza_marker_holder_" + this.map_id); 132 else 133 container = $(this.currAdvancedTableHTML); 134 135 this.applyToAdvancedTable(container); 136 } 137 }; 138 139 /** 140 * This function is a quick hack to re-apply the last response after the store locator 141 * has been used or marker listing filtering changes. This should be deprecated and 142 * the filtering system unified at some point. 143 * @return void 144 */ 145 WPGMZA.CustomFieldFilterController.prototype.reapplyLastResponse = function() { 146 if(!this.lastResponse) 147 return; 148 149 var response = this.lastResponse; 150 151 for(var marker_id in marker_array[this.map_id]) 152 { 153 var visible = (response.marker_ids.indexOf(marker_id) > -1); 154 marker_array[this.map_id][marker_id].setVisible(visible); 155 } 156 }; 157 158 WPGMZA.CustomFieldFilterController.prototype.applyToAdvancedTable = function() { 159 if(!this.lastResponse) 160 return; 161 162 var response = this.lastResponse; 163 var container = $("#wpgmza_marker_holder_" + this.map_id); 164 165 $(container).find("[mid]").each(function(index, el) { 166 var marker_id = $(el).attr("mid"); 167 if(response.marker_ids.indexOf(marker_id) == -1) 168 $(el).remove(); 169 }); 170 }; 171 172 $(window).on("load", function(event) { 173 174 if(WPGMZA.is_admin == 1) 175 return; 176 177 $(".wpgmza_map").each(function(index, el) { 178 var map_id = parseInt( $(el).attr("id").match(/\d+/)[0] ); 179 180 /*MYMAP[map_id].customFieldFilterController 181 = MYMAP[map_id].map.customFieldFilterController 182 = WPGMZA.CustomFieldFilterController.createInstance(map_id);*/ 183 184 setTimeout(function () { 185 $(el).children('div').first().after($('.wpgmza-modern-marker-open-button')); 186 }, 500); 187 }); 188 189 190 }); 191 192});
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.