r84094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84093‎ | r84094 | r84095 >
Date:12:04, 16 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on map input js
Modified paths:
  • /branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php (modified) (history)
  • /branches/SemanticMaps0.8/includes/forminputs/ext.sm.forminputs.js (deleted) (history)
  • /branches/SemanticMaps0.8/includes/forminputs/jquery.mapforminput.js (modified) (history)
  • /branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js (modified) (history)

Diff [purge]

Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
@@ -12,17 +12,49 @@
1313 (function( $ ){ $.fn.googlemapsinput = function( mapDivId, options ) {
1414
1515 var self = this;
 16+ var geocoder = false;
1617
 18+ /**
 19+ * Creates and places a new marker on the map at the provided
 20+ * coordinate set and the pans to it.
 21+ * @param {Object} coordinate
 22+ */
1723 this.showCoordinate = function( coordinate ) {
1824 this.mapDiv.removeMarkers();
1925 coordinate.icon = '';
2026 coordinate.title = '';
2127 coordinate.text = coord.dms( coordinate.lat, coordinate.lon );
22 - this.mapDiv.addMarker( coordinate );
 28+ var marker = this.mapDiv.addMarker( coordinate );
 29+ this.mapDiv.map.panTo( marker.getPosition() );
2330 };
2431
 32+ /**
 33+ * Calls this.showCoordinate with the provided latLng and updates the input field.
 34+ * @param {google.maps.LatLng} latLng
 35+ */
 36+ this.showLatLng = function( latLng ) {
 37+ var location = { lat: latLng.lat(), lon: latLng.lng() };
 38+ this.showCoordinate( location );
 39+ this.updateInput( [ location ] );
 40+ }
 41+
 42+ this.setupGeocoder = function() {
 43+ if ( geocoder === false ) {
 44+ geocoder = new google.maps.Geocoder();
 45+ }
 46+ }
 47+
2548 this.geocodeAddress = function( address ) {
26 -
 49+ this.setupGeocoder();
 50+ geocoder.geocode( { 'address': address }, function( results, status ) {
 51+ if ( status == google.maps.GeocoderStatus.OK ) {
 52+ self.showLatLng( results[0].geometry.location );
 53+ }
 54+ else {
 55+ // TODO: i18n
 56+ alert( "Geocode was not successful for the following reason: " + status );
 57+ }
 58+ } );
2759 };
2860
2961 this.mapforminput( mapDivId, options, { canGeocode: true } );
@@ -30,10 +62,7 @@
3163 this.mapDiv.googlemaps( options );
3264
3365 google.maps.event.addListener( this.mapDiv.map, 'click', function( event ) {
34 - var location = { lat: event.latLng.lat(), lon: event.latLng.lng() };
35 - self.mapDiv.map.panTo( event.latLng );
36 - self.showCoordinate( location );
37 - self.input.attr( 'value', semanticMaps.buildInputValue( [ location ] ) );
 66+ self.showLatLng( event.latLng );
3867 } );
3968
4069 return this;
Index: branches/SemanticMaps0.8/includes/forminputs/ext.sm.forminputs.js
@@ -1,24 +0,0 @@
2 -/**
3 - * JavasSript for the Semantic Maps extension.
4 - * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
5 - *
6 - * @since 0.8
7 - * @ingroup SemanticMaps
8 - *
9 - * @licence GNU GPL v3
10 - * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
11 - */
12 -
13 -window.semanticMaps = new ( function( $ ) {
14 -
15 - this.buildInputValue = function( locations ) {
16 - var floats = [];
17 -
18 - for ( i in locations ) {
19 - floats.push( coord.float( locations[i].lat, locations[i].lon ) );
20 - }
21 -
22 - return floats.join( '; ' );
23 - };
24 -
25 -} )( jQuery );
Index: branches/SemanticMaps0.8/includes/forminputs/jquery.mapforminput.js
@@ -23,11 +23,34 @@
2424
2525 var self = this;
2626
 27+ /**
 28+ * Creates a string with the provided coordinates to populate the main input field with.
 29+ * @param {Array} locations
 30+ * @return {string}
 31+ */
 32+ this.buildInputValue = function( locations ) {
 33+ var floats = [];
 34+
 35+ for ( i in locations ) {
 36+ floats.push( coord.float( locations[i].lat, locations[i].lon ) );
 37+ }
 38+
 39+ return floats.join( '; ' );
 40+ };
 41+
 42+ /**
 43+ * Populate the main input field with the provided coordinates.
 44+ * @param {Array} locations
 45+ */
 46+ this.updateInput = function( locations ) {
 47+ this.input.attr( 'value', this.buildInputValue( locations ) );
 48+ }
 49+
2750 this.input = $( '<input />' ).attr( {
2851 'type': 'text',
2952 'name': options.inputname,
3053 'id': mapDivId + '_values',
31 - 'value': semanticMaps.buildInputValue( options.locations ),
 54+ 'value': this.buildInputValue( options.locations ),
3255 'size': options.fieldsize
3356 } );
3457
Index: branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php
@@ -19,8 +19,7 @@
2020 'remoteBasePath' => $smgScriptPath . '/includes/forminputs',
2121 'group' => 'ext.semanticmaps',
2222 'scripts' => array(
23 - 'jquery.mapforminput.js',
24 - 'ext.sm.forminputs.js',
 23+ 'jquery.mapforminput.js'
2524 ),
2625 'messages' => array(
2726 )

Status & tagging log