]> git.ipfire.org Git - ipfire.org.git/blob - static/js/site.js
Styled the other sections.
[ipfire.org.git] / static / js / site.js
1 $(document).ready(function () {
2 $(window).scroll(function () {
3 if ($(document).scrollTop() > 100) {
4 $(".fixed-top").addClass("scrolled");
5 } else {
6 $(".fixed-top").removeClass("scrolled");
7 }
8 });
9 });
10
11 //jQuery to collapse the navbar on scroll
12 $(window).scroll(function() {
13 if ($(".navbar").offset().top > 50) {
14 $(".navbar-fixed-top").addClass("top-nav-collapse");
15 } else {
16 $(".navbar-fixed-top").removeClass("top-nav-collapse");
17 }
18 });
19
20 //jQuery for page scrolling feature - requires jQuery Easing plugin
21 $(function() {
22 $('.page-scroll a, a.page-scroll').bind('click', function(event) {
23 var $anchor = $(this);
24 $('html, body').stop().animate({
25 scrollTop: $($anchor.attr('href')).offset().top
26 }, 1500, 'easeInOutExpo');
27 event.preventDefault();
28 });
29 });
30
31 $.query = function(name){
32 var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
33 return results[1] || 0;
34 }
35
36 $("a.download-splash").click(function(event) {
37 event.preventDefault();
38 linkLocation = this.href;
39
40 window.location = "http://downloads.ipfire.org/download-splash?file="+linkLocation;
41 });
42
43 var $window = $(window);
44
45 $(".sidenav").affix({
46 offset: {
47 top: function () { return $window.width() <= 980 ? 290 : 240 }
48 , bottom: 270
49 }
50 });
51
52 if (/.*download-splash.*/i.test(window.location.href)) {
53 $("p.download-path").ready(function(){
54 var valid = false;
55 var allowed_prefixes = [
56 "http://downloads.ipfire.org/",
57 ]
58
59 var file_url = $.query("file");
60
61 // Only accept URLs beginning with our known prefix.
62 for (i in allowed_prefixes) {
63 prefix = allowed_prefixes[i];
64 if (file_url.substring(0, prefix.length) == prefix) {
65 valid = true;
66 }
67 }
68
69 if (valid) {
70 $("p.download-path").prepend($("<a>", {
71 href: encodeURI(file_url),
72 text: file_url
73 }))
74 setTimeout(function() { window.location = file_url }, "2000");
75 }
76 });
77 }
78
79 /* $(".planet-search-autocomplete").typeahead({
80 source: function(query, process) {
81 $.get("/api/planet/search/autocomplete", { q: query }, function(data) {
82 if (data.query == query) {
83 process(data.results);
84 }
85 });
86 },
87 }); */
88
89 function getCookie(name) {
90 var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
91 return r ? r[1] : undefined;
92 }
93
94 jQuery.postJSON = function(url, args, callback) {
95 args._xsrf = getCookie("_xsrf");
96 $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
97 success: function(response) {
98 callback(eval("(" + response + ")"));
99 }
100 });
101 };