blob: 81b07cd6ffed3163198ed899956fc863a275d1b1 [file] [log] [blame]
Alexander Afanasyev3c95c852013-03-01 18:58:50 -08001var CHRONOSHARE;
2
3var PAGE; // no default page anymore (no reason to have)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -08004var PARAMS = [];
Alexander Afanasyev3c95c852013-03-01 18:58:50 -08005var URIPARAMS = "";
6
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -08007function nav_anchor(aurl)
8{
9 aurl = aurl.split('#');
10 if (aurl[1]) {
11 aurl_split = aurl[1].split('&');
12 page = aurl_split[0];
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080013
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080014 vars = [];
15 for (var i = 1; i < aurl_split.length; i++) {
16 hash = aurl_split[i].split('=');
17 vars.push(hash[0]);
18 // there is strange double-encoding problem...
19 vars[hash[0]] = decodeURIComponent(decodeURIComponent(hash[1]));
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080020 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080021
22 // if (page != PAGE)
23 // {
24 // PAGE = page;
25 // PARAMS = vars;
26 // URIPARAMS = aurl[1];
27
28 // if (CHRONOSHARE) {
Alexander Afanasyeve16ed212016-12-25 18:09:44 -080029 // CHRONOSHARE.run();
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080030 // }
31 // }
32 // else if (aurl[1] != URIPARAMS)
33 // {
34 // PARAMS = vars;
35 // URIPARAMS = aurl[1];
36
37 // if (CHRONOSHARE) {
Alexander Afanasyeve16ed212016-12-25 18:09:44 -080038 // CHRONOSHARE.run();
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080039 // }
40 // }
41
42 // this way we can reload by just clicking on the same link
43 PAGE = page;
44 PARAMS = vars;
45 URIPARAMS = aurl[1];
46
47 if (CHRONOSHARE) {
48 CHRONOSHARE.run();
49 }
50 }
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080051}
52
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080053$(document).ready(function() {
54 nav_anchor(window.location.href);
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080055
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080056 if (!PARAMS.user || !PARAMS.folder) {
57 $("#error").html("user and folder must be be specified in the URL");
58 $("#error").removeClass("hidden");
59 return;
60 }
61 else {
62 // update in-page URLs
63 $(".needs-get-url").each(function(index, element) {
64 this.href +=
65 "&user=" + encodeURIComponent(encodeURIComponent(PARAMS.user)) +
66 "&folder=" + encodeURIComponent(encodeURIComponent(PARAMS.folder));
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080067 });
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080068 $(".needs-get-url").removeClass("needs-get-url");
69 }
Alexander Afanasyev4c17b482013-03-02 01:32:35 -080070
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080071 CHRONOSHARE = new ChronoShare(PARAMS.user, PARAMS.folder);
72 CHRONOSHARE.run();
73
74 $(window).on('hashchange', function() {
75 nav_anchor(window.location.href);
76 });
77
78 $("#reload-button").click(function() {
79 nav_anchor(window.location.href);
80 });
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080081});