ProfesseurCraft

Système de vote Minecraft - HTML

Aug 4th, 2013
2,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.67 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="fr">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Action sur bouton de vote</title>
  6.     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  7.  
  8.     <!-- _________ CECI EST UNE REQUETE JAVASCRIPT POUR RECUPERER CE QUE NOUS RENVOIE NOTRE PAGE action_bouton_vote.php ______-->
  9.  
  10.     <script type="text/javascript">
  11.  
  12.     $(document).ready(function(){
  13.  
  14.         function getJSONAPI(voted,service_selected) {
  15.  
  16.             var dataService,href;
  17.             var list_services = {};
  18.  
  19.             $('.service').each(function(){
  20.                 dataService = $(this).attr('data-service');
  21.                 href = $(this).find('a').attr('href');
  22.  
  23.             list_services[dataService] = href;
  24.  
  25.             });
  26.  
  27.             var vote,status,msg;
  28.  
  29.             (voted) ? vote = 'on' : vote = 'off';
  30.  
  31.             jQuery.ajax({
  32.               url: 'action_bouton_vote.php',
  33.               type: 'GET',
  34.               dataType: 'json',
  35.               data: {vote : ''+vote+'', list_services : list_services, service_selected : service_selected},
  36.               beforeSend:function(){
  37.               $('#results').html('<p class="info"><img src="http://www.domaine-lafage.com/skin/frontend/colinus/lafage/images/loading.gif" /></p>');
  38.               },
  39.               complete: function(xhr, textStatus) {
  40.                 //called when complete
  41.               },
  42.               success: function(data, textStatus, xhr) {
  43.  
  44.                 status = data.status;
  45.                 msg = data.msg;
  46.  
  47.                     switch (status) {
  48.                         case "error":
  49.                             $('#results').html('<p class="error">'+msg+'</p>');
  50.                         break;
  51.                         case "info":
  52.                             $('#results').html('<p class="info">'+msg+'</p>');
  53.                         break;
  54.                         case "warning":
  55.                             $('#results').html('<p class="warning">'+msg+'</p>').queue(setTimeout(getJSONAPI,5000)).dequeue();
  56.                         break;
  57.  
  58.                         default:
  59.                             $('#results').html('<p class="ok">'+msg+'</p>').queue(setTimeout(getJSONAPI,5000)).dequeue();
  60.                         break;
  61.                     }
  62.  
  63.               },
  64.               error: function(xhr, textStatus, errorThrown) {
  65.                 $('#results').html('<p class="error">Error !!!!: ' + textStatus + errorThrown +'</p>');
  66.                 console.log(textStatus + errorThrown);
  67.               }
  68.             });
  69.         };
  70.         getJSONAPI();
  71.  
  72.         $(".button_vote").click(function(e){ e.preventDefault();
  73.  
  74.             var service = $(this).parent().attr("data-service"); //identifier le service pour lequel on vote
  75.             var href = $(this).prev().attr("href");
  76.             var service_selected = {}
  77.             service_selected[service] = href;
  78.  
  79.             getJSONAPI(true,service_selected);
  80.  
  81.         });
  82.     });
  83.  
  84.     </script>
  85.  
  86.     <!-- _________ DANS CETTE PARTIE, ON DECORE NOTRE LIEN POUR CREER UN JOLIE BOUTON ______-->
  87.  
  88.     <style type="text/css">
  89.     html,body {height:100%;background:#eee;margin:0px;padding:0px; }
  90.         #wrap {width:900px; height:100%; margin:auto; text-align:center;background:#fff;border-left:solid 1px black;border-right:solid 1px black;}
  91.             #service_list {
  92.                 display:inline-block; vertical-align:middle; width:400px; min-height:400px; height:auto;
  93.                 border:solid 1px gray; border-radius:5px; background:#fff;
  94.             }
  95.  
  96.             /* on détermine une couleur pour chaque type de message que nous renvera notre page action_bouton_vote.php */
  97.             .error,.warning,.ok,.info{
  98.             font-size:15px; padding:8px; width:400px; height: auto; text-align:center; font-weight:bold; border-top: solid 1px black; border-bottom: solid 1px black;box-sizing: border-box;
  99.             }        
  100.             .error {background-color:#f5d1d3;}.warning{background-color:#fcf7d9;}.ok {background-color:#e3ebc6;}.info {background-color:#f2f2f2;}
  101.  
  102.             /* on décore notre lien */
  103.             .service {display:inline-block;width:250px; background-color:#f2f2f2; border:1px solid black;margin:10px;padding:5px;}
  104.                 .link_vote {text-decoration:none; color:#0000FF;}
  105.                 .button_vote {float:right;width:25px; height:25px; border:solid 1px black; border-radius: 12.5px; background-color:yellow;cursor:pointer;}
  106.  
  107.     </style>
  108. </head>
  109.  
  110. <body>
  111.     <div id="wrap">
  112.         <div id="service_list">
  113.             <h3>Système de vote avec récompense</h3> 
  114.  
  115.             <div id="results"></div>
  116.  
  117.             <div class="service" data-service="mcserv">
  118.                 <a href="http://www.mcserv.org/TheCraftfr_394.html" class="link_vote" title="Votez sur McServ" target="_blanck">Votez sur McServ</a>
  119.                 <button class="button_vote" >€</button>
  120.             </div>
  121.  
  122.             <div class="service" data-service="top-serveurs-minecraft">
  123.                 <a href="http://top-serveurs-minecraft.fr/fiche_serveur.php?id=161#a" class="link_vote" title="Votez sur McServ" target="_blanck">Votez sur top-serveurs-minecraft</a>
  124.                 <button class="button_vote" >€</button>
  125.             </div>
  126.  
  127.             <div class="service" data-service="minecraftservers">
  128.                 <a href="http://minecraftservers.org/server/40480" class="link_vote" title="Votez sur minecraftservers" target="_blanck">Votez sur minecraftservers</a>
  129.                 <button class="button_vote" >€</button>
  130.             </div>
  131.  
  132.         </div>
  133.  
  134.     </div>
  135. </body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment