rebuilding site Wed Oct 20 02:59:48 PM CST 2021

master
James Feng Cao 3 years ago
parent c751c8e355
commit 9de97472ca

@ -18,32 +18,6 @@
<body>
<div id="for_viewer"></div>
<script>
function makeRequest (method, url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
//xhr.overrideMimeType("application/octet-stream");
xhr.responseType="arraybuffer";
xhr.onload = function () {
if (this.status == 0 || (this.status >= 200 && this.status < 300)) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send();
});
}
// save as a global value
window.viewer = new DjVu.Viewer();
viewer.render(document.querySelector("#for_viewer"));
@ -54,20 +28,22 @@
let lhash = location.hash;
if(lhash)
page = parseInt(lhash.substring(6),10);
//viewer.loadDocumentByUrl(url,{"pageNumber": page,});
/*fetch(new Request(url))
.then(function(response) {
return response.arrayBuffer();
})
*/
makeRequest('GET', url)
.then(function(buffer) {
viewer.loadDocument(buffer," ",{"pageNumber":page,});
});
viewer.loadDocumentByUrl(url,{"pageNumber": page,});
}
window.addEventListener('hashchange', function() {
let page = 1;
let lhash = location.hash;
if(lhash)
page = parseInt(lhash.substring(6),10);
viewer.configure({pageNumber: page,});
/*
viewer.store.dispatch({
type: DjVu.Viewer.ActionTypes.SET_NEW_PAGE_NUMBER_ACTION,
pageNumber: page,
shouldScrollToPage: true,
});
*/
});
</script>
</body>

Loading…
Cancel
Save