Changeset 994 for trunk/Dug

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

abstracting js and syncing with FavoriteScoring? and FiveStarRating? plugins

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Dug/README.txt

    r867 r994  
    1 Dug - an example plugin that leverages the Rating Framework of Movable Type 4.x. 
     1Dug - 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/Dug/Template_Snippets.txt

    r972 r994  
    1 Add the following template snippet to entry's metadata section to show the number of votes 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 <a href="javascript:void(0)" onclick="dug('<$MTEntryID$>');">((<span id="dug_count_<$MTEntryID$>"><$MTDugCount$></span>))</a
     3<$mt:DugScore$
    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 dug(entry_id) { 
     9 
     10// Dug Specific Functions 
     11function dugScore(obj_id) { 
     12    var score = 1; 
     13    mtScore('dug', obj_id, score, 'dug-pending', 'dug-complete'); 
     14
     15function dugScoreResponse(obj_id, score) { mtScoreResponse('dug', obj_id, score, 'dug-pending', 'dug-complete') } 
     16 
     17// Generic mtScoring Functions 
     18function mtScore(ns, obj_id, score, pending, complete) { 
     19    var el = document.getElementById(ns + obj_id); 
     20    if( !el ) return false; 
     21    if (DOM.hasClassName(el, pending)) return false; 
     22    if (DOM.hasClassName(el, complete)) return false; 
    923    var xh = mtGetXmlHttp(); 
    10     if (!xh) return; 
    11     var url = '<MTCGIPath><MTCommentScript>?__mode=dug_dig&static=1&entry_id=' + entry_id; 
     24    if (!xh) return false; 
     25    DOM.addClassName( el, pending ); 
     26    var url = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=' + ns + '_score&static=1&entry_id=' + obj_id + '&score=' + score; 
    1227    xh.open('POST', url, true); 
    1328    xh.onreadystatechange = function() { 
     
    2237    xh.send(null); 
    2338} 
    24 function dug_response(count,entry_id) { 
    25     var el = document.getElementById('dug_count_' + entry_id); 
    26     if (el) el.innerHTML = count; 
     39function mtScoreResponse(ns, obj_id, score, pending, complete) { 
     40    var el = document.getElementById(ns + obj_id); 
     41    if (!el) 
     42        return false; 
     43    el.innerHTML = score; 
     44    DOM.removeClassName( el, pending ); 
     45    DOM.addClassName( el, complete ); 
    2746} 
     47 
    2848</script> 
     49 
  • trunk/Dug/plugins/Dug/config.yaml

    r867 r994  
    11id: dug 
    22name: Dug 
    3 version: 0.1 
     3version: 0.2 
    44description: Example plugin to explain the Ratings Framework 
     5author_name: Six Apart, Ltd. 
     6author_link: http://www.sixapart.com/ 
    57 
    68applications: 
    79    comments: 
    810        methods: 
    9             dug_dig: $dug::Dug::App::dig 
     11            dug_score: $dug::Dug::App::score 
    1012 
    1113tags: 
    1214    function: 
    1315        DugCount: $dug::Dug::Tag::_hdlr_dug_count 
     16        DugScore: $dug::Dug::Tag::_hdlr_dug_score 
  • trunk/Dug/plugins/Dug/lib/Dug/App.pm

    r972 r994  
    55sub NAMESPACE { 'dug' } 
    66 
    7 sub dig
     7sub score
    88    my $app = shift; 
    99    my $q = $app->param; 
     
    2121    my $count = $entry->votes_for( NAMESPACE() ); 
    2222 
    23     $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1
     23    $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1, BuildIndexes => 1
    2424      or return $app->handle_error( 
    2525        $app->translate( "Publish failed: [_1]", $app->errstr ) ); 
     
    2828    $app->{no_print_body} = 1; 
    2929    require JSON; 
    30     $app->print("dug_response($count,$entry_id);"); 
     30    $app->print("dugScoreResponse($entry_id,$count);"); 
    3131    return undef; 
    3232} 
  • trunk/Dug/plugins/Dug/lib/Dug/Tag.pm

    r867 r994  
    1111} 
    1212 
     13sub _hdlr_dug_score { 
     14    my ( $ctx, $args ) = @_; 
     15    my $entry = $ctx->stash('entry') 
     16        or return $ctx->_no_entry_error(); 
     17    my $score = $entry->votes_for( 'dug' ); 
     18    my $id = $entry->id; 
     19    my $html = <<HTML; 
     20<a href="javascript:void(0)" id="dug$id" onclick="dugScore('$id');">$score</a> 
     21HTML 
     22    return $html; 
     23} 
     24 
    13251; 
    1426__END__