Make WordPress Core

Changeset 24636


Ignore:
Timestamp:
07/10/2013 05:40:45 AM (13 years ago)
Author:
markjaquith
Message:

Revisions: remove some redundant code.

  • Move some slider code into the slider view that was loitering in the checkmark view.
  • this.$(), not $().
  • Cache a selector.
  • toggleClass(), not addClass() with a ternary.
  • Remove two classes with a single removeClass().

See #24425.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/revisions.js

    r24629 r24636  
    496496
    497497                updateCompareTwoMode: function() {
    498                         if ( this.model.get('compareTwoMode') ) {
    499                                 $('.compare-two-revisions').prop( 'checked', true );
    500                                 // in RTL mode the 'left handle' is the second in the slider, 'right' is first
    501                                 $('.wp-slider a.ui-slider-handle').first().addClass( isRtl ? 'right-handle' : 'left-handle' );
    502                                 $('.wp-slider a.ui-slider-handle').last().addClass( isRtl ? 'left-handle' : 'right-handle' );
    503                         } else {
    504                                 $('.compare-two-revisions').prop( 'checked', false );
    505                                 $('.wp-slider a.ui-slider-handle').removeClass('left-handle').removeClass('right-handle');
    506                         }
    507 
     498                        this.$('.compare-two-revisions').prop( 'checked', this.model.get('compareTwoMode') );
    508499                },
    509500
     
    721712
    722713                updateSliderSettings: function() {
     714                        var handles;
     715
    723716                        if ( this.model.get('compareTwoMode') ) {
    724717                                var leftValue, rightValue;
     
    751744                                        range: true // Range mode ensures handles can't cross
    752745                                } );
     746
     747                                handles = this.$('a.ui-slider-handle');
     748                                // in RTL mode the 'left handle' is the second in the slider, 'right' is first
     749                                handles.first()
     750                                        .toggleClass( 'right-handle', !! isRtl )
     751                                        .toggleClass( 'left-handle', ! isRtl );
     752                                handles.last()
     753                                        .toggleClass( 'left-handle', !! isRtl )
     754                                        .toggleClass( 'right-handle', ! isRtl );
     755
    753756                        } else {
    754757                                this.$el.slider( { // Set handle to current to model
    755758                                        // Reverse order for RTL.
    756                                         value: isRtl ?  this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 1 :
     759                                        value: isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 1 :
    757760                                                                        this.model.revisions.indexOf( this.model.get('to') ),
    758761                                        values: null, // Clear existing two handled values
    759762                                        range: false
    760763                                } );
    761                         }
    762 
    763                         if ( this.model.get('compareTwoMode') ){
    764                                 // in RTL mode the 'left handle' is the second in the slider, 'right' is first
    765                                 $( 'a.ui-slider-handle', this.$el )
    766                                         .first()
    767                                         .addClass( isRtl ? 'right-handle' : 'left-handle' )
    768                                         .removeClass( isRtl ? 'left-handle' : 'right-handle' );
    769                                 $( 'a.ui-slider-handle', this.$el )
    770                                         .last()
    771                                         .addClass( isRtl ? 'left-handle' : 'right-handle' )
    772                                         .removeClass( isRtl ? 'right-handle' : 'left-handle' );
     764                                this.$('a.ui-slider-handle').removeClass('left-handle right-handle');
    773765                        }
    774766                },
Note: See TracChangeset for help on using the changeset viewer.