").html(data).evalScripts();
//alert($('param', data).each(function(){alert($(this).attr('value'));}));
return data;
}
})
/***************
* Ratings API *
***************/
/*
* Usage:
* rate_scene(2356, 24, 5);
*/
var ratings_module = '/index.php?m=api&s=ratings';
/*
* entry_id: of the article, comment, or scene
* member_id: of the person rating
* rating: 1-5
*/
function rate_scene(entry_id, member_id, rating) {
rate_entry('scene', entry_id, member_id, false, rating);
}
function rate_comment(entry_id, member_id, rating) {
rate_entry('comment', entry_id, member_id, false, rating);
}
function rate_show(entry_id, member_id, channel, rating) {
rate_entry('show', entry_id, member_id, channel, rating);
}
function record_vote(type, entry_id, rating) {
var mydate = new Date;
var one_day = 60*60*24*1000;dislikes_this_topic
mydate.setTime(mydate.toGMTString()+one_day+one_day);
cookie_val = type + '_' + entry_id + '=' + rating + '; expires='+mydate.toGMTString()+'; path=/';
document.cookie = cookie_val;
}
function already_voted(type, entry_id, member_id) {
return (get_cookie(type + "_" + entry_id));
}
function get_cookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
// a cookie with the requested name does not exist
return null;
}
function rate_entry(type, entry_id, member_id, channel, rating) {
var stats;
if(!already_voted(type, entry_id, member_id)) {
var query = ratings_module + "&action=save&entry_id=" + entry_id + "&type=" + type + "&rating=" + rating + "&member_id=" + member_id + "&channel=" + channel;
$.getJSON( query,
{
m: 'api',
s: 'ratings',
entry_id: entry_id,
type: type,
rating: rating,
member_id: member_id,
channel: channel },
function(data) {
stats = data;
//alert(data['stars_5'] + ' / ' + data['total_votes']);
if(data) {
$('.likes').html(data['like_percentage']);
$('.votes').html(data['total_votes']);
}
});
record_vote(type, entry_id, rating);
}
else {
alert('You have already voted.');
}
}
/* Parameters
* entry_id: Number representing the scene, show or comment
* type: 'scene', 'show', 'comment'
* stat: 'likes', 'dislikes', 'votes', 'average'
*/
function lookup_entry_rating(type, entry_id, stat, element) {
$.get(ratings_module,
{ entry_id: entry_id,
type: type,
statistic: stat},
function(data) {
//alert(stat + ": " + data);
return data;
});
}
/* ********** Helper functions to make usage easier ********** */
function rate_data(entry_id, member_id, rating, rating_type, entry_date, brand) {
rate_entry('ratings', entry_id, member_id, rating, rating_type, entry_date, brand);
}
function update_stats(increment_likes){
var total = $(".total").html();
var likes = $(".likes").val();
// Add 1 to the total and update the page
total = eval(total) + 1;
$(".total").html(total);
// Only increment the likes when someone hits a thumbs up
if (increment_likes == true) {
likes++;
}
var percent_val = Math.round(eval(likes) / eval(total) * 100);
$(".percent").html(percent_val);
}
// AUTO UPDATE AGVERAGE RATING ON PAGE
function update_stars(rating, brand){
var total = $(".total").html();
var total_plus = eval(total)+1;
if(total_plus == 0){
total_plus = 1;
$(".total").html(eval(total)-1);
}else{
$(".total").html(total);
}
var get_sum = $(".pre_sum").html();
var sum = eval(get_sum) + eval(rating);
var ave = Math.round(eval(sum) / eval(total_plus));
}
// GRAPHIC INTERFACE FOR RATING (BOX HOVER STATE)
function roll_box(id, box, brand)
{
var imgPath = new String();
imgPath = document.getElementById(id).style.backgroundImage;
if(box == box)
{
document.getElementById(id).style.backgroundImage = "url(http://content.naughtyamerica.com/naughty/public/images/"+ brand +"/stars/active_box.png)";
}
if(box == 0)
{
document.getElementById(id).style.backgroundImage = "url(http://content.naughtyamerica.com/naughty/public/images/"+ brand +"/stars/inactive_box.png)";
}
}
// Swaps out boxes and posts members rating
function update_box(id, rating, actor_name)
{
$(".update"+id).hide('slow');
$(".update"+id).show('slow').html('You gave '+actor_name+' a rating of '+rating);
}
function ratings_update(id, rating, type){
if(type == 'scene')
{
// Update Total Votes
var votes = $(".votes").html();
var votes_plus = eval(votes)+1;
if(votes_plus == 0){
votes_plus = 1;
$(".votes").html(eval(votes)-1);
}else{
$(".votes").html(votes_plus);
}
// Update Scene Average
var get_sum = $(".sum").html();
var sum = eval(get_sum) + eval(rating);
var ave = (eval(sum) / eval(votes_plus)).toFixed(1);
$(".average"+id).html(ave);
}
// Update Actors Averages
var actor_votes = $(".actor_total"+id).html();
var actor_votes_plus = eval(actor_votes)+1;
if(actor_votes_plus == 0)
{
actor_votes_plus = 1;
}
var get_actor_sum = $(".actor_sum"+id).html();
var actor_sum = eval(get_actor_sum) + eval(rating);
var ave_actor = (eval(actor_sum) / eval(actor_votes_plus)).toFixed(1);
$(".actor"+id).html(ave_actor);
}
function member_rating(entry_id, member_id, rating, rating_type, brand, ip, a_id){
naughty_rpc('Ratings.save_rating', {entry_id: entry_id, member_id: member_id, rating: rating, rating_type: rating_type, brand: brand, ip: ip, a_id: a_id},
function(data) {
if(data != 'You have already voted.') {
if(rating > 1) {
// This means they pushed thumbs up
update_stats(true);
}
else {
// This means they pushed thumbs down
update_stats(false);
}
}
else {
console.log("The user HAS voted, this vote will be ignored: " + rating);
// Let them know they have already voted
alert(data);
}
});
}
function likes_this_topic(entry_id, member_id) {
rate_entry('topic', entry_id, member_id, '', '5');
}
function dislikes_this_topic(entry_id, member_id) {
rate_entry('topic', entry_id, member_id, '', '1');
}
function in_array (needle, haystack, argStrict)
{
var key = '', strict = !!argStrict;
if (strict) {
for (key in haystack) {
if ( (strict && haystack[key] === needle) || ( !strict && strict && haystack[key] == needle ) ) {
return true;
}
}
}
return false;
}
/**
* This jQuery plugin displays pagination links inside the selected elements.
*
* This plugin needs at least jQuery 1.4.2
*
* @author Gabriel Birke (birke *at* d-scribe *dot* de)
* @version 2.0rc
* @param {int} maxentries Number of entries to paginate
* @param {Object} opts Several options (see README for documentation)
* @return {Object} jQuery Object
*/
(function($){
/**
* @class Class for calculating pagination values
*/
$.PaginationCalculator = function(maxentries, opts) {
this.maxentries = maxentries;
this.opts = opts;
}
$.extend($.PaginationCalculator.prototype, {
/**
* Calculate the maximum number of pages
* @method
* @returns {Number}
*/
numPages:function() {
return Math.ceil(this.maxentries/this.opts.items_per_page);
},
/**
* Calculate start and end point of pagination links depending on
* current_page and num_display_entries.
* @returns {Array}
*/
getInterval:function(current_page) {
var ne_half = Math.ceil(this.opts.num_display_entries/2);
var np = this.numPages();
var upper_limit = np - this.opts.num_display_entries;
var start = current_page > ne_half ? Math.max( Math.min(current_page - ne_half, upper_limit), 0 ) : 0;
var end = current_page > ne_half?Math.min(current_page+ne_half, np):Math.min(this.opts.num_display_entries, np);
return {start:start, end:end};
}
});
// Initialize jQuery object container for pagination renderers
$.PaginationRenderers = {}
/**
* @class Default renderer for rendering pagination links
*/
$.PaginationRenderers.defaultRenderer = function(maxentries, opts) {
this.maxentries = maxentries;
this.opts = opts;
this.pc = new $.PaginationCalculator(maxentries, opts);
}
$.extend($.PaginationRenderers.defaultRenderer.prototype, {
/**
* Helper function for generating a single link (or a span tag if it's the current page)
* @param {Number} page_id The page id for the new item
* @param {Number} current_page
* @param {Object} appendopts Options for the new item: text and classes
* @returns {jQuery} jQuery object containing the link
*/
createLink:function(page_id, current_page, appendopts){
var lnk, np = this.pc.numPages();
page_id = page_id<0?0:(page_id
" + appendopts.text + "");
}
else
{
lnk = $("" + appendopts.text + "")
.attr('href', this.opts.link_to.replace(/__id__/,page_id));
}
if(appendopts.classes){ lnk.addClass(appendopts.classes); }
lnk.data('page_id', page_id);
return lnk;
},
// Generate a range of numeric links
appendRange:function(container, current_page, start, end) {
var i;
for(i=start; i ");
// Generate "Previous"-Link
if(this.opts.prev_text && (current_page > 0 || this.opts.prev_show_always)){
fragment.append(this.createLink(current_page-1, current_page, {text:this.opts.prev_text, classes:"prev"}));
}
// Generate starting points
if (interval.start > 0 && this.opts.num_edge_entries > 0)
{
end = Math.min(this.opts.num_edge_entries, interval.start);
this.appendRange(fragment, current_page, 0, end);
if(this.opts.num_edge_entries < interval.start && this.opts.ellipse_text)
{
jQuery("