1/* global $, jQuery, l10n, validateL10n, appthemes_map_vars, appthemes_map_icon */ 2( function( $ ) { 3 4 $.extend( true, $.appthemes.appthemes_map.prototype, { 5 options: { 6 zoom: 17 7 }, 8 9 _auto_zoom: function() { 10 11 if ( this.markers.length < 1 ) { 12 return; 13 } 14 15 var markerBounds = new google.maps.LatLngBounds(); 16 for ( var i = 0; i < this.markers.length; i++ ) { 17 markerBounds.extend( this.markers[i].getPosition() ); 18 } 19 20 // Don't zoom in too far on only one marker 21 if ( markerBounds.getNorthEast().equals( markerBounds.getSouthWest() ) ) { 22 var extendPoint1 = new google.maps.LatLng( markerBounds.getNorthEast().lat() + 0.01, markerBounds.getNorthEast().lng() + 0.01 ); 23 var extendPoint2 = new google.maps.LatLng( markerBounds.getNorthEast().lat() - 0.01, markerBounds.getNorthEast().lng() - 0.01 ); 24 markerBounds.extend( extendPoint1 ); 25 markerBounds.extend( extendPoint2 ); 26 } 27 28 this.options.map.fitBounds( markerBounds ); 29 }, 30 31 _create_map: function() { 32 var mapOptions = { 33 zoom: this.options.zoom, 34 scrollwheel: false, 35 center: { lat: this.options.center_lat, lng: this.options.center_lng }, 36 streetViewControl: true, 37 styles: this.options.styles 38 }; 39 40 return new google.maps.Map( this.element[0], mapOptions ); 41 }, 42 43 _create_marker: function( marker_opts ) { 44 if ( this.options.use_app_icon ) { 45 46 _icon_url = this._get_icon_url( marker_opts ); 47 48 var marker_icon = { 49 url: _icon_url, 50 scaledSize: new google.maps.Size(this.options.app_icon_width, this.options.app_icon_height) 51 }; 52 53 /* 54 var marker_icon_shadow = new google.maps.MarkerImage( this.options.app_icon_shadow_url, 55 new google.maps.Size( this.options.app_icon_shadow_width, this.options.app_icon_shadow_height ), 56 new google.maps.Point( 0, 0 ) ); 57 58 var marker_icon_shape = { 59 coord: this.options.app_icon_click_coords, 60 type: "rect" 61 }; 62 */ 63 } 64 65 var marker = new google.maps.Marker( { 66 position: new google.maps.LatLng( marker_opts.lat, marker_opts.lng ), 67 map: this.options.map, 68 animation: ( this.options.animation ? google.maps.Animation.DROP : false ), 69 draggable: ( marker_opts.draggable ? true : false ), 70 title: ( typeof marker_opts.marker_text !== 'undefined' ? marker_opts.marker_text : '' ), 71 icon: ( typeof marker_icon !== 'undefined' ? marker_icon : '' ), 72 //shadow: ( typeof marker_icon_shadow !== 'undefined' ? marker_icon_shadow : '' ), 73 //shape: ( typeof marker_icon_shape !== 'undefined' ? marker_icon_shape : '' ), 74 optimized: false 75 } ); 76 77 return marker; 78 }, 79 80 _create_marker_info: function() { 81 return new google.maps.InfoWindow( { 82 content: '', 83 pixelOffset: new google.maps.Size( parseInt( this.options.app_popup_offset_x ), parseInt( this.options.app_popup_offset_y ) ), 84 maxWidth: this.options.info_max_width 85 } ); 86 }, 87 88 _set_marker_info: function( info, marker, marker_opts ) { 89 var map = this.options.map; 90 91 google.maps.event.addListener( map, 'click', function() { 92 info.close(); 93 } ); 94 95 google.maps.event.addListener( marker, "click", function( e ) { 96 info.close(); 97 info.setContent( marker_opts.popup_content ); 98 info.setPosition( marker.getPosition() ); 99 info.open( map, marker ); 100 } ); 101 }, 102 103 _set_marker_anchor: function( marker, anchor ) { 104 google.maps.event.addListener( marker, "click", function( e ) { 105 location = anchor; 106 } ); 107 }, 108 109 _get_marker_position: function( marker ) { 110 return marker.getPosition(); 111 }, 112 113 _marker_drag_end: function( marker ) { 114 var $this = this; 115 google.maps.event.addListener( marker, "dragend", function() { 116 var drag_position = marker.getPosition(); 117 118 $this.options.marker_drag_end( marker, drag_position.lat(), drag_position.lng() ); 119 }); 120 }, 121 122 _update_marker_position: function( updated_pos, marker, map ) { 123 var updated_position = new google.maps.LatLng( updated_pos.lat, updated_pos.lng ); 124 map.setCenter( updated_position ); 125 marker.setPosition( updated_position ); 126 }, 127 128 _directions_btn_handler: function( start_address, end_address, directions_panel, print_directions_btn ) { 129 var $this = this; 130 var directionsDisplay = new google.maps.DirectionsRenderer(); 131 var directionsService = new google.maps.DirectionsService(); 132 var start = jQuery( '#' + start_address ).val(); 133 var end = end_address; // This is the address for the listing 134 var map = this.options.map; 135 var request = { 136 origin: start, 137 destination: end, 138 region: appthemes_map_vars.geo_region, 139 travelMode: google.maps.TravelMode.DRIVING, 140 unitSystem: ( appthemes_map_vars.geo_unit == 'mi' ) ? google.maps.UnitSystem.IMPERIAL : google.maps.UnitSystem.METRIC 141 }; 142 143 directionsService.route( request, function( result, status ) { 144 jQuery( '#' + directions_panel ).show(); 145 if ( status == google.maps.DirectionsStatus.OK ) { 146 directionsDisplay.setDirections( result ); 147 this.markers[0].setVisible( false ); 148 jQuery( '#' + print_directions_btn ).slideDown( 'fast' ); 149 directionsDisplay.setPanel( document.getElementById( directions_panel ) ); 150 directionsDisplay.setMap( map ); 151 } else { 152 jQuery( '#' + print_directions_btn ).hide(); 153 jQuery( '#' + directions_panel ).html( appthemes_map_vars.text_directions_error ).fadeOut( 5000, function() { 154 $( this ).html( '' ); 155 } ); 156 // restore original map on failure 157 directionsDisplay.setMap( null ); 158 159 if ( $this.options.markers ) { 160 $.each( $this.options.markers, function( i, marker_opts ) { 161 var marker = $this.add_marker( marker_opts ); 162 $this.markers.push( marker ); 163 } ); 164 165 $this.auto_zoom(); 166 } 167 } 168 } ); 169 } 170 } ); 171 172} )( jQuery ); 173 174( function( $ ) { 175 176 var onPlaceChange = $.appthemes.appAddressAutocomplete.prototype.onPlaceChange; 177 178 $.extend( true, $.appthemes.appAddressAutocomplete.prototype, { 179
180 enterpressed: false, 181 182 onPlaceChange: function() { 183 onPlaceChange.apply( this, arguments ); 184 if ( this.enterpressed ) { 185 this.options.form.submit(); 186 } 187 }, 188 189 loadAPI: function() { 190 var api = new google.maps.places.Autocomplete( 191 this.element[0], { 192 types: [] 193 } 194 ); 195 196 var $this = this; 197 198 // Trigger if location field value changes. 199 api.addListener( 'place_changed', function() { 200 $this.onPlaceChange(); 201 } ); 202 203 // Emulate location select when enter key (13 o 9) is pressed. 204 this.element.keydown( function( event ) { 205 if ( event.keyCode == 13 || event.keyCode == 9 ) { 206 if ( $( '.pac-item-selected' ).length === 0 ) { 207 google.maps.event.trigger( event.target, "keydown", { 208 keyCode: 40 209 } ); 210 } 211 google.maps.event.trigger( event.target, "keydown", { 212 keyCode: 13 213 } ); 214 $this.enterpressed = true; 215 return false; 216 } else { 217 return true; 218 } 219 } ); 220 221 return api; 222 }, 223 224 getPlaceData: function() { 225 var place = this.api.getPlace(); 226 227 if ( !place.geometry && '' !== $.trim( this.element.val() ) ) { 228 window.alert( this.options.no_geocode ); 229 return; 230 } 231 232 var data = { 233 lat: place.geometry.location.lat(), 234 lng: place.geometry.location.lng(), 235 formatted_address: place.formatted_address, 236 place_id: place.place_id, 237 address_components: place.address_components, 238 radius: this.options.radius_input.val() 239 }; 240 241 // The smart radius implementation. 242 if ( place.geometry.viewport && this.options.radius_input.length !== 0 && this.options.default_radius === '' ) { 243 var ne_lat = place.geometry.viewport.getNorthEast().lat(); 244 var ne_lng = place.geometry.viewport.getNorthEast().lng();
245 var sw_lat = place.geometry.viewport.getSouthWest().lat(); 246 var sw_lng = place.geometry.viewport.getSouthWest().lng(); 247 248 data.radius = this.getSmartRadius( data.lat, data.lng, sw_lat, sw_lng, ne_lat, ne_lng, this.options.geo_unit ); 249 } 250 251 return data; 252 } 253 254 } ); 255 256} )( 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.