/*********************************************************************** elearning_functions.js ************************************************************************ Do not change this file unless it should change for all users. This file defines general functions that have nothing to do with layout. ************************************************************************/ //Används för att visa kapitelindikering Content.prototype.nextTriggered = false; /* Drag and drop-functions */ Content.prototype.helper_makeDraggable = function(){ var c = this; $(".lcDraggable").each(function(i,v){ //$(v).css("left",$(v).attr("x")+"px").css("top",parseInt(topOffset[0])+parseInt($(v).attr("y"))+"px"); $(v).attr("id",$(v).attr("e-id")); if($(v).find("img").length > 0){ $(v).find("img").parent().addClass("DragImg"); } $(v).draggable({ snap:false, containment: $("#at_main"), scroll: 'true', zIndex: 500, opacity: 0.7, handle:".DragDropText, .DragImg" }); }); var t = setTimeout(function(){ $(".lcDraggable").each(function(i,v){ if($(v).find(".lcDragDropText").length > 0){ $(".DragDropText").css("height",$(".DragDropText").parent().height()-5+"px"); } }) },200); } /*Completely rewritten for Tobii to fix problems with dragging in and out and changing responses resulting in incorrect responses and errors messages when attributes didn't exist*/ Content.prototype.helper_makeDroppable = function(){ var c = this; $(".lcDroppable").each(function(i,v){ $(v).droppable({ accept:$(".lcDraggable"), tolerance:"intersect", hoverClass: "drop-hover", drop:function(event,ui){ var responseList = $(event.target).attr("correct_response"); if(responseList.length == 0){ //We have no correct responses here, set responses to nothing to avoid length problems responses = ""; } else { responses = $(event.target).attr("correct_response").split(","); } thisresponse = $(ui.draggable).attr("id"); //Check if the attribute even exists var dropAttr = $(event.target).attr("dropped"); if (typeof dropAttr == typeof undefined || dropAttr == false) { //Attribute doesn't exist $(event.target).attr("dropped",thisresponse); }else if(dropAttr[0] == ","){ //First character is a , this means it should just be replaced entirely $(event.target).attr("dropped",thisresponse); }else{ //Just add our response to the list $(event.target).attr("dropped",$(event.target).attr("dropped")+","+thisresponse); } if(responses.length > 1){ //Multiple responses droppedResponses = $(event.target).attr("dropped").split(","); //If length of correct responses and dropped responses match, check if correct ones been dropped correct = 0; if(responses.length == droppedResponses.length){ for(var i=0;i 0){ $(v).find("img").on("load", function(){ }).each(function() { if(this.complete) $(this).load(); }); } }) },200); } /********************************************* Function: resolveDataObject Indata: dataObjectTags (array with dataobjects) Decides what types of dataobjects exist and then handles them *********************************************/ var tempID = 0; Content.prototype.resolveDataObject = function(dataObjectTags, template){ tempID ++; var dataObjects; var dataType; var c = this; $(dataObjectTags).each(function(i,v){ /***FLIPBOOK START***/ //Check if there is a type=flipbook var objectType = $(this).attr("type"); if(objectType == "flipbook"){ c.Flipbook(); } /***FLIPBOOK END***/ else if(objectType == "audio"){ //Audio is specified in arbortext //Don't do anything right now, we're going to handle audio separately //c.resolveAudio(this); } else if(objectType == "video"){ /*Used with the new video tag from arbortext, still comes out as an img though*/ var imgObjects = $(this).find("img.videofile"); if(imgObjects.length){ var videoObjects=new Array(); for(var vInd = 0; vInd < imgObjects.length;vInd++) { videoObjects[vInd] = $(imgObjects[vInd]).attr("src"); } if(videoObjects.length){ var videohtml = createVideo(videoObjects, template); var videoObjID = $(this).attr("id"); var divName2 = $("div[id='"+videoObjID+"']"); $(divName2).html(videohtml).addClass("vPlayer"); //Now pause the video! var jwPlayerObject = jwplayer(videoObjID); jwPlayerObject.pause(); }else{ if(consoleSupported){ console.log("ERROR: No video files found!"); } } } else { //Look for video links and make them into iframes var videoSource = $(this).find(".videolink").attr("href"); var currTemplate = c.pageTemplate; var videoHTML = ""; //Check if this is a youtube clip var isYouTube = (videoSource.toLowerCase().indexOf('youtube') >= 0); var isVimeo = (videoSource.toLowerCase().indexOf('vimeo') >= 0); if(isYouTube){ //Add some stuff to the link to allow it to work with youtube's api videoSource = videoSource + "?enablejsapi=1&wmode=transparent&"; //Go create an iframe videoHTML = c.createExternalLink(videoSource); } else if(isVimeo){ //Add some stuff to the link to allow it to work with vimeo's api videoSource = videoSource + "?api=1&"; //Go create an iframe videoHTML = c.createExternalLink(videoSource); } var videoObjID = $(this).attr("id"); var divName2 = $("div[id='"+videoObjID+"']"); $(divName2).html(videoHTML).addClass("vPlayer"); } } else { dataObjects = $(this).find("img"); if(dataObjects.length > 0){ dataType = checkObjectDataType($(dataObjects[0]).attr("src")); } if(!dataType){ //OM datatype är falsk, radera elementet ur DOM $(this).remove(); } if(dataType == "cdata"){ //Om den inte ingår i en section-4... loadCDATA($(dataObjects[0]).attr("src"),$(this).attr("id")); } else if(dataType == "audio"){ //No audio type was set, we figure out ourselves that it is audio //Don't do anything right now, we're going to handle audio separately //c.resolveAudio(this); } else if(dataType == "video"){ var videoObjects=new Array(); for(var vInd = 0; vInd < dataObjects.length;vInd++) { videoObjects[vInd] = $(dataObjects[vInd]).attr("src"); } var videohtml = createVideo(videoObjects, template); var videoObjID = $(this).attr("id"); var divName2 = $("div[id='"+videoObjID+"']"); $(divName2).html(videohtml).addClass("vPlayer"); } } }); //Om flera video-element finns på sidan c.helper_videoCarousel(); //Show all the vPlayers (they start as hidden to avoid flashing) $('.video_object').css('visibility','visible'); }; var videoPlayerId = 0; /********************************************* Function: createExternalLink Indata: link Outdata: html string Creates a video link with the proper sizes *********************************************/ Content.prototype.createExternalLink = function(linkString){ var c = this; var currTemplate = c.currentPageItem.template; var playerId = "iframe_video_"+videoPlayerId; var videoHTML = '