From: <var...@us...> - 2011-11-29 12:53:02
|
Revision: 8200 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=8200&view=rev Author: vargenau Date: 2011-11-29 12:52:51 +0000 (Tue, 29 Nov 2011) Log Message: ----------- Use getElementById Modified Paths: -------------- trunk/themes/fusionforge/wikilens.js Modified: trunk/themes/fusionforge/wikilens.js =================================================================== --- trunk/themes/fusionforge/wikilens.js 2011-11-29 12:51:25 UTC (rev 8199) +++ trunk/themes/fusionforge/wikilens.js 2011-11-29 12:52:51 UTC (rev 8200) @@ -30,7 +30,7 @@ function displayRating(imgId, imgPrefix, ratingvalue, pred, init) { var ratings = new Array('Not Rated','Awful','Very Poor','Poor','Below Average', - 'Average','Above Average','Good','Very Good','Excellent','Outstanding'); + 'Average','Above Average','Good','Very Good','Excellent','Outstanding'); var cancel = imgId + imgPrefix + 'Cancel'; var curr_rating = rating[imgId]; var curr_pred = prediction[imgId]; @@ -43,13 +43,13 @@ title = title+' '+msg_curr_prediction+ curr_pred+' '+ratings[curr_pred*2]; } if (canRate[imgId]) { - if (curr_rating) { - document[cancel].style.display = 'inline'; - } - else { - document[cancel].style.display = 'none'; - } - } + if (curr_rating) { + document.getElementById(cancel).style.display = 'inline'; + } + else { + document.getElementById(cancel).style.display = 'none'; + } + } } for (var i=1; i<=10; i++) { var imgName = imgId + i; @@ -58,33 +58,33 @@ var j = i/2; if (ratingvalue > 0) { if (curr_rating) { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; } else if (curr_pred) { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,curr_pred,1,0) }; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,curr_pred,1,0) }; } if (curr_rating != ratingvalue && typeof(msg_chg_rating) != "undefined") { - document[imgName].title = msg_chg_rating+curr_rating+' '+ratings[curr_rating*2]+msg_to+j+' '+ratings[i]; - } + document.getElementById(imgName).title = msg_chg_rating+curr_rating+' '+ratings[curr_rating*2]+msg_to+j+' '+ratings[i]; + } } else { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; - document[imgName].title = msg_add_rating+j+' '+ratings[i]; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; + document.getElementById(imgName).title = msg_add_rating+j+' '+ratings[i]; } } var imgType = 'N'; if (pred) { if (init) - document[imgName].title = title+linebreak+msg_add_rating+ratings[i]; + document.getElementById(imgName).title = title+linebreak+msg_add_rating+ratings[i]; imgType = 'R'; } else if (i<=(ratingvalue*2)) { imgType = 'O'; } - document[imgName].src = imgSrc + imgPrefix + imgType + ((i%2) ? 'k1' : 'k0') + '.png'; + document.getElementById(imgName).src = imgSrc + imgPrefix + imgType + ((i%2) ? 'k1' : 'k0') + '.png'; } } function displayRating2(imgId, imgPrefix, ratingvalue, pred, init) { var ratings = new Array('Not Rated','Awful','Very Poor','Poor','Below Average', - 'Average','Above Average','Good','Very Good','Excellent','Outstanding'); + 'Average','Above Average','Good','Very Good','Excellent','Outstanding'); var cancel = imgId + imgPrefix + 'Cancel'; var curr_rating = rating[imgId]; var curr_pred = prediction[imgId]; @@ -97,10 +97,10 @@ title = title+' '+msg_curr_prediction+ curr_pred+' '+ratings[curr_pred*2]; } if (curr_rating) { - document[cancel].style.display = 'inline'; + document.getElementById(cancel).style.display = 'inline'; } else { - document[cancel].style.display = 'none'; + document.getElementById(cancel).style.display = 'none'; } } for (var i=1; i<=10; i++) { @@ -110,99 +110,97 @@ var j = i/2; if (ratingvalue > 0) { if (curr_rating) { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; } else if (curr_pred) { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,curr_pred,1,0) }; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,curr_pred,1,0) }; } if (curr_rating != ratingvalue && typeof(msg_chg_rating) != "undefined") { - document[imgName].title = msg_chg_rating+curr_rating+' '+ratings[curr_rating*2]+msg_to+j+' '+ratings[i]; - } + document.getElementById(imgName).title = msg_chg_rating+curr_rating+' '+ratings[curr_rating*2]+msg_to+j+' '+ratings[i]; + } } else { - document[imgName].onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; - document[imgName].title = msg_add_rating+j+' '+ratings[i]; + document.getElementById(imgName).onmouseout = function() { displayRating(imgId,imgPrefix,avg[imgId],0,0) }; + document.getElementById(imgName).title = msg_add_rating+j+' '+ratings[i]; } } var imgType = 'N'; if (pred) { if (init) - document[imgName].title = title+linebreak+msg_add_rating+ratings[i]; + document.getElementById(imgName).title = title+linebreak+msg_add_rating+ratings[i]; imgType = 'R'; - } else { - if (ratingvalue <= curr_rating) { - if (i <= (ratingvalue * 2)) - imgType = 'Rp'; - else - if (i <= (curr_rating * 2)) - imgType = 'R'; - } - else { - if (i <= (curr_rating * 2)) - imgType = 'Rp'; - else - if (i <= (ratingvalue * 2)) - imgType = 'Rm'; - } + } else { + if (ratingvalue <= curr_rating) { + if (i <= (ratingvalue * 2)) + imgType = 'Rp'; + else + if (i <= (curr_rating * 2)) + imgType = 'R'; + } + else { + if (i <= (curr_rating * 2)) + imgType = 'Rp'; + else + if (i <= (ratingvalue * 2)) + imgType = 'Rm'; + } } - document[imgName].src = imgSrc + imgPrefix + imgType + ((i%2) ? 'k1' : 'k0') + '.png'; + document.getElementById(imgName).src = imgSrc + imgPrefix + imgType + ((i%2) ? 'k1' : 'k0') + '.png'; } } function sprintfRating(s, num, count) { - var num1 = Math.round(num * 10) / 10; - if (count < 2) s = s.replace(/votes/, 'vote'); - return s.replace(/\%.1f/, num1).replace(/\%d/, count); + var num1 = Math.round(num * 10) / 10; + if (count < 2) s = s.replace(/votes/, 'vote'); + return s.replace(/\%.1f/, num1).replace(/\%d/, count); } function clickRating(imgPrefix,pagename,version,imgId,dimension,newrating) { var actionImg = imgId+'Action'; var top = document.getElementById('rateit-widget-top'); var nusers = numusers[imgId]; var old_rating = rating[imgId]; + var sum1 = avg[imgId] * nusers; + var new_avg; if (newrating == 'X') { deleteRating(actionImg,pagename,dimension); if (top && nusers) { - var sum1 = avg[imgId] * nusers; - var new_avg; - if (old_rating && old_rating > 0) { - if (nusers > 1) { - new_avg = (sum1 - old_rating) / (nusers - 1); - numusers[imgId]--; - } - else { - new_avg = 0; - numusers[imgId] = 0; - } - } - if (new_avg.toString() != "NaN" && idTop == imgId) { - avg[imgId] = new_avg; - top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, new_avg, nusers-1); + if (old_rating && old_rating > 0) { + if (nusers > 1) { + new_avg = (sum1 - old_rating) / (nusers - 1); + numusers[imgId]--; } + else { + new_avg = 0; + numusers[imgId] = 0; + } + } + if (new_avg.toString() != "NaN" && idTop == imgId) { + avg[imgId] = new_avg; + top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, new_avg, nusers-1); + } } rating[imgId] = 0; displayRating2(imgId,imgPrefix,0,0,1); } else { submitRating(actionImg,pagename,version,dimension,newrating); if (top && nusers) { - var sum1 = avg[imgId] * nusers; - var new_avg; - if (old_rating && (old_rating > 0)) { - new_avg = (sum1 + newrating - old_rating) / nusers; - } else { - new_avg = (sum1 + newrating) / (nusers + 1); - numusers[imgId]++; + if (old_rating && (old_rating > 0)) { + new_avg = (sum1 + newrating - old_rating) / nusers; + } else { + new_avg = (sum1 + newrating) / (nusers + 1); + numusers[imgId]++; + } + if (new_avg.toString() != "NaN" && idTop == imgId) { + avg[imgId] = new_avg; + if (newrating != rating[imgId]) { + top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, new_avg, numusers[imgId]); } - if (new_avg.toString() != "NaN" && idTop == imgId) { - avg[imgId] = new_avg; - if (newrating != rating[imgId]) { - top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, new_avg, numusers[imgId]); - } - } + } } else if (top && idTop == imgId) { - top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, newrating, 1); - avg[imgId] = newrating; - numusers[imgId] = 1; + top.childNodes[0].innerHTML = sprintfRating(msg_rating_votes, newrating, 1); + avg[imgId] = newrating; + numusers[imgId] = 1; } rating[imgId] = newrating; - displayRating2(imgId,imgPrefix,newrating,0,1); + displayRating2(imgId,imgPrefix,newrating,0,1); } } function submitRating(actionImg,page,version,dimension,newrating) { @@ -210,14 +208,14 @@ // currently ratings are changed with side-effect, but GET should be side-effect free. var myRand = Math.round(Math.random()*(1000000)); var imgSrc = WikiURL(page) + 'version=' + version + '&action=' + rateit_action + '&mode=add&rating=' + newrating + '&dimension=' + dimension + '&nocache=1&nopurge=1&rand=' + myRand; - document[actionImg].title = msg_thanks; - document[actionImg].src = imgSrc; + document.getElementById(actionImg).title = msg_thanks; + document.getElementById(actionImg).src = imgSrc; } function deleteRating(actionImg, page, dimension) { //TODO: GET => DELETE request // currently ratings are changed with side-effect, but GET should be side-effect free. var myRand = Math.round(Math.random()*(1000000)); var imgSrc = WikiURL(page) + 'action=' + rateit_action + '&mode=delete&dimension=' + dimension + '&nocache=1&nopurge=1&rand=' + myRand; - document[actionImg].title = msg_rating_deleted; - document[actionImg].src = imgSrc; + document.getElementById(actionImg).title = msg_rating_deleted; + document.getElementById(actionImg).src = imgSrc; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |