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
3
2
$ . 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
4
9
$ ( document ) . pjax ( 'a' , '#pjax-content' , { fragment : '#pjax-content' } ) ;
5
10
// set explicit links in nav bars to use pjax
6
11
$ ( document ) . pjax ( 'a[data-pjax]' , '#pjax-content' , { fragment : '#pjax-content' } ) ;
7
12
13
+ // things to do on pjax _link_ to page
8
14
$ ( document ) . on ( 'pjax:complete' , function ( ) {
9
15
console . log ( 'pjax:complete' ) ;
10
- // things to do on pjax link to specific page
11
16
var loc = window . location . pathname ;
12
17
if ( loc === '/index.html' || loc === '/' || loc === '' ) {
13
18
reloadSocial ( ) ;
14
19
} else if ( loc === '/donate.html' ) {
15
20
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
+ } )
16
26
}
17
27
setNavigation ( ) ;
18
28
} )
19
29
30
+ // things to do on pjax BACK/FORWARD to specific page
20
31
$ ( document ) . on ( 'pjax:popstate' , function ( ) {
21
32
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
28
37
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 ( ) ;
29
52
} )
30
- }
31
- setNavigation ( ) ;
53
+ } )
32
54
} )
33
55
34
56
57
+ // things to do on initial page load
35
58
$ ( window ) . on ( 'load' , function ( ) {
36
59
console . log ( 'window initial load' ) ;
37
- // things to do on initial page load (defined in main.js)
38
60
// for all pages:
39
- loadGoogleAnalytics ( ) ;
40
61
setNavigation ( ) ;
62
+ loadGoogleAnalytics ( ) ;
41
63
42
64
$ ( ".carousel-control" ) . click ( function ( e ) {
43
65
$ ( "#tip" ) . hide ( ) ;
@@ -56,33 +78,27 @@ $(window).on('load', function() {
56
78
// for specific pages:
57
79
var loc = window . location . pathname ;
58
80
if ( loc === '/index.html' || loc === '/' || loc === '' ) {
59
- console . log ( 'loc = index' ) ;
81
+ // console.log('loc = index');
60
82
loadGooglePlus ( ) ;
61
83
loadFacebook ( ) ;
62
84
loadTwitterWidget ( ) ;
63
85
refreshNews ( ) ;
64
86
$ ( '.nav li' ) . removeClass ( 'active' ) ;
65
87
$ ( '#home' ) . addClass ( 'active' ) ;
66
88
} else if ( loc === '/donate.html' ) {
67
- console . log ( 'loc = donate' ) ;
89
+ // console.log('loc = donate');
68
90
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
+ } )
69
96
}
70
97
} )
71
98
72
- window . ___gcfg = {
73
- lang : 'en-GB'
74
- } ;
75
99
76
- // function definitions (hoisted so order does not matter)
77
100
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
86
102
87
103
function setNavigation ( ) {
88
104
$ ( ".nav li" ) . removeClass ( 'active' ) ;
@@ -91,23 +107,22 @@ function setNavigation() {
91
107
$ ( ".nav a" ) . each ( function ( ) {
92
108
var href = $ ( this ) . attr ( 'href' ) ;
93
109
// href is returned as ./index.hml, so add . to path
110
+ // this is most likely error moving from local to online site?
94
111
if ( '.' + path === href ) {
95
112
$ ( this ) . closest ( 'li' ) . addClass ( 'active' ) ;
96
113
return ;
97
114
}
98
- } ) ;
115
+ } )
99
116
}
100
117
118
+
101
119
function refreshNews ( ) {
102
120
$ ( "#news-feed" ) . PaRSS ( "http://openworm.tumblr.com/rss" , // url to the feed
103
121
6 , // number of items to retrieve
104
122
"M jS Y, g:i a" , // date format
105
123
false , // include descriptions
106
124
function ( ) {
107
- /*
108
- * optional callback function performed after list is appended to the
109
- * page
110
- */
125
+ // optional callback function
111
126
} )
112
127
}
113
128
@@ -118,7 +133,6 @@ var _gaq = _gaq || [];
118
133
_gaq . push ( [ '_setAccount' , 'UA-29668455-1' ] ) ;
119
134
_gaq . push ( [ '_trackPageview' ] ) ;
120
135
121
-
122
136
function loadGoogleAnalytics ( ) {
123
137
var ga = document . createElement ( 'script' ) ;
124
138
ga . type = 'text/javascript' ;
@@ -145,7 +159,6 @@ function loadTwitterWidget () {
145
159
t = window . twtter || { } ;
146
160
if ( document . getElementById ( "twitter-wjs" ) ) return t ;
147
161
js = document . createElement ( "script" ) ;
148
- js . async = true ;
149
162
js . id = "twitter-wjs" ;
150
163
js . src = "//platform.twitter.com/widgets.js" ;
151
164
fjs . parentNode . insertBefore ( js , fjs ) ;
@@ -158,6 +171,10 @@ function loadTwitterWidget () {
158
171
return t ;
159
172
}
160
173
174
+ // sets language for google+ widget
175
+ window . ___gcfg = {
176
+ lang : 'en-GB'
177
+ } ;
161
178
162
179
function loadGooglePlus ( ) {
163
180
var po = document . createElement ( 'script' ) ;
@@ -170,7 +187,7 @@ function loadGooglePlus() {
170
187
171
188
172
189
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
174
191
175
192
// Twitter widget
176
193
if ( typeof ( twttr ) != 'undefined' ) {
@@ -183,7 +200,6 @@ function reloadSocial() {
183
200
refreshNews ( ) ;
184
201
185
202
// Facebook
186
- console . log ( typeof ( FB ) ) ;
187
203
if ( typeof ( FB ) != 'undefined' ) {
188
204
delete FB ;
189
205
$ ( '#facebook-jssdk' ) . remove ( ) ;
@@ -204,7 +220,7 @@ function reloadSocial() {
204
220
}
205
221
206
222
207
- // donation
223
+ // donation controls
208
224
209
225
function loadDonationControls ( ) {
210
226
$ ( ".donation" ) . on ( 'click' , function ( ) {
@@ -254,7 +270,6 @@ function loadDonationControls() {
254
270
}
255
271
}
256
272
257
-
258
273
function getUrlParameter ( sParam ) {
259
274
var sPageURL = decodeURIComponent ( window . location . search . substring ( 1 ) ) ,
260
275
sURLVariables = sPageURL . split ( '&' ) ,
0 commit comments