]>
Commit | Line | Data |
---|---|---|
60024cc8 MT |
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 | ||
9b5ac075 MT |
13 | var $window = $(window); |
14 | ||
15 | $(".sidenav").affix({ | |
16 | offset: { | |
17 | top: function () { return $window.width() <= 980 ? 290 : 210 } | |
18 | , bottom: 270 | |
19 | } | |
20 | }); | |
21 | ||
60024cc8 MT |
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 | } | |
0e824faf MT |
48 | |
49 | function getCookie(name) { | |
50 | var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); | |
51 | return r ? r[1] : undefined; | |
52 | } | |
53 | ||
54 | jQuery.postJSON = function(url, args, callback) { | |
55 | args._xsrf = getCookie("_xsrf"); | |
56 | $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST", | |
57 | success: function(response) { | |
58 | callback(eval("(" + response + ")")); | |
59 | } | |
60 | }); | |
61 | }; |