1
- // set all links inside pjax-content to try pjax:
1
+ // set ALL links inside pjax-content to try pjax
2
+ // this may slow down outside links with pjax request?
2
3
$ ( document ) . pjax ( 'a' , '#pjax-content' , { fragment : '#pjax-content' } ) ;
3
-
4
4
// set explicit links in nav bars to use pjax
5
5
$ ( document ) . pjax ( 'a[data-pjax]' , '#pjax-content' , { fragment : '#pjax-content' } ) ;
6
6
7
7
$ ( document ) . on ( 'pjax:complete' , function ( ) {
8
- // things to do on page change back to index.html
9
- if ( window . location . pathname === '/index.html' ) {
8
+ console . log ( 'pjax:complete' ) ;
9
+ // things to do on pjax link to specific page
10
+ var loc = window . location . pathname ;
11
+ if ( loc === '/index.html' || loc === '/' || loc === '' ) {
10
12
reloadSocial ( ) ;
13
+ } else if ( loc === '/donate.html' ) {
14
+ loadDonationControls ( ) ;
11
15
}
12
16
setNavigation ( ) ;
13
17
} )
14
18
19
+ $ ( document ) . on ( 'pjax:popstate' , function ( ) {
20
+ console . log ( 'pjax:popstate' ) ;
21
+ // things to do on pjax BACK/FORWARD to specific page
22
+ var loc = window . location . pathname ;
23
+ if ( loc === '/donate.html' ) {
24
+ // hack to make donate controls reload _after_ page load on back
25
+ $ ( document ) . on ( 'pjax:end' , function ( ) {
26
+ console . log ( 'loadDonationControls' ) ;
27
+ loadDonationControls ( ) ;
28
+ } )
29
+ }
30
+ setNavigation ( ) ;
31
+ } )
32
+
33
+
15
34
$ ( window ) . on ( 'load' , function ( ) {
35
+ console . log ( 'window initial load' ) ;
16
36
// things to do on initial page load (defined in main.js)
37
+ // for all pages:
17
38
loadGoogleAnalytics ( ) ;
18
39
setNavigation ( ) ;
40
+
41
+ $ ( ".carousel-control" ) . click ( function ( e ) {
42
+ $ ( "#tip" ) . hide ( ) ;
43
+ } )
44
+
45
+ $ ( '.carousel' ) . carousel ( {
46
+ interval : 13000
47
+ } )
48
+
49
+ $ ( '.minilogo' ) . tooltip ( ) ;
50
+
51
+ window . ___gcfg = {
52
+ lang : 'en-GB'
53
+ }
54
+
55
+ // for specific pages:
19
56
var loc = window . location . pathname ;
20
57
if ( loc === '/index.html' || loc === '/' || loc === '' ) {
58
+ console . log ( 'loc = index' ) ;
21
59
loadGooglePlus ( ) ;
22
60
loadFacebook ( ) ;
23
61
loadTwitterWidget ( ) ;
24
62
refreshNews ( ) ;
25
63
$ ( '.nav li' ) . removeClass ( 'active' ) ;
26
64
$ ( '#home' ) . addClass ( 'active' ) ;
27
- }
28
- } )
29
-
30
- $ ( function ( ) {
31
- // unclear what this does?
32
- // side bar
33
- $ ( '.bs-docs-sidenav' ) . affix ( {
34
- offset : {
35
- top : function ( ) {
36
- return $ ( window ) . width ( ) <= 980 ? 290 : 210
37
- } ,
38
- bottom : 270
39
- }
40
- } )
41
-
42
- $ ( ".carousel-control" ) . click ( function ( e ) {
43
- $ ( "#tip" ) . hide ( ) ;
44
- } ) ;
45
-
46
- $ ( '.carousel' ) . carousel ( {
47
- interval : 13000
48
- } ) ;
49
-
50
- $ ( '.minilogo' ) . tooltip ( ) ;
65
+ } else if ( loc === '/donate.html' ) {
66
+ console . log ( 'loc = donate' ) ;
67
+ loadDonationControls ( ) ;
68
+ }
51
69
} )
52
70
53
-
54
71
window . ___gcfg = {
55
72
lang : 'en-GB'
56
73
} ;
@@ -164,6 +181,7 @@ function reloadSocial() {
164
181
refreshNews ( ) ;
165
182
166
183
// Facebook
184
+ console . log ( typeof ( FB ) ) ;
167
185
if ( typeof ( FB ) != 'undefined' ) {
168
186
delete FB ;
169
187
$ ( '#facebook-jssdk' ) . remove ( ) ;
@@ -182,3 +200,70 @@ function reloadSocial() {
182
200
loadGooglePlus ( ) ;
183
201
}
184
202
}
203
+
204
+
205
+ // donation
206
+
207
+ function loadDonationControls ( ) {
208
+ $ ( ".donation" ) . on ( 'click' , function ( ) {
209
+ $ ( ".donation" ) . removeClass ( "active" ) ;
210
+ $ ( "#otherAmount" ) . removeClass ( "active" ) ;
211
+ $ ( "#amountSent" ) . attr ( "value" , $ ( this ) . html ( ) . replace ( "$" , "" ) ) ;
212
+ $ ( this ) . addClass ( "active" ) ;
213
+ } )
214
+
215
+ $ ( ".other" ) . click ( function ( ) {
216
+ $ ( "#otherAmount" ) . addClass ( "active" ) ;
217
+ $ ( "#amountSent" ) . attr ( "value" , $ ( this ) . val ( ) ) ;
218
+ $ ( "#otherAmount" ) . focus ( ) ;
219
+ } )
220
+
221
+ $ ( "#otherAmount" ) . click ( function ( ) {
222
+ $ ( "#otherAmount" ) . addClass ( "active" ) ;
223
+ $ ( ".donation" ) . removeClass ( "active" ) ;
224
+ $ ( "#amountSent" ) . attr ( "value" , $ ( this ) . val ( ) ) ;
225
+ $ ( ".other" ) . addClass ( "active" ) ;
226
+ } )
227
+
228
+ $ ( "#otherAmount" ) . on ( "input" , function ( ) {
229
+ $ ( "#amountSent" ) . attr ( "value" , $ ( this ) . val ( ) ) ;
230
+ } )
231
+
232
+ var amount = getUrlParameter ( 'amount' ) ;
233
+ if ( amount == "" || amount == undefined ) {
234
+ $ ( "#d50" ) . click ( ) ;
235
+ }
236
+ else if ( amount == "5" ) {
237
+ $ ( "#d5" ) . click ( ) ;
238
+ }
239
+ else if ( amount == "25" ) {
240
+ $ ( "#d25" ) . click ( ) ;
241
+ }
242
+ else if ( amount == "50" ) {
243
+ $ ( "#d50" ) . click ( ) ;
244
+ }
245
+ else if ( amount == "100" ) {
246
+ $ ( "#d100" ) . click ( ) ;
247
+ }
248
+ else {
249
+ $ ( ".other" ) . click ( ) ;
250
+ $ ( "#otherAmount" ) . val ( amount ) ;
251
+ $ ( "#amountSent" ) . attr ( "value" , amount ) ;
252
+ }
253
+ }
254
+
255
+
256
+ function getUrlParameter ( sParam ) {
257
+ var sPageURL = decodeURIComponent ( window . location . search . substring ( 1 ) ) ,
258
+ sURLVariables = sPageURL . split ( '&' ) ,
259
+ sParameterName ,
260
+ i ;
261
+
262
+ for ( i = 0 ; i < sURLVariables . length ; i ++ ) {
263
+ sParameterName = sURLVariables [ i ] . split ( '=' ) ;
264
+
265
+ if ( sParameterName [ 0 ] === sParam ) {
266
+ return sParameterName [ 1 ] === undefined ? true : sParameterName [ 1 ] ;
267
+ }
268
+ }
269
+ }
0 commit comments