Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #308 from g-k/fix-hash-script-src
Browse files Browse the repository at this point in the history
Move init JS script to separate file
  • Loading branch information
jaredlockhart committed Feb 8, 2017
2 parents 020c6a4 + 1100f20 commit 2ce2a83
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
1 change: 0 additions & 1 deletion leaderboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@

CSP_SCRIPT_SRC = (
"'self'",
"'sha256-Ri/knIQy+te80bBUW2ViOjxeh+qSuEtuLCIT0mCqX7U='", # for landing.html L57 inline script window.onload = ...
"mozorg.cdn.mozilla.net",
"www.google-analytics.com",
"www.mozilla.org",
Expand Down
21 changes: 21 additions & 0 deletions leaderboard/static/js/onload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
window.onload = function () {
var getAppAttr = function (attrName) {
document.getElementById('leaderboard-container').getAttribute('data-' + attrName);
};

leaderboard.init({
leafletJSUrl: getAppAttr('leaflet-js-url'),
leafletGeometryJSUrl: getAppAttr('leaflet-geometry-js-url'),
leafletCSSUrl: getAppAttr('leaflet-css-url'),
countriesGeoUrl: getAppAttr('countries-geo-url'),
countriesInfoUrl: getAppAttr('countries-info-url'),
globalLeadersUrl: getAppAttr('global-leaders-url'),
countryLeadersUrl: getAppAttr('country-leaders-url'),
leaderProfileUrl: getAppAttr('leader-profile-url')
});

try {
Tabzilla.disableEasterEgg()
} catch (e) {
}
}
34 changes: 11 additions & 23 deletions leaderboard/templates/home/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
{% block page_title %}{% endblock %}

{% block content %}
<div id="leaderboard-container" data-ga-id="{{ GOOGLE_ANALYTICS_ID }}">
<div id="leaderboard-container"
data-ga-id="{{ GOOGLE_ANALYTICS_ID }}"
data-leaflet-js-url="{% static "lib/leaflet/leaflet.js" %}"
data-leaflet-geometry-js-url="{% static "lib/leaflet/leaflet.geometryutil.js" %}"
data-leaflet-css-url="{% static "lib/leaflet/leaflet.css" %}"
data-countries-geo-url="{% static "geojson/countries.named.geojson" %}"
data-countries-info-url="{% url "countries-list" %}"
data-global-leaders-url="{% url "leaders-global-list" %}"
data-country-leaders-url="{% url "leaders-country-list" country_id="XX" %}"
data-leader-profile-url="{% url "leaders-profile" uid="XX" %}">
</div>

<div class="section">
Expand Down Expand Up @@ -53,27 +62,6 @@ <h2>How do I contribute?</h2>
<script src="{% static "js/dist/leaderboard.react.js" %}"></script>
{% endif %}


<script>
window.onload = function () {
leaderboard.init({
leafletJSUrl: '{% static "lib/leaflet/leaflet.js" %}',
leafletGeometryJSUrl: '{% static "lib/leaflet/leaflet.geometryutil.js" %}',
leafletCSSUrl: '{% static "lib/leaflet/leaflet.css" %}',

countriesGeoUrl: '{% static "geojson/countries.named.geojson" %}',
countriesInfoUrl: '{% url "countries-list" %}',
globalLeadersUrl: '{% url "leaders-global-list" %}',
countryLeadersUrl: '{% url "leaders-country-list" country_id="XX" %}',
leaderProfileUrl: '{% url "leaders-profile" uid="XX" %}',
});

try {
Tabzilla.disableEasterEgg()
} catch (e) {
}
}
</script>

<script src="{% static "js/onload.js" %}"></script>
<script src="{% static "js/load_ga.js" %}"></script>
{% endblock %}

0 comments on commit 2ce2a83

Please sign in to comment.