Ticket #49177: 49177.patch
| File 49177.patch, 10.4 KB (added by , 6 years ago) |
|---|
-
wp-admin/js/revisions.js
71 71 this.frame = options.frame; 72 72 this.revisions = options.revisions; 73 73 74 // Listen for changes to the revisions or mode from outside 74 // Listen for changes to the revisions or mode from outside. 75 75 this.listenTo( this.frame, 'update:revisions', this.receiveRevisions ); 76 76 this.listenTo( this.frame, 'change:compareTwoMode', this.updateMode ); 77 77 78 // Listen for internal changes 78 // Listen for internal changes. 79 79 this.on( 'change:from', this.handleLocalChanges ); 80 80 this.on( 'change:to', this.handleLocalChanges ); 81 81 this.on( 'change:compareTwoMode', this.updateSliderSettings ); 82 82 this.on( 'update:revisions', this.updateSliderSettings ); 83 83 84 // Listen for changes to the hovered revision 84 // Listen for changes to the hovered revision. 85 85 this.on( 'change:hoveredRevision', this.hoverRevision ); 86 86 87 87 this.set({ … … 105 105 this.getSliderValue( 'from', 'to' ) 106 106 ], 107 107 value: null, 108 range: true // ensures handles cannot cross 108 range: true // ensures handles cannot cross. 109 109 }); 110 110 } else { 111 111 this.set({ … … 117 117 this.trigger( 'update:slider' ); 118 118 }, 119 119 120 // Called when a revision is hovered 120 // Called when a revision is hovered. 121 121 hoverRevision: function( model, value ) { 122 122 this.trigger( 'hovered:revision', value ); 123 123 }, 124 124 125 // Called when `compareTwoMode` changes 125 // Called when `compareTwoMode` changes. 126 126 updateMode: function( model, value ) { 127 127 this.set({ compareTwoMode: value }); 128 128 }, 129 129 130 // Called when `from` or `to` changes in the local model 130 // Called when `from` or `to` changes in the local model. 131 131 handleLocalChanges: function() { 132 132 this.frame.set({ 133 133 from: this.get('from'), … … 135 135 }); 136 136 }, 137 137 138 // Receives revisions changes from outside the model 138 // Receives revisions changes from outside the model. 139 139 receiveRevisions: function( from, to ) { 140 140 // Bail if nothing changed 141 141 if ( this.get('from') === from && this.get('to') === to ) { … … 152 152 defaults: { 153 153 revision: null, 154 154 offset: {}, 155 hovering: false, // Whether the mouse is hovering 156 scrubbing: false // Whether the mouse is scrubbing 155 hovering: false, // Whether the mouse is hovering. 156 scrubbing: false // Whether the mouse is scrubbing. 157 157 }, 158 158 159 159 initialize: function( options ) { … … 255 255 } else { 256 256 this.trigger( 'ensure:load', ids, from, to, deferred.promise() ); 257 257 _.each( ids, _.bind( function( id ) { 258 // Remove anything that has an ongoing request 258 // Remove anything that has an ongoing request. 259 259 if ( this.requests[ id ] ) { 260 260 delete ids[ id ]; 261 261 } 262 // Remove anything we already have 262 // Remove anything we already have. 263 263 if ( this.get( id ) ) { 264 264 delete ids[ id ]; 265 265 } 266 266 }, this ) ); 267 267 if ( ! request ) { 268 // Always include the ID that started this ensure 268 // Always include the ID that started this ensure. 269 269 ids[ id ] = true; 270 270 request = this.load( _.keys( ids ) ); 271 271 } … … 280 280 return deferred.promise(); 281 281 }, 282 282 283 // Returns an array of proximal diffs 283 // Returns an array of proximal diffs. 284 284 getClosestUnloaded: function( ids, centerId ) { 285 285 var self = this; 286 286 return _.chain([0].concat( ids )).initial().zip( ids ).sortBy( function( pair ) { … … 303 303 }).fail( function() { 304 304 if ( 1 === num ) { // Already tried 1. This just isn't working. Give up. 305 305 deferred.reject(); 306 } else { // Request fewer diffs this time 306 } else { // Request fewer diffs this time. 307 307 self._loadAll( allRevisionIds, centerId, Math.ceil( num / 2 ) ).done( function() { 308 308 deferred.resolve(); 309 309 }); … … 410 410 compareTwoMode : state.compareTwoMode 411 411 } ); 412 412 413 // Start the router if browser supports History API 413 // Start the router if browser supports History API. 414 414 if ( window.history && window.history.pushState ) { 415 415 this.router = new revisions.Router({ model: this }); 416 416 if ( Backbone.History.started ) { … … 593 593 initialize: function() { 594 594 _.bindAll( this, 'setWidth' ); 595 595 596 // Add the button view 596 // Add the button view. 597 597 this.views.add( new revisions.view.Buttons({ 598 598 model: this.model 599 599 }) ); 600 600 601 // Add the checkbox view 601 // Add the checkbox view. 602 602 this.views.add( new revisions.view.Checkbox({ 603 603 model: this.model 604 604 }) ); 605 605 606 // Prep the slider model 606 // Prep the slider model. 607 607 var slider = new revisions.model.Slider({ 608 608 frame: this.model, 609 609 revisions: this.model.revisions 610 610 }), 611 611 612 // Prep the tooltip model 612 // Prep the tooltip model. 613 613 tooltip = new revisions.model.Tooltip({ 614 614 frame: this.model, 615 615 revisions: this.model.revisions, … … 616 616 slider: slider 617 617 }); 618 618 619 // Add the tooltip view 619 // Add the tooltip view. 620 620 this.views.add( new revisions.view.Tooltip({ 621 621 model: tooltip 622 622 }) ); 623 623 624 // Add the tickmarks view 624 // Add the tickmarks view. 625 625 this.views.add( new revisions.view.Tickmarks({ 626 626 model: tooltip 627 627 }) ); 628 628 629 // Add the slider view 629 // Add the slider view. 630 630 this.views.add( new revisions.view.Slider({ 631 631 model: slider 632 632 }) ); 633 633 634 // Add the Metabox view 634 // Add the Metabox view. 635 635 this.views.add( new revisions.view.Metabox({ 636 636 model: this.model 637 637 }) ); … … 672 672 } 673 673 }); 674 674 675 // The tickmarks view 675 // The tickmarks view. 676 676 revisions.view.Tickmarks = wp.Backbone.View.extend({ 677 677 className: 'revisions-tickmarks', 678 678 direction: isRtl ? 'right' : 'left', … … 686 686 thisOffset = this.$el.allOffsets(); 687 687 parentOffset = this.$el.parent().allOffsets(); 688 688 if ( index === this.model.revisions.length - 1 ) { 689 // Last one 689 // Last one. 690 690 offset = { 691 691 rightPlusWidth: thisOffset.left - parentOffset.left + 1, 692 692 leftPlusWidth: thisOffset.right - parentOffset.right + 1 693 693 }; 694 694 } else { 695 // Normal tick 695 // Normal tick. 696 696 tick = this.$('div:nth-of-type(' + (index + 1) + ')'); 697 697 offset = tick.allPositions(); 698 698 _.extend( offset, { … … 719 719 } 720 720 }); 721 721 722 // The metabox view 722 // The metabox view. 723 723 revisions.view.Metabox = wp.Backbone.View.extend({ 724 724 className: 'revisions-meta', 725 725 726 726 initialize: function() { 727 // Add the 'from' view 727 // Add the 'from' view. 728 728 this.views.add( new revisions.view.MetaFrom({ 729 729 model: this.model, 730 730 className: 'diff-meta diff-meta-from' 731 731 }) ); 732 732 733 // Add the 'to' view 733 // Add the 'to' view. 734 734 this.views.add( new revisions.view.MetaTo({ 735 735 model: this.model 736 736 }) ); … … 737 737 } 738 738 }); 739 739 740 // The revision meta view (to be extended) 740 // The revision meta view (to be extended). 741 741 revisions.view.Meta = wp.Backbone.View.extend({ 742 742 template: wp.template('revisions-meta'), 743 743 … … 760 760 } 761 761 }); 762 762 763 // The revision meta 'from' view 763 // The revision meta 'from' view. 764 764 revisions.view.MetaFrom = revisions.view.Meta.extend({ 765 765 className: 'diff-meta diff-meta-from', 766 766 type: 'from' 767 767 }); 768 768 769 // The revision meta 'to' view 769 // The revision meta 'to' view. 770 770 revisions.view.MetaTo = revisions.view.Meta.extend({ 771 771 className: 'diff-meta diff-meta-to', 772 772 type: 'to' … … 880 880 this.disabledButtonCheck(); 881 881 }, 882 882 883 // Go to a specific model index 883 // Go to a specific model index. 884 884 gotoModel: function( toIndex ) { 885 885 var attributes = { 886 886 to: this.model.revisions.at( toIndex ) … … 895 895 this.model.set( attributes ); 896 896 }, 897 897 898 // Go to the 'next' revision 898 // Go to the 'next' revision. 899 899 nextRevision: function() { 900 900 var toIndex = this.model.revisions.indexOf( this.model.get('to') ) + 1; 901 901 this.gotoModel( toIndex ); 902 902 }, 903 903 904 // Go to the 'previous' revision 904 // Go to the 'previous' revision. 905 905 previousRevision: function() { 906 906 var toIndex = this.model.revisions.indexOf( this.model.get('to') ) - 1; 907 907 this.gotoModel( toIndex ); … … 970 970 currentModelIndex = this.model.revisions.length - 1; 971 971 } 972 972 973 // Update the tooltip mode 973 // Update the tooltip mode. 974 974 this.model.set({ hoveredRevision: this.model.revisions.at( currentModelIndex ) }); 975 975 }, 976 976 … … 987 987 var handles = this.$('a.ui-slider-handle'); 988 988 989 989 if ( this.model.get('compareTwoMode') ) { 990 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 990 // in RTL mode the 'left handle' is the second in the slider, 'right' is first. 991 991 handles.first() 992 992 .toggleClass( 'to-handle', !! isRtl ) 993 993 .toggleClass( 'from-handle', ! isRtl ); … … 1019 1019 // Adjust left/right boundaries and reset points. 1020 1020 if ( view.model.get('compareTwoMode') ) { 1021 1021 handles = handle.parent().find('.ui-slider-handle'); 1022 if ( handle.is( handles.first() ) ) { // We're the left handle 1022 if ( handle.is( handles.first() ) ) { // We're the left handle. 1023 1023 rightDragBoundary = handles.last().offset().left; 1024 1024 rightDragReset = rightDragBoundary - sliderOffset; 1025 } else { // We're the right handle 1025 } else { // We're the right handle. 1026 1026 leftDragBoundary = handles.first().offset().left + handles.first().width(); 1027 1027 leftDragReset = leftDragBoundary - sliderOffset; 1028 1028 } … … 1043 1043 return isRtl ? this.model.revisions.length - position - 1: position; 1044 1044 }, 1045 1045 1046 // Responds to slide events 1046 // Responds to slide events. 1047 1047 slide: function( event, ui ) { 1048 1048 var attributes, movedRevision; 1049 // Compare two revisions mode 1049 // Compare two revisions mode. 1050 1050 if ( this.model.get('compareTwoMode') ) { 1051 // Prevent sliders from occupying same spot 1051 // Prevent sliders from occupying same spot. 1052 1052 if ( ui.values[1] === ui.values[0] ) { 1053 1053 return false; 1054 1054 } … … 1072 1072 } 1073 1073 movedRevision = this.model.revisions.at( this.getPosition( ui.value ) ); 1074 1074 1075 // If we are scrubbing, a scrub to a revision is considered a hover 1075 // If we are scrubbing, a scrub to a revision is considered a hover. 1076 1076 if ( this.model.get('scrubbing') ) { 1077 1077 attributes.hoveredRevision = movedRevision; 1078 1078 } … … 1082 1082 1083 1083 stop: function() { 1084 1084 $( window ).off('mousemove.wp.revisions'); 1085 this.model.updateSliderSettings(); // To snap us back to a tick mark 1085 this.model.updateSliderSettings(); // To snap us back to a tick mark. 1086 1086 this.model.set({ scrubbing: false }); 1087 1087 } 1088 1088 });