blob: 8856ec0738c3df0d735e819ecf0e9da5fc869f2c [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
Alexander Afanasyev4c17b482013-03-02 01:32:35 -080023 // if (page != PAGE)
24 // {
25 // PAGE = page;
26 // PARAMS = vars;
27 // URIPARAMS = aurl[1];
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080028
Alexander Afanasyev4c17b482013-03-02 01:32:35 -080029 // if (CHRONOSHARE) {
30 // CHRONOSHARE.run ();
31 // }
32 // }
33 // else if (aurl[1] != URIPARAMS)
34 // {
35 // PARAMS = vars;
36 // URIPARAMS = aurl[1];
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080037
Alexander Afanasyev4c17b482013-03-02 01:32:35 -080038 // if (CHRONOSHARE) {
39 // CHRONOSHARE.run ();
40 // }
41 // }
42
43 // this way we can reload by just clicking on the same link
44 PAGE = page;
45 PARAMS = vars;
46 URIPARAMS = aurl[1];
47
48 if (CHRONOSHARE) {
49 CHRONOSHARE.run ();
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080050 }
51 }
52}
53
54$(document).ready (function () {
55 nav_anchor (window.location.href);
56
57 if (!PARAMS.user || !PARAMS.folder)
58 {
59 $("#error").html ("user and folder must be be specified in the URL");
60 $("#error").removeClass ("hidden");
61 return;
62 }
63 else {
64 // update in-page URLs
65 $(".needs-get-url").each (function (index,element) {
66 this.href += "&user="+encodeURIComponent (encodeURIComponent (PARAMS.user))
67 + "&folder="+encodeURIComponent (encodeURIComponent (PARAMS.folder));
68 });
69 $(".needs-get-url").removeClass ("needs-get-url");
70 }
71
72 CHRONOSHARE = new ChronoShare (PARAMS.user, PARAMS.folder);
73 CHRONOSHARE.run ();
74
75 $(window).on('hashchange', function() {
76 nav_anchor (window.location.href);
77 });
Alexander Afanasyev4c17b482013-03-02 01:32:35 -080078
79 $("#reload-button").click (function() {
80 nav_anchor (window.location.href);
81 });
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080082});
83