]> git.ipfire.org Git - ipfire.org.git/blob - static/js/site.js
d13f286f32917883043d621d961de9c3b10ba743
[ipfire.org.git] / static / js / site.js
1 $(document).ready(function () {
2 $("#scrollto").click(function(e) {
3 e.preventDefault();
4 $('body').animate({
5 scrollTop: $("#features").offset().top -72
6 }, 1000);
7 });
8 $(window).scroll(function () {
9 if ($(document).scrollTop() > 100) {
10 $(".fixed-top").addClass("scrolled");
11 $(".menu-text").addClass("hidden");
12 } else {
13 $(".fixed-top").removeClass("scrolled");
14 $(".menu-text").removeClass("hidden");
15 }
16 });
17 //* Menu *//
18 $('.navbar-toggler-left').click(function() {
19 $('#navbarSupportedContent, #mask').addClass('open');
20 });
21 $('#mask').click(function() {
22 $('#navbarSupportedContent, #mask').removeClass('open');
23 });
24 });
25
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
35 window.location = "https://downloads.ipfire.org/download-splash?file="+linkLocation;
36 });
37
38 if (/.*download-splash.*/i.test(window.location.href)) {
39 $("p.download-path").ready(function(){
40 var valid = false;
41 var allowed_prefixes = [
42 "https://downloads.ipfire.org/",
43 ]
44
45 var file_url = $.query("file");
46
47 // Only accept URLs beginning with our known prefix.
48 for (i in allowed_prefixes) {
49 prefix = allowed_prefixes[i];
50 if (file_url.substring(0, prefix.length) == prefix) {
51 valid = true;
52 }
53 }
54
55 if (valid) {
56 $("p.download-path").prepend($("<a>", {
57 href: encodeURI(file_url),
58 text: file_url
59 }))
60 setTimeout(function() { window.location = file_url }, "2000");
61 }
62 });
63 }
64
65 /* $(".planet-search-autocomplete").typeahead({
66 source: function(query, process) {
67 $.get("/api/planet/search/autocomplete", { q: query }, function(data) {
68 if (data.query == query) {
69 process(data.results);
70 }
71 });
72 },
73 }); */
74
75 function getCookie(name) {
76 var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
77 return r ? r[1] : undefined;
78 }
79
80 jQuery.postJSON = function(url, args, callback) {
81 args._xsrf = getCookie("_xsrf");
82 $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
83 success: function(response) {
84 callback(eval("(" + response + ")"));
85 }
86 });
87 };