diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/.index.js.swp | bin | 40960 -> 24576 bytes | |||
| -rw-r--r-- | js/index.js | 87 |
2 files changed, 25 insertions, 62 deletions
diff --git a/js/.index.js.swp b/js/.index.js.swp Binary files differindex 71452a0..b4c26c8 100644 --- a/js/.index.js.swp +++ b/js/.index.js.swp diff --git a/js/index.js b/js/index.js index 01fd866..5c9d89e 100644 --- a/js/index.js +++ b/js/index.js @@ -17,29 +17,19 @@ */ // Login-Popup beim Start -$('#loginpage').on('pagebeforeshow', function(){ +$('#mainpage').on('pagebeforeshow', function(){ setTimeout(function(){ + load(); $('#lnklogin').click(); }, 500); }); -$('#loginpage').on('pageshow', function(){ +$('#mainpage').on('pageshow', function(){ setTimeout(function(){ trylogin(); }, 2000); }); -// Page-Template für Vertretungsplan -var page_html = '\n\ -<div data-role="page" class="page" id="page-vplan-{ID}" data-prefetch>\n\ - <div data-role="header">\n\ - <h1>WvS VPlan | Vertretungen</h1>\n\ - </div>\n\ - <div role="main" class="ui-content" id="pdf-{ID}" data-plan-url="">\n\ - </div>\n\ -</div>\n\ -'; - /* PDF Rendering */ function renderPage(div, pdf, pageNumber, callback){ pdf.getPage(pageNumber).then(function(page){ @@ -70,11 +60,11 @@ function renderPage(div, pdf, pageNumber, callback){ }); } -function render_pdf(viewerstr){ - console.log('Rendere PDF: ' + $(viewerstr).attr('data-plan-url') + ' (' + viewerstr + ')'); +function render_pdf(url, divstr){ + console.log('Rendere PDF: ' + url + ' (' + divstr + ')'); - PDFJS.getDocument($(viewerstr).attr('data-plan-url')).then(function(pdf){ - var viewer = document.getElementById(viewerstr.replace(/#/, '')); + PDFJS.getDocument(url).then(function(pdf){ + var viewer = document.getElementById(divstr); var pageNumber = 1; renderPage(viewer, pdf, pageNumber++, function pageRenderingComplete(){ if(pageNumber > pdf.numPages){ @@ -94,19 +84,23 @@ function fail(text){ } /* fügt die lokale URL des Plans ein und ruft die Seite zum Rendering auf */ -function addplanattr(fileEntry, id){ +function addplanattr(fileEntry){ var sPath = fileEntry.toURL(); + var name = fileEntry.name.replace('.pdf', ''); - console.log('Datei: ' + sPath); - $('#pdf-' + id).attr('data-plan-url', sPath); + console.log('Dateiname: ' + name); - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + id); - } + var vplantabs = $('#vplantabs').tabs(); + var ul = vplantabs.find('ul'); + $('<li><a href="#' + name + '">' + name + '</a></li>').appendTo(ul); + $('<div id="' + name + '"></div>').appendTo(vplantabs); + + render_pdf(sPath, name); + vplantabs.tabs('refresh'); // TODO geht nicht } /* lädt ein PDF anhand eines Links herunter, benötigt ID zur Sortierung */ -function download_pdf(link, id){ +function download_pdf(link){ var filename = link.substring(link.lastIndexOf("/") + 1); window.requestFileSystem( @@ -118,7 +112,7 @@ function download_pdf(link, id){ function(fileEntry){ // Datei ist schon heruntergeladen console.log('lade Datei nicht erneut herunter'); - addplanattr(fileEntry, id); + addplanattr(fileEntry); }, function(err){ // Datei existiert noch nicht @@ -131,7 +125,7 @@ function download_pdf(link, id){ sPath, function(theFile){ console.log('Download fertig: ' + theFile.toURL()); - addplanattr(theFile, id); + addplanattr(theFile); }, fail); }, fail); }); @@ -140,13 +134,13 @@ function download_pdf(link, id){ } /* sucht den Downloadlink eines Plans mithilfe eines Links aus der Kursübersicht */ -function get_plan(link, id){ +function get_plan(link){ var request = $.ajax({ url: link }); request.done(function gotplan(resulthtml){ - 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(resulthtml)[1]; if(pdflink == null){ @@ -154,7 +148,7 @@ function get_plan(link, id){ } console.log('Plan gefunden: ' + pdflink); - download_pdf(pdflink, id); + download_pdf(pdflink); return 1; }); @@ -162,31 +156,6 @@ function get_plan(link, id){ request.fail(fail); } -/* erstellt dynamisch die Seiten für die Vertretungspläne und aktiviert Wischgesten */ -function prepare_html(number){ - for(j = 0; j < number; j++){ - new_html = page_html.replace(/{ID}/g, j); - - $('#loginpage').after(new_html); - - if(j + 1 < number){ - $('#page-vplan-' + j).on('swipeleft', function(event){ - $.mobile.changePage('#page-vplan-' + (parseInt($('.ui-page-active').attr('id').match(/\d+/)[0]) + 1)); - }); - } - - if(j - 1 >= 0){ - $('#page-vplan-' + j).on('swiperight', function(event){ - $.mobile.changePage('#page-vplan-' + (parseInt($('.ui-page-active').attr('id').match(/\d+/)[0]) - 1)); - }); - } - - $('#page-vplan-' + j).on('pageshow', function(event){ - render_pdf($('.ui-page-active').attr('id').replace(/page-vplan/, '#pdf')); - }); - } -} - /* ruft get_plan für jeden Link in der Kursübersicht auf */ function gotoverview(resulthtml){ var plans_re = new RegExp('window\\.open\\('(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&redirect=1'\\)', 'g'); @@ -202,13 +171,9 @@ function gotoverview(resulthtml){ var resultl = resultarr.length; - prepare_html(resultl); - - j = 0; - while((link = plans_re.exec(resulthtml)) !== null){ console.log('suche Plan ' + link[1]); - get_plan(link[1], j++); + get_plan(link[1]); } console.log('Übersichts-Request erfolgreich'); @@ -360,10 +325,8 @@ function load(){ console.log("Im Speicher: " + actual.length + " Pläne"); if(actual.length > 0){ - prepare_html(actual.length); - for(j = 0; j < actual.length; j++){ - addplanattr(actual[j], j); + addplanattr(actual[j]); } }else{ |
