WordPress.org

Make WordPress Core

Changeset 24638


Ignore:
Timestamp:
07/10/2013 06:08:56 AM (8 years ago)
Author:
markjaquith
Message:

Revisions: simpler hash URLs. Misc refactoring.

  • Single mode: #at/:to
  • Compare two mode: #from/:from/to/:to
  • Make use of _.isUndefined()

See #24425.

File:
1 edited

Legend:

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

    r24636 r24638  
    77
    88    // Link settings.
    9     revisions.settings = typeof _wpRevisionsSettings === 'undefined' ? {} : _wpRevisionsSettings;
     9    revisions.settings = _.isUndefined( _wpRevisionsSettings ) ? {} : _wpRevisionsSettings;
    1010
    1111    // For debugging
     
    719719                // In single handle mode, the 1st stored revision is 'blank' and the 'from' model is not set
    720720                // In this case we move the to index over one
    721                 if ( 'undefined' == typeof this.model.get('from') ) {
     721                if ( _.isUndefined( this.model.get('from') ) ) {
    722722                    if ( isRtl ) {
    723723                        leftValue  = this.model.revisions.length -  this.model.revisions.indexOf( this.model.get('to') ) - 2;
     
    837837            var attributes;
    838838            // Compare two revisions mode
    839             if ( 'undefined' !== typeof ui.values && this.model.get('compareTwoMode') ) {
     839            if ( ! _.isUndefined( ui.values ) && this.model.get('compareTwoMode') ) {
    840840                // Prevent sliders from occupying same spot
    841841                if ( ui.values[1] === ui.values[0] )
     
    894894
    895895        routes: {
    896             'revision/from/:from/to/:to/handles/:handles': 'gotoRevisionId'
     896            'from/:from/to/:to': 'handleRoute',
     897            'at/:to': 'routeSingle'
    897898        },
    898899
     
    900901            var from = this.model.has('from') ? this.model.get('from').id : 0;
    901902            var to = this.model.get('to').id;
    902             var handles = this.model.get('compareTwoMode') ? '2' : '1';
    903 
    904             this.navigate( '/revision/from/' + from + '/to/' + to + '/handles/' + handles );
    905         },
    906 
    907         gotoRevisionId: function( from, to, handles ) {
    908             from = parseInt( from, 10 );
    909             to = parseInt( to, 10 );
    910 
    911             this.model.set({ compareTwoMode: ( '2' === handles ) });
    912 
    913             if ( 'undefined' !== typeof this.model ) {
     903            if ( this.model.get('compareTwoMode' ) )
     904                this.navigate( 'from/' + from + '/to/' + to );
     905            else
     906                this.navigate( 'at/' + to );
     907        },
     908
     909        handleRoute: function( a, b ) {
     910            var from, to, compareTwo;
     911
     912            // If `b` is undefined, this was a 'revision/:to' route
     913            if ( _.isUndefined( b ) ) {
     914                b = a;
     915                a = 0;
     916                compareTwo = true;
     917            } else {
     918                compareTwo = false;
     919            }
     920
     921            from = parseInt( a, 10 );
     922            to = parseInt( b, 10 );
     923
     924            this.model.set({ compareTwoMode: compareTwo });
     925
     926            if ( ! _.isUndefined( this.model ) ) {
    914927                var selectedToRevision = this.model.revisions.findWhere({ id: to }),
    915928                    selectedFromRevision = this.model.revisions.findWhere({ id: from });
Note: See TracChangeset for help on using the changeset viewer.