Mercurial > hg > Papers > 2019 > anatofuz-thesis
comparison presen/fig/tgraph/assets/idrviewer.querystring-navigation.js @ 77:2327c951dfb9
update
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Feb 2019 19:46:14 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
76:582b97946af6 | 77:2327c951dfb9 |
---|---|
1 /* v1.2.0 */ | |
2 (function() { | |
3 "use strict"; | |
4 | |
5 var getURLParamValue = function(param) { | |
6 var url = document.URL; | |
7 var jumIdx = url.toString().indexOf('?'); | |
8 var params = (jumIdx != -1) ? url.substr(jumIdx + 1).split("&") : ""; | |
9 for (var i = 0; i < params.length; i++) { | |
10 params[i] = params[i].split('='); | |
11 if (params[i][0] == param) { | |
12 return params[i][1]; | |
13 } | |
14 } | |
15 return ""; | |
16 }; | |
17 | |
18 var layout; | |
19 var handlePageChange = function(data) { | |
20 if (history.pushState) { | |
21 if (layout === IDRViewer.LAYOUT_CONTINUOUS) { | |
22 try { | |
23 history.replaceState({page: data.page}, null, '?page=' + data.page); | |
24 } catch (ignore) { } // Chrome throws error on file:// protocol | |
25 } else { | |
26 try { | |
27 history.pushState({page: data.page}, null, '?page=' + data.page); | |
28 } catch (ignore) { } // Chrome throws error on file:// protocol | |
29 } | |
30 } | |
31 }; | |
32 | |
33 var pg = parseInt(getURLParamValue('page')); | |
34 if (isNaN(pg)) { | |
35 pg = 1; | |
36 } | |
37 IDRViewer.goToPage(pg); | |
38 | |
39 if (history.pushState) { | |
40 IDRViewer.on('ready', function (data) { | |
41 layout = data.layout; | |
42 | |
43 try { | |
44 history.replaceState({page: data.page}, null, '?page=' + data.page); | |
45 } catch (ignore) { } // Chrome throws error on file:// protocol | |
46 | |
47 window.onpopstate = function (event) { | |
48 IDRViewer.off('pagechange', handlePageChange); | |
49 IDRViewer.goToPage(event.state.page); | |
50 IDRViewer.on('pagechange', handlePageChange); | |
51 }; | |
52 | |
53 IDRViewer.on('pagechange', handlePageChange); | |
54 | |
55 IDRViewer.on('layoutchange', function (data) { | |
56 layout = data.layout; | |
57 }); | |
58 }); | |
59 } | |
60 | |
61 })(); |