diff options
author | vdigital <vdigital@piwigo.org> | 2008-05-23 21:05:41 +0000 |
---|---|---|
committer | vdigital <vdigital@piwigo.org> | 2008-05-23 21:05:41 +0000 |
commit | 77fd1f51a3c5f5a52f72ef8a299fe368228e2285 (patch) | |
tree | a67ede42904657ccf3349ecdaef1cec8b8e36ff8 /BSF/template/yoga/rating.js | |
parent | 553727dffacc48e8337c1d141f2a25af359e74b1 (diff) |
git-svn-id: http://piwigo.org/svn/trunk@2357 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | BSF/template/yoga/rating.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/BSF/template/yoga/rating.js b/BSF/template/yoga/rating.js new file mode 100644 index 000000000..a4f8f86b8 --- /dev/null +++ b/BSF/template/yoga/rating.js @@ -0,0 +1,90 @@ +makeNiceRatingForm(); + +function makeNiceRatingForm() +{ + var form = document.getElementById('rateForm'); + if (!form) return; //? template changed + gRatingButtons = form.getElementsByTagName('input'); + + gUserRating = ""; + for (var i=0; i<gRatingButtons.length; i++) + { + if ( gRatingButtons[i].type=="button" ) + { + gUserRating = gRatingButtons[i].value; + break; + } + } + + for (var i=0; i<gRatingButtons.length; i++) + { + var rateButton = gRatingButtons[i]; + rateButton.initialRateValue = rateButton.value; // save it as a property + + rateButton.value = ""; //hide the text IE/Opera + with (rateButton.style) + { + textIndent = "-50px"; //hide the text FF + marginLeft = marginRight = 0; + } + + if (i!=gRatingButtons.length-1 && rateButton.nextSibling.nodeType == 3 /*TEXT_NODE*/) + rateButton.parentNode.removeChild(rateButton.nextSibling); + if (i>0 && rateButton.previousSibling.nodeType == 3 /*TEXT_NODE*/) + rateButton.parentNode.removeChild(rateButton.previousSibling); + + if(window.addEventListener){ // Mozilla, Netscape, Firefox + rateButton.addEventListener("click", updateRating, false ); + rateButton.addEventListener("mouseout", resetRatingStarDisplay, false ); + rateButton.addEventListener("mouseover", updateRatingStarDisplayEvt, false ); + } + else if(window.attachEvent) { // IE + rateButton.attachEvent("onclick", updateRating); + rateButton.attachEvent("onmouseout", resetRatingStarDisplay); + rateButton.attachEvent("onmouseover", updateRatingStarDisplayEvt); + } + } + resetRatingStarDisplay(); +} + +function resetRatingStarDisplay() +{ + updateRatingStarDisplay( gUserRating ); +} + +function updateRatingStarDisplay(userRating) +{ + for (i=0; i<gRatingButtons.length; i++) + { + var rateButton = gRatingButtons[i]; + if (userRating!=="" && userRating>=rateButton.initialRateValue ) + { + rateButton.className = "rateButtonStarFull"; + } + else + { + rateButton.className = "rateButtonStarEmpty"; + } + } +} + +function updateRatingStarDisplayEvt(e) +{ + if (e.target) + updateRatingStarDisplay(e.target.initialRateValue); + else //IE + updateRatingStarDisplay(e.srcElement.initialRateValue); +} + +function updateRating(e) +{ + if (e.target) + var rateButton = e.target; + else //IE + var rateButton = e.srcElement; + if (rateButton.initialRateValue == gUserRating) + return false; //nothing to do + // some ajax here one day would be nice + rateButton.value = rateButton.initialRateValue; // put back real value + return true; +}
\ No newline at end of file |