/*********************************************************************** template_functions.js ************************************************************************ Do not change this file unless it should change for all users. This file creates the general setup for most templates. ************************************************************************/ /********************************************* Function: template_applyTemplate Indata: template name Calls the correct function for the template Adds some generic functions afterwards *********************************************/ var current_template = ""; Content.prototype.template_applyTemplate = function(){ var c = this; template = c.currentPageItem.template; if(template != "Start"){ $("#homeBtn").show(); $("#TOCParent").show(); } switch(template){ case "Start": c.template_createFirstPage(); break; case "TOC": c.template_createTOCPage(); break; case "Page": c.template_createTwoPanelPage(); break; case "Page_Centered_Text": c.template_createPageCenteredText(); break; case "Page_Double_Text": c.template_createPageDoubleText(); break; case "Page_Image": c.template_createLargeImagePage(); break; case "Page_Wide": c.template_createWidePage(); break; case "Quiz_Text_Choice": c.template_createQuestionPage(); break; case "Quiz_Image_Choice": c.template_createQuestionImagePage(); break; case "Branch": c.template_createBranchingPage(); break; case "Quiz_External": c.template_createExternalQuiz(); break; case "Chapter_Page": c.template_chapterPage(); break; case "Quiz_Drag_Drop": c.template_createDragDropQuiz(); break; default: //No matching template, warn then create a normal page c.warn(); break; } //Add all the shared elements c.addSharedElements(); //Add in sound if needed c.helper_createListenBtn(); //Resize stuff c.helper_resizeStuff(); }; /********************************************* Function: warn Indata: templateName (string) Called when the template is not recognized. Then creates a normal two panel page. *********************************************/ Content.prototype.warn = function(){ var c = this; template = c.currentPageItem.template; if(consoleSupported){ console.log("Template Not Supported: " + template); } c.template_createTwoPanelPage(); } //Called by applytemplate to create the first page of the education Content.prototype.template_createFirstPage = function() { setCookie("nexttriggered",0); var c = this; //Dölj navigering //hideElements([$("#at_bottomNav,#homeBtn,#chapIndicators,#TOCParent")]); hideElements([$(".navBtn_div"), $(".chapIndicators"), $("#white_bar"), $("#at_topNav"), $('#logo')]); c.helper_removeEmptyDivs(); //wrap inside of page $("."+elements.pageDelimiter).wrapInner("
"); //check if the start_section exists if($(".Start_section").length){ //Remove the scroll section if it is empty (prevents extra space) var startText = $(".Start_section").children(); if(!$(startText).length){ $(".Start_section").remove(); } } else{ //We don't have a learningcontent section, so we need to do a bit of extra work. //Create scroll area that is between the title and the button $("#startpage_box").wrapInner("
"); $(".Start_Heading").detach().prependTo("#startpage_box"); //Remove the Start_scroll if it is empty (prevents extra space from existing) var startText = $("#Start_scroll").children(); if(!$(startText).length){ $("#Start_scroll").remove(); } } //Move graphic c.helper_moveGraphics(); //Create start button var nextID = c.currentPageItem.nextPage; var buttonHTML = '
' +GENTEXT_START_BTN+ '

'; $("#startpage_box").append(buttonHTML); $("#startBtn").click(function(e){ c.loadCurrentPage(nextID); }); }; Content.prototype.template_createTOCPage = function() { var c = this; c.helper_showNormalElements(); //Rewrite this without using the toc.js file. That is now obselete. }; //Creates a default two panel page with the image on the right and text to the left //Edit to change how page looks Content.prototype.template_createTwoPanelPage = function() { var c = this; c.helper_showNormalElements(); $("."+elements.pageDelimiter).wrapInner("
"); c.helper_removeEmptyDivs(); c.helper_moveGraphics(); }; Content.prototype.template_createPageCenteredText = function(){ var c = this; c.helper_showNormalElements(); //Check if this is a quiz summary page var title = $(".Page_Centered_Text_Heading").text(); if(title === "TEMPQuizSummary"){ //This is a quiz summary page, follow other instructions c.quiz_createSummaryPage(); } else{ //This isn't a quiz summary page, do the normal stuff //Create a scroll section $("."+elements.pageDelimiter).wrapInner("
"); //Move the graphics out of the scroll c.helper_moveGraphics(); c.helper_removeEmptyDivs(); } }; //Use sections as column areas Content.prototype.template_createPageDoubleText = function(){ var c = this; c.helper_showNormalElements(); //The whole page gets a scroll, not the individual columns $("."+elements.pageDelimiter).wrapInner("
"); c.helper_moveGraphics(); }; //Creates a template page for a page_wide layout. Either text or image Content.prototype.template_createWidePage = function() { var c = this; c.helper_showNormalElements(); //Create a scroll section $("."+elements.pageDelimiter).wrapInner("
"); //Move the graphics out of the scroll c.helper_moveGraphics(); c.helper_removeEmptyDivs(); $(".hotspotlink").prependTo($(".section-3")); }; //Creates a template page for a whole image pages (instead of two columns) //Edit to change the way this page looks Content.prototype.template_createLargeImagePage = function() { var c = this; c.helper_showNormalElements(); c.helper_removeEmptyDivs(); c.helper_moveGraphics(); //Fix imagemap images (prevents scrollbar) $(".hotspotlink").prependTo($(".section-3")); }; //Creates a template page for a question //Edit to change the way this page looks. Content.prototype.template_createQuestionPage = function() { var c = this; c.helper_showNormalElements(); c.helper_removeEmptyDivs(); showElements([$("#at_bottomNav")]); $("."+elements.pageDelimiter).wrapInner("
"); c.helper_moveGraphics(); c.quiz_makeSpanClickable(); }; //Creates a template page for a question with images as responses //Edit to change the way this page looks. Content.prototype.template_createDragDropQuiz = function() { var c = this; c.helper_showNormalElements(); c.helper_moveGraphics(); //Prevent draggable text from being highlighted $('.lcDraggable').bind('mousedown', function(event) { event.preventDefault() }); //Move all p elements into the editor created wrapper $(".Quiz_Drag_Drop_p").appendTo($(".dragdrop_p_wrapper")); //Create a div for all draggable/droppable elements $(".lcDraggable").appendTo($(".Quiz_Drag_Drop_overlay")); $(".lcDroppable").appendTo($(".Quiz_Drag_Drop_overlay")); //Fill with content c.helper_makeDraggable(); c.helper_makeDroppable(); }; //Creates a template page for a question with images as responses //Edit to change the way this page looks. Content.prototype.template_createQuestionImagePage = function() { var c = this; //Create the two panel page first c.template_createTwoPanelPage(); var images = $("."+elements.answerGroup).find("."+elements.answerContent); $("."+elements.answerGroup).attr("id","imageAnswerGroup"); $(".imageAnswerGroup").removeClass(elements.answerGroup); var graphicData = $("."+elements.answerGroup).find("."+elements.graphicdata); $(graphicData).wrap("
"); $("."+elements.graphicdata).addClass("imageResponse"); $("."+elements.answerOption).addClass("imageAnswerOption"); //c.quiz_makeSpanClickable(); }; //Creates branching-page //Hides all section-4 content, shows up on link-click Content.prototype.template_createBranchingPage = function(){ var c = this; c.template_createTwoPanelPage(); hideElements([$(".section-4"),$("#"+elements.nextButton)]); //Fixa länkar så att de öppnar branchingsidor var ahrefs = $("."+elements.webRefs); $(ahrefs).each(function(i,v){ var id = $(v).attr("href"); $(v).click(function(e){ c.showBranching(id); }); $(v).attr("href","javascript:void(0);").attr("branch",id); }); }; /* External quiz template */ Content.prototype.template_createExternalQuiz = function(){ c.helper_showNormalElements(); var c = this; //Hide section-4-content hideElements([$(".section-4")]); //c.helper_showNormalElements(); //$(".section ."+elements.paragraph).addClass("external"); /*$("."+elements.pageDelimiter).wrapInner("
");*/ $(".Quiz_External_lcb").prepend("




Laddar modulprov, vänligen vänta
"); c.quiz_makeSpanClickable(); //Event-lyssnare för anrop från externa prov try{ // Internet Explorer window.attachEvent('onmessage',c.receiveMessage); }catch(e){} try{ // Opera/Mozilla/Webkit window.addEventListener("message", c.receiveMessage, false); }catch(e){} }; /********************************************* Function: template_chapterPage Indata: none Creates a chapter coverpage, similar to large image page Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_chapterPage = function(){ var c = this; c.helper_showNormalElements(); c.helper_moveGraphics(); var checkText = $(".Chapter_Page_section").text(); //Check if there is any content in this section by removing all whitespace with an empty string if (!checkText.replace(/\s/g, '').length) { //String only contained whitespace (ie. spaces, tabs or line breaks) //Remove our Chapter_Page section $(".Chapter_Page_section").remove(); } }; /********************************************* Function: template_setCourseTitle Indata: courseTitle (string) Sets name for the entire education in the titlebar as well as anywhere in the course that it should be displayed. Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setCourseTitle = function(courseTitle) { //Sets the course title in the course box $("#at_courseTitle").prepend("
"+courseTitle+"
"); //sets what is seen at the top of the browser document.title = courseTitle; }; /********************************************* Function: template_setBodyContent Indata: content (html string) Sets the content into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setBodyContent = function() { var content = this.currentPageItem.pagecontent; $("#at_content").html("
"+$(content).html()+"
"); }; /********************************************* Function: template_setProductCategory Indata: prodInfo (string) Sets the prodInfo into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setProductCategory = function(prodCat){ //Not used currently }; /********************************************* Function: template_setProductName Indata: prodCat (string) Sets the prodInfo into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setProductName = function(prodCat){ //Not used currently }; /********************************************* Function: template_setSection1Title Indata: title (string) Sets the section 1 title into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setSection1Title = function(title) { //Not used currently }; /********************************************* Function: template_setSection2Title Indata: title (string) Sets the section 2 title into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setSection2Title = function(title) { //Not used currently }; /********************************************* Function: template_setSection3Title Indata: title (string) Sets the section 3 title into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setSection3Title = function(title) { //Not used currently }; /********************************************* Function: template_setPageNumber Indata: currPage (string), totalPages (string) Sets the page number into the page template Copy and paste this to the client specific file if this should be changed. *********************************************/ Content.prototype.template_setPageNumber = function(currPage,totalPages) { if(currPage == "0"){ //Do not show pages $("#pagination").hide(); return; } var pageString = currPage + "/" + totalPages; $("#pagination").html(pageString); /*var htmlString = ""; if($("#pagination").length == 0){ $("#at_bottomNav").append(htmlString); }else{ $("#pagination").html(pageString); }*/ $("#pagination").show(); } /********************************************* Function: helper_removeEmptyDivs Indata: none Removes extra empty sections. *********************************************/ Content.prototype.helper_removeEmptyDivs = function (){ this.helper_removeEmptyh2(); this.helper_removeEmptyFigureTitle(); } /********************************************* Function: helper_removeEmptyh2 Indata: none Removes extra empty h2 sections to make the layout flow a bit nicer. *********************************************/ Content.prototype.helper_removeEmptyh2 = function (){ if(!$("."+elements.subPageTitle).text().length){ $("."+elements.subPageTitle).remove(); } } /********************************************* Function: helper_removeEmptyFigureTitle Indata: none Removes extra empty figure_title sections to prevent empty divs with backgrounds sitting around. *********************************************/ Content.prototype.helper_removeEmptyFigureTitle = function (){ var figureTitles = $(".figuretitle"); $(figureTitles).each(function(i,v){ if($(this).text().length === 0){ $(this).remove(); } }); } /********************************************* Function: helper_moveGraphics Indata: none Moves graphics onto the pageDelimiter *********************************************/ Content.prototype.helper_moveGraphics = function(){ //Items that should be moved, should be given the classname lcObject in styler //extraInfo_object var c = this; var curTemplate = c.currentPageItem.template; if(curTemplate == "Page_Wide" ||curTemplate == "Page_Image" || curTemplate == "Page_Double_Text" || curTemplate == "Page_Centered_Text" || curTemplate == "Chapter_Page"){ //we have a whole page image $("
").prependTo($("."+elements.pageDelimiter)); } else if(curTemplate == "Quiz_Drag_Drop"){ //We don't need an imageholder here. } else if(curTemplate == "Start"){ //we have a whole page image $("
").prependTo($("."+elements.pageDelimiter)); $("#startpage_box").detach().prependTo("#imageHolder"); } else{ //the icons should be under the image to the right. $("
").prependTo($("."+elements.pageDelimiter)); } //$(".lcObject").not(".Extra_Info_eObject").not(".Extra_Info_object").not(".Extra_Info_figure").not(".imagemap_figure").prependTo($('#imageHolder')); $(".lcObject").not(".Extra_Info_eObject").not(".Extra_Info_object").not(".Extra_Info_figure").not(".imagemap_figure").not(".Quiz_Drag_Drop_figure").prependTo($('#imageHolder')); } /********************************************* Function: addSharedElements Indata: none Fixes shared functions *********************************************/ Content.prototype.addSharedElements = function(){ var c = this; c.addSearchBar(); c.helper_removeEmptyDivs(); c.createCarousels(); if($(".map").length){ c.createImagemap(); } c.helper_makelinks(); //Set title c.template_setSection1Title(c.currentPageItem.chaptername); c.helper_indicateChapter(); c.helper_onExitActivity(); //Show Sound if sound exists /*var soundExists = $("audio_object"); if(soundExists.length){ $("#soundBtn").css('visibility', 'visible'); } else{ $("#soundBtn").css('visibility', 'hidden'); }*/ //Show the body container now that everything is loaded. $("#at_body_container").show(); }; /********************************************* Function: helper_indicateChapter Indata: none Creates and updates the chapter indicator Creates a flash of the chosen chapter when it changes too. *********************************************/ var markedChapter = 0; Content.prototype.helper_indicateChapter = function(){ var c = this; //Don't create this for the first page if(c.currentPageItem.template == "Start"){ return; } var numchapters = c.totalChapNr; var currentChapter = c.currentPageItem.chapNr; var allChapters = new Array(); if(currentChapter == 0){ $("#chapIndicators").hide(); return; } //imgActive.src = "images/chapter_active.png"; //imgInactive.src = "images/chapter_inactive.png"; //Create the indicator if it doesn't exist if(!($("#chapIndicators").length)){ var totalChapNr = c.totalChapNr; var chapHtml = "
"; for(var i=1;i
"; } chapHtml += "
"; $("#at_topNav").append(chapHtml); } $(".chapMark").find("img").attr("src","images/chapter_inactive.png"); $("#chapMark_"+currentChapter).attr("src","images/chapter_active.png"); //Show the indicator in case it got hidden for any reason $("#chapIndicators").show(); //Animation for the top chapter indicators var t = setTimeout(function(){ if(currentChapter !== markedChapter){ $("#chapMark_"+currentChapter).animate({width:"+=4"},"fast",function(e){ //Changed to not use a defined number of pixels for the final width //$("#chapMark_"+currentChapter).animate({width:"-=4"},"fast"); $("#chapMark_"+currentChapter).animate({width:"100%"},"fast"); }); } markedChapter = currentChapter; },100); } //Adds exit-button with scorm-call to top bar Content.prototype.helper_onExitActivity = function(){ var btn = "
"; $("#at_topNav").append(btn); var courseid = window.top.courseid; if(courseid == -1){ var scormid = getParameterByName("a"); if(window.console){ console.log("Scorm id: "+scormid); } $.get("/theme/autolms/functions/ajax.php?find=id&scormid="+scormid,function(data){ courseid = data; if(window.console){ console.log("Course id: "+courseid); } }); } $("#exit_activity").click(function(e){ doQuit(); /**/ window.top.location.href = "/course/view.php?id="+courseid; }); } Content.prototype.helper_showNormalElements = function(){ showElements([$("#at_bottomNav"),$(".navBtn_div"),$("#white_bar"), $("#at_topNav")]); if(lmsConnected == false){ $("#logo").show(); }else{ $("#helpbtn_div").css("right","3%"); $("#helpbtn_div").css("right","3rem"); var t = setInterval(function(e){ if($("#chapIndicators").length > 0){ clearTimeout(t); $("#chapIndicators").css("right","5%"); $("#chapIndicators").css("right","5rem"); } },10); $("#exit_div").show(); } } //If a span exists called 'soundBtn_span' which is created by arbortext, we need a listen button added there. Content.prototype.helper_createListenBtn = function(){ var soundSpan = $('.soundBtn_span'); if($(soundSpan).length){ $('.soundBtn_span').html(''); } }