r74267 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74266‎ | r74267 | r74268 >
Date:19:48, 4 October 2010
Author:catrope
Status:deferred
Tags:
Comment:
ArticleAssessment: Fix bug in jquery.stars plugin that was contributing to bug 22680 (unconditionally setting an unload handler, breaking bfcache in Firefox)
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.min.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -24,13 +24,13 @@
2525 array( 'src' => 'js/ArticleAssessment.js', 'version' => 4 ),
2626 array( 'src' => 'js/jquery.cookie.js', 'version' => 1 ),
2727 array( 'src' => 'js/jquery.tipsy.js', 'version' => 1 ),
28 - array( 'src' => 'js/jquery.stars.js', 'version' => 1 ),
 28+ array( 'src' => 'js/jquery.stars.js', 'version' => 2 ),
2929 ),
3030 'combined' => array(
31 - array( 'src' => 'js/ArticleAssessment.combined.js', 'version' => 3 )
 31+ array( 'src' => 'js/ArticleAssessment.combined.js', 'version' => 4 )
3232 ),
3333 'minified' => array(
34 - array( 'src' => 'js/ArticleAssessment.combined.min.js', 'version' => 3 )
 34+ array( 'src' => 'js/ArticleAssessment.combined.min.js', 'version' => 4 )
3535 ),
3636 );
3737
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.js
@@ -804,12 +804,15 @@
805805 /*
806806 * Clean up to avoid memory leaks in certain versions of IE 6
807807 */
808 - $(window).unload(function(){
809 - self.$cancel.unbind('.stars');
810 - self.$stars.unbind('.stars');
811 - self.$form.unbind('.stars');
812 - self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
813 - });
 808+ // CHANGE: Only do this in IE, so as not to break bfcache in Firefox --catrope
 809+ if ( window.attachEvent && !window.addEventListener ) {
 810+ $(window).unload(function(){
 811+ self.$cancel.unbind('.stars');
 812+ self.$stars.unbind('.stars');
 813+ self.$form.unbind('.stars');
 814+ self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
 815+ });
 816+ }
814817 /*
815818 * Star selection helpers
816819 */
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.combined.min.js
@@ -62,7 +62,8 @@
6363 o.val2id[el.value]=starId;o.id2val[starId]=el.value;o.id2title[starId]=el.title;if(el.isDefault){o.checked=starId;o.value=o.defaultValue=el.value;o.title=el.title;}
6464 var $s=$('<div/>').addClass(o.starClass);var $a=$('<a/>').attr('title',o.showTitles?el.title:'').text(el.value);if(o.split){var oddeven=(starId%o.split);var stwidth=Math.floor(o.starWidth/o.split);$s.width(stwidth);$a.css('margin-left','-'+(oddeven*stwidth)+'px');}
6565 starId++;return $s.append($a).get(0);});o.items=starId;o.isSelect?this.$selec.remove():this.$rboxs.remove();this.$cancel=$('<div/>').addClass(o.cancelClass).append($('<a/>').attr('title',o.showTitles?o.cancelTitle:'').text(o.cancelValue));o.cancelShow&=!o.disabled&&!o.oneVoteOnly;o.cancelShow&&this.element.append(this.$cancel);this.element.append(this.$stars);if(o.checked===undefined){o.checked=-1;o.value=o.defaultValue=o.cancelValue;o.title='';}
66 -this.$value=$("<input type='hidden' name='"+o.name+"' value='"+o.value+"' />");this.element.append(this.$value);this.$stars.bind('click.stars',function(e){if(!o.forceSelect&&o.disabled)return false;var i=self.$stars.index(this);o.checked=i;o.value=o.id2val[i];o.title=o.id2title[i];self.$value.attr({disabled:o.disabled?'disabled':'',value:o.value});fillTo(i,false);self.disableCancel();!o.forceSelect&&self.callback(e,'star');}).bind('mouseover.stars',function(){if(o.disabled)return false;var i=self.$stars.index(this);fillTo(i,true);}).bind('mouseout.stars',function(){if(o.disabled)return false;fillTo(self.options.checked,false);});this.$cancel.bind('click.stars',function(e){if(!o.forceSelect&&(o.disabled||o.value==o.cancelValue))return false;o.checked=-1;o.value=o.cancelValue;o.title='';self.$value.val(o.value);o.disableValue&&self.$value.attr({disabled:'disabled'});fillNone();self.disableCancel();!o.forceSelect&&self.callback(e,'cancel');}).bind('mouseover.stars',function(){if(self.disableCancel())return false;self.$cancel.addClass(o.cancelHoverClass);fillNone();self.showCap(o.cancelTitle);}).bind('mouseout.stars',function(){if(self.disableCancel())return false;self.$cancel.removeClass(o.cancelHoverClass);self.$stars.triggerHandler('mouseout.stars');});this.$form.bind('reset.stars',function(){!o.disabled&&self.select(o.defaultValue);});$(window).unload(function(){self.$cancel.unbind('.stars');self.$stars.unbind('.stars');self.$form.unbind('.stars');self.$selec=self.$rboxs=self.$stars=self.$value=self.$cancel=self.$form=null;});function fillTo(index,hover){if(index!=-1){var addClass=hover?o.starHoverClass:o.starOnClass;var remClass=hover?o.starOnClass:o.starHoverClass;self.$stars.eq(index).prevAll('.'+o.starClass).andSelf().removeClass(remClass).addClass(addClass);self.$stars.eq(index).nextAll('.'+o.starClass).removeClass(o.starHoverClass+' '+o.starOnClass);self.showCap(o.id2title[index]);}
 66+this.$value=$("<input type='hidden' name='"+o.name+"' value='"+o.value+"' />");this.element.append(this.$value);this.$stars.bind('click.stars',function(e){if(!o.forceSelect&&o.disabled)return false;var i=self.$stars.index(this);o.checked=i;o.value=o.id2val[i];o.title=o.id2title[i];self.$value.attr({disabled:o.disabled?'disabled':'',value:o.value});fillTo(i,false);self.disableCancel();!o.forceSelect&&self.callback(e,'star');}).bind('mouseover.stars',function(){if(o.disabled)return false;var i=self.$stars.index(this);fillTo(i,true);}).bind('mouseout.stars',function(){if(o.disabled)return false;fillTo(self.options.checked,false);});this.$cancel.bind('click.stars',function(e){if(!o.forceSelect&&(o.disabled||o.value==o.cancelValue))return false;o.checked=-1;o.value=o.cancelValue;o.title='';self.$value.val(o.value);o.disableValue&&self.$value.attr({disabled:'disabled'});fillNone();self.disableCancel();!o.forceSelect&&self.callback(e,'cancel');}).bind('mouseover.stars',function(){if(self.disableCancel())return false;self.$cancel.addClass(o.cancelHoverClass);fillNone();self.showCap(o.cancelTitle);}).bind('mouseout.stars',function(){if(self.disableCancel())return false;self.$cancel.removeClass(o.cancelHoverClass);self.$stars.triggerHandler('mouseout.stars');});this.$form.bind('reset.stars',function(){!o.disabled&&self.select(o.defaultValue);});if(window.attachEvent&&!window.addEventListener){$(window).unload(function(){self.$cancel.unbind('.stars');self.$stars.unbind('.stars');self.$form.unbind('.stars');self.$selec=self.$rboxs=self.$stars=self.$value=self.$cancel=self.$form=null;});}
 67+function fillTo(index,hover){if(index!=-1){var addClass=hover?o.starHoverClass:o.starOnClass;var remClass=hover?o.starOnClass:o.starHoverClass;self.$stars.eq(index).prevAll('.'+o.starClass).andSelf().removeClass(remClass).addClass(addClass);self.$stars.eq(index).nextAll('.'+o.starClass).removeClass(o.starHoverClass+' '+o.starOnClass);self.showCap(o.id2title[index]);}
6768 else fillNone();};function fillNone(){self.$stars.removeClass(o.starOnClass+' '+o.starHoverClass);self.showCap('');};this.select(o.value);o.disabled&&this.disable();},disableCancel:function(){var o=this.options,disabled=o.disabled||o.oneVoteOnly||(o.value==o.cancelValue);if(disabled)this.$cancel.removeClass(o.cancelHoverClass).addClass(o.cancelDisabledClass);else this.$cancel.removeClass(o.cancelDisabledClass);this.$cancel.css('opacity',disabled?0.5:1);return disabled;},disableAll:function(){var o=this.options;this.disableCancel();if(o.disabled)this.$stars.filter('div').addClass(o.starDisabledClass);else this.$stars.filter('div').removeClass(o.starDisabledClass);},showCap:function(s){var o=this.options;if(o.captionEl)o.captionEl.text(s);},value:function(){return this.options.value;},select:function(val){var o=this.options,e=(val==o.cancelValue)?this.$cancel:this.$stars.eq(o.val2id[val]);o.forceSelect=true;e.triggerHandler('click.stars');o.forceSelect=false;},selectID:function(id){var o=this.options,e=(id==-1)?this.$cancel:this.$stars.eq(id);o.forceSelect=true;e.triggerHandler('click.stars');o.forceSelect=false;},enable:function(){this.options.disabled=false;this.disableAll();},disable:function(){this.options.disabled=true;this.disableAll();},destroy:function(){this.$form.unbind('.stars');this.$cancel.unbind('.stars').remove();this.$stars.unbind('.stars').remove();this.$value.remove();this.element.unbind('.stars').html(this.element.data('former.stars')).removeData('stars');return this;},callback:function(e,type){var o=this.options;o.callback&&o.callback(this,type,o.value,e);o.oneVoteOnly&&!o.disabled&&this.disable();}}
6869 $.fn.stars=function(){var args=Array.prototype.slice.call(arguments);var out=$(this);$(this).each(function(){var context=$(this).data('stars-context');if(typeof context=='undefined'||context==null){context=$.extend({},{element:$(this),options:$.stars.defaults},$.stars);}
6970 if(args.length>0){if(typeof args[0]=='object'){context.options=$.extend({},context.options,args[0]);$.stars.create.call(context);}else if(typeof args[0]=='string'){var funcName=args[0];out=$.stars[funcName].call(context,args.slice(1))||out;}}else{$.stars.create.call(context);}
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js
@@ -172,12 +172,15 @@
173173 /*
174174 * Clean up to avoid memory leaks in certain versions of IE 6
175175 */
176 - $(window).unload(function(){
177 - self.$cancel.unbind('.stars');
178 - self.$stars.unbind('.stars');
179 - self.$form.unbind('.stars');
180 - self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
181 - });
 176+ // CHANGE: Only do this in IE, so as not to break bfcache in Firefox --catrope
 177+ if ( window.attachEvent && !window.addEventListener ) {
 178+ $(window).unload(function(){
 179+ self.$cancel.unbind('.stars');
 180+ self.$stars.unbind('.stars');
 181+ self.$form.unbind('.stars');
 182+ self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
 183+ });
 184+ }
182185 /*
183186 * Star selection helpers
184187 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r742681.16wmf4: MFT r74252, r74259, r74267catrope19:50, 4 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68229UsabilityInitiative: (bug 22680) Make EditWarning no longer break Firefox's p...catrope18:28, 18 June 2010

Status & tagging log