1/** 2 * CodePeople Post Map 3 * Version: 1.0.1 4 * Author: CodePeople 5 * Plugin URI: http://wordpress.dwbooster.com 6*/ 7 8jQuery(function(){ 9 (function($){ 10 // Create a class with CodePeople Post Map functionalities and attributes 11 $.CPM = function(container, config){ 12 this.data = $.extend(true, {}, this.defaults, config); 13 this.container = container; 14 }; 15 16 $.CPM.prototype = { 17 markers : [], 18 windows : [], 19 defaults : { 20 markers : [], 21 zoom : 10, 22 dynamic_zoom : false, 23 type : 'ROADMAP', 24 mousewheel : true, 25 scalecontrol : true, 26 zoompancontrol : true, 27 typecontrol : true, 28 show_window : true, 29 show_default : true, 30 display : 'map', 31 highlight : true, 32 route : false, 33 mode : 'DRIVING', 34 highlight_class : 'cpm_highlight' 35 }, 36 37 // private methods to complete every steps in map generation 38 39 _empty : function (v){ 40 return (!v || /^\s*$/.test(v)); 41 }, 42 43 _get_latlng : function(i){ 44 var me = this, 45 g = new google.maps.Geocoder(), 46 m = me.data.markers, 47 a = m[i]['address']; 48 49 g.geocode({address:a}, function(result, status){ 50 me.counter--; 51 if(status && status == "OK"){ 52 m[i]['latlng'] = new google.maps.LatLng(result[0]['geometry']['location'].lat(), result[0]['geometry']['location'].lng()) 53 }else{ 54 m[i]['invalid'] = true; 55 } 56 57 // All points have been checked now is possible to load the map 58 if(me.counter == 0){ 59 me._load_map(); 60 61 // Set Route 62 me._set_route(); 63 } 64 }); 65 }, 66 67 _set_route : function(){ 68 var me = this, 69 m = me.data.markers; 70 71 if(!me.data.route) return; 72 // Create the matix of waypoints 73 var wps_list = [], 74 c = -1, 75 d = 1, 76 post = ''; 77 78 for(var i = 0, h = m.length; i < h; i++){ 79 if(!m[i]['invalid']){ 80 if(m[i].post != post || d%9 == 0){ 81 c++; 82 wps_list[c] = []; 83 84 if(d%9 == 0 && m[i].post == post){ 85 wps_list[c].push(wps_list[c-1][wps_list[c-1].length-1]); 86 } 87 88 post = m[i].post; 89 d = 1; 90 } 91 92 wps_list[c].push({location:m[i].latlng}); 93 d++; 94 } 95 } 96 97 for(var i = 0, h = wps_list.length; i < h; i++){ 98 var rendererOptions = { map: me.map, suppressMarkers: true }, 99 directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions), 100 directionsService = new google.maps.DirectionsService(), 101 wps = wps_list[i], 102 origin, destination, request; 103 104 105 var l = wps.length; 106 if( l > 1){ 107 108 request = { 109 origin : wps.shift().location, 110 destination : wps.pop().location, 111 waypoints : wps, 112 travelMode: google.maps.DirectionsTravelMode[me.data.mode] 113 }; 114 115 directionsService.route( 116 request, 117 (function (dd) { 118 return function(response, status) { 119 if (status == google.maps.DirectionsStatus.OK) { 120 dd.setDirections(response); 121 } 122 else 123 if(console) 124 console.log('failed to get directions'); 125 } 126 })(directionsDisplay) 127 ); 128 } 129 } 130 }, 131 _str_transform : function( t ){ 132 return t.replace( /</g, '<').replace( />/g, '>').replace( /&/g, '&').replace( /"/g, '"').replace(/\\'/g, "'"); 133 }, 134 _load_map : function(){ 135 136 var me = this, 137 m = me.data.markers, 138 h = m.length, 139 c = 0, 140 v = 0; // Number of valid points 141 142 while(c < h && m[c]['invalid']) c++; 143 144 if(c < h){ 145 me.map = new google.maps.Map( me.container, { 146 zoom: me.data.zoom, 147 center: m[c].latlng, 148 mapTypeId: google.maps.MapTypeId[me.data.type], 149 150 // Show / Hide controls 151 panControl: me.data.zoompancontrol, 152 scaleControl: me.data.scalecontrol, 153 zoomControl: me.data.zoompancontrol, 154 mapTypeControl: me.data.typecontrol, 155 scrollwheel: me.data.mousewheel 156 }); 157 158 if( typeof me.data[ 'map_styles' ] != 'undefined' ) me.map.setOptions({styles: me.data.map_styles }); 159 var map = me.map, 160 bounds = new google.maps.LatLngBounds (), 161 open_by_default; 162 163 if(me.data.show_default){ 164 google.maps.event.addListenerOnce(map, 'idle', function(){ 165 setTimeout(function(){ 166 if(open_by_default) 167 google.maps.event.trigger(me.markers[open_by_default - 1], 'click'); 168 }, 1000); 169 }); 170 } 171 172 me.infowindow = new google.maps.InfoWindow({maxWidth:340}); 173 174 for (var i = c; i < h; i++){ 175 if(!m[i]['invalid']){ 176 bounds.extend(m[i].latlng); 177 var marker = new google.maps.Marker({ 178 position: m[i].latlng, 179 map: map, 180 icon: new google.maps.MarkerImage(m[i].icon), 181 title:((m[i].address) ? me._str_transform( m[i].address ) : '') 182 }); 183 184 marker.id = i; 185 me.markers.push(marker); 186 if( typeof open_by_default == 'undefined' ){ 187 open_by_default = me.markers.length; 188 } 189 190 google.maps.event.addListener(marker, 'click', function(){ me.o
190pen_infowindow(this); }); 191 google.maps.event.addListener(marker, 'mouseover', function(){ me.set_highlight(this); }); 192 google.maps.event.addListener(marker, 'mouseout', function(){ me.unset_highlight(this); }); 193 } 194 } 195 196 if (h > 1 && me.data.dynamic_zoom) { 197 map.fitBounds(bounds); 198 } 199 else if (h == 1 || !me.data.dynamic_zoom) { 200 map.setCenter(bounds.getCenter()); 201 map.setZoom(me.data.zoom); 202 } 203 } 204 }, 205 206 // public methods 207 set_map: function(){ 208 var me = this; 209 if(me.data.markers.length){ 210 211 var m = me.data.markers, 212 h = m.length; 213 214 me.counter = h; // Counter is used to know the momment where all latitudes or longitudes were calculated 215 216 for(var i=0; i < h; i++){ 217 if( (me._empty(m[i].lat) || me._empty(m[i].lng)) && !me._empty(m[i].address)){ 218 me._get_latlng(i); 219 }else if(me._empty(m[i].lat) && me._empty(m[i].lng)){ 220 // The address is not present so the point may be removed from the list 221 m[i]['invalid'] = true; 222 me.counter--; 223 }else{ 224 m[i]['latlng'] = new google.maps.LatLng(m[i].lat, m[i].lng); 225 me.counter--; 226 } 227 228 } 229 230 // All points have been checked now is possible to load the map 231 if(me.counter == 0){ 232 me._load_map(); 233 234 // Set Route 235 me._set_route(); 236 } 237 } 238 }, 239 240 // Open the marker bubble 241 open_infowindow : function(m){ 242 if( !this.data.show_window ) return; 243 this.infowindow.setContent(this._str_transform(this.data.markers[m.id].info)); 244 this.infowindow.open(this.map, m); 245 }, 246 247 // Set the highlight class to the post with ID m['post'] 248 set_highlight : function(m){ 249 if(this.data.highlight){ 250 var id = this.data.markers[m.id]['post']; 251 $('.post-'+id).addClass(this.data.highlight_class); 252 } 253 }, 254 255 // Remove the highlight class from the post with ID m['post_id'] 256 unset_highlight : function(m){ 257 if(this.data.highlight){ 258 var id = this.data.markers[m.id]['post']; 259 $('.post-'+id).removeClass(this.data.highlight_class); 260 } 261 } 262 }; 263 // End CPM class definition 264 265 // Load the street view on infowindow 266 267 $( document ).on( 'click', '#cpm_display_streetview_btn', function(){ 268 var me = $(this), 269 c = me.parents( '.cpm-map' ), 270 latlng = new google.maps.LatLng( me.attr( 'lat' ), me.attr( 'lng' ) ), 271 st = new google.maps.StreetViewPanorama( 272 c[ 0 ], 273 { 274 'position': latlng, 275 'enableCloseButton': true 276 } 277 ); 278 st.setVisible(true); 279 } ); 280
281 282 // Callback function to be called after loading the maps api 283 function initialize( e ) 284 { 285 var map_container = $( e ), 286 map_id = map_container.attr('id'); 287 288 if( map_container.parent().is( ':hidden' ) ) 289 { 290 setTimeout( function(){ initialize( e ); }, 500 ); 291 return; 292 } 293 294 if(cpm_global && cpm_global[map_id] && cpm_global[map_id]['markers'].length){ 295 // The maps data are defined 296 var cpm = new $.CPM( e, cpm_global[map_id]); 297 298 // Display map 299 if(cpm_global[map_id]['display'] == 'map'){ 300 map_container.show(); 301 cpm.set_map(); 302 }else{ 303 // Insert a icon to display map 304 var map_icon = $('<div class="cpm-mapicon"></div>'); 305 map_icon.click(function(){ 306 map_container.show(); 307 cpm.set_map(); 308 }); 309 map_icon.insertBefore(map_container); 310 } 311 312 313 } 314 }; 315 window['cpm_init'] = function(){ 316 $('.cpm-map').each(function(){ 317 318 if( $( this ).parent().is( ':hidden' ) ) 319 { 320 setTimeout( 321 ( function ( e ) 322 { 323 return function(){ initialize( e ); }; 324 } )( this ), 325 500 326 ); 327 } 328 else 329 { 330 initialize( this ); 331 } 332 333 }); 334 }; 335 336 var map = $('.cpm-map'); 337 if(map.length){ 338 if(typeof google == 'undefined' || google['maps'] == null){ 339 // Create the script tag and load the maps api 340 var script=document.createElement('script'); 341 script.type = "text/javascript"; 342 script.src='http://maps.google.com/maps/api/js?sensor=false'+((typeof cpm_language != 'undefined' && cpm_language.lng) ? '&language='+cpm_language.lng: '')+'&callback=cpm_init'; 343 document.body.appendChild(script); 344 }else{ 345 cpm_init(); 346 } 347 } 348 349 })(jQuery); 350});
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.