if(typeof jQuery == 'undefined'){ document.write(''); } var has_style=false,static_css='',static_css_prefix='',minimum_mode=false; if( document.styleSheets ) { for( var _wr_x = 0; _wr_x < document.styleSheets.length; _wr_x++ ) { if( typeof document.styleSheets[_wr_x] == 'undefined' ) continue; if( document.styleSheets[_wr_x].href && document.styleSheets[_wr_x].href.indexOf('php/widget-rating.php') + 1 ) { has_style=true; break; } } } if(!has_style){ var scrp = document.createElement('link'); scrp.type = 'text/css'; scrp.rel = 'stylesheet'; scrp.href = 'php/widget-rating.php?css'; try{ document.head.appendChild(scrp); } catch(err) { try{ document.body.appendChild(scrp); } catch(err) { try{ document.appendChild(scrp); } catch(err) {} } } } if(typeof widget_rating_obj == 'undefined'){ var widget_rating_obj = {}; var widget_rating_processing = {}; var widget_rating_click_callback = function(_wr_id,x,json_res,btn){ var val = json_res.val, o = widget_rating_obj[_wr_id]; if(typeof x == "undefined" || typeof o == "undefined"){ return; } $(btn).parent().parent().fadeOut(); $('.widget-rating-thanks',$(btn).parent().parent().parent()).html(json_res.message).fadeIn(); if(typeof o.settings['r'+x] != 'undefined'){ var ot = o.settings['r'+x].split(','); }else{ var ot = [ (val == 'up' || val == 'do') ? 'yn' : 's' ]; } switch(ot[0]){ case "s": if(typeof json_res.all_rating[x] != 'undefined'){ var w2 = parseFloat(json_res.all_rating[x]) * o.icon_width; $('.widget-rating-current',$(btn).parent().parent()).width(w2+'px'); } break; case "yn": if(typeof json_res.rating != 'undefined' && typeof json_res.rating[x] != 'undefined' && typeof json_res.rating[x][val] != 'undefined'){ $(btn).html(json_res.rating[x][val]); } break; } setTimeout(function(){ widget_rating_processing[_wr_id+'-'+x] = false; $(btn).parent().parent().fadeIn(); $('.widget-rating-thanks',$(btn).parent().parent().parent()).fadeOut(); }, 2000); }; var widget_rating_click = function(_wr_id,btn){ var val = $(btn).attr('rel'), x = $(btn).parent().parent().parent().attr('rel'), o = widget_rating_obj[_wr_id]; if(typeof x == "undefined" || typeof o == "undefined"){ return; } if(typeof widget_rating_processing[_wr_id+'-'+x] != 'undefined' && widget_rating_processing[_wr_id+'-'+x] == true){ return; } widget_rating_processing[_wr_id+'-'+x] = true; $.ajax({ type: "GET", url: "php/widget-rating.php?click="+escape(_wr_id)+"&x="+x+"&val="+val+"&m="+escape( (typeof o.thanks[x] != 'undefined') ? o.thanks[x] : 'Thanks!' ), dataType: "json", success: function(json_res){ widget_rating_click_callback(_wr_id,x,json_res,btn); }, error: function(){ alert('Widget Rating: Unable to record click for "'+_wr_id+'"'); } }); }; var widget_rating_callback = function(_wr_id,json_res){ var o = widget_rating_obj[_wr_id]; if(typeof json_res.rating != undefined){ o.rating = json_res.rating; }else{ o.rating = 0; } if(typeof json_res.all_rating != undefined){ o.all_rating = json_res.all_rating; }else{ o.all_rating = 0; } var count = parseInt(o.settings.r); var max_width = 0; static_css = ''; var exists = true, bound=false; if( $('.widget-rating-rate', o.holder).length<1){ exists = false; } if(exists){ if(typeof o.all_rating != 'undefined'){ for(var xxx in o.all_rating){ var rating = parseFloat(o.all_rating[xxx]); $('.widget-rating-'+xxx+' .widget-rating-current').width(rating * 25); } } if(typeof o.rating != 'undefined'){ for(var xxx in o.rating){ var rating_yn_up = 0,rating_yn_do = 0; if(typeof o.rating[xxx]['up'] != 'undefined'){ rating_yn_up = parseFloat(o.rating[xxx]['up']); } if(typeof o.rating[xxx]['do'] != 'undefined'){ rating_yn_do = parseFloat(o.rating[xxx]['do']); } $('.widget-rating-'+xxx+' .widget-rating-up a').html(rating_yn_up); $('.widget-rating-'+xxx+' .widget-rating-do a').html(rating_yn_do); } } }else{ for(var x = 0;x < count;x++){ if(!exists){ $(o.holder).append( '
' ); } var ot = o.settings['r'+x].split(','); o.thanks[x] = ( typeof o.thanks[x] != 'undefined' ) ? o.thanks[x] : "Thanks!"; if(!exists){ $('.widget-rating-'+x, o.holder).append('
'+o.thanks[x]+'
'); } switch(ot[0]){ case "s": o.icon_width = 25; var rating=0; if(typeof o.all_rating != 'undefined' && typeof o.all_rating[x] != 'undefined'){ rating = parseFloat(o.all_rating[x]); } var w1 = parseInt(ot[2] * o.icon_width); max_width = Math.max(w1,max_width); var w2 = rating * o.icon_width; if(!exists){ var li_css = 'background-image: url('+ot[1]+');'; $('.widget-rating-'+x, o.holder).append(''); var title = (typeof o.titles[x] != 'undefined') ? o.titles[x] : ''; $('.widget-rating-'+x, o.holder).append(' '+title+''); o.current = $('
  • '); $('.widget-rating-'+x+' ul', o.holder).append(o.current); }else{ $('.widget-rating-'+x+' .widget-rating-current').width(w2); } if(!exists){ for(var cc = 0; cc < ot[2]; cc++){ if(!exists){ var t = $('
  • '+(cc+1)+'
  • '); }else{ var t = $('.widget-rating-'+x+'_'+(cc+1)+''); } if(!t.length)continue; static_css += '' + static_css_prefix + ' .widget-rating-'+x+'_'+(cc+1)+' a,' + static_css_prefix + ' .widget-rating-'+x+'_'+(cc+1)+' a:link,' + static_css_prefix + ' .widget-rating-'+x+'_'+(cc+1)+' a:visited{ background-image:none !important; width: '+o.icon_width+'px !important; left:'+(o.icon_width * cc)+'px !important; }'; static_css += '' + static_css_prefix + ' .widget-rating-'+x+'_'+(cc+1)+' a:hover{ background-image:url('+ot[1]+') !important; width: '+((cc+1)*o.icon_width)+'px !important; left:0px !important; }'; $('a',t).css('left', (o.icon_width * cc) ); $('a',t).hover( function(){ $(this).css('left', 0 ); $(this).width( parseInt($(this).attr('rel')) * o.icon_width); $(this).css('backgroundImage', $(this).attr('bgs') ); }, function(){ $(this).css('left', $(this).attr('l') ) .width( o.icon_width); $(this).css('backgroundImage', 'none' ); } ); $('a',t).click(function(){ widget_rating_click(_wr_id,this); return false; }); bound=true; if(!exists){ $('.widget-rating-'+x+' ul', o.holder).append(t); } } } break; case "yn": var rating_yn_up = 0; var rating_yn_do = 0; if(typeof o.rating != 'undefined' && typeof o.rating[x] != 'undefined'){ if(typeof o.rating[x]['up'] != 'undefined'){ rating_yn_up = parseFloat(o.rating[x]['up']); } if(typeof o.rating[x]['do'] != 'undefined'){ rating_yn_do = parseFloat(o.rating[x]['do']); } } if(!exists){ var li_css = 'background-image: url('+ot[1]+');'; var w1 = 88; max_width = Math.max(w1,max_width); $('.widget-rating-'+x, o.holder).append(''); var title = (typeof o.titles[x] != 'undefined') ? o.titles[x] : ''; $('.widget-rating-'+x, o.holder).append(' '+title+''); var rate_up = $('
  • '+(rating_yn_up)+'
  • '); var rate_do = $('
  • '+(rating_yn_do)+'
  • '); }else{ var rate_up = $('.widget-rating-'+x+' .widget-rating-up'); var rate_do = $('.widget-rating-'+x+' .widget-rating-do'); } if(!rate_up.length && !rate_do.length)continue; if(exists){ $('a',rate_up).html(rating_yn_up); $('a',rate_do).html(rating_yn_do); } $('a',rate_up).click(function(){ widget_rating_click(_wr_id,this); return false; }); bound = true; $('a',rate_do).click(function(){ widget_rating_click(_wr_id,this); return false; }); if(!exists){ $('.widget-rating-'+x+' ul', o.holder).append(rate_up); $('.widget-rating-'+x+' ul', o.holder).append(rate_do); } break; } if(!exists){ $('.widget-rating-'+x+' .widget-rating-thanks',o.holder).width((w1-5)+'px'); } } } if(!bound){ $('a',o.holder).click(function(){ widget_rating_click(_wr_id,this); return false; }); } if(!exists){ $('span',o.holder).css('paddingLeft',(max_width)+'px'); } if(typeof widget_rating_complete_callback == 'function'){ widget_rating_complete_callback(_wr_id); } }; var widget_rating_load = function(_wr_id){ $.ajax({ type: "GET", url: "php/widget-rating.php?id="+escape(_wr_id), dataType: "json", success: function(res){ widget_rating_callback(_wr_id,res); }, error: function(){ alert('Widget Rating: Unable to load settings for "'+_wr_id+'"'); } }); }; var widget_rating_gogo = function(){ if(typeof jQuery == 'undefined'){ alert('jQuery failed to load automatically for the Widget Rating script.'); return; } $('.widget-rating').each(function(){ var _wr_id = $(this).attr('id'); if(typeof widget_rating_obj[_wr_id] != 'undefined'){ alert('Widget Rating: You have multuple "'+_wr_id+'" widgets on this single page. Please only have one.'); return; } var t = {}; if(typeof $(this).attr('t') != 'undefined'){ t = $(this).attr('t').split('|'); }else{ if( $('span:last',this).html() && $('span:last',this).html() != ''){ t = $('span:last',this).html().split('|'); } } widget_rating_obj[_wr_id] = { id : _wr_id, holder : this, titles : t, settings : {}, thanks : [] }; if( typeof $(this).attr('thanks') != 'undefined' ){ widget_rating_obj[_wr_id].thanks = $(this).attr('thanks').split('|'); } var rel = $(this).attr('rel'); if(typeof rel == 'undefined'){ rel = ''; if( $('span:first',this).html() && $('span:first',this).html() != ''){ rel = $('span:first',this).html(); } } var _wr_temp = rel.split('|'); for(var i in _wr_temp){ var _wr_temp2 = _wr_temp[i].split('='); widget_rating_obj[_wr_id].settings[_wr_temp2[0]] = _wr_temp2[1]; } widget_rating_load(_wr_id); }); }; if(typeof jQuery != 'undefined'){ $(window).ready(widget_rating_gogo); }else{ window.onload = widget_rating_gogo; } }