jQuery Upvote - a voting plugin
jQuery Upvote is a plugin that generates a voting widget like the one used on Stack Exchange sites, for example:
Version
@version 1.0.2
@since 2013.06.19
@author Janos Gyerik
@homepage https://janosgyerik.github.io/jquery-upvote
@twitter twitter.com/janosgyerik
Required files
- lib/jquery.upvote.js
- lib/jquery.upvote.css
- lib/images/sprites-stackoverflow.png
Options and their default values
id : undefinedcount : 0upvoted : falsedownvoted : falsestarred : false {}
If unspecified, most of these options will be set based on the passed in dom object:
id
: fromdata-id
attribute, for example in<div data-id="123">...</div>
. If there is no such attribute in the dom, the value will be left undefined.count
: fromcount
class, for example in<div><span class="count">7</span>...</div>
. If there is no such class in the dom, the value will default to 0.upvoted
: fromupvoted
class, for example in<div>...<a class="upvote upvoted"></a>...</div>
. If there is no such class in the dom, the value will default tofalse
.downvoted
: fromdownvoted
class, for example in<div>...<a class="downvote downvoted"></a>...</div>
. If there is no such class in the dom, the value will default tofalse
.starred
: fromstarred
class, for example in<div>...<a class="star starred"></a>...</div>
. If there is no such class in the dom, the value will default tofalse
.
The id
parameter is not used for rendering.
It's useful when you implement a callback method,
so that you can identify to your server backend the object that is voted on.
Markup
Basic example:
0
Upvoted:
6
Downvoted:
4
Starred:
5
Initialization examples
;;;; var { $;};;
Methods
// Create, pick up initial values from HTML markup; // Mutators; // Upvote!; // Downvote!; // Star! // Getters; // Get the current vote count; // Get the upvoted state -> boolean; // Get the downvoted state -> boolean; // Get the starred state -> boolean
License
Licensed under Creative Commons Attribution 3.0 Unported http://creativecommons.org/licenses/by/3.0/
Donate
You can do it via PayPal. Thanks! :)