Skip to content

Commit 355d883

Browse files
committed
put people.html loadContributors execution into main.js. removed unused detectmob function. ready to push
1 parent 412d058 commit 355d883

File tree

3 files changed

+59
-51
lines changed

3 files changed

+59
-51
lines changed

war/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ <h2>Latest news</h2>
265265
</div>
266266
<div class="span6">
267267
<h2>Social stream</h2>
268-
<a class="twitter-timeline" href="https://twitter.com/OpenWorm" data-widget-id="293717776768569344">Tweets
269-
by @OpenWorm</a>
268+
<div id="tweeter">
269+
<a class="twitter-timeline" href="https://twitter.com/OpenWorm" data-widget-id="293717776768569344">Tweets by @OpenWorm</a>
270+
</div>
270271
</div>
271272
</div>
272273
</div>

war/js/main.js

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,65 @@
1-
// set ALL links inside pjax-content to try pjax
2-
// this may slow down outside links with pjax request?
1+
// set pjax timeout - after timeout, regular html request is sent. 1500ms is arbitrary
32
$.pjax.defaults.timeout = 1500
3+
4+
// fragment extracts div id='pjax content' from full HTML
5+
// server could alternatively be configured to send only the needed fragment
6+
7+
// set ALL links inside pjax-content to try pjax
8+
// this may slow down outside links but is easier than labelling each link data-pjax
49
$(document).pjax('a', '#pjax-content', {fragment: '#pjax-content'});
510
// set explicit links in nav bars to use pjax
611
$(document).pjax('a[data-pjax]', '#pjax-content', {fragment: '#pjax-content'});
712

13+
// things to do on pjax _link_ to page
814
$(document).on('pjax:complete', function() {
915
console.log('pjax:complete');
10-
// things to do on pjax link to specific page
1116
var loc = window.location.pathname;
1217
if (loc === '/index.html' || loc === '/' || loc === '') {
1318
reloadSocial();
1419
} else if (loc === '/donate.html') {
1520
loadDonationControls();
21+
} else if (loc === '/people.html') {
22+
$.getScript("https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.0/mustache.min.js",
23+
function() {
24+
loadContributors();
25+
})
1626
}
1727
setNavigation();
1828
})
1929

30+
// things to do on pjax BACK/FORWARD to specific page
2031
$(document).on('pjax:popstate', function() {
2132
console.log('pjax:popstate');
22-
// things to do on pjax BACK/FORWARD to specific page
23-
var loc = window.location.pathname;
24-
if (loc === '/donate.html') {
25-
// hack to make donate controls reload _after_ page load on back
26-
$(document).on('pjax:end', function () {
27-
console.log('loadDonationControls');
33+
$(document).on('pjax:end', function () {
34+
var loc = window.location.pathname;
35+
if (loc === '/donate.html') {
36+
// hack to make donate controls reload _after_ page load on back
2837
loadDonationControls();
38+
}
39+
else if (loc === '/index.html' || loc === '/' || loc === '') {
40+
// Twitter widget
41+
$('#fb-root').html('');
42+
$('#tweeter').html('<a class="twitter-timeline" href="https://twitter.com/OpenWorm" data-widget-id="293717776768569344">Tweets by @OpenWorm</a>');
43+
//$.pjax.reload('#pjax-content', {fragment:'#pjax-content'});
44+
reloadSocial();
45+
// setNavigation();
46+
}
47+
console.log(loc);
48+
$(function () {
49+
setNavigation();
50+
//deselect old link
51+
document.activeElement.blur();
2952
})
30-
}
31-
setNavigation();
53+
})
3254
})
3355

3456

57+
// things to do on initial page load
3558
$(window).on('load', function() {
3659
console.log('window initial load');
37-
// things to do on initial page load (defined in main.js)
3860
// for all pages:
39-
loadGoogleAnalytics();
4061
setNavigation();
62+
loadGoogleAnalytics();
4163

4264
$(".carousel-control").click(function(e) {
4365
$("#tip").hide();
@@ -56,33 +78,27 @@ $(window).on('load', function() {
5678
// for specific pages:
5779
var loc = window.location.pathname;
5880
if (loc === '/index.html' || loc === '/' || loc === '') {
59-
console.log('loc = index');
81+
//console.log('loc = index');
6082
loadGooglePlus();
6183
loadFacebook();
6284
loadTwitterWidget();
6385
refreshNews();
6486
$('.nav li').removeClass('active');
6587
$('#home').addClass('active');
6688
} else if (loc === '/donate.html') {
67-
console.log('loc = donate');
89+
//console.log('loc = donate');
6890
loadDonationControls();
91+
} else if (loc === '/people.html') {
92+
$.getScript("https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.0/mustache.min.js",
93+
function() {
94+
loadContributors();
95+
})
6996
}
7097
})
7198

72-
window.___gcfg = {
73-
lang: 'en-GB'
74-
};
7599

76-
// function definitions (hoisted so order does not matter)
77100

78-
// no idea what uses this function...this should not be here.
79-
function detectmob() {
80-
if (window.innerWidth <= 800 && window.innerHeight <= 600) {
81-
return true;
82-
} else {
83-
return false;
84-
}
85-
}
101+
// general function definitions
86102

87103
function setNavigation() {
88104
$(".nav li").removeClass('active');
@@ -91,23 +107,22 @@ function setNavigation() {
91107
$(".nav a").each(function() {
92108
var href = $(this).attr('href');
93109
// href is returned as ./index.hml, so add . to path
110+
// this is most likely error moving from local to online site?
94111
if ('.' + path === href) {
95112
$(this).closest('li').addClass('active');
96113
return;
97114
}
98-
});
115+
})
99116
}
100117

118+
101119
function refreshNews() {
102120
$("#news-feed").PaRSS("http://openworm.tumblr.com/rss", // url to the feed
103121
6, // number of items to retrieve
104122
"M jS Y, g:i a", // date format
105123
false, // include descriptions
106124
function() {
107-
/*
108-
* optional callback function performed after list is appended to the
109-
* page
110-
*/
125+
// optional callback function
111126
})
112127
}
113128

@@ -118,7 +133,6 @@ var _gaq = _gaq || [];
118133
_gaq.push(['_setAccount', 'UA-29668455-1']);
119134
_gaq.push(['_trackPageview']);
120135

121-
122136
function loadGoogleAnalytics() {
123137
var ga = document.createElement('script');
124138
ga.type = 'text/javascript';
@@ -145,7 +159,6 @@ function loadTwitterWidget () {
145159
t = window.twtter || {};
146160
if (document.getElementById("twitter-wjs")) return t;
147161
js = document.createElement("script");
148-
js.async = true;
149162
js.id = "twitter-wjs";
150163
js.src = "//platform.twitter.com/widgets.js";
151164
fjs.parentNode.insertBefore(js, fjs);
@@ -158,6 +171,10 @@ function loadTwitterWidget () {
158171
return t;
159172
}
160173

174+
// sets language for google+ widget
175+
window.___gcfg = {
176+
lang: 'en-GB'
177+
};
161178

162179
function loadGooglePlus() {
163180
var po = document.createElement('script');
@@ -170,7 +187,7 @@ function loadGooglePlus() {
170187

171188

172189
function reloadSocial() {
173-
// http://www.blackfishweb.com/blog/asynchronously-loading-twitter-google-facebook-and-linkedin-buttons-and-widgets-ajax-bonus
190+
// partially stolen from: http://www.blackfishweb.com/blog/asynchronously-loading-twitter-google-facebook-and-linkedin-buttons-and-widgets-ajax-bonus
174191

175192
// Twitter widget
176193
if (typeof (twttr) != 'undefined') {
@@ -183,7 +200,6 @@ function reloadSocial() {
183200
refreshNews();
184201

185202
// Facebook
186-
console.log(typeof (FB));
187203
if (typeof (FB) != 'undefined') {
188204
delete FB;
189205
$('#facebook-jssdk').remove();
@@ -204,7 +220,7 @@ function reloadSocial() {
204220
}
205221

206222

207-
// donation
223+
// donation controls
208224

209225
function loadDonationControls() {
210226
$(".donation").on('click', function() {
@@ -254,7 +270,6 @@ function loadDonationControls() {
254270
}
255271
}
256272

257-
258273
function getUrlParameter(sParam) {
259274
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
260275
sURLVariables = sPageURL.split('&'),

war/people.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,8 @@
4747
<body>
4848
<div id="pjax-content">
4949
<!-- END REPEAT-->
50-
<script>
51-
$(document).on('pjax:end', function() {
52-
loadContributors();
53-
})
54-
$(function() {
55-
loadContributors();
56-
})
57-
</script>
5850

59-
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.0/mustache.min.js"></script>
60-
<script type="text/javascript">
51+
<script>
6152
function rowify(data, rowLength) {
6253
var data3 = {};
6354
var rows = [];
@@ -75,11 +66,12 @@
7566
data3 ["rows"] = rows;
7667
return data3;
7768
}
69+
7870
function loadContributors() {
7971
//Grab the inline template
8072
var template = document.getElementById('template').innerHTML;
8173

82-
//Parse it (optional, only necessary if template is to be used again)
74+
// Parse it (optional, only necessary if template is to be used again)
8375
Mustache.parse(template);
8476

8577
var contributors = [{

0 commit comments

Comments
 (0)