]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - static/js/site.js
648b2a5b7e2119b1a1e21d96c636d782e4616ec4
[people/shoehn/ipfire.org.git] / static / js / site.js
1 $.query = function(name){
2 var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
3 return results[1] || 0;
4 }
5
6 $("a.download-splash").click(function(event) {
7 event.preventDefault();
8 linkLocation = this.href;
9
10 window.location = "http://downloads.ipfire.org/download-splash?file="+linkLocation;
11 });
12
13 var $window = $(window);
14
15 $(".sidenav").affix({
16 offset: {
17 top: function () { return $window.width() <= 980 ? 290 : 240 }
18 , bottom: 270
19 }
20 });
21
22 if (/.*download-splash.*/i.test(window.location.href)) {
23 $("p.download-path").ready(function(){
24 var valid = false;
25 var allowed_prefixes = [
26 "http://downloads.ipfire.org/",
27 ]
28
29 var file_url = $.query("file");
30
31 // Only accept URLs beginning with our known prefix.
32 for (i in allowed_prefixes) {
33 prefix = allowed_prefixes[i];
34 if (file_url.substring(0, prefix.length) == prefix) {
35 valid = true;
36 }
37 }
38
39 if (valid) {
40 $("p.download-path").prepend($("<a>", {
41 href: encodeURI(file_url),
42 text: file_url
43 }))
44 setTimeout(function() { window.location = file_url }, "2000");
45 }
46 });
47 }
48
49 /* $(".planet-search-autocomplete").typeahead({
50 source: function(query, process) {
51 $.get("/api/planet/search/autocomplete", { q: query }, function(data) {
52 if (data.query == query) {
53 process(data.results);
54 }
55 });
56 },
57 }); */
58
59 function getCookie(name) {
60 var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
61 return r ? r[1] : undefined;
62 }
63
64 jQuery.postJSON = function(url, args, callback) {
65 args._xsrf = getCookie("_xsrf");
66 $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
67 success: function(response) {
68 callback(eval("(" + response + ")"));
69 }
70 });
71 };