Skip to content

Commit 821b9e6

Browse files
authored
refactor js (#320)
1 parent f05fe6a commit 821b9e6

File tree

3 files changed

+99
-115
lines changed

3 files changed

+99
-115
lines changed

_includes/js.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<script src="/js/jquery.toc.min.js"></script>
44
<script src="/js/contributors.js"></script>
55
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.2.0/list.min.js"></script>
6-
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
6+
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
7+
<script src="/js/js.js"></script>

_layouts/bootstrap.html

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -298,120 +298,6 @@ <h4>they support us_</h4>
298298

299299
{% include js.html %}
300300

301-
<!-- SCRIPTS -->
302-
<script>
303-
$(document).ready(function () {
304-
function randomCarousel(id) {
305-
var num = $(id + ' .item').length;
306-
var slide = Math.floor((Math.random() * num));
307-
$(id + ' .item').each(function (index) {
308-
if (index == slide) {
309-
$(this).addClass('active');
310-
} else {
311-
$(this).removeClass('active');
312-
}
313-
});
314-
}
315-
316-
randomCarousel('#carousel-tweets');
317-
randomCarousel('#carousel-companies');
318-
});
319-
</script>
320-
321-
<script>
322-
$(document).ready(function () {
323-
var toc = $('#toc');
324-
if(toc.length) {
325-
toc.toc({
326-
'selectors': 'h2',
327-
'prefix': 'toc',
328-
'container': '#page',
329-
'anchorName': function (i, heading, prefix) { //custom function for anchor name
330-
return $(heading).text().replace(/\s/g, '-').replace(/[^\w-]/g, '');
331-
},
332-
});
333-
}
334-
});
335-
</script>
336-
337-
<script>
338-
$(document).ready(function () {
339-
var cpContainer = $(".cp:contains('<?php')");
340-
var cpContains = $(".cp:contains('?>')");
341-
var page = $('#page table');
342-
var tocNext = $('#toc');
343-
var tocNextUl = $('#toc > ul');
344-
var tocNextUlLi = $('#toc ul.list li a');
345-
346-
if(cpContainer.length) {
347-
cpContainer.css({ visibility : 'hidden' });
348-
}
349-
350-
if(cpContains.length) {
351-
cpContains.css({ visibility : 'hidden' });
352-
}
353-
354-
if(page.length) {
355-
page.addClass('table table-striped table-bordered');
356-
}
357-
358-
if(tocNext.length) {
359-
tocNext.toc({
360-
'selectors': 'h2,h3,h4',
361-
'prefix': 'toc',
362-
'container': '#page',
363-
//custom function for anchor name
364-
'anchorName': function(i, heading, prefix) {
365-
return $(heading).text().replace(/\s/g, '-').replace(/[^\w-]/g, '');
366-
},
367-
});
368-
}
369-
370-
// List.js
371-
if(tocNextUl.length) {
372-
tocNextUl.addClass('list');
373-
}
374-
375-
if(tocNextUlLi.length) {
376-
tocNextUlLi.addClass('searchitem');
377-
}
378-
379-
var options = {
380-
valueNames: [ 'searchitem' ]
381-
};
382-
var userList = new List('searchable', options);
383-
// end List.js
384-
385-
}); // docrdy
386-
</script>
387-
388-
<script>
389-
var _gaq = _gaq || [];
390-
_gaq.push(['_setAccount', 'UA-1899308-9']);
391-
_gaq.push(['_trackPageview']);
392-
393-
(function () {
394-
var ga = document.createElement('script');
395-
ga.type = 'text/javascript';
396-
ga.async = true;
397-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
398-
var s = document.getElementsByTagName('script')[0];
399-
s.parentNode.insertBefore(ga, s);
400-
})();
401-
</script>
402-
403-
<script>
404-
// Adding this layout functionality for mobile views with the homepage hero
405-
$(document).ready(function(){
406-
var navbarToggle = $('.navbar-toggle')
407-
if(navbarToggle.length) {
408-
navbarToggle.click(function(){
409-
$('.row.home').toggleClass('no-padding-top');
410-
});
411-
}
412-
});
413-
</script>
414-
415301
{% include twitter.html %}
416302

417303
{% include algolia.html %}

js/js.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
$(document).ready(function () {
2+
function randomCarousel(id) {
3+
var num = $(id + ' .item').length;
4+
var slide = Math.floor((Math.random() * num));
5+
$(id + ' .item').each(function (index) {
6+
if (index == slide) {
7+
$(this).addClass('active');
8+
} else {
9+
$(this).removeClass('active');
10+
}
11+
});
12+
}
13+
14+
randomCarousel('#carousel-tweets');
15+
randomCarousel('#carousel-companies');
16+
17+
var toc = $('#toc');
18+
if(toc.length) {
19+
toc.toc({
20+
'selectors': 'h2',
21+
'prefix': 'toc',
22+
'container': '#page',
23+
'anchorName': function (i, heading, prefix) { //custom function for anchor name
24+
return $(heading).text().replace(/\s/g, '-').replace(/[^\w-]/g, '');
25+
},
26+
});
27+
}
28+
29+
var cpContainer = $(".cp:contains('<?php')");
30+
var cpContains = $(".cp:contains('?>')");
31+
var page = $('#page table');
32+
var tocNext = $('#toc');
33+
var tocNextUl = $('#toc > ul');
34+
var tocNextUlLi = $('#toc ul.list li a');
35+
36+
if(cpContainer.length) {
37+
cpContainer.css({ visibility : 'hidden' });
38+
}
39+
40+
if(cpContains.length) {
41+
cpContains.css({ visibility : 'hidden' });
42+
}
43+
44+
if(page.length) {
45+
page.addClass('table table-striped table-bordered');
46+
}
47+
48+
if(tocNext.length) {
49+
tocNext.toc({
50+
'selectors': 'h2,h3,h4',
51+
'prefix': 'toc',
52+
'container': '#page',
53+
//custom function for anchor name
54+
'anchorName': function(i, heading, prefix) {
55+
return $(heading).text().replace(/\s/g, '-').replace(/[^\w-]/g, '');
56+
},
57+
});
58+
}
59+
60+
// List.js
61+
if(tocNextUl.length) {
62+
tocNextUl.addClass('list');
63+
}
64+
65+
if(tocNextUlLi.length) {
66+
tocNextUlLi.addClass('searchitem');
67+
}
68+
69+
var options = {
70+
valueNames: [ 'searchitem' ]
71+
};
72+
var userList = new List('searchable', options);
73+
// end List.js
74+
// docrdy
75+
76+
// Adding this layout functionality for mobile views with the homepage hero
77+
var navbarToggle = $('.navbar-toggle')
78+
if(navbarToggle.length) {
79+
navbarToggle.click(function(){
80+
$('.row.home').toggleClass('no-padding-top');
81+
});
82+
}
83+
});
84+
85+
86+
var _gaq = _gaq || [];
87+
_gaq.push(['_setAccount', 'UA-1899308-9']);
88+
_gaq.push(['_trackPageview']);
89+
90+
(function () {
91+
var ga = document.createElement('script');
92+
ga.type = 'text/javascript';
93+
ga.async = true;
94+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
95+
var s = document.getElementsByTagName('script')[0];
96+
s.parentNode.insertBefore(ga, s);
97+
})();

0 commit comments

Comments
 (0)