Changeset 995
- Timestamp:
- 08/27/08 05:57:29 (3 months ago)
- Files:
-
- trunk/FiveStarRating/README.txt (modified) (1 diff)
- trunk/FiveStarRating/Template_Snippets.txt (modified) (2 diffs)
- trunk/FiveStarRating/plugins/FiveStarRating/config.yaml (modified) (1 diff)
- trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/App.pm (modified) (3 diffs)
- trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/Tag.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/FiveStarRating/README.txt
r878 r995 1 FiveStarRating - an example plugin that leverages the Rating Framework of Movable Type 4.x.1 FiveStarRating - an example plugin that leverages the Scoring Framework of Movable Type 4.x. 2 2 3 The plugin is tested on Movable Type 4.2. Detailed documentation is coming soon on www.movabletype.org. 3 The plugin is tested on Movable Type 4.2. 4 5 Detailed documentation is coming soon on www.movabletype.org. trunk/FiveStarRating/Template_Snippets.txt
r878 r995 1 Add the following template snippet to entry's metadata section to show the stars that represents the score of the entry, and clickable link. 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 2 3 < MTFiveStars>3 <$mt:FiveStarScore$> 4 4 5 Also add the following template snippet to the <head> section of Entry archive template. 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>) 6 7 7 8 <script type="text/javascript"> 8 function rcUpdate(entry_id, rating, hover) 9 { 10 var i, image, image_file; 11 for( i = 0; i <= 5; i++ ) 12 { 13 image = document.getElementById(entry_id + '-rc-' + i); 14 if( !image ) 15 return false; 16 if( i > 0 ) 17 if( i <= rating ) 18 image_file = 'star'; 19 else 20 image_file = 'bullet'; 21 else 22 image_file = 'no_rating'; 23 if( hover ) 24 if( ( image_file == 'star' ) || ( ( image_file == 'no_rating' ) && ( rating == 0 ) ) ) 25 image_file = image_file + '-hover'; 26 if( image_file != '' ) 27 image.src = '<MTStaticWebPath>plugins/FiveStarRating/' + image_file + '.gif'; 28 } 29 return true; 30 } 31 function rcOut(entry_id) { 32 var obj = document.getElementById(entry_id + '-rating'); 33 if( !obj ) 34 return false; 35 var rating = obj.innerHTML; 36 return rcUpdate(entry_id, rating, false); 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); 37 17 } 38 function rcClick(entry_id, rating) { 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; 39 25 var xh = mtGetXmlHttp(); 40 if (!xh) return; 41 var url = '<MTCGIPath><MTCommentScript>?__mode=fivestar_rate&static=1&entry_id=' + entry_id + '&score=' + rating; 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; 42 29 xh.open('POST', url, true); 43 30 xh.onreadystatechange = function() { … … 52 39 xh.send(null); 53 40 } 54 function fivestar_response(entry_id, stars) { 55 var obj = document.getElementById(entry_id + '-rating'); 56 if( !obj ) 57 return false; 58 obj.innerHTML = stars; 59 return rcUpdate(entry_id, stars, false); 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 ); 60 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 61 80 </script> 62 81 trunk/FiveStarRating/plugins/FiveStarRating/config.yaml
r877 r995 9 9 comments: 10 10 methods: 11 fivestar_ rate: $fivestarrating::FiveStarRating::App::rate11 fivestar_score: $fivestarrating::FiveStarRating::App::score 12 12 13 13 tags: 14 14 function: 15 FiveStar s: $fivestarrating::FiveStarRating::Tag::_hdlr_five_stars15 FiveStarScore: $fivestarrating::FiveStarRating::Tag::_hdlr_five_star_score trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/App.pm
r877 r995 5 5 sub NAMESPACE { 'FiveStarRating' } 6 6 7 sub rate {7 sub score { 8 8 my $app = shift; 9 9 my $q = $app->param; … … 26 26 my $stars = int( $avg + 0.5 ); 27 27 28 $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1 )28 $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1, BuildIndexes => 1 ) 29 29 or return $app->handle_error( 30 30 $app->translate( "Publish failed: [_1]", $app->errstr ) ); … … 33 33 $app->{no_print_body} = 1; 34 34 require JSON; 35 $app->print("five star_response($entry_id, $stars);");35 $app->print("fiveStarScoreResponse($entry_id, $stars, $avg, '" . NAMESPACE() . "');"); 36 36 return undef; 37 37 } trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/Tag.pm
r877 r995 3 3 use strict; 4 4 5 sub _hdlr_five_star s{5 sub _hdlr_five_star_score { 6 6 my ( $ctx, $args ) = @_; 7 7 my $plugin = MT->component('fivestarrating'); … … 33 33 34 34 my $html = <<HTML; 35 <span id="$id-rating" class="hidden">$stars</span> 36 <img id="$id-rc-0" onmouseover="rcUpdate('$id', 0, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 0)" src="$image_url/no_rating.gif" /> 37 <img id="$id-rc-1" onmouseover="rcUpdate('$id', 1, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 1)" src="$image_url/$src1.gif" /> 38 <img id="$id-rc-2" onmouseover="rcUpdate('$id', 2, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 2)" src="$image_url/$src2.gif" /> 39 <img id="$id-rc-3" onmouseover="rcUpdate('$id', 3, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 3)" src="$image_url/$src3.gif" /> 40 <img id="$id-rc-4" onmouseover="rcUpdate('$id', 4, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 4)" src="$image_url/$src4.gif" /> 41 <img id="$id-rc-5" onmouseover="rcUpdate('$id', 5, true)" onmouseout="rcOut('$id')" onclick="rcClick('$id', 5)" src="$image_url/$src5.gif" /> 35 <span id="fivestar$id" class="hidden">$stars</span><img 36 id="fivestar$id-0" onmouseover="fiveStarScoreUpdate('$id', 0, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 0)" src="$image_url/no_rating.gif" /><img 37 id="fivestar$id-1" onmouseover="fiveStarScoreUpdate('$id', 1, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 1)" src="$image_url/$src1.gif" /><img 38 id="fivestar$id-2" onmouseover="fiveStarScoreUpdate('$id', 2, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 2)" src="$image_url/$src2.gif" /><img 39 id="fivestar$id-3" onmouseover="fiveStarScoreUpdate('$id', 3, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 3)" src="$image_url/$src3.gif" /><img 40 id="fivestar$id-4" onmouseover="fiveStarScoreUpdate('$id', 4, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 4)" src="$image_url/$src4.gif" /><img 41 id="fivestar$id-5" onmouseover="fiveStarScoreUpdate('$id', 5, true)" onmouseout="fiveStarScoreOut('$id')" onclick="fiveStarScore('$id', 5)" src="$image_url/$src5.gif" /><img 42 src="http://hotness.local/rtrunk/mt-static/plugins/FiveStarRating/border-right.gif" /> 42 43 HTML 43 44 return $html;
