Skip to content

Commit

Permalink
Optimized for chrome (electricitymaps#53)
Browse files Browse the repository at this point in the history
* add overlay

* trigger overlay when not google chrome. Load viz only when google chrome. Fixes electricitymaps#48

* render viz even if not Chrome

* add <continue without Chrome> option
  • Loading branch information
Guilherme Coelho authored and corradio committed Sep 14, 2016
1 parent d26c538 commit 1bc52a4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
29 changes: 29 additions & 0 deletions public/app/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
// Snippet taken from: http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome/13348618#13348618
//
// please note
// that IE11 now returns undefined again for window.chrome
// and new Opera 30 outputs true for window.chrome
// and new IE Edge outputs to true now for window.chrome
// and if not iOS Chrome check
// so use the below updated condition
var isChromium = window.chrome,
winNav = window.navigator,
vendorName = winNav.vendor,
isOpera = winNav.userAgent.indexOf("OPR") > -1,
isIEedge = winNav.userAgent.indexOf("Edge") > -1,
isIOSChrome = winNav.userAgent.match("CriOS");

if(isIOSChrome){
// is Google Chrome on IOS
} else if(isChromium !== null && isChromium !== undefined && vendorName === "Google Inc." && isOpera == false && isIEedge == false) {
// is Google Chrome
} else {
// not Google Chrome

// show force-chrome overlay
document.getElementById('force-chrome-overlay').style.display = "flex";
}

var ENDPOINT = document.domain == 'localhost' ? 'http://localhost:8000' : 'http://electricitymap-api.tmrow.co';

var co2color = d3.scale.linear()
Expand Down Expand Up @@ -514,3 +540,6 @@ window.onresize = function () {

redraw();
fetchAndReschedule();



Binary file added public/chromelogo-highres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@
</div>
<small class="contribute-text">Help out with missing data by contributing on <a href="https://github.com/corradio/electricitymap#contribute" target="_blank">GitHub</a>. Follow us on <a href="https://twitter.com/tmrowco" target="_blank">Twitter</a> for the latest updates.</small>
<div class="loading overlay"></div>
<div id="force-chrome-overlay" class="force-chrome" style="display: none;">
<div class="centered">
<h1>Bummer!</h1>
<p>In order to ensure the best viewing experience we’ve optimized the Electricity Map to the Chrome web browser.</p>

<p>Please switch to Chrome in oder to view this <b>real-time visualization of Energy production in Europe</b>.</p>

<p style="margin-top:3em;"><small>If you don't have Chrome, you can click the button below to install it, or simply <a href="#" onclick="document.getElementById('force-chrome-overlay').style.display = 'none';">continue without it</a> (not recommended).</small></p>
<p style="text-align:center;"><a class="button" href="https://www.google.com/chrome/browser/desktop/">Install <img src="chromelogo-highres.png"/></a></p>
</div>
</div>
</body>

<script src="app/main.js"></script>
Expand Down
55 changes: 55 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,61 @@ html, body {
width: 300px;
}

.force-chrome {
position: absolute;
z-index: 99;
width: 100%;
height: 100%;
background-color: white;
display: flex;
align-items: center;
justify-content: center;
color: dimgrey;
}

.force-chrome .centered {
max-width: 400px;
}

.force-chrome h1{
text-align: center;
font-size: 2.5em;
margin-bottom: 1em;
}

.force-chrome img {
height: 17px;
float: right;
margin-left: 7px;
}

.force-chrome a {
color: dimgrey;
text-decoration: underline;
}

.force-chrome a.button {
font-size: 13px;
display: inline-block;
border: 1px solid #a2a2a2;
border-radius: 10px;
padding: 7px 12px;
text-decoration: none;
}

.force-chrome a.button:hover {
text-decoration: none;
background-color: #f1f1f1;
}


.force-chrome p {
font-size: 0.9em;
font-weight: lighter;
text-align: justify;
line-height: 1.4;
}

a {
text-decoration: none;
color: lightblue;
Expand Down
4 changes: 4 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def favicon_GET():
def logo_GET():
return flask.send_from_directory('public', 'tomorrow_logo_open_source.svg')

@app.route('/chromelogo-highres.png')
def chrome_logo_GET():
return flask.send_from_directory('public', 'chromelogo-highres.png')

@app.route('/vendor/<path:path>', methods=['GET', 'OPTIONS'])
def vendor_GET(path):
return flask.send_from_directory('public/vendor', path)
Expand Down

0 comments on commit 1bc52a4

Please sign in to comment.