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) |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 4 | var PARAMS = []; |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 5 | var URIPARAMS = ""; |
| 6 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 7 | function nav_anchor(aurl) |
| 8 | { |
| 9 | aurl = aurl.split('#'); |
| 10 | if (aurl[1]) { |
| 11 | aurl_split = aurl[1].split('&'); |
| 12 | page = aurl_split[0]; |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 14 | 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 Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 20 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 21 | |
| 22 | // if (page != PAGE) |
| 23 | // { |
| 24 | // PAGE = page; |
| 25 | // PARAMS = vars; |
| 26 | // URIPARAMS = aurl[1]; |
| 27 | |
| 28 | // if (CHRONOSHARE) { |
Alexander Afanasyev | e16ed21 | 2016-12-25 18:09:44 -0800 | [diff] [blame] | 29 | // CHRONOSHARE.run(); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 30 | // } |
| 31 | // } |
| 32 | // else if (aurl[1] != URIPARAMS) |
| 33 | // { |
| 34 | // PARAMS = vars; |
| 35 | // URIPARAMS = aurl[1]; |
| 36 | |
| 37 | // if (CHRONOSHARE) { |
Alexander Afanasyev | e16ed21 | 2016-12-25 18:09:44 -0800 | [diff] [blame] | 38 | // CHRONOSHARE.run(); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 39 | // } |
| 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 Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 53 | $(document).ready(function() { |
| 54 | nav_anchor(window.location.href); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 55 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 56 | 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 Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 67 | }); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 68 | $(".needs-get-url").removeClass("needs-get-url"); |
| 69 | } |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 71 | 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 Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 81 | }); |