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