Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 1 | var CHRONOSHARE; |
| 2 | |
| 3 | var PAGE; // no default page anymore (no reason to have) |
| 4 | var PARAMS = [ ]; |
| 5 | var URIPARAMS = ""; |
| 6 | |
| 7 | function 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 Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 23 | // if (page != PAGE) |
| 24 | // { |
| 25 | // PAGE = page; |
| 26 | // PARAMS = vars; |
| 27 | // URIPARAMS = aurl[1]; |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 29 | // if (CHRONOSHARE) { |
| 30 | // CHRONOSHARE.run (); |
| 31 | // } |
| 32 | // } |
| 33 | // else if (aurl[1] != URIPARAMS) |
| 34 | // { |
| 35 | // PARAMS = vars; |
| 36 | // URIPARAMS = aurl[1]; |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 38 | // 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 Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 50 | } |
| 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 Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 78 | |
| 79 | $("#reload-button").click (function() { |
| 80 | nav_anchor (window.location.href); |
| 81 | }); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 82 | }); |
| 83 | |