]> git.ipfire.org Git - ipfire.org.git/blame - static/js/site.js
add responsive layout.
[ipfire.org.git] / static / js / site.js
CommitLineData
4b4334da
S
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
60b0917c
MT
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
20df8773
S
20$("#scrollto").click(function() {
21 $('html, body').animate({
22 scrollTop: $("#features").offset().top - $('.fixed-top').height()
23 }, 1500, 'easeInOutExpo');
60b0917c
MT
24});
25
60024cc8
MT
26$.query = function(name){
27 var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
28 return results[1] || 0;
29}
30
31$("a.download-splash").click(function(event) {
32 event.preventDefault();
33 linkLocation = this.href;
34
73493ea6 35 window.location = "https://downloads.ipfire.org/download-splash?file="+linkLocation;
60024cc8
MT
36});
37
9b5ac075
MT
38var $window = $(window);
39
40$(".sidenav").affix({
41 offset: {
66f34dde 42 top: function () { return $window.width() <= 980 ? 290 : 240 }
9b5ac075
MT
43 , bottom: 270
44 }
45});
46
60024cc8
MT
47if (/.*download-splash.*/i.test(window.location.href)) {
48 $("p.download-path").ready(function(){
49 var valid = false;
50 var allowed_prefixes = [
73493ea6 51 "https://downloads.ipfire.org/",
60024cc8
MT
52 ]
53
54 var file_url = $.query("file");
55
56 // Only accept URLs beginning with our known prefix.
57 for (i in allowed_prefixes) {
58 prefix = allowed_prefixes[i];
59 if (file_url.substring(0, prefix.length) == prefix) {
60 valid = true;
61 }
62 }
63
64 if (valid) {
65 $("p.download-path").prepend($("<a>", {
66 href: encodeURI(file_url),
67 text: file_url
68 }))
69 setTimeout(function() { window.location = file_url }, "2000");
70 }
71 });
72}
0e824faf 73
c9275d4e 74/* $(".planet-search-autocomplete").typeahead({
a3e3c96d 75 source: function(query, process) {
8876f3df 76 $.get("/api/planet/search/autocomplete", { q: query }, function(data) {
a3e3c96d
MT
77 if (data.query == query) {
78 process(data.results);
79 }
80 });
81 },
c9275d4e 82}); */
a3e3c96d 83
0e824faf
MT
84function getCookie(name) {
85 var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
86 return r ? r[1] : undefined;
87}
88
89jQuery.postJSON = function(url, args, callback) {
90 args._xsrf = getCookie("_xsrf");
91 $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
92 success: function(response) {
93 callback(eval("(" + response + ")"));
94 }
95 });
96};