Supervisor |
"> |
| Miko | |
|
[JS] Sistema de calificación - 3/7/2019, 9:45 am
Descripción:Con este JS vas a añadir la valoración en estrellas. Códigos:JS The placement: Temas - Código:
/* * Application: Rating System * Date: 19/04/2018 * Version: 1.019042018 * Copyright (c) 2018 Daemon <help.forumotion.com> * This work is free. You can redistribute it and/or modify it */ function ratingSystem() { var images = { goldstar: "https://i62.servimg.com/u/f62/18/12/37/46/goldst10.png", graystar: "https://i62.servimg.com/u/f62/18/12/37/46/grayst10.png", like: "https://i62.servimg.com/u/f62/18/12/37/46/like-011.png", unlike: "https://i62.servimg.com/u/f62/18/12/37/46/dislik11.png" }; /* In the array contains 6 different values, which by default will add 6 stars depending on the percentage of votes in relation to the value in the array */ var ratingConfig = [16.6, 32.2, 49.8, 66.4, 83, 100]; var vote = document.querySelectorAll(".vote"), voteBar = null, voteButton = null, myDiv = null, numsBar = null, pct = 0, num = 0, plus = 0, minus = 0, myImg = null, myDiv2 = null; for(var i = 0; i < vote.length; ++i) { voteBar = vote[i].getElementsByClassName("vote-bar")[0], voteButton = vote[i].getElementsByClassName("vote-button")[0]; // Creating a new DIV element myDiv = document.createElement("DIV"); // Adding a class to the element myDiv.className = "rating"; // Checking the existence of the voting bar if(typeof voteBar !== "undefined") { // Picking up the title numbers numsBar = voteBar.title.match(/\d+/g), // Taking percentage pct = parseInt(numsBar[0]), // Taking number of votes num = parseInt(numsBar[1]), // Taking positive votes plus = Math.round(pct * num) / 100, // Taking negative votes minus = Math.round(num - plus); // For each array item ratingConfig.forEach(function(item, i) { myImg = document.createElement("IMG"); myImg.title = plus + " / " + minus; if (item <= pct) { // If the value in the array is less than or equal to the percentage of votes, add gold star myImg.src = images.goldstar; } else { // If the value is higher, add gray star myImg.src = images.graystar; } myDiv.appendChild(myImg); }); } else { plus = 0, minus = 0; } // Checking the existence of the voting button if(typeof voteButton !== "undefined") { myDiv2 = document.createElement("DIV"); // Adding voting buttons myDiv2.innerHTML = "<span onclick='rating("" + voteButton.firstChild.href + "",this);' class='rating-button'>" + " <img src='" + images.like + "'><span>" + plus + "</span>" + "</span>" + "<span onclick='rating("" + voteButton.nextSibling.nextSibling.firstChild.href + "",this);' class='rating-button'>" + " <img src='" + images.unlike + "'><span>" + minus + "</span>" + "</span>"; myDiv.insertBefore(myDiv2, myDiv.firstChild); } // Adding vote buttons after postbody $(".postbody", vote[i].parentNode.parentNode.parentNode.parentNode).after(myDiv); // Removing default bar vote[i].parentNode.removeChild(vote[i]); } }; function rating(b,a) { a.removeAttribute("onclick"); $.get(b, function() { var c = a.lastChild, b = parseInt(/\d+/.exec(c.innerHTML)[0])+1; c.innerHTML = c.innerHTML.replace(/\d+/,b); }); } document.onreadystatechange = function () { if(document.readyState == "complete") { ratingSystem(); } } CSS: - Código:
/*Rating System*/ .vote {display: none;} .rating { float: right; font-size: 13px; color: #000; margin: 0 5px 5px 0; } .rating span span { background-color: #888; padding: 1px 3px; border-radius: 3px; color: #fff; font-weight: bold; } .rating img {vertical-align: middle;} .rating .rating-button { cursor: pointer; opacity: 0.8; } .rating .rating-button:hover {opacity: 1;}
| Permisos de este foro: | No puedes responder a temas en este foro.
Código [IMG] está Activado Código HTML está Activado
|
|
|