Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/168208
Change subject: Load nearby by url coordinates
......................................................................
Load nearby by url coordinates
Change-Id: I29bf5b25f8a02659a81cbd10227a9175b1517f32
---
M javascripts/specials/nearby.js
1 file changed, 35 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/08/168208/1
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index 89c040c..b4cf7bb 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -5,27 +5,47 @@
$( function() {
var
nearby,
- options = { el: $( '#mw-mf-nearby' ), useCurrentLocation: true
},
+ options = { el: $( '#mw-mf-nearby' ) },
$btn = $( '#secondary-button' );
- function refresh() {
- if ( nearby ) {
- nearby.initialize( options );
- } else {
- nearby = new Nearby( options );
- }
- }
-
- // replace user button with refresh button
+ // Replace user button with refresh button
if ( $btn.length ) {
$btn.remove();
}
- $btn = $( '<a class="icon-refresh main-header-button icon"
id="secondary-button">' ).
- text( mw.msg( 'mobile-frontend-nearby-refresh' ) ).
- attr( 'title', mw.msg( 'mobile-frontend-nearby-refresh' ) ).
- on( 'click', refresh ).appendTo( '.header' );
- refresh();
+ // Routing on the nearby view
+ var coords = getCoordsFromHash(window.location.hash);
+ if ( coords ) {
+ // Search with coordinates
+ $.extend( options, coords );
+ } else {
+ // Search with current location
+ options.useCurrentLocation = true;
+
+ // Create refresh button on the header
+ $btn = $( '<a class="icon-refresh main-header-button icon"
id="secondary-button">' ).
+ text( mw.msg( 'mobile-frontend-nearby-refresh' ) ).
+ attr( 'title', mw.msg( 'mobile-frontend-nearby-refresh'
) ).
+ on( 'click', refresh ).appendTo( '.header' );
+ }
+
+ nearby = new Nearby( options );
+
+ function refresh() { nearby.initialize( options ); }
+
} );
+/*
+ * Given a location hash, returns a coordinates object if it matches
/num/num
+ * or null if it doesn't
+*/
+function getCoordsFromHash(hash) {
+ var matches = hash.match(
/^#\/coord\/(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)/ );
+ if (!matches) { return null; }
+ return {
+ latitude: parseFloat(matches[1]),
+ longitude: parseFloat(matches[2])
+ };
+}
+
}( mw.mobileFrontend, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/168208
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I29bf5b25f8a02659a81cbd10227a9175b1517f32
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits