/*********************************************************************** content.js ************************************************************************ Main blackbox function *****Note: This document should only have changes made to it that don't *****break any previous e-learning functions. The majority of the functions here send data to the client-specific template file for parsing after finding the data required. ************************************************************************/ var navLoaded = false; var swipeLoaded = false; var timer, soundtimer; /* Content-object */ function Content(){ this.toc; this.page; this.paceimgs; this.pageDelays = new Array(); this.pageTemplate = "Page"; this.swipeCarousel; this.currentPageItem; this.tocdiv; this.courseTitle; this.totalChapNr = 0; this.totalPageNr = 0; this.courseLanguage; this.containsTest = false; //Used to determine if scorm complete should be set on last page or not this.chapterArray = new Array(); //Used to hold chapter links for the chapter indicator this.pageArray = new Array(); //Used to hold the contents of the pages }; Content.prototype.init = function(){ try{ document.documentElement.requestFullScreen(); /*screen.orientation.lock('landscape').catch(function() { //Prevents Chrome errors. });*/ screen.orientation.lock('landscape'); screen.msLockOrientation('landscape'); screen.mozLockOrientation('landscape'); window.scrollTo(0,1); }catch(err){ } // Find matches try{ var isMobile = window.matchMedia("screen"); if (isMobile.matches) { //Conditional script here var mql = window.matchMedia("(orientation: portrait)"); // If there are matches, we're in portrait if(mql.matches) { // Portrait orientation alert('This e-learning is best viewed in landscape mode.'); } else { // Landscape orientation } } }catch(err){ } var c = this; //Hide the body container until everything is loaded. $("#at_body_container").hide(); c.paceimgs = paceImages; //Hämtas från settings-filen /*c.toc = new Toc(); c.toc.loadToc();*/ //Om cookien redan är satt if(getCookie("thepace") != null){ var cookieok = false; //Kolla om cookien innehåller ett giltigt värde for(var i=0;i

'+courseTitle+'

'; } if(c.pageArray[i].chaptername !== curChapTitle){ //Create Chapter curChapTitle = c.pageArray[i].chaptername; toc_html += '

'+curChapTitle+'

'; } if(c.pageArray[i].subchaptername !== curSubChapTitle){ //Create SubChapter curSubChapTitle = c.pageArray[i].subchaptername; toc_html += '

'+curSubChapTitle+'

'; } toc_html += '

'+c.pageArray[i].pagetitle+'

'; } toc_html += ''; c.tocdiv = toc_html; $("#at_menu_inner").prepend(toc_html); $("#at_menu_container").wrapAll( "
"); } Content.prototype.setNextID = function(){ var c = this; var nextPage = ""; var arrayLength = c.pageArray.length; var curIndex = ""; var nextID = ""; for(curIndex = arrayLength-1; curIndex >= 0;curIndex--){ if(nextID.length){ c.pageArray[curIndex].nextPage = nextID; } else { c.pageArray[curIndex].nextPage = false; } nextID = c.pageArray[curIndex].pageid; } } Content.prototype.gotoFirstPage = function(){ var c = this; firstID = c.pageArray[0].pageid; c.loadCurrentPage(firstID); }; /*This function is slower than the default method of linking to the next page, use this only when it is not known in advance what the next page is*/ Content.prototype.gotoNextPage = function(){ var c = this; var id = content.getPageID(); var tempID = id.split('#'); var tempID2 = tempID.length; var shortpageID = tempID[tempID2-1];//Gets the part of the page after the # var pageIndex = c.findPageIndex(shortpageID); var nextPageID = c.pageArray[pageindex].nextPage; c.loadCurrentPage(nextPageID); } /*Called when the right arrow is clicked*/ Content.prototype.rightArrowFunction = function(){ var btnClicked = false; //Check if the next button exists var nextBtn = $("#"+ elements.nextButton); if(nextBtn.length){ //check if the button is visible (active) var display = $('#nextBtn_div').is(":visible"); if(display){ //Simulate a click on the next button $("#"+ elements.nextButton).trigger('click'); btnClicked = true; } } if(!btnClicked){ //Check if there is a start button var startBtn = $('#startBtn'); if(startBtn.length){ //Simulate a click on the start button $('#startBtn').trigger('click'); } } } /*Called when the left arrow is clicked*/ Content.prototype.leftArrowFunction = function(){ //Check if the back button exists var backBtn = $("#"+ elements.backButton); if(backBtn.length){ var display = $('#backBtn_div').is(":visible"); if(display){ //Simulate a click on the back button $("#"+ elements.backButton).trigger('click'); } } } function removeAudio(){ try{ jwplayer().remove(); }catch(e){ if(window.console){ //console.log("Couldn't remove jwplayer"); } } $(".audioPlayer").remove(); } Content.prototype.loadCurrentPage = function(curPageID){ var c = this; //Hide any existing dialogs. $(".ui-dialog-content").dialog("close"); //Hide any quiz feedback $(".questionFeedbackBox").remove(); //Remove audio removeAudio(); //Hide the menu if it is out. if(c.menuState !== 0){ $("#at_menu_container").hide(); c.toggleMenu(); c.menuState = 0; } var pageindex = 0; if(curPageID !== DEFAULT_PAGE){ //Locate array index for current page pageindex = c.findPageIndex(curPageID); } var currPageItem = c.pageArray[pageindex]; c.currentPageItem = currPageItem; //Set next and prev buttons, do this BEFORE applyTemplate in case we need to later hide something //This prevents it from reappearing. c.setNextButton(currPageItem.nextPage); c.setBackButton(currPageItem.prevPage); c.setNavigationButtons(); c.template_setBodyContent(currPageItem.pagecontent); c.template_applyTemplate(currPageItem); //Check for any iframe div's and replace them with actual iframs. //
Laddar modulprov, vänligen vänta
// var iframeList = $( ".inlineframe" ); if( $(iframeList).length){ c.createIframes(iframeList); } //Delays c.scanForDelay(currPageItem.pagecontent); //Set page id in the address bar (fixes reload as well) c.setAddressBar(curPageID); //Set pageNumber var totalPages = c.pageArray.length-1; c.setPagination( currPageItem.pageNumber, c.totalPageNr ); var dataObjLoaded = false; //Scanna dokument för att hitta var dataObjectTags = $("."+elements.dataObjectTag+ ",.eObject[type='audio'],.eObject[type='video']"); if($(dataObjectTags).length){ var curPage = c.currentPageItem.pageid; //Skicka in sökväg till objectdatatype //om den inte ingår i en section-4setTimeout(function(e){ setTimeout(function(){ c.startDataObject(curPage, dataObjectTags); },100); }; c.setSound(); //Scanna dokument för att hitta quiz if($("."+elements.challenge).length > 0){ //Anropa funktion för att skapa quizzar c.quiz_createChallenge(); }; }; Content.prototype.createIframes = function(listOfIframes){ $(listOfIframes).each(function(){ var iframeClass = $(this).attr("class"); var iframeFrame = $(this).attr("frameborder"); var iframeBorder = $(this).attr("border"); var iframeSrc = $(this).attr("src"); var iframeWidth = $(this).attr("width"); var iframeHeight = $(this).attr("height"); var iframeText = $(this).text(); $( this ).replaceWith( '' ); }); } Content.prototype.startDataObject = function(pageId1, dataObjectTags){ var c = this; if(pageId1 == c.currentPageItem.pageid){ c.resolveDataObject(dataObjectTags, c.currentPageItem.template); c.setupAudio(); } } Content.prototype.setAddressBar = function(pageID){ window.location.hash = "page=sect1.html,pageid="+pageID; } Content.prototype.findPageIndex = function(pageID){ var c = this; var numPages = c.pageArray.length-1; for(var i = 0; i < c.pageArray.length;i++){ if(pageID == c.pageArray[i].pageid) return i; } //Nothing found return false; }; Content.prototype.scanForDelay = function(context){ var c = this; //Scanna dokument för att hitta delay if($(context).find($("."+elements.delay)).length > 0 || $(context).find("."+elements.delay).length > 0){ c.pageDelays = []; //Sätter upp delay för respektive delay-element i DOM c.makeDelay(); }; } /** function loadResources Laddar in script och css */ function loadCss(url, callback) { var css = document.createElement("link") css.type = "text/css"; css.rel = 'stylesheet'; css.media = 'screen';   if (css.readyState) { //IE css.onreadystatechange = function () { if (css.readyState == "loaded" || css.readyState == "complete") { css.onreadystatechange = null; callback(); }; }; } else { //Others css.onload = function () { callback(); }; }; css.href = url; document.getElementsByTagName("head")[0].appendChild(css); }; function loadScript(url, callback) { var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState) { //IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); }; }; } else { //Others script.onload = function () { callback(); }; };   script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; /** function getPageID Extraherar id från adressfältet In Out = pid (string) */ Content.prototype.getPageID = function(){ var c = this; // Extract filename from url var pid = ""; var strLocation = String(document.location); //Find last occurance of / var pageIndex = strLocation.lastIndexOf("pageid="); var pageID = ""; if(pageIndex != -1){ pageID = strLocation.substring(pageIndex+7,strLocation.length); } else { //If we don't find anything, just go to the default page. It's generally a good bet. pageID = c.pageArray[0].pageid; } return pageID; }; /** Initierar content-objekt och laddar in nödvändiga script */ var content = new Content(); $(document).ready(function(e) { //Init everything content.init(); });