rdsedmundo

[simple] quest script

Apr 18th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var d = document;
  2. var config = {
  3.      num_quest:3,
  4.      max_time_to_response:300000,
  5.      cookie_name:'resps'
  6. }
  7. cookie = {
  8.     clear:function(){
  9.         document.cookie = config.cookie_name + '=';
  10.     },
  11.     set:function(x){
  12.         x = cookie.get() + x;
  13.         document.cookie = config.cookie_name + '=' + x;
  14.     },
  15.     get:function(){
  16.         try {
  17.     return (document.cookie.toString().split(config.cookie_name)[1].split('=')[1].split(';')[0]);  
  18.         }catch(e){
  19.             return '';
  20.         }
  21.     }
  22. };
  23. function show(param){
  24.         try{
  25.     $('#q_'+param).show(2200); 
  26.     param--;   
  27.     $('#q_'+(eval(param))).hide(900);
  28.     if(param >= config.num_quest) {
  29.         alert('Pronto!');
  30.         config.finish = true;
  31.                 check_result();
  32.             }
  33.         }catch(e){
  34.         alert(e);
  35.         }
  36.      }
  37. function form_send(pragma){
  38.          try{
  39.        var p = pragma;
  40.        if(p[0].checked){
  41.            resp_from_form = 'a';
  42.        } else if(p[1].checked){
  43.        resp_from_form = 'b';
  44.          } else if(p[2].checked){
  45.          resp_from_form = 'c';
  46. } else {
  47.   alert('Marque alguma questão antes de prosseguir');
  48.   return false;
  49. };
  50.     cookie.set(resp_from_form);
  51.        atual = p.name.toString().split('_')[1];
  52.        atual++;
  53.        show(atual);
  54.          return (!1);
  55.          }catch(e){
  56.              alert(e);
  57.              return false;
  58.          }
  59.      }
  60. function check_result(){
  61.  var gabarito = ['b','b','a'];
  62.  var resp_c = (cookie.get()).split('');
  63.  var alert_req = '';
  64.  if(!resp_c){ return (alert('Erro'));};
  65.   for(i=0;i<gabarito.length;i++){
  66.       q = i + 1;
  67.     if(gabarito[i]==resp_c[i]) {
  68.         alert_req += 'Você acertou a questão '+q+'\n';  
  69.   } else {
  70.       alert_req += 'Você errou a questão '+q+'\n';
  71.   }
  72.   }
  73.   alert(alert_req);
  74.  // cookie.clear();
  75. }
  76. function start_time(){
  77. config.prototype.counter_var = setTimeout(function(){
  78.     if(!config.finish){
  79.     alert('Você atingiu o máximo de tempo para responder as '+config.num_quest+' questão(es)');
  80.     $('input').attr('disabled','disabled');
  81.     cookie.clear();
  82.     setTimeout(function(){
  83.         location.reload();
  84.         },3000);
  85.     }
  86.     },config.max_time_to_response);
  87. }
  88.  $(function(){
  89.      /*
  90.      $.getScript('http://pastebin.com/raw.php?i=FB3YNQ5a',function(){
  91.          Overlay.show('Carregando...');
  92.          */
  93.          var cssObj = {
  94.             'height' : '400px',
  95.             'width' : '700px'
  96.          };
  97.          $('#q').css(cssObj).tabs().show(3000,function(){
  98.              d.title = 'Questionário';
  99.         //   Overlay.hide();
  100.          }
  101.              );
  102.              $('button').button().first().click(function(p){
  103.               show('1');
  104.               start_time();
  105.              });
  106.              $('input:submit').button();
  107.             /*
  108.      });
  109.      */
  110.  });
Advertisement
Add Comment
Please, Sign In to add comment