| 1 |
1. Add the following template snippet in an entry context (such as in the entry metadata section) to show the number of votes and clickable link |
|---|
| 2 |
|
|---|
| 3 |
<$mt:FiveStarScore$> |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
2. Also add the following template snippet to the <head> section of Entry archive template (or place into a new index template and link to the published template in the <head>) |
|---|
| 7 |
|
|---|
| 8 |
<script type="text/javascript"> |
|---|
| 9 |
|
|---|
| 10 |
// FiveStarScore Specific Functions |
|---|
| 11 |
function fiveStarScoreUpdate(obj_id, score, hover) { mtScoreUpdate('fivestar', obj_id, score, 5, hover, 'star', 'bullet', 'no_rating', 'FiveStarRating') } |
|---|
| 12 |
function fiveStarScoreOut(obj_id) { mtScoreOut('fivestar', obj_id, fiveStarScoreUpdate) } |
|---|
| 13 |
function fiveStarScore(obj_id, score) { mtScore('fivestar', obj_id, score, 'fivestar-pending', 'fivestar-complete') } |
|---|
| 14 |
function fiveStarScoreResponse(obj_id, score) { |
|---|
| 15 |
mtScoreResponse('fivestar', obj_id, score, 'fivestar-pending', 'fivestar-complete'); |
|---|
| 16 |
fiveStarScoreUpdate(obj_id, score, false); |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
// Generic mtScoring Functions |
|---|
| 20 |
function mtScore(ns, obj_id, score, pending, complete) { |
|---|
| 21 |
var el = document.getElementById(ns + obj_id); |
|---|
| 22 |
if( !el ) return false; |
|---|
| 23 |
if (DOM.hasClassName(el, pending)) return false; |
|---|
| 24 |
if (DOM.hasClassName(el, complete)) return false; |
|---|
| 25 |
var xh = mtGetXmlHttp(); |
|---|
| 26 |
if (!xh) return false; |
|---|
| 27 |
DOM.addClassName( el, pending ); |
|---|
| 28 |
var url = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=' + ns + '_score&static=1&entry_id=' + obj_id + '&score=' + score; |
|---|
| 29 |
xh.open('POST', url, true); |
|---|
| 30 |
xh.onreadystatechange = function() { |
|---|
| 31 |
if ( xh.readyState == 4 ) { |
|---|
| 32 |
if ( xh.status && ( xh.status != 200 ) ) { |
|---|
| 33 |
// error - ignore |
|---|
| 34 |
} else { |
|---|
| 35 |
eval(xh.responseText); |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
}; |
|---|
| 39 |
xh.send(null); |
|---|
| 40 |
} |
|---|
| 41 |
function mtScoreResponse(ns, obj_id, score, pending, complete) { |
|---|
| 42 |
var el = document.getElementById(ns + obj_id); |
|---|
| 43 |
if (!el) |
|---|
| 44 |
return false; |
|---|
| 45 |
el.innerHTML = score; |
|---|
| 46 |
DOM.removeClassName( el, pending ); |
|---|
| 47 |
DOM.addClassName( el, complete ); |
|---|
| 48 |
} |
|---|
| 49 |
function mtScoreOut(ns, obj_id, callbackf) { |
|---|
| 50 |
var obj = document.getElementById(ns + obj_id); |
|---|
| 51 |
if( !obj ) |
|---|
| 52 |
return false; |
|---|
| 53 |
var score = obj.innerHTML; |
|---|
| 54 |
callbackf.call(this, obj_id, score, false); |
|---|
| 55 |
} |
|---|
| 56 |
function mtScoreUpdate(ns, obj_id, score, size, hover, on_img, off_img, zero_img, plugin_name) |
|---|
| 57 |
{ |
|---|
| 58 |
var i, image, image_file; |
|---|
| 59 |
for( i = 0; i <= size; i++ ) |
|---|
| 60 |
{ |
|---|
| 61 |
image = document.getElementById(ns + obj_id + '-' + i); |
|---|
| 62 |
if( !image ) |
|---|
| 63 |
return false; |
|---|
| 64 |
if( i > 0 ) |
|---|
| 65 |
if( i <= score ) |
|---|
| 66 |
image_file = on_img; |
|---|
| 67 |
else |
|---|
| 68 |
image_file = off_img; |
|---|
| 69 |
else |
|---|
| 70 |
image_file = zero_img; |
|---|
| 71 |
if( hover ) |
|---|
| 72 |
if( ( image_file == on_img ) || ( ( image_file == zero_img ) && ( score == 0 ) ) ) |
|---|
| 73 |
image_file = image_file + '-hover'; |
|---|
| 74 |
if( image_file != '' ) |
|---|
| 75 |
image.src = '<$mt:StaticWebPath$>plugins/' + plugin_name +'/' + image_file + '.gif'; |
|---|
| 76 |
} |
|---|
| 77 |
return true; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
</script> |
|---|
| 81 |
|
|---|