]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/revisions.js
WordPress 4.0-scripts
[autoinstalls/wordpress.git] / wp-admin / js / revisions.js
index 26b22cf259b25c9a756675ad12a3cbe4ef8b86bb..521e55ce09a2040b90dc3d6fa740f68c925f33d2 100644 (file)
@@ -399,11 +399,23 @@ window.wp = window.wp || {};
                },
 
                changeMode: function( model, value ) {
-                       // If we were on the first revision before switching, we have to bump them over one
-                       if ( value && 0 === this.revisions.indexOf( this.get('to') ) ) {
+                       var toIndex = this.revisions.indexOf( this.get( 'to' ) );
+
+                       // If we were on the first revision before switching to two-handled mode,
+                       // bump the 'to' position over one
+                       if ( value && 0 === toIndex ) {
+                               this.set({
+                                       from: this.revisions.at( toIndex ),
+                                       to:   this.revisions.at( toIndex + 1 )
+                               });
+                       }
+
+                       // When switching back to single-handled mode, reset 'from' model to
+                       // one position before the 'to' model
+                       if ( ! value && 0 !== toIndex ) { // '! value' means switching to single-handled mode
                                this.set({
-                                       from: this.revisions.at(0),
-                                       to: this.revisions.at(1)
+                                       from: this.revisions.at( toIndex - 1 ),
+                                       to:   this.revisions.at( toIndex )
                                });
                        }
                },
@@ -1048,15 +1060,12 @@ window.wp = window.wp || {};
                }
        });
 
-       // The revisions router
-       // takes URLs with #hash fragments and routes them
+       // The revisions router.
+       // Maintains the URL routes so browser URL matches state.
        revisions.Router = Backbone.Router.extend({
                initialize: function( options ) {
                        this.model = options.model;
-                       this.routes = _.object([
-                               [ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ],
-                               [ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ]
-                       ]);
+
                        // Maintain state and history when navigating
                        this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
                        this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
@@ -1070,9 +1079,9 @@ window.wp = window.wp || {};
                        var from = this.model.has('from') ? this.model.get('from').id : 0,
                                to   = this.model.get('to').id;
                        if ( this.model.get('compareTwoMode' ) ) {
-                               this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ) );
+                               this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ), { replace: true } );
                        } else {
-                               this.navigate( this.baseUrl( '?revision=' + to ) );
+                               this.navigate( this.baseUrl( '?revision=' + to ), { replace: true } );
                        }
                },
 
@@ -1085,12 +1094,6 @@ window.wp = window.wp || {};
                                b = b ? b.id : 0;
                                a = a ? a.id : 0;
                        }
-
-                       this.model.set({
-                               from: this.model.revisions.get( parseInt( a, 10 ) ),
-                               to: this.model.revisions.get( parseInt( a, 10 ) ),
-                               compareTwoMode: compareTwo
-                       });
                }
        });