This page last changed on Aug 21, 2012 by rehan.iftikhar@involver.com.
General Considerations
This tag is intended for "casual voting". This tag uses a server-side cookie that the user cannot clear to keep track of which accounts have voted. You can control how many days (24 hour intervals) that cookie will last using the cookie_days attribute.
Users can vote on as many items as they want. If you do not use cookie_days they will by default be restricted to one vote per item every 90 days.
This tag is a best-effort mechanism. Involver does NOT guarantee the uniqueness and validity of individual votes. Voting is intended for entertainment purposes only.
Caching Considerations
Votes registered with this tag are processed asynchronously to ensure reliable handling in large volume integrations. As such, vote counts are cached at the page level & may take up to 10 minutes to reflect.
Cookies
By default, votes are allowed once per 90 days. You can override this default by using the cookie_days attribute.
An example of limiting votes to once every 24 hours would be:
{% content_vote entry cookie_days:1 %}
Note: This is time-zone independent and does not reset at midnight. The timer starts immediately after a vote is registered and users will only be able to vote again after 24 total hours have passed.
Additionally, this cookie attribute is not auto-inherited by Canvas pages and should be defined there as well.
Attributes
name |
type |
required |
description |
action_text |
string |
no |
This is text of the link to vote for the content (ie, Vote) |
noun |
string |
no |
This is the singular noun for the description (ie, person). |
noun_plural |
string |
no |
This is the plural noun for the description (ie, people) |
verb |
string |
no |
This is the singular verb for the description (ie, voted for this) |
verb_plural |
string |
no |
This is the verb to use with the plural noun (ie, voted for this) |
success_callback |
string |
no |
JS function to fire after a user has successfully voted. |
failure_callback |
string |
no |
JS function to fire after a user tries to vote but has already voted. |
cookie_days |
integer |
no |
Sets the number of days before the user can vote again. |
class |
string |
no |
The class attribute for the vote link |
style |
string |
no |
The style attribute for the vote link |
onclick |
string |
no |
The handler for javascript code on every click of the vote link |
onfirstclick |
string |
no |
Same as onclick, except the javascript is only executed on the first click of the vote link |
Examples
<h2>Tweets from Involver, Follow us<br>
@<a href="http:>Involver</a></h2>
{% twitter_feed %}
{% paginate twitter_feed.tweets per_page:5 %}
{% for story in tweets %}
<div class="tweet">
<h3>{{ story.title | twitter_link | auto_link }}</h3>
<p>{{ story.published_relative_time }} - {% content_vote story %}</p>
</div>
{% endfor %}
{% endpaginate %}
{% endtwitter_feed %}
Here is an example of how to override the default callbacks for when a user successfully votes on an item (success_callback) and when a user tries to vote but they are not allowed to (failure_callback). Note: changing these callbacks will prevent the default behavior (updating the number of votes or popping an error dialog).
<script type="text/javascript">
function testSuccessCallback(){
var dialog = new sml.ui.PlatformDialog({
title:"Success Title",
body:"Success Body"
});
dialog.show();
}
function testFailureCallback(){
var dialog = new sml.ui.PlatformDialog({
title:"Failure Title",
body:"Failure Body"
});
dialog.show();
}
</script>
{% twitter_feed %}
{% assign item = twitter_feed.tweet_items.first %}
{% content_vote item success_callback:"testSuccessCallback" failure_callback:"testFailureCallback" %}
{% endtwitter_feed %}
FAQ
1 How do I use an anonymous function with the success_callback attribute?
You can use anonymous functions in the success_callback attribute. You must return your inline code as a function from a self-invoking anonymous function. For example:
{% content_vote [item] success_callback:"(function(){ return function(resp){ sml.log(resp) }})()" %}
2 How do I set the voting mechanism so users can vote repeatedly at regular intervals?
You can use the attribute cookie_days to set how many days (server side) the user must wait to vote again. Any whole positive integer will work as a value. A value of Zero removes all restrictions on voting and lets people vote as often as they like.
{% twitter_feed %}
{% paginate twitter_feed.tweets per_page:5 %}
{% for story in tweets %}
<div class="tweet">
<h3>{{ story.title | twitter_link | auto_link }}</h3>
<p>{{ story.published_relative_time }} - {% content_vote story cookie_days:1 %}</p>
</div>
{% endfor %}
{% endpaginate %}
{% endtwitter_feed %}
Related Topics
|