Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8">
- <title>Action sur bouton de vote</title>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <!-- _________ CECI EST UNE REQUETE JAVASCRIPT POUR RECUPERER CE QUE NOUS RENVOIE NOTRE PAGE action_bouton_vote.php ______-->
- <script type="text/javascript">
- $(document).ready(function(){
- function getJSONAPI(voted,service_selected) {
- var dataService,href;
- var list_services = {};
- $('.service').each(function(){
- dataService = $(this).attr('data-service');
- href = $(this).find('a').attr('href');
- list_services[dataService] = href;
- });
- var vote,status,msg;
- (voted) ? vote = 'on' : vote = 'off';
- jQuery.ajax({
- url: 'action_bouton_vote.php',
- type: 'GET',
- dataType: 'json',
- data: {vote : ''+vote+'', list_services : list_services, service_selected : service_selected},
- beforeSend:function(){
- $('#results').html('<p class="info"><img src="http://www.domaine-lafage.com/skin/frontend/colinus/lafage/images/loading.gif" /></p>');
- },
- complete: function(xhr, textStatus) {
- //called when complete
- },
- success: function(data, textStatus, xhr) {
- status = data.status;
- msg = data.msg;
- switch (status) {
- case "error":
- $('#results').html('<p class="error">'+msg+'</p>');
- break;
- case "info":
- $('#results').html('<p class="info">'+msg+'</p>');
- break;
- case "warning":
- $('#results').html('<p class="warning">'+msg+'</p>').queue(setTimeout(getJSONAPI,5000)).dequeue();
- break;
- default:
- $('#results').html('<p class="ok">'+msg+'</p>').queue(setTimeout(getJSONAPI,5000)).dequeue();
- break;
- }
- },
- error: function(xhr, textStatus, errorThrown) {
- $('#results').html('<p class="error">Error !!!!: ' + textStatus + errorThrown +'</p>');
- console.log(textStatus + errorThrown);
- }
- });
- };
- getJSONAPI();
- $(".button_vote").click(function(e){ e.preventDefault();
- var service = $(this).parent().attr("data-service"); //identifier le service pour lequel on vote
- var href = $(this).prev().attr("href");
- var service_selected = {}
- service_selected[service] = href;
- getJSONAPI(true,service_selected);
- });
- });
- </script>
- <!-- _________ DANS CETTE PARTIE, ON DECORE NOTRE LIEN POUR CREER UN JOLIE BOUTON ______-->
- <style type="text/css">
- html,body {height:100%;background:#eee;margin:0px;padding:0px; }
- #wrap {width:900px; height:100%; margin:auto; text-align:center;background:#fff;border-left:solid 1px black;border-right:solid 1px black;}
- #service_list {
- display:inline-block; vertical-align:middle; width:400px; min-height:400px; height:auto;
- border:solid 1px gray; border-radius:5px; background:#fff;
- }
- /* on détermine une couleur pour chaque type de message que nous renvera notre page action_bouton_vote.php */
- .error,.warning,.ok,.info{
- 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;
- }
- .error {background-color:#f5d1d3;}.warning{background-color:#fcf7d9;}.ok {background-color:#e3ebc6;}.info {background-color:#f2f2f2;}
- /* on décore notre lien */
- .service {display:inline-block;width:250px; background-color:#f2f2f2; border:1px solid black;margin:10px;padding:5px;}
- .link_vote {text-decoration:none; color:#0000FF;}
- .button_vote {float:right;width:25px; height:25px; border:solid 1px black; border-radius: 12.5px; background-color:yellow;cursor:pointer;}
- </style>
- </head>
- <body>
- <div id="wrap">
- <div id="service_list">
- <h3>Système de vote avec récompense</h3>
- <div id="results"></div>
- <div class="service" data-service="mcserv">
- <a href="http://www.mcserv.org/TheCraftfr_394.html" class="link_vote" title="Votez sur McServ" target="_blanck">Votez sur McServ</a>
- <button class="button_vote" >€</button>
- </div>
- <div class="service" data-service="top-serveurs-minecraft">
- <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>
- <button class="button_vote" >€</button>
- </div>
- <div class="service" data-service="minecraftservers">
- <a href="http://minecraftservers.org/server/40480" class="link_vote" title="Votez sur minecraftservers" target="_blanck">Votez sur minecraftservers</a>
- <button class="button_vote" >€</button>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment