summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/index.js56
1 files changed, 44 insertions, 12 deletions
diff --git a/js/index.js b/js/index.js
index 837d5eb..162a810 100644
--- a/js/index.js
+++ b/js/index.js
@@ -15,21 +15,52 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+function fail(text){
+ alert("Etwas ist schiefgelaufen: " + text);
+}
function download_pdf(link){
- var request = $.ajax({
- type: "GET",
- url: link
- });
+ var filename = link.substring(link.lastIndexOf('/') + 1);
- request.done(function(result){
- // TODO
- console.log('Plan heruntergeladen');
- });
+ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
+ fileSystem.root.getFile(filename, {create: true, exclusive: false}, function(fileEntry){
+ var localPath = fileEntry.fullPath;
+ if(device.platform == "Android" && localPath.indexOf("file://") == 0){
+ localPath = localPath.substring(7);
+ }
+ var ft = new FileTransfer();
+ ft.download(link,
+ localPath, function(entry){
+ $('#input').attr('src', entry.fullPath);
- request.fail(function(jqXHR, textStatus){
- alert("Etwas ist schiefgelaufen: " + textStatus);
- });
+ var input = document.getElementById("input");
+ var processor = document.getElementById("processor");
+ var output = document.getElementById("output");
+
+ window.addEventListener("message", function(event){
+ if(event.source != processor.contentWindow) return;
+
+ switch(event.data){
+ case "ready":
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", input.getAttribute("src"), true);
+ xhr.responseType = "arraybuffer";
+
+ xhr.onload = function(event){
+ processor.contentWindow.postMessage(this.response, "*");
+ };
+
+ xhr.send();
+ break;
+
+ default:
+ output.textContent = event.data.replace(/\s+/g, " ");
+ break;
+ }
+ }, true);
+ }, fail);
+ }, fail);
+ }, fail);
}
function get_plan(link){
@@ -39,7 +70,7 @@ function get_plan(link){
});
request.done(function(result){
- var pdf_re = new RegExp("http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+.*?\\.pdf");
+ var pdf_re = new RegExp("(http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+.*?\\.pdf)");
var pdflink = pdf_re.exec(result)[1];
console.log('Plan gefunden: ' + pdflink);
@@ -63,6 +94,7 @@ function get_overview(link){
var links = plans_re.exec(result);
for(var i = 1; i < links.length; i += 2){
+ console.log('suche Plan ' + links[i]);
get_plan(links[i]);
}