//+---------------------------------------------------------------------+ //| name : Download Alert | //| author : runzheimer | //| description: Displays an alert box before download starts | //| depends on : fancybox.js | //| important : relies on presence of "#downloadArea" in HTML template | //+---------------------------------------------------------------------+ downloadHintCounter = 0; jQuery.fn.downloadAlert = function(){ var o = $(this[0]); if(!$("#downloadArea").length>=1){ var downloadBox = '
'+ '
'+ 'Template lacks download hint.'+ '
'+ '
'; }else{ var downloadBox = ''; } var tmp = ""; function setBackState(){ $("#downloadCheckbox").prop('checked', false); $("#downloadArea").hide(); $("#downloadStep1").show(); $("#downloadStep2").hide(); } o.fancybox({ 'hideOnContentClick': false, 'title': null, 'maxWidth': 600, 'autoResize': true, 'autoSize': true, 'afterClose': function() { setBackState(); }, 'autoCenter': true, onComplete: function(){ setBackState(); }, onClosed: function(){ setBackState(); } }); o.click(function(event){ event.preventDefault(); $("#downloadArea a").attr("title",$(this).attr("title")); $("#downloadHiddenField").val($(this).attr("title").substring($(this).attr("title").indexOf("=")+1)); }); if(downloadHintCounter<=0){ $('*:not(* *)').append(downloadBox); setBackState(); $("#downloadCheckbox").click(function(event){ $("#downloadArea").toggle(); $.fancybox.update(); }); $("#downloadArea a").click(function(event){ event.preventDefault(); if($("#downloadCheckbox").is(':checked') && $(this).attr("title")){ $(location).attr('href',$(this).attr("title")); $.fancybox.close(); } }); $("#downloadSubmit").click(function(event){ if($("#downloadName").val() != "" && $("#downloadMail").val() != ""){ var name = $("#downloadName").val(); var mail = $("#downloadMail").val(); var jqxhr = $.get("senddownloadvalidationcode.do?name="+name+"&emailaddress="+mail, function() { $("#downloadStep1").hide(); $("#downloadActivity").show(); }) .done(function() { $("#downloadStep2").show(); $("#downloadActivity").hide(); $.fancybox.update(); }) .fail(function() { $("#downloadError").show(); $("#downloadActivity").hide(); }); }else{ alert("Please fill in both fields!"); } }); $("#downloadProceed").click(function(event){ if($("#downloadCode").val() == ""){ event.preventDefault(); alert("Please fill in the code!"); }else{ $.fancybox.close(); } }); downloadHintCounter++; } };