[329] Rebase hashchange tab code on core plugin developed for ticket 329.
--- a/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
+++ b/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
@@ -69,9 +69,9 @@
spotColor: '',
maxSpotColor: '',
minSpotColor: '',
- highlightSpotColor: '000000',
- lineColor: '3F8E6D',
- fillColor: 'B7E66B'
+ highlightSpotColor: '#000000',
+ lineColor: '#3F8E6D',
+ fillColor: '#B7E66B'
};
$('.sparkline').sparkline('html',sparkOptions);
created = true;
@@ -87,7 +87,7 @@
* Show the correct rickshaw graph in the sidebar.
* Not to be called before all graphs load.
*/
- $('a[data-toggle="hashchange"]').on(
+ $('a[data-toggle="hashtab"]').on(
'shown',
function(e) {
var href = $(e.target).attr('href');
@@ -104,6 +104,8 @@
$(legend_name).show();
}
);
+ /* The first tab might already have been shown */
+ $('li.active > a[data-toggle="hashtab"]').trigger('shown');
};
CKAN.GA_Reports.bind_month_selector = function() {
@@ -118,22 +120,3 @@
selectors.bind('change', handler);
};
-/*
- * Custom bootstrap plugin for handling data-toggle="hashchange".
- * Behaves like data-toggle="tab" but I respond to the hashchange.
- * Page state is memo-ized in the URL this way. Why doesn't Bootstrap do this?
- */
-$(function() {
- var mapping = {};
- $('a[data-toggle="hashchange"]').each(
- function(i,link) {
- link = $(link);
- mapping[link.attr('href')] = link;
- }
- );
- $(window).hashchange(function() {
- var link = mapping[window.location.hash];
- if (link) { link.tab('show'); }
- });
-});
-
--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -41,36 +41,40 @@
<div class="tabbable">
<ul class="nav nav-tabs">
- <li><a href="#totals" data-toggle="hashchange">Totals</a></li>
+ <li class="active"><a href="#totals" data-toggle="hashtab">Totals</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Browsers
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#browsers_names" data-toggle="hashchange">Browsers</a></li>
- <li><a href="#browsers_versions" data-toggle="hashchange">Versions</a></li>
+ <li><a href="#browsers_names" data-toggle="hashtab">Browsers</a></li>
+ <li><a href="#browsers_versions" data-toggle="hashtab">Versions</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Operating Systems
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#os" data-toggle="hashchange">Operating Systems</a></li>
- <li><a href="#os_versions" data-toggle="hashchange">Versions</a></li>
+ <li><a href="#os" data-toggle="hashtab">Operating Systems</a></li>
+ <li><a href="#os_versions" data-toggle="hashtab">Versions</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Social
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#social_networks" data-toggle="hashchange">All networks</a></li>
- <li><a href="#social_referrals_totals" data-toggle="hashchange">Referral links</a></li>
+ <li><a href="#social_networks" data-toggle="hashtab">All networks</a></li>
+ <li><a href="#social_referrals_totals" data-toggle="hashtab">Referral links</a></li>
</ul>
</li>
- <li><a href="#languages" data-toggle="hashchange">Languages</a></li>
- <li><a href="#country" data-toggle="hashchange">Country</a></li>
+ <li><a href="#languages" data-toggle="hashtab">Languages</a></li>
+ <li><a href="#country" data-toggle="hashtab">Country</a></li>
</ul>
<div class="tab-content">
- <div class="tab-pane" id="totals">
+ <div class="tab-pane active" id="totals">
+ <form class="form-inline" action="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='index')}" method="get">
+ <label>Show stats table for:</label>
+ ${month_selector(c.month, c.months, c.day)}
+ </form>
<table class="ga-reports-table table table-condensed table-bordered table-striped">
<tr>
<th>Name</th>
@@ -167,12 +171,6 @@
CKAN.GA_Reports.bind_sparklines();
CKAN.GA_Reports.bind_sidebar();
CKAN.GA_Reports.bind_month_selector();
- if (!window.location.hash) {
- window.location.hash='totals';
- }
- else {
- $(window).trigger('hashchange');
- }
});
</script>
</py:def>