PageSourceSearch

https://www.goo-net.com/common_v2/js/jquery.rating.js?171128

js goo-net.com collected 2026-10-01 10:29:52 UTC 5,147 bytes, 176 lines download raw bytes

1// JavaScript Document
2/*************************************************
3Star Rating System
4First Version: 21 November, 2006
5Second Version: 17 May, 2007
6Author: Ritesh Agrawal (http://php.scripts.psu.edu/rja171/widgets/rating.php)
7        email: ragrawal [at] gmail (dot) com
8Inspiration: Will Stuckey's star rating system (http://sandbox.wilstuckey.com/jquery-ratings/)
9Half-Star Addition: Karl Swedberg
10Demonstration: http://examples.learningjquery.com/rating/
11Usage: $('#rating').rating('url-to-post.php', {maxvalue:5, curvalue:0});
12
13arguments
14url : required -- post changes to 
15options
16  increment : 1, // value to increment by
17    maxvalue: number of stars
18    curvalue: number of selected stars
19    
20
21************************************************/
22
23//À±¤ÎÃͤò¼èÆÀ¤·¤ÆÉ½¼¨¤µ¤»¤ë add 2011.04.27
24function StarCount(id,count){
25    var tmp       = id;
26    var replace_id = id.replace('rate','starBoxCount');
27    $('#'+replace_id).text(count);
28    return true;
29}
30
31
32jQuery.fn.rating = function(url, options, fix) {
33    var settings = {
34        url : url, // post changes to 
35        increment : 1, // value to increment by
36        maxvalue  : 5,   // max number of stars
37        curvalue  : 0    // number of selected stars
38    };
39    
40    if(options) {
41        jQuery.extend(settings, options);
42    };
43    jQuery.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false});
44
45    var container = jQuery(this);
46
47    jQuery.extend(container, {
48        averageRating: settings.curvalue,
49        url: settings.url
50    });
51
52    settings.increment = (settings.increment < .75) ? .5 : 1;
53    var s = 0;
54    for(var i= 0; i <= settings.maxvalue ; i++){
55        if (i == 0) {
56            if(settings.cancel == true && fix != 1){
57                var div = '<div class="cancel"><a href="#0" title="ɾ²Á¤·¤Ê¤¤"></a></div>';
58                container.empty().append(div);
59            }
60        } else {
61            var $div = $('<div class="star"></div>')
62            .append('<a href="#'+i+'" title="ɾ²Á '+i+'/'+settings.maxvalue+'">'+i+'</a>')
63            .appendTo(container);
64            if (settings.increment == .5) {
65                if (s%2) {
66                    $div.addClass('star-left');
67                } else {
68                    $div.addClass('star-right');
69                }
70            }
71        }
72        i=i-1+settings.increment;
73        s++;
74    }
75
76    var stars = jQuery(container).children('.star');
77    var cancel = jQuery(container).children('.cancel');
78
79    stars
80    .mouseover(function(){
81        if (fix != 1) {
82            event.drain();
83            event.fill(this);
84        }
85    })
86    .mouseout(function(){
87        if (fix != 1) {
88            event.drain();
89            event.reset();
90        }
91    })
92    .focus(function(){
93        if (fix != 1) {
94            event.drain();
95            event.fill(this);
96        }
97    })
98    .blur(function(){
99        if (fix != 1) {
100            event.drain();
101            event.reset();
102        }
103    });
104
105    stars.click(function(){
106        if (fix != 1) {
107
108            if(settings.cancel == true){
109                settings.curvalue = (stars.index(this) * settings.increment) + settings.increment;
110                //À±¤Î¿ô¤ò¼èÆÀ¤·¤ÆÉ½¼¨¤µ¤»¤ë add 2011.04.27
111                StarCount(container[0].id,settings.curvalue);
112
113                return false;
114            } else if (settings.maxvalue == 1) {
115                settings.curvalue = (settings.curvalue == 0) ? 1 : 0;
116                $(this).toggleClass('on');
117                return false;
118            }
119            return true;
120        }
121    });
122
123
124    // cancel button events
125    if(cancel){
126        cancel
127        
128        .focus(function(){
129            if (fix != 1) {
130                event.drain();
131                jQuery(this).addClass('on');
132            }
133        })
134        .blur(function(){
135            if (fix != 1) {
136                event.reset();
137                jQuery(this).removeClass('on');
138            }
139        });
140
141        // click events.
142        cancel.click(function(){
143            if (fix != 1) {
144                event.drain();
145                settings.curvalue = 0;
146                //À±¤Î¿ô¤ò¼èÆÀ¤·¤ÆÉ½¼¨¤µ¤»¤ë add 2011.04.27
147                StarCount(container[0].id,settings.curvalue);
148            }
149            return false;
150        });
151    }
152
153    var event = {
154        fill: function(el){ // fill to the current mouse position.
155            var index = stars.index(el) + 1;
156            stars
157                .children('a').css('width', '100%').end()
158                .slice(0,index).addClass('starHover').end();
159        },
160        drain: function() { // drain all the stars.
161            stars
162                .filter('.on').removeClass('on').end()
163                .filter('.starHover').removeClass('starHover').end();
164        },
165        reset: function(){ // Reset the stars to the default index.
166            stars.slice(0,settings.curvalue / settings.increment).addClass('on').end();
167            if (fix == 1) { 
168                stars.slice(settings.curvalue / settings.increment,settings.maxvalue).addClass('off').end();
169            }
170        }
171    };    
172    event.reset();
173
174    return(this);
175
176};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.