// JavaScript Document // Cookie handling functions for Pace and SetPace methods function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function deleteCookie(name) { setCookie(name,"",-1); } /** Döljer element i array */ function hideElements(arrObject){ $(arrObject).each(function(i,v){ $(this).hide(); }); } function showElements(arrObject){ $(arrObject).each(function(i,v){ $(this).show(); }); } function showDialogBox(id){ //Close all existing dialog boxes before opening the new one $(".ui-dialog-content").dialog("close"); //Open the requested dialog box $(id).dialog("open"); } function exitCourse(){ //Avsluta aktiviteten i LMS'et //unloadPage(); //I nuläget, dirigera användaren tillbaka till startsidan document.location.href = "default.htm"; } /* OBJECT DATATYPE-CHECKER */ //Supported Video Types var VideoTypes = [".mp4", ".m4v", ".f4v", ".mov", ".ogv", ".webm"]; var AudioTypes = [ ".aac", ".m4a", ".f4a", ".ogg", ".oga", ".mp3" ]; //Supported text types (For cdata) var TextTypes = [".txt", ".html", ".htm", ".xml"]; //indata: object data's link //outdata: video, cdata, false (unvalid file type) function checkObjectDataType(objDataHref) { var linkString = objDataHref.toString(); var endString = ""; var dotPos = linkString.lastIndexOf("."); if(dotPos === -1){ //Not found return false; } else{ endString = linkString.substring(dotPos); } //Checks for a video tag for(var i = 0; i < VideoTypes.length;i++){ if(endString === VideoTypes[i]){ return "video"; } } //Checks for a audio tag for(var i = 0; i < AudioTypes.length;i++){ if(endString === AudioTypes[i]){ return "audio"; } } //Checks for a cdata tag for(var j = 0; j < TextTypes.length;j++){ if(endString === TextTypes[j]){ return "cdata"; } } return false; } function loadCDATA(objDataHref, divName, append){ var divName2 = $("div[id='newdiv_"+divName+"']"); $(divName2).load(objDataHref,function(){ //Check if cdata contains object/video/audio if(cdataHasObject(divName)){ //Handle stuff in extrainfo sections if($("#"+divName).hasClass("Extra_Info_object")){ $(divName2).detach().appendTo("#"+divName); return; } else if($("#"+divName).hasClass("Extra_Info_figure")){ $(divName2).detach().appendTo("#"+divName); return; } //Move object out from scrollable div if it isn't part of an extrainfo section if(append == undefined || append == false){ $(divName2).detach().appendTo("."+elements.pageDelimiter); }else{ $(".object").removeClass("object"); $(".scrollable").css("width","500px"); } }else{ $(divName2).appendTo("."+elements.pageDelimiter); $(".object").css("text-align","center").css("position","relative").css("top","20px"); $(".heading1").css("top","-=40px").css("left","-=10px"); } }); } function cdataHasObject(id){ var objects = $(".object"); if($(objects).length > 0){ //Hittade return true; } return false; } /* VIDEO FUNCTIONS */ var numVideos = 0; //keeps track of how many videos in order to create unique ids for each video //createVideo function //indata: an array with links to the videos (hopefully same video in different formats) //outdata: a string with the right encoding and tags to play video in a variety of formats var videoID = null; function createVideo(arrayWithFileNames, template){ //Creates the unique name of the video id var idString = 'videoID' + numVideos; //Holds the html markup to embed a video into a page var videoObjekt = ""; //Kolla om ljudsetting är avstängd, i såna fall, muta ljudet på videon var mute = false; if( getCookie("speakerState") == "off" ){ mute = true; } var vHeight = VIDEO_HEIGHT, vWidth = VIDEO_WIDTH; var extraObjects = $(this).hasClass("Extra_Info_object"); if(extraObjects.length){ //Maybe we should do something here? } else{ //var template = c.currentPageItem.template; } if(template.toLowerCase() == "page_wide" ||template.toLowerCase() == "page_image" || template.toLowerCase() == "page_double_text" || template.toLowerCase() == "page_centered_text" || template.toLowerCase() == "start" || template.toLowerCase() == "chapter_page"){ vHeight = HELBILD_VIDEO_HEIGHT; vWidth = HELBILD_VIDEO_WIDTH; } videoObjekt = videoObjekt + '"; numVideos++; return videoObjekt; } function y(){ var r = false; if(window.console){ r = true; } return r; } var between = function(a,b){ if(a>b){ return this>=b && this<=a; }else{ return this>=a && this<=b; } } Number.prototype.between = between; function getFlashMovieObject(movieName){ if (window.document[movieName]){ return window.document[movieName]; } if (navigator.appName.indexOf("Microsoft Internet")==-1){ if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; } else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1) return document.getElementById(movieName); } } Content.prototype.doSearch = function(strFor){ var c = this; var searchPage = c.page.split("#")[0]; var pages = []; var texts = []; var chapters = []; $.get(searchPage,function(data){ var divs = $(data).find("div:contains('"+strFor+"')"); $(divs).each(function(i,v){ if($(this).parent().hasClass('section-3') && !$(this).hasClass('section-4') && $(this).parent().attr("webtemplate") != "Quiz_External"){ //hittat texten inuti section //lägg till i array och sortera sedan ut unika sidor från arrayen pages.push($(this).parent().find(".heading1").filter(":first").attr("id")); texts.push($(this).parent().find(".heading1").filter(":first").text()); chapters.push($(this).parentsUntil(".section-1").parent().find("."+elements.chapterTitle).text()); } }); var result = $.unique(pages); var textsTrim = $.unique(texts); //var chaptersTrim = $.unique(chapters); //chapters = chapters.reverse(); //Presentera resultatet i en popup c.searchResult(result.reverse(),textsTrim.reverse(),strFor,searchPage,chapters); }); } Content.prototype.searchResult = function(resultArray,textArray,strFor,landingpage,chapters){ var c = this; var strTitle = "Sökträffar för \""+strFor+"\""; var strText = ""; $(resultArray).each(function(i,v){ if(typeof textArray[i] != "undefined"){ strText += ""+chapters[i]+" > "+textArray[i]+"
"; } }); $("#resultText").html(strTitle+"

"+strText); var hrefs = $("#resultText").find(".searchLink"); $(hrefs).each(function(ii,vv){ $(vv).click(function(e){ c.trigger(); }); }); $( "#searchResult" ).dialog( "open" ); //Sätt cookie för att lagra sökord setCookie("searchString",strFor,360); } Content.prototype.trigger = function(){ var c = this; //FIX SEARCH //c.toc.PageSelect(); } //Postmessage var XD = function(){ var interval_id, last_hash, cache_bust = 1, attached_callback, window = this; return { postMessage : function(message, target_url, target) { if (!target_url) { return; } target = target || parent; // default to parent if (window['postMessage']) { // the browser supports window.postMessage, so call it with a targetOrigin // set appropriately, based on the target_url parameter. target['postMessage'](message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1')); } else if (target_url) { // the browser does not support window.postMessage, so use the window.location.hash fragment hack target.location = target_url.replace(/#.*$/, '') + '#' + (+new Date) + (cache_bust++) + '&' + message; } }, receiveMessage : function(callback, source_origin) { // browser supports window.postMessage if (window['postMessage']) { // bind the callback to the actual event associated with window.postMessage if (callback) { attached_callback = function(e) { if ((typeof source_origin === 'string' && e.origin !== source_origin) || (Object.prototype.toString.call(source_origin) === "[object Function]" && source_origin(e.origin) === !1)) { return !1; } callback(e); }; } if (window['addEventListener']) { window[callback ? 'addEventListener' : 'removeEventListener']('message', attached_callback, !1); } else { window[callback ? 'attachEvent' : 'detachEvent']('onmessage', attached_callback); } } else { // a polling loop is started & callback is called whenever the location.hash changes interval_id && clearInterval(interval_id); interval_id = null; if (callback) { interval_id = setInterval(function() { var hash = document.location.hash, re = /^#?\d+&/; if (hash !== last_hash && re.test(hash)) { last_hash = hash; callback({data: hash.replace(re, '')}); } }, 100); } } } }; }(); //Function to extract values from querystring-parameters function getParameterByName(name, url) { if (!url) { try{ url = window.parent.frames("scorm_object").src; }catch(e){ url = window.parent.frames["scorm_object"].src; } } name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; var val = decodeURIComponent(results[2].replace(/\+/g, " ")); return val; } //Nice functions stolen from stackoverflow that replaces all occurances of 'replace' in the string 'search' String.prototype.replaceAll = function(search, replace){ //if replace is not sent, return original string otherwise it will //replace search string with 'undefined'. if (replace === undefined) { return this.toString(); } return this.replace(new RegExp('[' + search + ']', 'g'), replace); }; function getInternetExplorerVersion() { var rv = -1; if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } else if (navigator.appName == 'Netscape') { var ua = navigator.userAgent; var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } XD.receiveMessage(function(message){ content.receiveMessage(message); }, 'http://autotech.fmgateway.com'); // adds .naturalWidth() and .naturalHeight() methods to jQuery // for retreaving a normalized naturalWidth and naturalHeight. /* (function($){ var props = ['Width', 'Height'], prop; while (prop = props.pop()) { (function (natural, prop) { $.fn[natural] = (natural in new Image()) ? function () { return this[0][natural]; } : function () { var node = this[0], img, value; if (node.tagName.toLowerCase() === 'img') { img = new Image(); img.src = node.src, value = img[prop]; } return value; }; }('natural' + prop, prop.toLowerCase())); } }(jQuery));*/ // Example usage: /*var nWidth = $('img#example').naturalWidth(), nHeight = $('img#example').naturalHeight();*/