Skip to content

Commit

Permalink
Merge branch 'master' of github.com:depeele/contextual-clock
Browse files Browse the repository at this point in the history
Conflicts:
	index.html
  • Loading branch information
D. Elmo Peele committed Jun 21, 2016
2 parents e7c0699 + 7b0c711 commit 11d3867
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
25 changes: 25 additions & 0 deletions Geocoder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Returned from Google Geocoder
address_components[]
long_name
short_name
types[]
street_number (e.g. '7270')
route (e.g. 'Springfield Ave')
locality, political (e.g. City, 'Sykesville')
sublocality, political (e.g. 'Gaither')
administrative_area_level_3, political (e.g. District,'5, Freedom')
administrative_area_level_2, political (e.g. County, 'Carroll')
administrative_area_level_1, political (e.g. State, 'Maryland')
country (e.g. 'United States')
postal_code (e.g. '21784')
formatted_address
geometry{}
types[]
street_address (e.g. '7270 Springfield Ave,
Sykesville, MD 21784, USA')
locality, political (e.g. 'Sykesville, MD 21784, USA')
administrative_area_level_3, political (e.g. '5, Freedom, MD, USA')
administrative_area_level_2, political (e.g. 'Carroll, Maryland, USA')
administrative_area_level_1, political (e.g. 'Maryland, USA')
postal_code (e.g. 'Sykesville, MD 21784, USA')

9 changes: 9 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ body {
top: 0;
left: 10em;
}
#info .Geolocation {
position: absolute;
top: 8em;
}
.Geolocation .address {
}
.Geolocation .type {
padding: 0 1em;
}
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
<!-- div id="info">
<div class="Date"></div>
<div class="Time"></div>
<div class="Geolocation"></div>
</div -->
</div>
</article>
</section>
</body>
Expand Down
41 changes: 35 additions & 6 deletions js/jquery.contextualClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ $.ContextualClock.prototype = {
init: function(options) {
this.options = $.extend(true, {}, this.options, options);
var opts = this.options;

this.$info = $('#info');


if (opts.ctx === null)
{
Expand Down Expand Up @@ -188,23 +191,50 @@ $.ContextualClock.prototype = {
setLocation: function( location ) {
var self = this;
var opts = self.options;
var $info = self.$info.find('.Geolocation');

opts.location = location;

/* Look through the incoming location data for those that have
* a type of:
* 'locality' - city/state
* 'locality'
* or 'street_address'
*
* From this, pull the address components:
* 'locality' - city
* 'administrative_area_level_1' - state
*/
$info.empty();
opts.locationStr = '';
var choices = [];
var pref = 0;
$.each(opts.location, function() {
var addr = this;
var addrAr = [];
if (addr.types[0] !== 'locality') { return; }
var $div;

$div = $('<div>'+ addr.formatted_address +'</div>')
.addClass('address');
$info.append($div);
$.each(addr.types, function(idex) {
var type = this.toString();
if ((type === 'locality') ||
(type === 'street_address'))
{
if (type === 'locality') { pref = choices.length; }
choices.push(addr);
}

$div = $('<div>type #'+ idex +':'+ this +'</div>')
.addClass('type');

$info.append($div);
});
});

$.each(addr.address_components, function() {
if (choices.length > 0)
{
var addrAr = [];
$.each(choices[pref].address_components, function() {
switch (this.types[0])
{
case 'locality':
Expand All @@ -220,9 +250,8 @@ $.ContextualClock.prototype = {
if (addrAr.length > 0)
{
opts.locationStr = addrAr.join(', ');
return false;
}
});
}
},

/** @brief Left pad the provided string to the specified number of
Expand Down

0 comments on commit 11d3867

Please sign in to comment.