diff -r 0055b4bee4e3 -r 8c3f0b94d056 web/static/res/js/incchoice.js --- a/web/static/res/js/incchoice.js Tue Jan 15 17:17:14 2013 +0100 +++ b/web/static/res/js/incchoice.js Wed Jan 16 08:26:00 2013 +0100 @@ -7,6 +7,16 @@ this.image1; this.image2; this.image3; + this.prefixCookieChosenWords = "niv1_ChosenWords"; + this.prefixCookieChosenVideos = "niv1_ChosenVideos"; + this.prefixCookiePlayedVideos = "niv1_PlayedVideos"; + this.prefixCookieSingleVideo = "niv1_SingleVideo"; + this.prefixCookieHD = "niv1_HD"; + this.prefixCookieSeekTime = "niv1_SeekTime"; + + //---------------------------------------------------------------------------------------------------------------------------- + // Words display + //---------------------------------------------------------------------------------------------------------------------------- this.setMosaicImages = function(images1, images2, images3) { @@ -30,59 +40,32 @@ $("#mot3").html("travail"); $("#mot4").html("international"); $("#mot5").html("dieu"); - $("#mot6").html("president"); + $("#mot6").html("président"); // class - // by default there is the calss blue + // by default there is the class blue } else if (choiceIndex == 1) { $("#mot1").html("actif"); $("#mot2").html("passif"); $("#mot3").html("corps"); - $("#mot4").html("charite"); + $("#mot4").html("charité"); $("#mot5").html("patrie"); $("#mot6").html("politique"); // class - $("#choix").removeClass("blue").addClass("white"); + $("#choice").removeClass("blue").addClass("whiteN"); } else { $("#mot1").html("spleen"); - $("#mot2").html("ideal"); + $("#mot2").html("idéal"); $("#mot3").html("origines"); $("#mot4").html("peur"); - $("#mot5").html("desir"); + $("#mot5").html("désir"); $("#mot6").html("bonheur"); // class - $("#choix").removeClass("white").addClass("red"); - } - }; - - this.selectWord = function(wordIndex) - { - if (!this.canSelectWord) { - // Don't set the word 2 times - return; - } - - this.canSelectWord = false; - - // Save the word - this.setCookie("niv1_world" + this.currentWorldIndex, $("#mot" + wordIndex).html()); - - ++this.currentWorldIndex; - - if (this.currentWorldIndex == 3) { - // The 3 words get choosen - location.href = "niv1_videoplayer.html"; - } else { - - // Start the mosaic effect - incMosaic.UnpauseEffect(true); - - // Fade the text - $('.big_txt').animate({opacity: 0}, 20000 * 1 / effectSpeed); + $("#choice").removeClass("whiteN").addClass("red"); } }; @@ -100,20 +83,206 @@ $('.big_txt').animate({opacity: 1}, 10000 * 1 / effectSpeed); }; + //---------------------------------------------------------------------------------------------------------------------------- + // Selected Words + //---------------------------------------------------------------------------------------------------------------------------- + + this.selectWord = function(wordIndex) + { + if (!this.canSelectWord) { + // Don't set the word 2 times + return; + } + + this.canSelectWord = false; + + // Save the word + var allWorldIndex = this.currentWorldIndex * 6 + wordIndex; + this.setCookie(this.prefixCookieChosenWords + this.currentWorldIndex, allWorldIndex); + + ++this.currentWorldIndex; + + if (this.currentWorldIndex == 3) { + // The 3 words get choosen + location.href = "niv1_videoplayer.html"; + } else { + + // Start the mosaic effect + incMosaic.UnpauseEffect(true); + + // Fade the text + $('.big_txt').animate({opacity: 0}, 20000 * 1 / effectSpeed); + } + }; + this.getChoosenWords = function() { - return [this.getCookie("niv1_world0"), this.getCookie("niv1_world1"), this.getCookie("niv1_world2")]; + var words = []; + for (var i = 0; i < 3; ++i) { + words.push(this.getCookie(this.prefixCookieChosenWords + i)); + } + return words; + }; + + //---------------------------------------------------------------------------------------------------------------------------- + // Random Chosen Videos + //---------------------------------------------------------------------------------------------------------------------------- + + this.saveChosenVideos = function(indexs) + { + for (var i = 0; i < indexs.length; ++i) { + this.setCookie(this.prefixCookieChosenVideos + i, indexs[i]); + } + }; + + this.getChosenVideos = function() + { + var indexs = []; + for (var i = 0; i < 3; ++i) { + var n = this.getCookie(this.prefixCookieChosenVideos + i); + if (n !== null) { + n = parseInt(n); + if (n != -1) { + indexs.push(n); + } + } + } + return indexs; + }; + + //---------------------------------------------------------------------------------------------------------------------------- + // All time played videos + //---------------------------------------------------------------------------------------------------------------------------- + + this.getChoosenVideosFlags = function() + { + var var32bits = []; + + // Get previous used videos + for (var i = 0; i < 3; ++i) { + var v32 = this.getCookie(this.prefixCookiePlayedVideos + i); + v32 = v32 === null ? 0 : parseInt(v32); + var32bits.push(v32); + } + + return var32bits; }; + this.savePlayedVideos = function(indexs, markPlayed) + { + // This function used 3 values of 32 bits to records used videos + // This means we can record the state of 32 * 3 = 96 videos + + // Get previous used videos + var var32bits = this.getChoosenVideosFlags(); + + // Update 32 bits flags var + var i; + for (i = 0; i < indexs.length; ++i) { + var index = indexs[i]; + for (var j = 0; j < var32bits.length; ++j) { + var indexMax = (j+1)*32; + if (index < indexMax) { + var flag = 1 << (index - indexMax + 32); + if (markPlayed) { + var32bits[j] = var32bits[j] | flag; + } else { + var32bits[j] = var32bits[j] & ~flag; + } + break; + } + } + } + + // Save updated flags + for (i = 0; i < 3; ++i) { + this.setCookie(this.prefixCookiePlayedVideos + i, var32bits[i]); + } + }; + + this.IsThisVideoWasPlayed = function(var32bits, index) + { + for (var j = 0; j < var32bits.length; ++j) { + var indexMax = (j+1)*32; + if (index < indexMax) { + return var32bits[j] & (1 << (index - indexMax + 32)); + } + } + return false; + } + + this.clearAllVideosChoices = function() + { + for (i = 0; i < 3; ++i) { + this.removeCookie(this.prefixCookiePlayedVideos + i); + } + }; + + //---------------------------------------------------------------------------------------------------------------------------- + // Single video + //---------------------------------------------------------------------------------------------------------------------------- + + this.saveSingleVideo = function(name) + { + this.setCookie(this.prefixCookieSingleVideo, name); + }; + + this.getSingleVideo = function() + { + return this.getCookie(this.prefixCookieSingleVideo); + }; + + //---------------------------------------------------------------------------------------------------------------------------- + // Hd + //---------------------------------------------------------------------------------------------------------------------------- + + this.setHD = function(state) + { + this.setCookie(this.prefixCookieHD, state); + }; + + this.getHD = function() + { + var hd = this.getCookie(this.prefixCookieHD); + if (hd == "0") { + return false; + } + return true; + }; + + this.setSeekTime = function(time) + { + this.setCookie(this.prefixCookieSeekTime, time); + }; + + this.getSeekTime = function() + { + var time = this.getCookie(this.prefixCookieSeekTime); + if (time === null) { + return 0; + } + return time; + }; + + //---------------------------------------------------------------------------------------------------------------------------- + // Cookies tools + //---------------------------------------------------------------------------------------------------------------------------- + this.setCookie = function(name, value) { - $.removeCookie(name); + this.removeCookie(name); $.cookie(name, value, { expires: 7, path: '/' }); }; - this.getCookie = function(name) { + this.getCookie = function(name) + { return $.cookie(name); }; + + this.removeCookie = function(name) + { + $.removeCookie(name, { path: '/' }); + }; } var incChoice = new IncChoice(); \ No newline at end of file