main.js
6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
$(document).ready(function () {
$(".open-popup").on('click', function (e) {
e.preventDefault();
var popupId = $(this).data('id');
$('.navbar-collapse').hide()
$(".popup").hide();
$("#overlay").show();
$('#' + popupId).fadeIn();
});
$(".close-popup").on('click', function () {
$("#overlay").hide();
$(this).parents('.popup').fadeOut();
//$.cookie('redirectUrl', '', {path: '/'});
});
$(".close-mobile-menu").on('click', function () {
$("#overlay").hide();
$(this).parents('.navbar-collapse').fadeOut();
});
$(".close-popup-info").on('click', function () {
$("#overlay").hide();
$(this).parents('.info-popup').fadeOut();
});
$(".js-dropdown-toggle").on("click", function (e) {
e.preventDefault();
$(this).next(".dropdown-list").slideToggle();
$(this).find(".caret-down").toggleClass('arrow-up');
});
$(".js-dropdown-toggle-by-click").on("click", function (e) {
e.preventDefault();
$(this).next(".js-dropdown-list").slideToggle();
$(this).find(".caret-down").toggleClass('arrow-up');
});
$(document).on("mousedown", function (e) {
if ($(".js-dropdown-toggle").has(e.target).length === 0) {
$(".js-dropdown-toggle+.dropdown-list").slideUp();
$(".js-dropdown-toggle .caret-down").removeClass('arrow-up');
}
});
var dropParent;
$(".select-dropdown").each(function () {
dropParent = $(this).parent();
$(this).select2({
dropdownParent: dropParent
});
});
$(".scroll-block").mCustomScrollbar();
function initSlider(element) {
var inpMin = element.closest(".rangeslider").find(".minVal");
var inpMax = element.closest(".rangeslider").find(".maxVal");
var valMin = inpMin.val();
var valMax = inpMax.val();
element.slider({
range: true,
min: element.data('min'),
max: element.data('max'),
values: [valMin, valMax],
slide: function (event, ui) {
inpMin.val(ui.values[0]);
inpMax.val(ui.values[1]);
}
});
inpMin.val(element.slider("values", 0));
inpMax.val(element.slider("values", 1));
}
//initSlider($( "#slider-range" ));
$(".js-slider").each(function () {
initSlider($(this));
});
$(".js-show-filter").on("click", function () {
$(this).hide();
$(this).next(".filters").show(200);
});
$(".close-filter").on("click", function () {
$(this).closest(".filters").hide(200);
$(this).closest(".maps-action-elements").find(".js-show-filter").show(200);
});
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
function myFilter() {
var directions = $("[data-type]");
var directionMap = {};
var rangers = $("[data-range]");
var rangersMap = {};
var minRange, maxRange, selectVal;
var selects = $("[data-select]");
var selectMap = {};
for (var i = 0, len = directions.length; i < len; i++) {
var elem = directions.eq(i);
if (!elem.prop("checked")) {
continue;
}
var type = parseInt(elem.attr("data-type"));
if (directionMap[type]) {
directionMap[type].push(parseInt(elem.attr("data-direction")));
} else {
directionMap[type] = [parseInt(elem.attr("data-direction"))];
}
}
for (var j = 0, leng = rangers.length; j < leng; j++) {
minRange = parseFloat(rangers.eq(j).find(".minVal").val());
maxRange = parseFloat(rangers.eq(j).find(".maxVal").val());
if (rangers.eq(j).attr("data-range")) {
rangersMap[rangers.eq(j).attr("data-range")] = {"min": minRange, "max": maxRange};
}
}
for (var k = 0, l = selects.length; k < l; k++) {
selectVal = selects.eq(k).val();
if (selectVal) {
selectMap[selects.eq(k).attr("data-select")] = selectVal;
}
}
return function (el) {
var result = false;
if (directionMap[el.type] && directionMap[el.type].indexOf(+el.direction) >= 0) {
result = true;
} else {
return false;
}
for (var feald in rangersMap) {
var fieldVal = parseFloat(el[feald]);
var range = rangersMap[feald];
if (el[feald] &&
fieldVal >= parseFloat(range.min) &&
fieldVal <= parseFloat(range.max)) {
result = true;
} else {
return false;
}
}
for (var feald1 in selectMap) {
if (el[feald1] && el[feald1] === selectMap[feald1]) {
result = true;
} else {
return false;
}
}
return result;
};
}
$(".filters input[type='checkbox']").on("change", function () {
var predicate = myFilter();
markers.forEach(function (el) {
el.setVisible(predicate(el));
console.log(predicate(el));
console.log(el);
});
markerCluster.clearMarkers();
markerCluster.addMarkers(markers.filter(function (el) {
return el.visible;
}));
});
$("#filter").on("click", function () {
var predicate = myFilter();
markers.forEach(function (el) {
el.setVisible(predicate(el));
console.log(predicate(el));
console.log(el);
});
markerCluster.clearMarkers();
markerCluster.addMarkers(markers.filter(function (el) {
return el.visible;
}));
});
var initMobileActions = function () {
$(".js-m-dropdown").on('click', function (e) {
e.preventDefault();
$(this).parent().find(".second-dropdown-list").slideToggle();
$(this).find(".caret-down").toggleClass("arrow-right");
});
};
var destroyMobileActions = function () {
$(".js-m-dropdown").off();
};
window.matchMedia('(max-width: 980px)').addListener(function (mq3) {
if (mq3.matches) {
initMobileActions();
}
else {
destroyMobileActions();
}
});
if (window.innerWidth <= 980) {
initMobileActions();
} else {
destroyMobileActions();
}
});