Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pulled google namespace from main.js. Switched to new preferences sys…

…tem (not all used yet).
  • Loading branch information...
commit aa9187420495a2412344d864288693eb22ff6fe4 1 parent d5f3521
@patridge authored
View
3  StackGeography/StackGeography.csproj
@@ -88,6 +88,7 @@
<Content Include="scripts\jsrender.js" />
<Content Include="scripts\main.js" />
<Content Include="scripts\stackgeography.201201171142.min.js" />
+ <Content Include="scripts\jquery.stackgeography.preferences.js" />
<Content Include="scripts\uri.js" />
<Content Include="styles\main.201201101208.min.css" />
<Content Include="styles\main.css" />
@@ -119,7 +120,7 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
- <UseIIS>True</UseIIS>
+ <UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>50245</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
View
1  StackGeography/index.html
@@ -68,6 +68,7 @@
<script type="text/javascript" src="/scripts/stackgeography.201201171142.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.googlemaps.js"></script>
<script type="text/javascript" src="/scripts/jquery.geocode.js"></script>
+ <script type="text/javascript" src="/scripts/jquery.stackgeography.preferences.js"></script>
<script type="text/javascript" src="/scripts/main.js"></script>
</body>
</html>
View
25 StackGeography/scripts/jquery.googlemaps.js
@@ -78,22 +78,39 @@ var googleMapsCallback; // Required for Google Maps API to call back when it thi
mapTypeId: google.maps.MapTypeId.TERRAIN
});
};
- $.googleMaps.MarkerImage = function (url, size, origin, anchor) {
- return new google.maps.MarkerImage(url, new google.maps.Size(size.width, size.height), new google.maps.Point(origin.x, origin.y), new google.maps.Point(anchor.x, anchor.y));
+ $.googleMaps.MarkerImage = function (url, size, origin, anchor, scaledSize) {
+ var sizeObj = null,
+ originPoint = null,
+ anchorPoint = null,
+ scaledSizeObj = null;
+ if (size && size.width && size.height) {
+ sizeObj = new google.maps.Size(size.width, size.height);
+ }
+ if (origin && origin.x && origin.y) {
+ originPoint = new google.maps.Point(origin.x, origin.y);
+ }
+ if (anchor && anchor.x && anchor.y) {
+ anchorPoint = new google.maps.Point(anchor.x, anchor.y);
+ }
+ if (scaledSize && scaledSize.width && scaledSize.height) {
+ scaledSizeObj = new google.maps.Size(scaledSize.width, scaledSize.height);
+ }
+ //(siteInfo.iconSrc, null, null, null, new google.maps.Size(24, 24))
+ return new google.maps.MarkerImage(url, sizeObj, originPoint, anchorPoint, scaledSizeObj);
};
$.googleMaps.createMarker = function (options) {
var marker,
opts = $.extend({
title: ""
}, $.googleMaps.createMarker.defaults, options);
-
+
if (!opts.location || !opts.location.lat || !opts.location.lng) {
debug("Map marker creation failed: location not given.");
return;
}
opts.position = new google.maps.LatLng(opts.location.lat, opts.location.lng);
delete opts.location;
-
+
marker = new google.maps.Marker(opts);
if (opts.markerImage) {
View
60 StackGeography/scripts/jquery.stackgeography.preferences.js
@@ -0,0 +1,60 @@
+/*global jQuery, localStorage, console, QUOTA_EXCEEDED_ERR*/
+(function ($) {
+ "use strict";
+ if (!(!!JSON)) {
+ $.ajax({
+ url: "https://raw.github.com/douglascrockford/JSON-js/master/json2.js",
+ dataType: "script",
+ async: false
+ });
+ }
+ $.stackgeography = $.stackgeography || {};
+ $.stackgeography.preferences = (function () {
+ var Preference = function (key, defaultValue) {
+ var getItem = function (key) {
+ var result = defaultValue,
+ json;
+ if (localStorage && localStorage.getItem) {
+ json = localStorage.getItem(key);
+ if (null !== json) {
+ try {
+ result = JSON.parse(json);
+ } catch (e) {
+ localStorage.removeItem(key);
+ }
+ }
+ }
+ return result;
+ },
+ setItem = function (key, value) {
+ var json = JSON.stringify(value);
+ if (localStorage && localStorage.setItem) {
+ try {
+ localStorage.setItem(key, json);
+ } catch (e) {
+ if (e === QUOTA_EXCEEDED_ERR && console && console.error) {
+ console.error("`localStorage` quota exceeded.");
+ }
+ }
+ }
+ },
+ preference = {
+ key: key,
+ get: function () { return getItem(key); },
+ set: function (value) { setItem(key, value); }
+ };
+ return preference;
+ };
+ return {
+ maxMapMarkers: new Preference("maxMapMarkers", 500),
+ siteSelection: new Preference("siteSelection", "stackoverflow"),
+ useSiteIcons: new Preference("useSiteIcons", true),
+ mapCenterLatLng: new Preference("mapCenterLatLng", { lat: 200, lng: 0 }),
+ useFallbackLatLng: new Preference("useFallbackLatLng", false),
+ fallbackLatLng: new Preference("fallbackLatLng", {
+ lat: -78.4644915,
+ lng: 106.83397289999994
+ }) // Antarctica
+ };
+ }());
+}(jQuery));
View
54 StackGeography/scripts/main.js
@@ -9,7 +9,16 @@ $(function () {
key: "AIzaSyBOT4rTeK6L9WegBXUncMaQHrUULF9UtWM"
//, url: "/scripts/googlemapsv3.js"
}),
- defaultMapCenterLocation = { lat: 20, lng: 0 }, // Start with a default map center.
+ preferences = $.stackgeography.preferences,
+ options = (function () {
+ var $useSiteIcons = $("#use-site-icons"),
+ $maxMapMarkers = $("#max-marker-count");
+ return {
+ useSiteIcons: function () { return $useSiteIcons.is(":checked"); },
+ maxMapMarkers: function () { return parseInt($maxMapMarkers.val(), 10) || 500; }
+ };
+ }()),
+ defaultMapCenterLocation = preferences.mapCenterLatLng.get(), // Start with a default map center.
getMapCenter = $.Deferred(function (dfd) {
$.geocode.getIpLatLng().done(function (userLocation) {
dfd.resolve(userLocation);
@@ -24,14 +33,6 @@ $(function () {
lng: 106.83397289999994
}, // Antarctica
currentMapMarkers = [],
- options = (function () {
- var $useSiteIcons = $("#use-site-icons"),
- $maxMapMarkers = $("#max-marker-count");
- return {
- useSiteIcons: function () { return $useSiteIcons.is(":checked"); },
- maxMapMarkers: function () { return parseInt($maxMapMarkers.val(), 10) || 500; }
- };
- } ()),
useGeocodingFallback = false,
infoWindowTemplate = $.template("infoWindowTemplate", $("#infoWindowTemplate")),
$startPolling = $("#start-polling"),
@@ -96,7 +97,7 @@ $(function () {
markerOptions.location = locationForQuestion;
markerOptions.title = questionWithUser.title;
if (options.useSiteIcons() && siteInfo.iconSrc) {
- markerOptions.markerImage = new google.maps.MarkerImage(siteInfo.iconSrc, null, null, null, new google.maps.Size(24, 24));
+ markerOptions.markerImage = new $.googleMaps.MarkerImage(siteInfo.iconSrc, null, null, null, { width: 24, height: 24 });
markerOptions.markerImageShadow = null;
markerOptions.icon = siteInfo.iconSrc;
}
@@ -149,7 +150,7 @@ $(function () {
hasPending: hasPending,
stopAll: stopAll
};
- } ()),
+ }()),
stopPolling = function () {
pollingUtility.stopAll();
$startPolling.show();
@@ -174,32 +175,7 @@ $(function () {
}
});
}
- },
- preferences = (function () {
- var siteSelectionKey = "siteSelection",
- getItem = function (key) {
- var result = null;
- if (localStorage && localStorage.getItem) {
- result = localStorage.getItem(key);
- }
- return result;
- },
- setItem = function (key, value) {
- if (localStorage && localStorage.setItem) {
- try {
- localStorage.setItem(key, value);
- } catch (e) {
- if (e == QUOTA_EXCEEDED_ERR && console && console.error) {
- console.error("`localStorage` quota exceeded.");
- }
- }
- }
- };
- return {
- getSiteSelection: function () { return getItem(siteSelectionKey); },
- setSiteSelection: function (value) { setItem(siteSelectionKey, value); }
- };
- } ());
+ };
// Set Stack Exchange API app key for all requests.
$.stackExchangeApi.typicalDefaults = $.extend($.stackExchangeApi.typicalDefaults, {
@@ -218,7 +194,7 @@ $(function () {
modal: true,
closeOnEscape: false,
open: function () {
- var savedSiteSelection = preferences.getSiteSelection(),
+ var savedSiteSelection = preferences.siteSelection.get(),
$this = $(this);
$(".ui-dialog-titlebar-close").hide();
$this.on("keyup.enter", function (e) {
@@ -244,7 +220,7 @@ $(function () {
siteIconSrc = $("label[for='" + siteFilter + "']").find("img").attr("src") || "http://sstatic.net/stackoverflow/img/apple-touch-icon.png",
siteAudience = $selectedSiteInput.data("site-audience"),
siteName = $selectedSiteInput.siblings("label").first().text();
- preferences.setSiteSelection(siteFilter);
+ preferences.siteSelection.set(siteFilter);
startPolling({ filter: siteFilter, iconSrc: siteIconSrc, url: siteUrl, audience: siteAudience, name: siteName });
$(this).off("keyup.enter");
}
Please sign in to comment.
Something went wrong with that request. Please try again.