Advertisement
orksnork

Untitled

Jul 15th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.21 KB | None | 0 0
  1. var question = questions[Math.floor(Math.random()*questions.length)];
  2. var current = question.number;
  3. var collapsed = 0;
  4. var variable = ""
  5. $(document).ready(function() {
  6.        
  7.     function getQueryVariable(variable)
  8.     {
  9.        var query = window.location.search.substring(1);
  10.        var vars = query.split("&");
  11.        for (var i=0;i<vars.length;i++) {
  12.                var pair = vars[i].split("=");
  13.                if(pair[0] == variable){return pair[1];}
  14.        }
  15.        return(false);
  16.        }
  17.    
  18.     function writeQueryVariable(){
  19.         variable = getQueryVariable("question");
  20.        
  21.     }
  22.    
  23.     writeQueryVariable();
  24.    
  25.     function writeCount(){
  26.         $.get( "count.txt", function(data) {
  27.             $("#count").html( data );
  28.             });
  29.     }
  30.    
  31.     writeCount();
  32.    
  33.     function writeQuestion(){
  34.         while (question.number == current) {
  35.             question = questions[Math.floor(Math.random()*questions.length)];
  36.            
  37.         }
  38.         current = question.number;
  39.         $('.questionimagearea').attr("src", question.questionimage);
  40.         $('#question-title').html(question.questiontitle);
  41.         $('#question-wrap').html(question.question);
  42.        
  43.     }
  44.    
  45.     function writeAnswer(){
  46.         $('.answerimagearea').attr("src", question.answerimage);
  47.         $('#answer-1-title').html(question.answer1title);
  48.         $('#answer-1-wrap').html(question.answer1);
  49.         $('#answer-2-title').html(question.answer2title);
  50.         $('#answer-2-wrap').html(question.answer2);
  51.         $('.permalink').html(question.number);
  52.     }
  53.    
  54.     $('body').on('click', '#flip-1', function(){
  55.         $('#question').fadeOut('400');
  56.         $('#answer-1').fadeIn('400', function() {
  57.             writeQuestion();
  58.         });
  59.     });
  60.     $('body').on('click', '#flip-2', function(){
  61.         $('#question').fadeOut('400');
  62.         $('#answer-2').fadeIn('400', function() {
  63.             writeQuestion();
  64.         });
  65.     });
  66.     $('body').on('click', '.flop', function(){
  67.         $('.answer').fadeOut('400');
  68.         $('#question').fadeIn('400', function(){
  69.             writeAnswer();
  70.             $.ajax({ url: 'script.php' });
  71.             writeCount();
  72.         });
  73.     });
  74.     $('body').on('click', '.btn-submit', function(){
  75.         $('.panel-content').fadeOut('400');
  76.         $('.panel-thanks').fadeIn('400');
  77.     });
  78.     $('#closelink').click(function(){
  79.         if (collapsed == 0) {
  80.             $('#close').fadeTo('slow', 1.0);
  81.             collapsed = 1;
  82.             }
  83.         else {
  84.             $('#close').fadeTo('slow', 0.0);
  85.             collapsed = 0;
  86.         }
  87.        
  88.     });
  89.    
  90.     function mainLoad(){
  91.         $('.questionimagearea').attr("src", question.questionimage);
  92.         $('.answerimagearea').attr("src", question.answerimage);
  93.         $('#question-title').html(question.questiontitle);
  94.         $('#question-wrap').html(question.question);
  95.         $('#answer-1-title').html(question.answer1title);
  96.         $('#answer-1-wrap').html(question.answer1);
  97.         $('#answer-2-title').html(question.answer2title);
  98.         $('#answer-2-wrap').html(question.answer2);
  99.        
  100.         $('.pagetitle').fadeIn('slow');
  101.         $('.questionimagearea').fadeIn('slow');
  102.         $('#question').fadeIn('slow');
  103.         $('.permalink').html(question.number);
  104.     }
  105.  
  106.        
  107.     if (variable == "") {
  108.         mainLoad();
  109.         $('#variable').html("nothing");
  110.         }
  111.     else if (variable != ""){
  112.         numberofquestions = questions.length;
  113.         if (variable <= numberofquestions) {
  114.             question = questions[variable]
  115.             mainLoad();
  116.             $('#variable').html("in bounds");
  117.             }
  118.         else {
  119.             mainLoad();
  120.             $('#variable').html("outta bounds");
  121.         }
  122.     }
  123.    
  124. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement