PluginProbe
Event Post / 4.4
Event Post v4.4
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
event-post / js / eventpost.js

eventpost.js in Event Post 4.4, at js/eventpost.js

312 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global ol, eventpost_params */
2 jQuery( window ).load(function() {
3
4 if(typeof ol !== 'undefined'){
5 ep_maps = [];
6 ep_vectorSources = [];
7 ep_pop_elements = [];
8 ep_popups = [];
9 ep_icons = [];
10 ep_proj_source = new ol.proj.Projection({code: 'EPSG:4326'});
11 ep_proj_destination = new ol.proj.Projection({code: 'EPSG:900913'});
12 ep_interactions = eventpost_params.map_interactions;
13
14 /* ------------------------------------------------------------------------------------------------------------------
15 * Single Location link
16 * show it in a tiny map instead of following the link
17 */
18 jQuery('a.event_link.gps').click(function () {
19 if (jQuery(this).parent().data('latitude') !== undefined && jQuery(this).parent().data('longitude') !== undefined) {
20 var lat = jQuery(this).parent().data('latitude');
21 var lon = jQuery(this).parent().data('longitude');
22 var marker = jQuery(this).parent().data('marker');
23 var id = jQuery(this).parent().data('id');
24 var zoom = 16;
25 var map_id = 'event_map' + id;
26 var position = new ol.proj.transform([lon, lat], ep_proj_source, ep_proj_destination);
27 if (jQuery('#' + map_id).length === 0) {
28 jQuery(this).parent().append('<div id="' + map_id + '-wrap"><div id="' + map_id + '" class="event_map"></div></div>');
29 jQuery('#' + map_id+'-wrap').css({
30 height: '400px',
31 margin: 'auto',
32 clear: 'both'
33 }).animate({height: 'toggle'}, 1);
34
35 ep_vectorSources[map_id] = new ol.source.Vector();
36 ep_maps[map_id] = new ol.Map({
37 target: map_id,
38 layers: [
39 new ol.layer.Tile({
40 source: new ol.source.XYZ({
41 urls: eventpost_params.maptiles[eventpost_params.defaulttile]['urls']
42 })
43 }),
44 new ol.layer.Vector({
45 source: ep_vectorSources[map_id]
46 })
47 ],
48 view: new ol.View({
49 center: position,
50 zoom: 12
51 })
52 });
53
54 ep_maps[map_id].addControl(new ol.control.Zoom());
55 var ep_feature = new ol.Feature({
56 geometry: new ol.geom.Point(position)
57 });
58
59 if (ep_icons[marker] === undefined) {
60 ep_icons[marker] = new ol.style.Style({
61 image: new ol.style.Icon(({
62 anchor: [16, 32],
63 anchorXUnits: 'pixels',
64 anchorYUnits: 'pixels',
65 opacity: 1,
66 src: marker
67 }))
68 });
69 }
70 ep_feature.setStyle(ep_icons[marker]);
71 ep_vectorSources[map_id].addFeature(ep_feature);
72
73 }
74 jQuery('#' + map_id+'-wrap').animate({height: 'toggle'}, 1000, function () {
75 ep_maps[map_id].getView().setCenter(position);
76 });
77 return false;
78 }
79 });
80
81
82
83
84 /* ------------------------------------------------------------------------------------------------------------------
85 * List of events
86 * Making a big map with all available locations
87 */
88 // Parse all list wich have to be displayed as a map
89
90 jQuery('.event_geolist').each(function () {
91 var geo_id = jQuery(this).attr('id');
92 var map_id = 'event_map_all' + geo_id;
93 var mark_id = 'event_markersall' + geo_id;
94 var width = jQuery(this).data('width');
95 var height = jQuery(this).data('height');
96 var maptile = jQuery(this).data('tile');
97 if(maptile===''){
98 maptile = eventpost_params.defaulttile;
99 }
100 var disabled_integrations = jQuery(this).data('disabled-interactions');
101
102 // Add html elements for map and popup
103 jQuery(this).addClass('event_geolist_parsed').append('<div id="' + map_id + '" class="event_map map"></div><div id="' + map_id + '-popup" class="event_map_popup"></div>');
104 css = {
105 margin: 'auto',
106 clear: 'both'
107 };
108 if (width !== 'auto')
109 css.width = width;
110 if (height !== 'auto')
111 css.height = height;
112 jQuery('#' + map_id).css(css);
113
114 // Create a layer for markers
115 ep_vectorSources[map_id] = new ol.source.Vector();
116
117 // Create a popup object
118 ep_pop_elements[map_id] = document.getElementById(map_id + '-popup');
119 ep_popups[map_id] = new ol.Overlay({
120 element: ep_pop_elements[map_id],
121 positioning: 'bottom-center',
122 stopEvent: false
123 });
124
125 // Initialize map
126 map_settings = {
127 target: map_id,
128 layers: [
129 new ol.layer.Tile({
130 source: new ol.source.XYZ({
131 urls: eventpost_params.maptiles[maptile]['urls']
132 })
133 }),
134 new ol.layer.Vector({
135 source: ep_vectorSources[map_id]
136 })
137 ],
138 view: new ol.View({
139 center: [0, 0],
140 zoom: 12,
141 maxZoom: 18
142 }),
143 overlays: [ep_popups[map_id]]
144 };
145
146 ep_maps[map_id] = new ol.Map(map_settings);
147 ep_maps[map_id].addControl(new ol.control.ZoomSlider());
148
149 //Add action for each markers
150 ep_maps[map_id].on('click', function (evt) {
151 var feature = ep_maps[map_id].forEachFeatureAtPixel(evt.pixel,
152 function (feature, layer) {
153 return feature;
154 });
155 if (feature) {
156 jQuery(ep_pop_elements[map_id]).hide(0);
157 view = ep_maps[map_id].getView();
158 var geometry = feature.getGeometry();
159 var coord = geometry.getCoordinates();
160 var pan = ol.animation.pan({
161 duration: 1000,
162 source: view.getCenter()
163 });
164 ep_maps[map_id].beforeRender(pan);
165 view.setCenter(coord);
166 ep_popups[map_id].setPosition(coord);
167
168 html_output = '<a href="' + feature.get('link') + '">' +
169 (feature.get('thumbnail')!==''&&feature.get('thumbnail')!==undefined?'<img src="'+feature.get('thumbnail')+'">':'')+
170 '<strong>' + feature.get('name') + '</strong><br>' +
171 '<time>' + feature.get('date') + '</time><br>' +
172 '<address>' + feature.get('address') + '</address>' +
173 (feature.get('desc')!==''&&feature.get('desc')!==undefined?'<p>'+feature.get('desc')+'</p>':'')+
174 '</a>';
175 jQuery(ep_pop_elements[map_id]).delay(500).html(html_output).show(500);
176
177 } else {
178 jQuery(ep_pop_elements[map_id]).hide(200);
179 }
180 });
181
182 // Parse all items to create markers and put them on the map
183 jQuery(this).find('address').each(function () {
184 var lat = parseFloat(jQuery(this).data('latitude'));
185 var lon = parseFloat(jQuery(this).data('longitude'));
186 if (lat !== undefined && lon !== undefined) {
187 var item = jQuery(this).parent().parent();
188 var marker = jQuery(this).data('marker');
189 var id = jQuery(this).data('id');
190 coords = new ol.proj.transform([lon, lat], ep_proj_source, ep_proj_destination);
191
192 obj={
193 geometry: new ol.geom.Point(coords),
194 name: item.find('h5').text(),
195 address: jQuery(this).html(),
196 date: item.find('time').text(),
197 link: item.find('a').attr('href'),
198 desc: item.find('.event_exerpt').html()
199 };
200 if(item.find('img').length>0){
201 obj.thumbnail=item.find('img').attr('src');
202 }
203 var ep_feature = new ol.Feature(obj);
204
205
206 if (ep_icons[marker] === undefined) {
207 ep_icons[marker] = new ol.style.Style({
208 image: new ol.style.Icon(({
209 anchor: [16, 32],
210 anchorXUnits: 'pixels',
211 anchorYUnits: 'pixels',
212 opacity: 1,
213 src: marker
214 }))
215 });
216 }
217 ep_feature.setStyle(ep_icons[marker]);
218 ep_vectorSources[map_id].addFeature(ep_feature);
219 }
220 });
221
222 //Center the map to show all markers
223 ep_maps[map_id].getView().fit(ep_vectorSources[map_id].getExtent(), ep_maps[map_id].getSize());
224
225 m_i=0;
226 var int_key;
227 for(int_key in ep_interactions){
228 if(disabled_integrations.indexOf(int_key+',')>-1){
229 ep_maps[map_id].getInteractions().getArray()[m_i].setActive(false);
230 }
231 m_i++;
232 }
233
234
235 });
236 }
237 else{
238 jQuery('.event_geolist').hide();
239 }
240
241
242 /* ------------------------------------------------------------------------------------------------------------------
243 * Calendar Widget
244 */
245 function eventpost_cal_links() {
246 jQuery('.eventpost_cal_bt').click(function () {
247 var calcont = jQuery(this).parents('.eventpost_calendar');
248 jQuery.get(
249 eventpost_params.ajaxurl,
250 {
251 action: 'EventPostCalendar',
252 date: jQuery(this).data('date'),
253 cat: calcont.data('cat'),
254 mf: calcont.data('mf'),
255 dp: calcont.data('dp'),
256 color: calcont.data('color'),
257 thumbnail: calcont.data('thumbnail')
258 },
259 function (data) {
260 calcont.html(data);
261 eventpost_cal_links();
262 });
263 }
264 );
265 jQuery('.eventpost_cal_link').click(function () {
266 var calcont = jQuery(this).parents('.eventpost_calendar');
267 jQuery('.eventpost_cal_list', calcont).fadeOut(function () {
268 jQuery(this).remove();
269 });
270 jQuery.get(
271 eventpost_params.ajaxurl,
272 {
273 action: 'EventPostCalendarDate',
274 date: jQuery(this).data('date'),
275 cat: calcont.data('cat'),
276 mf: calcont.data('mf'),
277 dp: calcont.data('dp'),
278 color: calcont.data('color'),
279 thumbnail: calcont.data('thumbnail')
280 },
281 function (data) {
282 calcont.append('<div class="eventpost_cal_list"><button class="eventpost_cal_close">x</button>' + data + '</div>');
283 calcont.find('.eventpost_cal_list').hide(1).fadeIn(500);
284 calcont.find('.eventpost_cal_close').click(function () {
285 jQuery(this).parent().hide(500).remove();
286 });
287 });
288 });
289
290 }
291 jQuery('.eventpost_calendar').each(function () {
292 var calcont = jQuery(this);
293 calcont.html('<img src="' + eventpost_params.imgpath + 'cal-loader.gif" class="eventpost_cal_loader"/>');
294 jQuery.get(
295 eventpost_params.ajaxurl,
296 {
297 action: 'EventPostCalendar',
298 date: jQuery(this).data('date'),
299 cat: jQuery(this).data('cat'),
300 mf: jQuery(this).data('mf'),
301 dp: jQuery(this).data('dp'),
302 color: jQuery(this).data('color'),
303 thumbnail: jQuery(this).data('thumbnail')
304 },
305 function (data) {
306 calcont.html(data);
307 eventpost_cal_links();
308 });
309 });
310
311 });
312