#= require jquery #= require jquery_ujs #= require jquery.ui.all #= require ./shared/jquery.ui.touch-punch #= require ./shared/jquery-jPuzzle test_question = (question) -> $(".info").hide() $(".quizz_img").hide() rep = question.find("input[type='radio']:checked").closest("div") rep.find(".info").show() if rep.find(".quizz_img").size() > 0 rep.find(".quizz_img").show() rep.closest(".question").find(".quizz_ill").hide() else rep.closest(".question").find(".quizz_ill").show() if question.find(".response input:checked")[0] question.find(".success").show(); question.find(".fail").hide(); rep = true else question.find(".fail").show(); question.find(".success").hide(); rep =false return rep (($) -> $.fn.nodoubletapzoom = -> $(this).bind "touchstart", preventZoom = (e) -> t2 = e.timeStamp t1 = $(this).data("lastTouch") or t2 dt = t2 - t1 fingers = e.originalEvent.touches.length $(this).data "lastTouch", t2 return if not dt or dt > 500 or fingers > 1 # not double-tap e.preventDefault() # double tap - prevent the zoom # also synthesize click events we just swallowed up $(this).trigger("click").trigger "click" return return return ) jQuery $ -> $("body").nodoubletapzoom() $("body").on "click","a.def", -> r = "

"+$(this).html()+"

"+$(this).data("def")+"

" $("body").append(r) $(".pane_hover").click -> $(this).remove(); $(document).on "click", ".receptable img", -> r = "

"+$(this).data("legend")+"

" $("body").append(r) $(".pane_hover").click -> $(this).remove(); $("body").on "click", "a.img",-> r = "
" if ($(this).data("legend")) r+= "

"+$(this).data("legend")+"

" if ($(this).data("desc")) r+= "

"+$(this).data("desc")+"

" r += "
" $("body").append(r) $(".pane_hover").on "click", -> $(this).remove(); $(".page").hide() $(".page:first").show() $("body").on "click",".prev_slide", -> $(this).closest(".page").hide() $(this).closest(".page").prev(".page").show() $("body").on "click",".next_slide", -> $(this).closest(".page").hide() $(this).closest(".page").next(".page").show() intialize_places_jeu2 = () -> $(".places_jeu2").each -> archive = $(this).html() $(this).find(".receptable").droppable tolerance: "touch" accept: (e) -> if e.hasClass("intru") == false and $(this).find("img").size() == 0 true drop: ( event, ui ) -> $( this ).append(ui.draggable) ui.draggable.attr("style", "") if $(this).closest(".places_jeu2").find(".vignettes img").size() == 2 $(this).closest(".places_jeu2").find(".success").show() $(this).find(".vignettes img").draggable #connectWith: ".receptable" tolerance: "pointer" revert: "invalid" $(this).find(".reset").click -> $(this).closest(".places_jeu2").html archive $(this).closest(".places_jeu2").find(".success").hide() intialize_places_jeu2() intialize_places_jeu = () -> $(".places_jeu").each -> archive = $(this).html() $(this).find(".receptable").droppable tolerance: "touch" accept: (e) -> if e.data("rep") == $(this).data("rep") true drop: ( event, ui ) -> $( this ).append(ui.draggable) ui.draggable.attr("style", "") if $(this).closest(".places_jeu").find(".vignettes img").size() == 0 $(this).closest(".places_jeu").find(".success").show() $(this).find(".vignettes img").draggable #connectWith: ".receptable" tolerance: "pointer" revert: "invalid" $(this).find(".reset").click -> $(this).closest(".places_jeu").html archive $(this).closest(".places_jeu").find(".success").hide() intialize_places_jeu() intialize_puzzle = () -> $(".puzzle").each -> archive = $(this).html() $(this).find(".piece_place").droppable tolerance: "touch" accept: (e) -> if e.data("rep") == $(this).data("rep") true drop: ( event, ui ) -> $( this ).append(ui.draggable) ui.draggable.attr("style", "") if $(this).closest(".puzzle").find(".pieces .piece").size() == 0 $(this).closest(".puzzle").find(".success").show() $(this).draggable( 'disable' ); $(this).find(".piece").draggable tolerance: "pointer" revert: "invalid" $(this).find(".reset").click -> $(this).closest(".puzzle").html archive $(this).closest(".puzzle").find(".success").hide() intialize_puzzle() intialize_arbre = () -> archive = $(".vie-arbre.story").closest(".sortable_quizz").html() $(".vie-arbre.story").sortable items: 'td' stop:() -> win = true i = 0 $(this).find("td").each -> i = i + 1 win = false unless i is $(this).data("order") if win is true $(".vie-arbre-place .success").show() $(".vie-arbre.story").closest(".sortable_quizz").find(".reset").click -> $(".vie-arbre.story").closest(".sortable_quizz").html archive intialize_arbre() initialize_vie_sol = () -> archive = $(".t_sortable").closest(".animaux_sol").html() $(".t_sortable").sortable items: 'tr' stop:() -> win = true i = 0 $(this).find("tr").each -> i = i + 1 win = false unless i is $(this).data("order") if win is true $(".success").show() $(".t_sortable").closest(".animaux_sol").find(".reset").click -> $(".t_sortable").closest(".animaux_sol").html archive initialize_vie_sol() initialize_jeu_1 = -> $(".sortable_quizz").each -> element = $(this) html = element.find(".sortable").html() element.find(".sortable").sortable stop: () -> win = true i = 0 element.find("img").each -> i = i + 1 win = false unless i is $(this).data("order") if win is true element.find(".win").show() element.find(".loose").hide() element.find(".sortable").disableSelection() element.find(".reset").click -> element.find(".sortable").html html element.find(".sortable").sortable "refresh" element.find(".win").hide() element.find(".loose").hide() initialize_jeu_2 = -> element = $("#insectes_jeu_2") html = element.find(".sortable").html() element.find(".receptable").sortable connectWith: ".labels,.receptable" items: ".label" tolerance: "pointer" receive: (event, ui) -> if $(this).children().length > 1 child = $(this).children().not(ui.item)[0] element.find(".labels").append child element.find(".receptable ul").disableSelection() element.find(".labels").sortable connectWith: ".receptable" tolerance: "pointer" items: ".label" receive: (event, ui) -> ui.item.attr "style", "" element.find(".labels").disableSelection() element.find(".verif").bind "click", -> win = true i = 0 element.find("img").each -> i = i + 1 win = false unless i is $(this).data("order") if win is true element.find(".win").show() element.find(".loose").hide() else element.find(".win").hide() element.find(".loose").show() element.find(".reset").click -> element.find(".sortable").html html element.find(".sortable").sortable "refresh" element.find(".win").hide() element.find(".loose").hide() $(document).ready -> initialize_plaquette = -> intialize_arbre() initialize_vie_sol() intialize_places_jeu2() intialize_places_jeu() intialize_puzzle() initialize_jeu_1() initialize_jeu_2() $(".quizz_img").hide() $(".quizz").each -> $(this).find(".prev").click -> test_question($(this).closest(".question")) $(this).closest(".question").hide() $(this).closest(".question").prev(".question").show() $(this).find(".next").on "click", -> if test_question($(this).closest(".question")) == true $(this).closest(".question").fadeOut(0) $(this).closest(".question").next(".question").fadeIn(0) $(this).find("input").change -> test_question($(this).closest(".question")) $(this).find(".fail, .success").hide() $(this).find(".question").hide() $(this).find(".question:first").show() archive_plaquette = $("body").html() initialize_plaquette() $("body").on "click",".restart_plaquette", -> $("body").html(archive_plaquette) initialize_plaquette()