Changeset 994
- Timestamp:
- 08/27/08 05:56:41 (3 months ago)
- Files:
-
- trunk/Dug/README.txt (modified) (1 diff)
- trunk/Dug/Template_Snippets.txt (modified) (2 diffs)
- trunk/Dug/plugins/Dug/config.yaml (modified) (1 diff)
- trunk/Dug/plugins/Dug/lib/Dug/App.pm (modified) (3 diffs)
- trunk/Dug/plugins/Dug/lib/Dug/Tag.pm (modified) (1 diff)
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.1 Dug - 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/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. 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 < a href="javascript:void(0)" onclick="dug('<$MTEntryID$>');">((<span id="dug_count_<$MTEntryID$>"><$MTDugCount$></span>))</a>3 <$mt:DugScore$> 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 dug(entry_id) { 9 10 // Dug Specific Functions 11 function dugScore(obj_id) { 12 var score = 1; 13 mtScore('dug', obj_id, score, 'dug-pending', 'dug-complete'); 14 } 15 function dugScoreResponse(obj_id, score) { mtScoreResponse('dug', obj_id, score, 'dug-pending', 'dug-complete') } 16 17 // Generic mtScoring Functions 18 function 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; 9 23 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; 12 27 xh.open('POST', url, true); 13 28 xh.onreadystatechange = function() { … … 22 37 xh.send(null); 23 38 } 24 function dug_response(count,entry_id) { 25 var el = document.getElementById('dug_count_' + entry_id); 26 if (el) el.innerHTML = count; 39 function 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 ); 27 46 } 47 28 48 </script> 49 trunk/Dug/plugins/Dug/config.yaml
r867 r994 1 1 id: dug 2 2 name: Dug 3 version: 0. 13 version: 0.2 4 4 description: Example plugin to explain the Ratings Framework 5 author_name: Six Apart, Ltd. 6 author_link: http://www.sixapart.com/ 5 7 6 8 applications: 7 9 comments: 8 10 methods: 9 dug_ dig: $dug::Dug::App::dig11 dug_score: $dug::Dug::App::score 10 12 11 13 tags: 12 14 function: 13 15 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 5 5 sub NAMESPACE { 'dug' } 6 6 7 sub dig{7 sub score { 8 8 my $app = shift; 9 9 my $q = $app->param; … … 21 21 my $count = $entry->votes_for( NAMESPACE() ); 22 22 23 $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1 )23 $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1, BuildIndexes => 1 ) 24 24 or return $app->handle_error( 25 25 $app->translate( "Publish failed: [_1]", $app->errstr ) ); … … 28 28 $app->{no_print_body} = 1; 29 29 require JSON; 30 $app->print("dug _response($count,$entry_id);");30 $app->print("dugScoreResponse($entry_id,$count);"); 31 31 return undef; 32 32 } trunk/Dug/plugins/Dug/lib/Dug/Tag.pm
r867 r994 11 11 } 12 12 13 sub _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> 21 HTML 22 return $html; 23 } 24 13 25 1; 14 26 __END__
