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

abstracting js and syncing with FavoriteScoring? and Dug plugins

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 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