discourse-legacysite-perl/site/common/static/js/rating.js
2024-06-17 22:27:49 +10:00

54 lines
1.4 KiB
JavaScript

function RateItem(varParentId, varItemId, varRating)
{
var elementId = varParentId+"_"+varItemId;
var varOrigClassName = document.getElementById(elementId).className;
// Retrieve Ajax Feeds
$.ajax({
url: 'ajax.rate.item.php',
method: 'post',
data: { parent: varParentId, item: varItemId, rating: varRating, classes: varOrigClassName },
success: ReloadRating,
error: RatingError
});
}
function ReadNameValuePairs(nameValuePair)
{
var trimspaces = /(\s)+/;
var returnData = new Array();
var pairs = nameValuePair.split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
returnData[pair[0].replace(trimspaces, "")] = pair[1];
}
return returnData;
}
function ReloadRating(requestObj, jsonObj)
{
var newlines = /(\r\n|\r|\n)/;
var returntext = typeof(requestObj) == 'object' ? requestObj.responseText : requestObj;
var returnData = ReadNameValuePairs(returntext.replace(newlines, ""));
var elementId = returnData['parent']+"_"+returnData['item'];
document.getElementById(elementId).className = returnData['classes'];
var liObj = document.getElementById(elementId).getElementsByTagName('a');
for (var i = 0; i < liObj.length; i++)
{
liObj[i].onclick = function(){};
}
document.getElementById(returnData['parent']).className = returnData['parentClass'];
}
function RatingError()
{
//alert ("Error");
}