// originalLoadDocument is the actual loadDocument function not the result of calling it
var originalLoadDocument = readerControl.loadDocument;
readerControl.loadDocument = function(doc) {
if (myXMLTestingFunction(doc)) {
console.log("show error");
} else {
originalLoadDocument.apply(this, arguments);
}
};
readerControl.loadDocument('../../xod-folder/magazine-04032015.xod','230115');
var library = [
{
id: "230315",
location: "myfile.xod"
}
];
$(document).on('viewerLoaded', function() {
readerControl.pageDisplay = readerControl.pageDisplayModes.Single;
readerControl.setPageMode();
var docInfo = library[0];
readerControl.doc_id = docInfo.id;
// check whether we've already downloaded this document
checkDownloaded(docInfo.id, function(isDownloaded) {
if (isDownloaded) {
readerControl.startOffline = true;
readerControl.loadDocument();
} else {
readerControl.loadDocument(docInfo.location);
storeOffline(docInfo, function(err) {
if (err) {
console.log('Error');
} else {
var doc = readerControl.docViewer.GetDocument();
doc.SetOfflineModeEnabled(true);
}
});
}
});
});
function checkDownloaded(id, onComplete) {
var doc = new CoreControls.Document(id);
doc.InitOfflineDB(function() {
onComplete(doc.IsDownloaded());
});
}
function storeOffline(docInfo, onComplete) {
console.log('inside storeOffline');
var cacheHinting = CoreControls.PartRetrievers.CacheHinting;
var partRetriever = new CoreControls.PartRetrievers.HttpPartRetriever(docInfo.location, cacheHinting.CACHE);
var doc = new CoreControls.Document(docInfo.id);
doc.LoadAsync(partRetriever, function(err) {
if (err) {
onComplete(err);
return;
}
doc.InitOfflineDB(function() {
doc.StoreOffline(function() {
onComplete();
console.log('offline db initialized');
});
});
});
}
Hi Kava,
The in MobileReaderControl.js in the loadDocument function just remove the code that sets window.readerControl.startOffline since we're setting it in the above code.
...
window.indexedDB.deleteDatabase(xod_id_here);