Skip to content

Instantly share code, notes, and snippets.

@jacktandrew
Created November 2, 2012 14:57
Show Gist options
  • Save jacktandrew/4001843 to your computer and use it in GitHub Desktop.
Save jacktandrew/4001843 to your computer and use it in GitHub Desktop.
html5 Summary part 2
function waitTilLoad(){
var editable = document.querySelector('.editable');
var reset = document.querySelector('.reset');
function blurring() {
localStorage.setItem('editedContent', this.innerHTML);
document.designMode = 'off';
}
function focusing() {
document.designMode = 'on';
};
function reseting() {
localStorage.clear();
location.reload();
};
if (localStorage.getItem('editedContent')) {
editable.innerHTML = localStorage.getItem('editedContent');
}
editable.addEventListener('blur', blurring, false);
editable.addEventListener('focus', focusing, false);
reset.addEventListener('click', reseting, false);
};
window.addEventListener('load', waitTilLoad, false);
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(48.2, -123),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
}
function tryGeoLocate() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});
map.setCenter(pos);
}, function() {
handleNoGeolocation(true);
});
} else {
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(160, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
google.maps.event.addDomListener(window, 'load', initialize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment