r73522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73521‎ | r73522 | r73523 >
Date:12:55, 22 September 2010
Author:catrope
Status:deferred
Tags:
Comment:
ArticleAssessment: Followup to r73256: use typeof foo != 'undefined' as this actually prevents JS errors. See also CR
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.min.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.js
@@ -270,7 +270,8 @@
271271 'afterGetRatingData' : function( data ) {
272272 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
273273 // add the correct data to the markup
274 - if ( data.query && data.query.articleassessment && data.query.articleassessment.length > 0 ) {
 274+ if ( typeof data.query != 'undefined' && typeof data.query.articleassessment != 'undefined' &&
 275+ typeof data.query.articleassessment[0] != 'undefined' ) {
275276 for ( var r in data.query.articleassessment[0].ratings ) {
276277 var rating = data.query.articleassessment[0].ratings[r],
277278 $rating = $( '#' + rating.ratingdesc ),
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -270,7 +270,8 @@
271271 'afterGetRatingData' : function( data ) {
272272 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
273273 // add the correct data to the markup
274 - if ( data.query && data.query.articleassessment && data.query.articleassessment.length > 0 ) {
 274+ if ( typeof data.query != 'undefined' && typeof data.query.articleassessment != 'undefined' &&
 275+ typeof data.query.articleassessment[0] != 'undefined' ) {
275276 for ( var r in data.query.articleassessment[0].ratings ) {
276277 var rating = data.query.articleassessment[0].ratings[r],
277278 $rating = $( '#' + rating.ratingdesc ),
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.min.js
@@ -44,7 +44,7 @@
4545 $structure.find('#article-assessment').data('articleAssessment-context',{'settings':settings,'config':config});$('#catlinks').before($structure);$.ArticleAssessment.fn.hideRatings();if($('#article-assessment-rate').height()>$('#article-assessment-ratings').height()){$('#article-assessment-ratings').css('minHeight',$('#article-assessment-rate').height());}else{$('#article-assessment-rate').css('minHeight',$('#article-assessment-ratings').height());}
4646 $.ArticleAssessment.fn.getRatingData();$('.rating-field').each(function(){$(this).wrapAll('<div class="rating-field"></div>').parent().stars({inputType:'select',callback:function(value,link){value.$stars.each(function(){$(this).removeClass('ui-stars-star-stale').removeClass('ui-stars-star-rated');$('#article-assessment input:disabled').removeAttr('disabled');});}});});$('.field-wrapper label[original-title]').each(function(){$(this).after($('<span class="rating-field-hint" />').attr('original-title',$(this).attr('original-title')).tipsy({gravity:'se',opacity:'0.9'}));});$('#article-assessment').submit(function(){$.ArticleAssessment.fn.submitRating();return false;});$('#article-assessment input[type=submit]').attr('disabled','disabled');},'showRatings':function(){$('#article-assessment-ratings').removeClass('article-assessment-ratings-disabled').find('.article-assessment-show-ratings').hide().end().find('.article-assessment-hide-ratings').show();return false;},'hideRatings':function(){$('#article-assessment-ratings').addClass('article-assessment-ratings-disabled').find('.article-assessment-hide-ratings').hide().end().find('.article-assessment-show-ratings').show();return false;},'getRatingData':function(){var config=$('#article-assessment').data('articleAssessment-context').config;var requestData={'action':'query','list':'articleassessment','aapageid':config.pageID,'aauserrating':1,'format':'json'}
4747 if(config.userID.length==32){requestData.aaanontoken=config.userID;}
48 -var request=$.ajax({url:wgScriptPath+'/api.php',data:requestData,dataType:'json',success:$.ArticleAssessment.fn.afterGetRatingData,error:function(XMLHttpRequest,textStatus,errorThrown){$.ArticleAssessment.fn.flashNotice($.ArticleAssessment.fn.getMsg('articleassessment-error'),{'class':'article-assessment-error-msg'});}});},'afterGetRatingData':function(data){var settings=$('#article-assessment').data('articleAssessment-context').settings;if(data.query&&data.query.articleassessment&&data.query.articleassessment.length>0){for(var r in data.query.articleassessment[0].ratings){var rating=data.query.articleassessment[0].ratings[r],$rating=$('#'+rating.ratingdesc),count=rating.count,total=(rating.total/count).toFixed(1),label=$.ArticleAssessment.fn.getMsg('articleassessment-noratings',[total,count]);$rating.find('.article-assessment-rating-field-value').text(total).end().find('.article-assessment-rating-count').text(label);if(rating.userrating){var $rateControl=$('#'+rating.ratingdesc.replace('rating','rate')+' .rating-field');$rateControl.stars('select',rating.userrating);$.ArticleAssessment.fn.showRatings();}}
 48+var request=$.ajax({url:wgScriptPath+'/api.php',data:requestData,dataType:'json',success:$.ArticleAssessment.fn.afterGetRatingData,error:function(XMLHttpRequest,textStatus,errorThrown){$.ArticleAssessment.fn.flashNotice($.ArticleAssessment.fn.getMsg('articleassessment-error'),{'class':'article-assessment-error-msg'});}});},'afterGetRatingData':function(data){var settings=$('#article-assessment').data('articleAssessment-context').settings;if(typeof data.query!='undefined'&&typeof data.query.articleassessment!='undefined'&&typeof data.query.articleassessment[0]!='undefined'){for(var r in data.query.articleassessment[0].ratings){var rating=data.query.articleassessment[0].ratings[r],$rating=$('#'+rating.ratingdesc),count=rating.count,total=(rating.total/count).toFixed(1),label=$.ArticleAssessment.fn.getMsg('articleassessment-noratings',[total,count]);$rating.find('.article-assessment-rating-field-value').text(total).end().find('.article-assessment-rating-count').text(label);if(rating.userrating){var $rateControl=$('#'+rating.ratingdesc.replace('rating','rate')+' .rating-field');$rateControl.stars('select',rating.userrating);$.ArticleAssessment.fn.showRatings();}}
4949 if(typeof data.query.articleassessment[0].stale!='undefined'){$('.ui-stars-star-on').addClass('ui-stars-star-stale');var msg=$.ArticleAssessment.fn.getMsg('articleassessment-stalemessage-norevisioncount');$.ArticleAssessment.fn.flashNotice(msg,{'class':'article-assessment-stale-msg'});}else{$('.ui-stars-star-on').addClass('ui-stars-star-rated');}}
5050 $('.article-assessment-rating-field-value').each(function(){$(this).css({'width':120-(120*(parseFloat($(this).text())/5))+'px'})});},'submitRating':function(){var config=$('#article-assessment').data('articleAssessment-context').config;$.ArticleAssessment.fn.flashNotice();$('.rating-field').stars('disable');$('#article-assessment input').attr('disabled','disabled');var results={};$('.rating-field input').each(function(){var fieldName=$(this).attr('name').match(/\[([a-zA-Z0-9\-]*)\]/)[1];results[fieldName]=$(this).val();});var request=$.ajax({url:wgScriptPath+'/api.php',type:'POST',data:{'action':'articleassessment','revid':config.revID,'pageid':config.pageID,'r1':results['wellsourced'],'r2':results['neutrality'],'r3':results['completeness'],'r4':results['readability'],'anontoken':config.userID,'format':'json'},dataType:'json',success:$.ArticleAssessment.fn.afterSubmitRating,error:function(XMLHttpRequest,textStatus,errorThrown){$.ArticleAssessment.fn.flashNotice($.ArticleAssessment.fn.getMsg('articleassessment-error'),{'class':'article-assessment-error-msg'});}});},'afterSubmitRating':function(data){$.ArticleAssessment.fn.getRatingData();$('.ui-stars-star-on').addClass('ui-stars-star-rated');$('.rating-field').stars('enable');$('#article-assessment input:disabled').removeAttr('disabled');$.ArticleAssessment.fn.showRatings();$.ArticleAssessment.fn.flashNotice($.ArticleAssessment.fn.getMsg('articleassessment-thanks'),{'class':'article-assessment-success-msg'});},'flashNotice':function(text,options){if(arguments.length==0){$('#article-assessment .article-assessment-flash').remove();}else{$('#article-assessment .article-assessment-flash').remove();var className=options['class'];$msg=$('<div />').addClass('article-assessment-flash').html(text);if(options['class']){$msg.addClass(options['class']);}
5151 $('#article-assessment .article-assessment-submit').append($msg);}},'showFeedback':function(){$.ArticleAssessment.fn.withJUI(function(){var $dialogDiv=$('#article-assessment-dialog');if($dialogDiv.size()==0){$dialogDiv=$('<div id="article-assessment-dialog" class="loading" />').dialog({width:600,height:400,bgiframe:true,autoOpen:true,modal:true,title:$.ArticleAssessment.fn.getMsg('articleassessment-survey-title'),close:function(){$(this).dialog('option','height',400).find('.article-assessment-success-msg, .article-assessment-error-msg').remove().end().find('form').show();}});$dialogDiv.load(wgScript+'?title=Special:SimpleSurvey&survey=articlerating&raw=1',function(){$(this).find('form').bind('submit',$.ArticleAssessment.fn.submitFeedback);$(this).removeClass('loading');});}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73256Add a little bulletproofing.bharris23:07, 17 September 2010

Status & tagging log