| 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:FavoriteScore$> |
|---|
| 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 | // FavoriteScore |
|---|
| 11 | var namespace = 'favorite'; |
|---|
| 12 | function favoriteScoreUpdate(obj_id, score, hover) { mtScoreUpdate(namespace, obj_id, score, 1, hover, 'star', 'bullet', 'no_rating', 'FavoriteScore') } |
|---|
| 13 | function favoriteScoreOut(obj_id) { mtScoreOut(namespace, obj_id, favoriteScoreUpdate) } |
|---|
| 14 | function favoriteScore(obj_id, score) { mtScore(namespace, obj_id, score, namespace + '-pending', namespace + '-complete') } |
|---|
| 15 | function favoriteScoreResponse(obj_id, score) { |
|---|
| 16 | mtScoreResponse(namespace, obj_id, score, namespace + '-pending', namespace + '-complete'); |
|---|
| 17 | favoriteScoreUpdate(obj_id, score, false); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | // Generic mtScoring Functions |
|---|
| 21 | function mtScore(ns, obj_id, score, pending, complete) { |
|---|
| 22 | var el = document.getElementById(ns + obj_id); |
|---|
| 23 | if( !el ) return false; |
|---|
| 24 | if (DOM.hasClassName(el, pending)) return false; |
|---|
| 25 | if (DOM.hasClassName(el, complete)) return false; |
|---|
| 26 | var xh = mtGetXmlHttp(); |
|---|
| 27 | if (!xh) return false; |
|---|
| 28 | DOM.addClassName( el, pending ); |
|---|
| 29 | var url = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=' + ns + '_score&static=1&entry_id=' + obj_id + '&score=' + score; |
|---|
| 30 | xh.open('POST', url, true); |
|---|
| 31 | xh.onreadystatechange = function() { |
|---|
| 32 | if ( xh.readyState == 4 ) { |
|---|
| 33 | if ( xh.status && ( xh.status != 200 ) ) { |
|---|
| 34 | // error - ignore |
|---|
| 35 | } else { |
|---|
| 36 | eval(xh.responseText); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | }; |
|---|
| 40 | xh.send(null); |
|---|
| 41 | } |
|---|
| 42 | function mtScoreResponse(ns, obj_id, score, pending, complete) { |
|---|
| 43 | var el = document.getElementById(ns + obj_id); |
|---|
| 44 | if (!el) |
|---|
| 45 | return false; |
|---|
| 46 | el.innerHTML = score; |
|---|
| 47 | DOM.removeClassName( el, pending ); |
|---|
| 48 | DOM.addClassName( el, complete ); |
|---|
| 49 | } |
|---|
| 50 | function mtScoreOut(ns, obj_id, callbackf) { |
|---|
| 51 | var obj = document.getElementById(ns + obj_id); |
|---|
| 52 | if( !obj ) |
|---|
| 53 | return false; |
|---|
| 54 | var score = obj.innerHTML; |
|---|
| 55 | callbackf.call(this, obj_id, score, false); |
|---|
| 56 | } |
|---|
| 57 | function mtScoreUpdate(ns, obj_id, score, size, hover, on_img, off_img, zero_img, plugin_name) |
|---|
| 58 | { |
|---|
| 59 | var i, image, image_file; |
|---|
| 60 | for( i = 0; i <= size; i++ ) |
|---|
| 61 | { |
|---|
| 62 | image = document.getElementById(ns + obj_id + '-' + i); |
|---|
| 63 | if( !image ) |
|---|
| 64 | return false; |
|---|
| 65 | if( i > 0 ) |
|---|
| 66 | if( i <= score ) |
|---|
| 67 | image_file = on_img; |
|---|
| 68 | else |
|---|
| 69 | image_file = off_img; |
|---|
| 70 | else |
|---|
| 71 | image_file = zero_img; |
|---|
| 72 | if( hover ) |
|---|
| 73 | if( ( image_file == on_img ) || ( ( image_file == zero_img ) && ( score == 0 ) ) ) |
|---|
| 74 | image_file = image_file + '-hover'; |
|---|
| 75 | if( image_file != '' ) |
|---|
| 76 | image.src = '<$mt:StaticWebPath$>plugins/' + plugin_name +'/' + image_file + '.gif'; |
|---|
| 77 | } |
|---|
| 78 | return true; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | </script> |
|---|
| 82 | |
|---|