aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-08-15 11:43:14 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-08-16 18:38:20 +0100
commit3425a7ba037612141f75321d3d0b226e4ca0ed1e (patch)
treea34a849d312dc4e56c2c82c7f9a1a53fa13d21f2
parentc87f28e944e2511f6f045dd3447e458697379f3a (diff)
[fixmystreet.com] Factor out poster JavaScript.
-rw-r--r--templates/web/fixmystreet.com/about/posters.html24
-rw-r--r--web/cobrands/fixmystreet.com/posters.js29
2 files changed, 32 insertions, 21 deletions
diff --git a/templates/web/fixmystreet.com/about/posters.html b/templates/web/fixmystreet.com/about/posters.html
index f330b57fe..8a53cf1e2 100644
--- a/templates/web/fixmystreet.com/about/posters.html
+++ b/templates/web/fixmystreet.com/about/posters.html
@@ -1,3 +1,6 @@
+[% extra_js = BLOCK %]
+ <script src="[% version('/cobrands/fixmystreet.com/posters.js') %]"></script>
+[% END %]
[% extra_css = BLOCK %]
<link rel="stylesheet" href="[% version('/cobrands/fixmystreet.com/posters.css') %]">
[% END %]
@@ -11,27 +14,6 @@
badge = '<a href="https://www.fixmystreet.com/"> <img src="https://www.fixmystreet.com/i/fms-badge.jpeg" alt="FixMyStreet - report, view or discuss local problems" border="0"></a>'
%]
-<script>
-
-$("[data-goodielink]").on('click', function(e){
- var url = $(this).attr('href')
- var name = $(this).attr('data-goodielink')
- var callback = function(){
- window.location.href = url
- }
- if(e.metaKey || e.ctrlKey){
- callback = function(){}
- } else {
- e.preventDefault()
- }
- ga('send', 'event', 'goodie', 'download', name, {
- 'hitCallback': callback
- })
- setTimeout(callback, 2000);
-});
-
-</script>
-
<div class="sticky-sidebar">
<aside>
<ul class="plain-list">
diff --git a/web/cobrands/fixmystreet.com/posters.js b/web/cobrands/fixmystreet.com/posters.js
new file mode 100644
index 000000000..caf09fd0e
--- /dev/null
+++ b/web/cobrands/fixmystreet.com/posters.js
@@ -0,0 +1,29 @@
+$.fn.link_track = function(eventCategory, eventAction, eventLabel) {
+ this.on('click', function(e) {
+ if (typeof ga === 'undefined') {
+ return;
+ }
+ var url = $(this).attr('href'),
+ name = $(this).attr('data-' + eventLabel),
+ callback = function() {
+ window.location.href = url;
+ };
+ if (e.metaKey || e.ctrlKey) {
+ callback = function(){};
+ } else {
+ e.preventDefault();
+ }
+ if (typeof ga !== 'undefined') {
+ ga('send', 'event', eventCategory, eventAction, name, {
+ 'hitCallback': callback
+ });
+ setTimeout(callback, 2000);
+ } else {
+ callback();
+ }
+ });
+};
+
+$(function() {
+ $("[data-goodielink]").link_track('goodie', 'download', 'goodielink');
+});