Changeset 995

Show
Ignore:
Timestamp:
08/27/08 05:57:29 (3 months ago)
Author:
bsmith
Message:

abstracting js and syncing with FavoriteScoring? and Dug plugins

Files:

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. 
     1FiveStarRating - an example plugin that leverages the Scoring Framework of Movable Type 4.x. 
    22 
    3 The plugin is tested on Movable Type 4.2.  Detailed documentation is coming soon on www.movabletype.org. 
     3The plugin is tested on Movable Type 4.2. 
     4 
     5Detailed 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. 
     11. 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 
    22 
    3 <MTFiveStars
     3<$mt:FiveStarScore$
    44 
    5 Also add the following template snippet to the <head> section of Entry archive template. 
     5 
     62. 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>) 
    67 
    78<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 
     11function fiveStarScoreUpdate(obj_id, score, hover) { mtScoreUpdate('fivestar', obj_id, score, 5, hover, 'star', 'bullet', 'no_rating', 'FiveStarRating') } 
     12function fiveStarScoreOut(obj_id) { mtScoreOut('fivestar', obj_id, fiveStarScoreUpdate) } 
     13function fiveStarScore(obj_id, score) { mtScore('fivestar', obj_id, score, 'fivestar-pending', 'fivestar-complete') } 
     14function fiveStarScoreResponse(obj_id, score) { 
     15    mtScoreResponse('fivestar', obj_id, score, 'fivestar-pending', 'fivestar-complete'); 
     16    fiveStarScoreUpdate(obj_id, score, false); 
    3717} 
    38 function rcClick(entry_id, rating) { 
     18 
     19// Generic mtScoring Functions 
     20function 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; 
    3925    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; 
    4229    xh.open('POST', url, true); 
    4330    xh.onreadystatechange = function() { 
     
    5239    xh.send(null); 
    5340} 
    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);  
     41function 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 ); 
    6048} 
     49function 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} 
     56function 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 
    6180</script> 
    6281 
  • trunk/FiveStarRating/plugins/FiveStarRating/config.yaml

    r877 r995  
    99    comments: 
    1010        methods: 
    11             fivestar_rate: $fivestarrating::FiveStarRating::App::rat
     11            fivestar_score: $fivestarrating::FiveStarRating::App::scor
    1212 
    1313tags: 
    1414    function: 
    15         FiveStars: $fivestarrating::FiveStarRating::Tag::_hdlr_five_stars 
     15        FiveStarScore: $fivestarrating::FiveStarRating::Tag::_hdlr_five_star_score 
  • trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/App.pm

    r877 r995  
    55sub NAMESPACE { 'FiveStarRating' } 
    66 
    7 sub rate { 
     7sub score { 
    88    my $app = shift; 
    99    my $q = $app->param; 
     
    2626    my $stars = int( $avg + 0.5 ); 
    2727 
    28     $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1
     28    $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1, BuildIndexes => 1
    2929      or return $app->handle_error( 
    3030        $app->translate( "Publish failed: [_1]", $app->errstr ) ); 
     
    3333    $app->{no_print_body} = 1; 
    3434    require JSON; 
    35     $app->print("fivestar_response($entry_id, $stars);"); 
     35    $app->print("fiveStarScoreResponse($entry_id, $stars, $avg, '" . NAMESPACE() . "');"); 
    3636    return undef; 
    3737} 
  • trunk/FiveStarRating/plugins/FiveStarRating/lib/FiveStarRating/Tag.pm

    r877 r995  
    33use strict; 
    44 
    5 sub _hdlr_five_stars
     5sub _hdlr_five_star_score
    66    my ( $ctx, $args ) = @_; 
    77    my $plugin = MT->component('fivestarrating'); 
     
    3333 
    3434    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" /> 
    4243HTML 
    4344    return $html;