r104101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104100‎ | r104101 | r104102 >
Date:23:22, 23 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Prevented classes from being removed and reset when they didn't actually change
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.HeadingView.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.ListItemView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.ListItemView.js
@@ -12,6 +12,7 @@
1313
1414 // Properties
1515 this.$icon = $( '<div class="es-listItemView-icon"></div>' ).prependTo( this.$ );
 16+ this.currentStylesHash = null;
1617
1718 // DOM Changes
1819 this.$.addClass( 'es-listItemView' );
@@ -26,20 +27,24 @@
2728 /* Methods */
2829
2930 es.ListItemView.prototype.setClasses = function() {
30 - var classes = this.$.attr( 'class' ),
31 - styles = this.model.getElementAttribute( 'styles' );
32 - this.$
33 - // Remove any existing level classes
34 - .attr(
35 - 'class',
36 - classes
37 - .replace( / ?es-listItemView-level[0-9]+/, '' )
38 - .replace( / ?es-listItemView-(bullet|number)/, '' )
39 - )
40 - // Set the list style class from the style on top of the stack
41 - .addClass( 'es-listItemView-' + styles[styles.length - 1] )
42 - // Set the list level class from the length of the stack
43 - .addClass( 'es-listItemView-level' + ( styles.length - 1 ) );
 31+ var styles = this.model.getElementAttribute( 'styles' ),
 32+ stylesHash = styles.join( '|' );
 33+ if ( this.currentStylesHash !== stylesHash ) {
 34+ this.currentStylesHash = stylesHash;
 35+ var classes = this.$.attr( 'class' );
 36+ this.$
 37+ // Remove any existing level classes
 38+ .attr(
 39+ 'class',
 40+ classes
 41+ .replace( / ?es-listItemView-level[0-9]+/, '' )
 42+ .replace( / ?es-listItemView-(bullet|number)/, '' )
 43+ )
 44+ // Set the list style class from the style on top of the stack
 45+ .addClass( 'es-listItemView-' + styles[styles.length - 1] )
 46+ // Set the list level class from the length of the stack
 47+ .addClass( 'es-listItemView-level' + ( styles.length - 1 ) );
 48+ }
4449 };
4550
4651 es.ListItemView.prototype.setNumber = function( number ) {
Index: trunk/extensions/VisualEditor/modules/es/views/es.HeadingView.js
@@ -10,6 +10,9 @@
1111 // Inheritance
1212 es.DocumentViewLeafNode.call( this, model );
1313
 14+ // Properties
 15+ this.currentLevelHash = null;
 16+
1417 // DOM Changes
1518 this.$.addClass( 'es-headingView' );
1619
@@ -23,13 +26,16 @@
2427 /* Methods */
2528
2629 es.HeadingView.prototype.setClasses = function() {
27 - var classes = this.$.attr( 'class' ),
28 - level = this.model.getElementAttribute( 'level' );
29 - this.$
30 - // Remove any existing level classes
31 - .attr( 'class', classes.replace( / ?es-headingView-level[0-9]+/, '' ) )
32 - // Add a new level class
33 - .addClass( 'es-headingView-level' + level );
 30+ var level = this.model.getElementAttribute( 'level' );
 31+ if ( level !== this.currentLevelHash ) {
 32+ this.currentLevelHash = level;
 33+ var classes = this.$.attr( 'class' );
 34+ this.$
 35+ // Remove any existing level classes
 36+ .attr( 'class', classes.replace( / ?es-headingView-level[0-9]+/, '' ) )
 37+ // Add a new level class
 38+ .addClass( 'es-headingView-level' + level );
 39+ }
3440 };
3541
3642 /* Registration */

Status & tagging log