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