PageSourceSearch

https://opendevelopmentcambodia.net/wp-content/themes/jeo/inc/js/groups.js?ver=0.2.7

js opendevelopmentcambodia.net collected 2026-10-02 03:27:03 UTC 4,164 bytes, 195 lines download raw bytes

1var groups = {};
2
3(function($) {
4
5	jeo.group = function(conf) {
6
7		var group = {};
8
9		var fragment = jeo.fragment();
10
11		var _init = function() {
12
13			if(conf.mainMap)
14				$('body').addClass('loading-map');
15
16			if(!conf.postID && typeof conf === 'object') { // conf ready
17				return group.build(conf);
18			}
19
20			$.getJSON(jeo_groups.ajaxurl,
21				{
22					action: 'mapgroup_data',
23					group_id: conf.postID
24				},
25				function(mapConf) {
26					mapConf = _.extend(mapConf, conf);
27					group.build(mapConf);
28				});
29
30		}
31
32		if($.isReady) {
33			_init();
34		} else {
35			$(document).ready(_init);
36		}
37
38		group.build = function(data) {
39
40			group.$ = $('#mapgroup_' + data.postID);
41
42			// store maps data
43			group.mapsData = data.maps;
44
45			// nodes
46			group.$.nav = group.$.find('.map-nav');
47			group.$.map = group.$.find('.map');
48
49			group.containerID = group.$.map.attr('id');
50
51			// prepare first map and group conf
52			var firstMapID = group.$.nav.find('li:first-child a').data('map');
53			if(fragment.get('map'))
54				firstMapID = fragment.get('map');
55
56			group.conf = _.extend(data, jeo.parseConf(group.mapsData[firstMapID]));
57			delete group.conf.postID;
58
59			// set jeo conf containerID to group id
60			group.conf.containerID = group.containerID;
61
62			// force main map
63			group.conf.mainMap = true;
64
65			// store current map id
66			group.currentMapID = firstMapID;
67
68			// build group
69			group.map = jeo(group.conf);
70			group.map.isGroup = true;
71			group.map.currentMapID = firstMapID;
72
73			if(jeo.fragmentEnabled)
74				fragment.set({'map': firstMapID});
75
76			group.updateUI();
77
78			group.$.nav.find('li a').click(function() {
79
80				// disable "more" tab click
81				if($(this).hasClass('toggle-more'))
82					return false;
83
84				if($(this).hasClass('active'))
85					return false;
86
87				var mapID = $(this).data('map');
88
89				// update layers
90				group.update(mapID);
91
92				// update ui
93				group.updateUI();
94
95				return false;
96			});
97
98			jeo.runCallbacks('groupReady', [group]);
99
100		}
101
102		group.updateUI = function() {
103
104			var mapID = group.currentMapID;
105			var $navEl = group.$.nav.find('[data-map="' + mapID + '"]');
106			var moreLabel = group.$.nav.find('.more-tab > a').text(); // store more label
107
108			group.$.nav.find('li a').removeClass('active');
109			$navEl.addClass('active');
110
111			// ui behaviour for more tab
112			if($navEl.parent().hasClass('more-item')) {
113				group.$.nav.find('.more-tab > a').addClass('active').text($navEl.text());
114			} else {
115				group.$.nav.find('.more-tab > a').removeClass('active').text(moreLabel);
116			}
117
118		}
119
120		group.update = function(mapID) {
121
122			// store prev conf
123			var prevMap = group.map;
124			var prevConf = prevMap.conf;
125
126			// prepare new conf and layers
127			var conf = jeo.parseConf(group.mapsData[mapID]);
128			var layers = jeo.loadLayers(group.map, jeo.parseLayers(group.map, conf.layers));
129
130			// store new conf
131			group.map.conf = conf;
132
133			// update current map id
134			group.currentMapID = mapID;
135			group.map.currentMapID = mapID;
136
137			var fragmentEnabled = jeo.fragmentEnabled;
138			if(fragmentEnabled)
139				fragment.set({'map': mapID});
140
141			/*
142			 * reset geocode
143			 */
144			if(prevConf.geocode)
145				group.map.geocode.removeFrom(group.map);
146
147			if(group.map.conf.geocode)
148				group.map.addControl(new jeo.geocode());
149
150
151			/*
152			 * reset filtering layers
153			 */
154			if(prevConf.filteringLayers)
155				group.map.filterLayers.removeFrom(group.map);
156
157			if(group.map.conf.filteringLayers)
158				group.map.addControl(new jeo.filterLayers());
159
160			/*
161			 * clear tooltips
162			 */
163			 group.$.find('.map-tooltip').hide();
164
165
166			/*
167			 * reset legend
168			 */
169			 if(typeof group.map.legendControl !== 'undefined') {
170				if(prevConf.legend_full_content)
171					group.map.legendControl.removeLegend(prevConf.legend_full_content);
172				else
173					group.map.legendControl.removeLegend(prevConf.legend);
174			}
175
176			if(conf.legend)
177				group.map.legendControl.addLegend(conf.legend);
178
179			if(conf.legend_full)
180				jeo.enableDetails(group.map, conf.legend, conf.legend_full);
181
182
183			// callbacks
184			jeo.runCallbacks('groupChanged', [group, prevMap]);
185
186		}
187
188		groups[group.id] = group;
189		return group;
190	}
191
192	jeo.createCallback('groupReady');
193	jeo.createCallback('groupChanged');
194
195})(jQuery);

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.