blob: 7dafd713290b55e21afaadd0c259d17b4caf535a [file] [log] [blame]
Alexander Afanasyev3c95c852013-03-01 18:58:50 -08001var CHRONOSHARE;
2
3var PAGE; // no default page anymore (no reason to have)
4var PARAMS = [ ];
5var URIPARAMS = "";
6
7function nav_anchor (aurl) {
8 aurl = aurl.split('#');
9 if (aurl[1])
10 {
11 aurl_split = aurl[1].split ('&');
12 page = aurl_split[0];
13
14 vars = [ ];
15 for (var i = 1; i < aurl_split.length; i++)
16 {
17 hash = aurl_split[i].split('=');
18 vars.push(hash[0]);
19 // there is strange double-encoding problem...
20 vars[hash[0]] = decodeURIComponent (decodeURIComponent (hash[1]));
21 }
22
23 if (page != PAGE)
24 {
25 PAGE = page;
26 PARAMS = vars;
27 URIPARAMS = aurl[1];
28
29 if (CHRONOSHARE) {
30 CHRONOSHARE.run ();
31 }
32 }
33 else if (aurl[1] != URIPARAMS)
34 {
35 PARAMS = vars;
36 URIPARAMS = aurl[1];
37
38 if (CHRONOSHARE) {
39 CHRONOSHARE.run ();
40 }
41 }
42 }
43}
44
45$(document).ready (function () {
46 nav_anchor (window.location.href);
47
48 if (!PARAMS.user || !PARAMS.folder)
49 {
50 $("#error").html ("user and folder must be be specified in the URL");
51 $("#error").removeClass ("hidden");
52 return;
53 }
54 else {
55 // update in-page URLs
56 $(".needs-get-url").each (function (index,element) {
57 this.href += "&user="+encodeURIComponent (encodeURIComponent (PARAMS.user))
58 + "&folder="+encodeURIComponent (encodeURIComponent (PARAMS.folder));
59 });
60 $(".needs-get-url").removeClass ("needs-get-url");
61 }
62
63 CHRONOSHARE = new ChronoShare (PARAMS.user, PARAMS.folder);
64 CHRONOSHARE.run ();
65
66 $(window).on('hashchange', function() {
67 nav_anchor (window.location.href);
68 });
69});
70