Created
November 3, 2016 13:19
-
-
Save ajberry/9b13e38bac94981b82d9be46811fa60c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
document.addEventListener('deviceready', onDeviceReady.bind(this), false); | |
function onDeviceReady() { | |
// Handle the Cordova pause and resume events | |
document.addEventListener('pause', onPause.bind(this), false); | |
document.addEventListener('resume', onResume.bind(this), false); | |
//Creates the database | |
$(document).ready(function () { | |
$('a.presentation').on('click', function (e) { | |
var ret = "" | |
var directory = cordova.file.applicationDirectory + "www/presentations/files/"; | |
var fileName = this.getAttribute("data-link") | |
window.resolveLocalFileSystemURL(directory, function (directoryEntry) { | |
directoryEntry.getFile(fileName, { create: false }, function (fileEntry) { | |
ret = fileEntry.nativeURL; | |
var VIEWER_OPTIONS = { | |
documentView: { | |
closeLabel: "Close" | |
}, | |
navigationView: { | |
closeLabel: "Close" | |
}, | |
email: { | |
enabled: false | |
}, | |
print: { | |
enabled: true | |
}, | |
openWith: { | |
enabled: false | |
}, | |
bookmarks: { | |
enabled: false | |
}, | |
search: { | |
enabled: false | |
} | |
}; | |
SitewaertsDocumentViewer.viewDocument(ret, 'application/pdf', VIEWER_OPTIONS, onShow, onClose, onMissingApp, onError); | |
}, ret = null); | |
}, fail); | |
}); | |
}); | |
function onShow(){ | |
window.console.log('document shown'); | |
//e.g. track document usage | |
} | |
function onClose(){ | |
window.console.log('document closed'); | |
//e.g. remove temp files | |
} | |
function onMissingApp(id, installer) | |
{ | |
if(confirm("Do you want to install the free PDF Viewer App " | |
+ appId + " for Android?")) | |
{ | |
installer(); | |
} | |
} | |
function onError(error){ | |
window.console.log(error); | |
alert("Sorry! Cannot view document."); | |
} | |
function fail(error) { | |
console.log("Failed to list directory contents: ", error); | |
} | |
var errorHandler = function (fileName, e) { | |
var msg = ''; | |
switch (e.code) { | |
case FileError.QUOTA_EXCEEDED_ERR: | |
msg = 'Storage quota exceeded'; | |
break; | |
case FileError.NOT_FOUND_ERR: | |
msg = 'File not found'; | |
break; | |
case FileError.SECURITY_ERR: | |
msg = 'Security error'; | |
break; | |
case FileError.INVALID_MODIFICATION_ERR: | |
msg = 'Invalid modification'; | |
break; | |
case FileError.INVALID_STATE_ERR: | |
msg = 'Invalid state'; | |
break; | |
default: | |
msg = 'Unknown error'; | |
break; | |
}; | |
console.log('Error (' + fileName + '): ' + msg); | |
} | |
}; | |
function onPause() { | |
// TODO: This application has been suspended. Save application state here. | |
}; | |
function onResume() { | |
// TODO: This application has been reactivated. Restore application state here. | |
}; | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment