Make WordPress Core

Ticket #24425: 24425.draft.37.diff

File 24425.draft.37.diff, 5.3 KB (added by adamsilverstein, 12 years ago)

two handled rtl, bug fixes

  • wp-admin/js/revisions.js

     
    357357
    358358                initialize: function() {
    359359                        this.$el.html( this.template() );
    360                         this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
    361360                },
    362361
    363362                updateCompareTwoMode: function() {
    364363                        if ( this.model.get( 'compareTwoMode' ) ) {
    365                                 $( '.compare-two-revisions' ).parent().css('border', '1px solid #f00;').prop( 'checked', true );
     364                                $( '.compare-two-revisions' ).prop( 'checked', true );
    366365                                $( '.revisions-control-frame' ).addClass( 'comparing-two-revisions' );
    367366                                // in RTL mode the 'left handle' is the second in the slider, 'right' is first
    368367                                $( '.wp-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' );
     
    392391                        // Hide compare two mode toggle when fewer than three revisions.
    393392                        if ( this.model.revisions.length < 3 )
    394393                                $( '.revision-toggle-compare-mode' ).hide();
     394
     395                        this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
     396
     397                        // Update the mode in case route has set it
     398                        this.updateCompareTwoMode();
    395399                }
    396400
    397401        });
     
    542546                        this.settings.attributes.value = this.model.revisions.indexOf(
    543547                                this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) );
    544548
     549                        // And update the slider in case the route has set it.
     550                        this.updateSliderSettings();
     551
    545552                        this.slide( '', this.settings.attributes );
    546553
    547554                        this.$el.slider( this.settings.toJSON() );
     
    556563                        // Listen for changes in the diffId
    557564                        this.listenTo( this.model, 'change:diffId', this.diffIdChanged );
    558565
     566
     567
    559568                },
    560569
    561570                mousemove: function( e ) {
     
    589598                },
    590599
    591600                updateSliderSettings: function() {
    592                         if ( isRtl ) {
    593                                 this.$el.slider( { // Order reversed in RTL mode
    594                                         value: this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1
     601                        if ( this.model.get( 'compareTwoMode' ) ) {
     602                                var leftValue, rightValue;
     603
     604                                // In single handle mode, the 1st stored revision is 'blank' and the 'from' model is not set
     605                                // In this case we move the to index over one
     606                                if ( 'undefined' == typeof this.model.get( 'from' ) ) {
     607                                        if ( isRtl ) {
     608                                                leftValue  = this.model.revisions.length -  this.model.revisions.indexOf( this.model.get( 'to' ) ) - 2;
     609                                                rightValue = leftValue + 1;
     610                                        } else {
     611                                                leftValue  = this.model.revisions.indexOf( this.model.get( 'to' ) );
     612                                                rightValue = leftValue + 1;
     613                                        }
     614                                } else {
     615                                        leftValue  = isRtl ?    this.model.revisions.length -  this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 :
     616                                                                                        this.model.revisions.indexOf( this.model.get( 'from' ) ),
     617                                        rightValue = isRtl ?    this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'from' ) ) - 1 :
     618                                                                                        this.model.revisions.indexOf( this.model.get( 'to' ) );
     619                                }
     620
     621                                // Set handles to current from / to models.
     622                                // Reverse order for RTL
     623                                this.$el.slider( {
     624                                        values: [
     625                                                leftValue,
     626                                                rightValue
     627                                                        ],
     628                                        value: null,
     629                                        range: true // Range mode ensures handles can't cross
    595630                                } );
    596631                        } else {
    597                                 if ( this.model.get( 'compareTwoMode' ) ) {
    598                                         this.$el.slider( { // Set handles to current from/to models
    599                                                 values: [
    600                                                         this.model.revisions.indexOf( this.model.get( 'from' ) ),
    601                                                         this.model.revisions.indexOf( this.model.get( 'to' ) )
    602                                                 ],
    603                                                 value: null,
    604                                                 range: true // Range mode ensures handles can't cross
    605                                         } );
    606                                 } else {
    607                                         this.$el.slider( { // Set handle to current to model
    608                                                 value: this.model.revisions.indexOf( this.model.get( 'to' ) ),
    609                                                 values: null, // Clear existing two handled values
    610                                                 range: false
    611                                         } );
    612                                 }
     632                                this.$el.slider( { // Set handle to current to model
     633                                        // Reverse order for RTL.
     634                                        value: isRtl ?  this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 :
     635                                                                        this.model.revisions.indexOf( this.model.get( 'to' ) ),
     636                                        values: null, // Clear existing two handled values
     637                                        range: false
     638                                } );
    613639                        }
    614640                        if ( this.model.get( 'compareTwoMode' ) ){
    615641                                $( '.revisions' ).addClass( 'comparing-two-revisions' );
     
    675701                                        return false;
    676702
    677703                                attributes = {
    678                                         to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[1] ), // Reverse directions for RTL.
    679                                         from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[0] ) // Reverse directions for RTL.
     704                                        to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[1] ), // Reverse directions for RTL.
     705                                        from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[0] ) // Reverse directions for RTL.
    680706                                };
     707
    681708                        } else {
    682709                                // Compare single revision mode
    683710                                var sliderPosition = this.getSliderPosition( ui );
  • wp-admin/css/wp-admin.css

     
    35203520        display: none;
    35213521}
    35223522
     3523.comparing-two-revisions .revisions-controls {
     3524        height: 80px;
     3525}
    35233526.revisions-previous {
    35243527        float: left;
    35253528}