Ticket #23901: 23901.2.patch
File 23901.2.patch, 48.5 KB (added by , 12 years ago) |
---|
-
wp-admin/js/revisions.js
1 1 window.wp = window.wp || {}; 2 2 3 3 (function($) { 4 wp.revisions = {4 var Revision, Revisions, Diff, l10n, revisions; 5 5 6 views: {}, 6 revisions = wp.revisions = function() { 7 Diff = revisions.Diff = new Diff(); 8 }; 7 9 8 Model: Backbone.Model.extend({ 9 idAttribute: 'ID', 10 urlRoot: ajaxurl + '?action=revisions-data' + 11 '&show_autosaves=true&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 12 defaults: { 13 ID: 0, 14 revision_date_author: '', 15 revision_date_author_short: '', 16 revisiondiff: '<div class="diff-loading"><div class="spinner"></div></div>', 17 restoreaction: '', 18 revision_from_date_author: '', 19 revision_toload: false, 20 lines_added: 0, 21 lines_deleted: 0, 22 scope_of_changes: 'none', 23 previous_revision_id: 0 24 }, 10 _.extend( revisions, { model: {}, view: {}, controller: {} } ); 25 11 26 url: function() { 27 if ( 1 === REVAPP._compareOneOrTwo ) { 28 return this.urlRoot + 29 '&single_revision_id=' + this.id + 30 '&compare_to=' + this.get( 'previous_revision_id' ) + 31 '&post_id=' + wpRevisionsSettings.post_id; 32 } else { 33 return this.urlRoot + 34 '&single_revision_id=' + this.id; 35 } 12 // Link any localized strings. 13 l10n = revisions.model.l10n = typeof wpRevisionsL10n === 'undefined' ? {} : wpRevisionsL10n; 36 14 37 } 15 // Link any settings. 16 revisions.model.settings = l10n.settings || {}; 17 delete l10n.settings; 38 18 39 }),40 19 41 app: _.extend({}, Backbone.Events), 20 /** 21 * ======================================================================== 22 * CONTROLLERS 23 * ======================================================================== 24 */ 42 25 43 App: Backbone.Router.extend({ 44 _revisions: null, 45 _leftHandleRevisions: null, 46 _rightHandleRevisions: null, 47 _revisionsInteractions: null, 48 _revisionsOptions: null, 49 _leftDiff: 1, 50 _rightDiff: 1, 51 _autosaves: true, 52 _showSplitView: true, 53 _compareOneOrTwo: 1, 54 _leftModelLoading: false, // keep track of model loads 55 _rightModelLoading: false, // disallow slider interaction, also repeat loads, while loading 56 _tickmarkView: null, // the slider tickmarks 26 /** 27 * wp.revisions.controller.Diff 28 * 29 * Controlls the diff 30 */ 31 Diff = revisions.controller.Diff = Backbone.Model.extend( { 32 rightDiff: 1, 33 leftDiff: 1, 34 revisions: null, 35 leftHandleRevisions: null, 36 rightHandleRevisions: null, 37 revisionsInteractions: null, 38 autosaves: true, 39 showSplitView: true, 40 singleRevision: true, 41 leftModelLoading: false, // keep track of model loads 42 rightModelLoading: false, // disallow slider interaction, also repeat loads, while loading 43 tickmarkView: null, // the slider tickmarks 44 slider: null, // the slider instance 57 45 58 routes: { 59 }, 46 constructor: function() { 47 this.slider = new revisions.view.Slider(); 48 if ( null === this.revisions ) { 49 this.revisions = new Revisions(); // set up collection 50 this.startRightModelLoading(); 60 51 61 reloadToLoadRevisions: function( model_collection, reverse_direction ) { 62 var self = this, 63 revisionsToLoad = model_collection.where( { revision_toload: true } ), 64 delay = 0; 65 // match slider to passed revision_id 66 _.each( revisionsToLoad, function( theModel ) { 67 if ( theModel.get( 'ID' ) == wpRevisionsSettings.revision_id ) { 68 self._rightDiff = self._revisions.indexOf( theModel ) + 1; 52 var self = this; 53 this.revisions.fetch({ // load revision data 54 success: function() { 55 self.stopRightModelLoading(); 56 self.completeApplicationSetup(); 69 57 } 70 71 58 }); 72 _.each( revisionsToLoad, function( theModel ) { 73 theModel.urlRoot = model_collection.url; 74 _.delay( function() { 75 theModel.fetch( { 76 update: true, 77 add: false, 78 remove: false, 79 success: function( model ) { 80 model.set( 'revision_toload', 'false' ); 59 } 60 }, 81 61 82 // stop spinner when all models are loaded 83 if ( 0 === model_collection.where( { revision_toload: true } ).length ) 84 self.stopModelLoadingSpinner(); 62 reloadToLoadRevisions: function( models, reverse_direction ) { 63 var self = this, 64 revisionsToLoad = models.where( { revision_toload: true } ), 65 delay = 0; 85 66 86 self._tickmarkView.render(); 67 // match slider to passed revision_id 68 _.each( revisionsToLoad, function( theModel ) { 69 if ( theModel.get( 'ID' ) == revisions.model.settings.revision_id ) 70 self.rightDiff = self.revisions.indexOf( theModel ) + 1; 71 }); 87 72 88 var total_changes = model.get( 'lines_added' ) + model.get( 'lines_deleted'), 89 scope_of_changes = 'vsmall'; 73 _.each( revisionsToLoad, function( theModel ) { 74 theModel.urlRoot = models.url(); 75 _.delay( function() { 76 theModel.fetch( { 77 update: true, 78 add: false, 79 remove: false, 80 success: function( model ) { 81 model.set( 'revision_toload', 'false' ); 90 82 91 // Note: hard coded scope of changes 92 // TODO change to dynamic based on range of values 93 if ( total_changes > 1 && total_changes <= 3 ) { 94 scope_of_changes = 'small'; 95 } else if(total_changes > 3 && total_changes <= 5 ) { 96 scope_of_changes = 'med'; 97 } else if(total_changes > 5 && total_changes <= 10 ) { 98 scope_of_changes = 'large'; 99 } else if(total_changes > 10 ) { 100 scope_of_changes = 'vlarge'; 101 } 102 model.set( 'scope_of_changes', scope_of_changes ); 103 if ( 0 !== self._rightDiff && 104 model.get( 'ID' ) === self._revisions.at( self._rightDiff - 1 ).get( 'ID' ) ) { 105 // reload if current model refreshed 106 self._revisionView.render(); 107 } 83 // stop spinner when all models are loaded 84 if ( 0 === models.where( { revision_toload: true } ).length ) 85 self.stopModelLoadingSpinner(); 108 86 87 self.tickmarkView.render(); 88 89 var total_changes = model.get( 'lines_added' ) + model.get( 'lines_deleted'), 90 scope_of_changes = 'vsmall'; 91 92 // Note: hard coded scope of changes 93 // TODO change to dynamic based on range of values 94 if ( total_changes > 1 && total_changes <= 3 ) { 95 scope_of_changes = 'small'; 96 } else if( total_changes > 3 && total_changes <= 5 ) { 97 scope_of_changes = 'med'; 98 } else if( total_changes > 5 && total_changes <= 10 ) { 99 scope_of_changes = 'large'; 100 } else if( total_changes > 10 ) { 101 scope_of_changes = 'vlarge'; 109 102 } 110 });111 }, delay ) ;112 delay = delay + 150; // stagger model loads to avoid hammering server with requests113 }114 );115 },103 model.set( 'scope_of_changes', scope_of_changes ); 104 if ( 0 !== self.rightDiff && 105 model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { 106 // reload if current model refreshed 107 self.revisionView.render(); 108 } 116 109 117 startLeftModelLoading: function() { 118 this._leftModelLoading = true; 119 $('.revisiondiffcontainer').addClass('leftmodelloading'); 120 }, 110 } 111 } ); 112 }, delay ) ; 113 delay = delay + 150; // stagger model loads to avoid hammering server with requests 114 } 115 ); 116 }, 121 117 122 stopLeftModelLoading: function() { 123 this._leftModelLoading = false; 124 }, 118 startLeftModelLoading: function() { 119 this.leftModelLoading = true; 120 $('.revisiondiffcontainer').addClass('leftmodelloading'); 121 }, 125 122 126 startRightModelLoading: function() { 127 this._rightModelLoading = true; 128 $('.revisiondiffcontainer').addClass('rightmodelloading'); 129 }, 123 stopLeftModelLoading: function() { 124 this.leftModelLoading = false; 125 }, 130 126 131 stopRightModelLoading: function() { 132 this._rightModelLoading = false; 133 }, 127 startRightModelLoading: function() { 128 this.rightModelLoading = true; 129 $('.revisiondiffcontainer').addClass('rightmodelloading'); 130 }, 134 131 135 stopModelLoadingSpinner: function() { 136 $('.revisiondiffcontainer').removeClass('rightmodelloading'); 137 $('.revisiondiffcontainer').removeClass('leftmodelloading'); 138 }, 132 stopRightModelLoading: function() { 133 this.rightModelLoading = false; 134 }, 139 135 140 reloadModel: function() { 141 if ( 2 === this._compareOneOrTwo ) { 142 this.reloadLeftRight(); 143 } else { 144 this.reloadModelSingle(); 145 } 146 }, 136 stopModelLoadingSpinner: function() { 137 $('.revisiondiffcontainer').removeClass('rightmodelloading'); 138 $('.revisiondiffcontainer').removeClass('leftmodelloading'); 139 }, 147 140 148 // load the models for the single handle mode 149 reloadModelSingle: function() { 150 var self = this; 151 self._revisions.url = ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 152 '&show_autosaves=' + self._autosaves + 153 '&show_split_view=' + self._showSplitView + 154 '&nonce=' + wpRevisionsSettings.nonce; 155 self.startRightModelLoading(); 156 self._revisions.fetch({ // reload revision data 157 success: function() { 158 console.log('loaded'); 159 // self.stopRightModelLoading(); 160 // REVAPP._rightDiff -= 1; 161 var revisionCount = self._revisions.length; 162 self._revisionView.model = self._revisions; 163 self._revisionView.render(); 164 self.reloadToLoadRevisions( self._revisions ); 165 self._tickmarkView.model = self._revisions; 166 self._tickmarkView.render(); 167 $( '#slider' ).slider( 'option', 'max', revisionCount - 1 ); // TODO: test this, if autosave option changed 168 $( '#slider' ).slider( 'value', self._rightDiff - 1 ).trigger( 'slide' ); 141 reloadModel: function() { 142 if ( this.singleRevision ) { 143 this.reloadModelSingle(); 144 } else { 145 this.reloadLeftRight(); 146 } 147 }, 169 148 170 }, 149 // load the models for the single handle mode 150 reloadModelSingle: function() { 151 var self = this; 171 152 172 error: function() { 173 self.stopRightModelLoading(); 174 } 153 // TODO: Only updates the query args yet 154 self.revisions.reload({ 155 'showAutosaves': self.autosaves, 156 'showSplitView': self.showSplitView 157 }); 175 158 176 }); 177 }, 159 self.startRightModelLoading(); 160 self.revisions.fetch({ // reload revision data 161 success: function() { 162 var revisionCount = self.revisions.length; 163 self.revisionView.model = self.revisions; 164 self.revisionView.render(); 165 self.reloadToLoadRevisions( self.revisions ); 166 self.tickmarkView.model = self.revisions; 167 self.tickmarkView.render(); 168 self.slider.refresh({ 169 'max': revisionCount - 1, 170 'value': self.rightDiff - 1 171 }, true); 172 }, 178 173 179 // load the models for the left handle 180 reloadLeft: function() { 181 var self = this; 182 self.startLeftModelLoading(); 183 self._leftHandleRevisions = new wp.revisions.Collection(); 174 error: function() { 175 self.stopRightModelLoading(); 176 } 184 177 185 self._leftHandleRevisions.url = 186 ajaxurl + 187 '?action=revisions-data&compare_to=' + self._revisions.at( self._rightDiff - 1 ).get( 'ID' ) + 188 '&post_id=' + wpRevisionsSettings.post_id + 189 '&show_autosaves=' + REVAPP._autosaves + 190 '&show_split_view=' + REVAPP._showSplitView + 191 '&nonce=' + wpRevisionsSettings.nonce + 192 '&right_handle_at=' + ( self._rightDiff ); 178 }); 179 }, 193 180 194 self._leftHandleRevisions.fetch({ 181 // load the models for the left handle 182 reloadLeft: function() { 183 var self = this; 184 self.startLeftModelLoading(); 185 self.leftHandleRevisions = new Revisions( {}, { 186 'compareTo': self.revisions.at( self.leftDiff ).get( 'ID' ), 187 'showAutosaves': self.autosaves, 188 'showSplitView': self.showSplitView, 189 'rightHandleAt': self.rightDiff 190 }); 195 191 196 success: function(){ 197 self.stopLeftModelLoading(); 198 self.reloadToLoadRevisions( self._leftHandleRevisions ); 199 self._tickmarkView.model = self._leftHandleRevisions; 200 $( '#slider' ).slider( 'option', 'max', self._revisions.length ); 201 // ensure right handle not beyond length, in particular if viewing autosaves is switched from on to off 202 // the number of models in the collection might get shorter, this ensures right handle is not beyond last model 203 if ( self._rightDiff > self._revisions.length ) 204 self._rightDiff = self._revisions.length; 205 }, 192 self.leftHandleRevisions.fetch({ 193 success: function(){ 194 self.stopLeftModelLoading(); 195 self.reloadToLoadRevisions( self.leftHandleRevisions ); 196 self.tickmarkView.model = self.leftHandleRevisions; 197 self.slider.refresh({ 198 'max': self.revisions.length 199 }); 200 // ensure right handle not beyond length, in particular if viewing autosaves is switched from on to off 201 // the number of models in the collection might get shorter, this ensures right handle is not beyond last model 202 if ( self.rightDiff > self.revisions.length ) 203 self.rightDiff = self.revisions.length; 204 }, 206 205 207 208 209 210 211 206 error: function() { 207 self.stopLeftModelLoading(); 208 } 209 }); 210 }, 212 211 213 // load the models for the right handle 214 reloadRight: function() { 215 var self = this; 216 self.startRightModelLoading(); 217 self._rightHandleRevisions = new wp.revisions.Collection(); 212 // load the models for the right handle 213 reloadRight: function() { 214 var self = this; 215 self.startRightModelLoading(); 216 self.rightHandleRevisions = new Revisions( {}, { 217 'compareTo': self.revisions.at( self.leftDiff ).get( 'ID' ) - 1, 218 'showAutosaves': self.autosaves, 219 'showSplitView': self.showSplitView 220 }); 218 221 219 self._rightHandleRevisions.url = 220 ajaxurl + 221 '?action=revisions-data&compare_to=' + ( self._revisions.at( self._leftDiff ).get( 'ID' ) - 1 )+ 222 '&post_id=' + wpRevisionsSettings.post_id + 223 '&show_autosaves=' + REVAPP._autosaves + 224 '&show_split_view=' + REVAPP._showSplitView + 225 '&nonce=' + wpRevisionsSettings.nonce; 222 self.rightHandleRevisions.fetch({ 223 success: function(){ 224 self.stopRightModelLoading(); 225 self.reloadToLoadRevisions( self.rightHandleRevisions ); 226 self.tickmarkView.model = self.rightHandleRevisions; 227 self.slider.refresh({ 228 'max': self.revisions.length, 229 'values': [ self.leftDiff, self.rightDiff] 230 }, true); 231 }, 226 232 227 self._rightHandleRevisions.fetch({ 233 error: function( response ) { 234 self.stopRightModelLoading(); 235 } 236 }); 228 237 229 success: function(){ 230 self.stopRightModelLoading(); 231 self.reloadToLoadRevisions( self._rightHandleRevisions ); 232 self._tickmarkView.model = self._rightHandleRevisions; 233 $( '#slider' ).slider( 'option', 'max', self._revisions.length ); 234 $( '#slider' ).slider( 'values', [ REVAPP._leftDiff, REVAPP._rightDiff] ).trigger( 'slide' ); 238 }, 235 239 236 // REVAPP._revisionView.render(); 240 reloadLeftRight: function() { 241 this.startRightModelLoading(); 242 this.startLeftModelLoading(); 243 this.reloadLeft(); 244 this.reloadRight(); 245 }, 237 246 238 }, 247 // TODO: New view 248 addTooltip: function( handle, message ) { 239 249 240 error: function( response ) { 241 self.stopRightModelLoading(); 250 handle.attr( 'title', '' ).tooltip({ 251 track: false, 252 253 position: { 254 my: "left-30 top-66", 255 at: "top left", 256 using: function( position, feedback ) { 257 $( this ).css( position ); 258 $( "<div>" ) 259 .addClass( "arrow" ) 260 .addClass( feedback.vertical ) 261 .addClass( feedback.horizontal ) 262 .appendTo( $( this ) ); 242 263 } 243 }); 264 }, 265 show: false, 266 hide: false, 267 content: function() { 268 return message; 269 } 244 270 245 }, 271 } ); 272 }, 246 273 247 reloadLeftRight: function() { 248 this.startRightModelLoading(); 249 this.startLeftModelLoading(); 250 this.reloadLeft(); 251 this.reloadRight(); 252 }, 274 completeApplicationSetup: function() { 275 this.revisionView = new revisions.view.Diff({ 276 model: this.revisions 277 }); 278 this.revisionView.render(); 253 279 254 /* 255 * initialize the revision application 256 */ 257 initialize: function( options ) { 258 var self = this; // store the application instance 259 if (this._revisions === null) { 260 self._revisions = new wp.revisions.Collection(); // set up collection 261 self.startRightModelLoading(); 262 self._revisions.fetch({ // load revision data 280 this.reloadToLoadRevisions( this.revisions ); 263 281 264 success: function() { 265 self.stopRightModelLoading(); 266 // self._rightHandleRevisions = self._revisions; 267 self.completeApplicationSetup(); 268 } 269 }); 270 } 271 return this; 272 }, 282 this.revisionsInteractions = new revisions.view.Interact({ 283 model: this.revisions 284 }); 285 this.revisionsInteractions.render(); 273 286 274 addTooltip: function( handle, message ) { 287 this.tickmarkView = new revisions.view.Tickmarks({ 288 model: this.revisions 289 }); 290 this.tickmarkView.render(); 291 this.tickmarkView.resetTicks(); 275 292 276 handle.attr( 'title', '' ).tooltip({277 track: false,293 } 294 }); 278 295 279 position: {280 my: "left-30 top-66",281 at: "top left",282 using: function( position, feedback ) {283 $( this ).css( position );284 $( "<div>" )285 .addClass( "arrow" )286 .addClass( feedback.vertical )287 .addClass( feedback.horizontal )288 .appendTo( $( this ) );289 }290 },291 show: false,292 hide: false,293 content: function() {294 return message;295 }296 296 297 } ); 298 }, 299 /**/ 297 /** 298 * ======================================================================== 299 * VIEWS 300 * ======================================================================== 301 */ 300 302 301 completeApplicationSetup: function() { 302 this._revisionView = new wp.revisions.views.View({ 303 model: this._revisions 304 }); 305 this._revisionView.render(); 306 $( '#slider' ).slider( 'option', 'max', this._revisions.length - 1 ); 303 /** 304 * wp.revisions.view.Slider 305 * 306 * The slider 307 */ 308 revisions.view.Slider = Backbone.View.extend({ 309 el: $( '#slider' ), 310 singleRevision: true, 307 311 308 this.reloadToLoadRevisions( this._revisions ); 312 initialize: function( options ) { 313 this.options = _.defaults( options || {}, { 314 value: 0, 315 min: 0, 316 max: 1, 317 step: 1 318 }); 319 }, 309 320 310 this._revisionsInteractions = new wp.revisions.views.Interact({ 311 model: this._revisions 312 }); 313 this._revisionsInteractions.render(); 321 slide: function( event, ui ) { 322 if ( this.singleRevision ) { 323 Diff.rightDiff = ( ui.value + 1 ); 324 Diff.revisionView.render(); 325 } else { 326 if ( ui.values[0] === ui.values[1] ) // prevent compare to self 327 return false; 314 328 315 this._tickmarkView = new wp.revisions.views.Tickmarks({316 model: this._revisions317 });318 this._tickmarkView.render();319 this._tickmarkView.resetTicks();329 var index = $( ui.handle ).index(); // 0 (left) or 2 (right) 330 switch ( index ) { 331 case 0: // left 332 if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle 333 return false; 320 334 335 Diff.leftDiff = ui.values[0]; 336 break; 321 337 322 /* 323 .on( 'mouseup', function( event ) { 324 REVAPP._keep_tooltip_open = false; 325 $( this ).find('.ui-slider-tooltip').hide(); 326 } ).on( 'mousedown', function( event ) { 327 REVAPP._keep_tooltip_open = true; 328 } ).on( 'mouseout', function( event ) { 329 if ( REVAPP._keep_tooltip_open) 330 event.stopImmediatePropagation(); 331 }); 332 */ 333 /* 334 // Options hidden for now, moving to screen options 335 this._revisionsOptions = new wp.revisions.views.Options({ 336 model: this._revisions 337 }); 338 this._revisionsOptions.render(); 339 */ 338 case 2: // right 339 if ( Diff.rightModelLoading ) // right model still loading, prevent sliding right handle 340 return false; 340 341 341 }342 })343 };342 Diff.rightDiff = ui.values[1]; 343 break; 344 } 344 345 345 wp.revisions.Collection = Backbone.Collection.extend({ 346 model: wp.revisions.Model, 347 url: ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 348 '&show_autosaves=true&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 346 if ( 0 === Diff.leftDiff ) { 347 $( '.revisiondiffcontainer' ).addClass( 'currentversion' ); 348 } else { 349 $( '.revisiondiffcontainer' ).removeClass( 'currentversion' ); 350 } 349 351 350 initialize: function() {352 Diff.revisionView.render(); 351 353 } 352 } );354 }, 353 355 354 _.extend(wp.revisions.views, { 356 start: function( event, ui ) { 357 // Not needed in one mode 358 if ( this.singleRevision ) 359 return; 355 360 356 // Ticks inside slider view 357 Tickmarks: Backbone.View.extend({ 358 el: $('#diff-slider-ticks')[0], 359 tagName: 'diff-slider-ticks-view', 360 className: 'diff-slider-ticks-container', 361 template: wp.template('revision-ticks'), 362 model: wp.revisions.Model, 361 var index = $( ui.handle ).index(); // 0 (left) or 2 (right) 362 switch ( index ) { 363 case 0: // left handle drag 364 if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle 365 return false; 363 366 364 resetTicks: function() { 365 var sliderMax = $( '#slider' ).slider( 'option', 'max'); 366 var sliderWidth = $( '#slider' ).width(); 367 var adjustMax = ( 2 === REVAPP._compareOneOrTwo ) ? 1 : 0; 368 var tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); 367 Diff.revisionView.draggingLeft = true; 369 368 370 // TODO: adjust right margins for wider ticks so they stay centered on handle stop point 369 if ( Diff.revisionView.model !== Diff.leftHandleRevisions && 370 null !== Diff.leftHandleRevisions ) { 371 Diff.revisionView.model = Diff.leftHandleRevisions; 372 Diff.tickmarkView.model = Diff.leftHandleRevisions; 373 Diff.tickmarkView.render(); 374 } 371 375 372 // set minimum and maximum widths for tick marks 373 tickWidth = (tickWidth > 50 ) ? 50 : tickWidth; 374 tickWidth = (tickWidth < 10 ) ? 10 : tickWidth; 376 Diff.leftDiffStart = ui.values[ 0 ]; 377 break; 375 378 376 sliderWidth = tickWidth * (sliderMax - adjustMax ) + 1; 379 case 2: // right 380 if ( Diff.rightModelLoading || 0 === Diff.rightHandleRevisions.length) // right model still loading, prevent sliding right handle 381 return false; 377 382 378 $( '#slider' ).width( sliderWidth ); 379 $( '.diff-slider-ticks-wrapper' ).width( sliderWidth ); 380 $( '#diffslider' ).width( sliderWidth ); 381 $( '#diff-slider-ticks' ).width( sliderWidth ); 383 if ( Diff.revisionView.model !== Diff.rightHandleRevisions && 384 null !== Diff.rightHandleRevisions ) { 385 Diff.revisionView.model = Diff.rightHandleRevisions; 386 Diff.tickmarkView.model = Diff.rightHandleRevisions; 387 Diff.tickmarkView.render(); 388 } 382 389 383 var aTickWidth = $( '.revision-tick' ).width(); 390 Diff.revisionView.draggingLeft = false; 391 Diff.rightDiffStart = ui.values[1]; 392 break; 393 } 394 }, 384 395 385 if ( tickWidth !== aTickWidth ) { // is the width already set correctly?386 $( '.revision-tick' ).each( function( ) {387 $(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin388 });396 stop: function( event, ui ) { 397 // Not needed in one mode 398 if ( this.singleRevision ) 399 return; 389 400 390 if( 2 === REVAPP._compareOneOrTwo ) { 391 $( '.revision-tick' ).first().remove(); // TODO - remove the check 392 } 393 $( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin 394 } 401 // calculate and generate a diff for comparing to the left handle 402 // and the right handle, swap out when dragging 403 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 395 404 396 }, 405 switch ( index ) { 406 case 1: // left 407 // left handle dragged & changed, reload right handle model 408 if ( Diff.leftDiffStart !== ui.values[0] ) 409 Diff.reloadRight(); 397 410 398 // render the tickmark view 399 render: function() { 400 var self = this; 411 break; 401 412 402 if ( null !== self.model ) { 403 var addHtml = ""; 404 _.each ( self.model.models, function( theModel ) { 405 addHtml = addHtml + self.template ( theModel.toJSON() ); 406 }); 407 self.$el.html( addHtml ); 413 case 2: // right 414 // right handle dragged & changed, reload left handle model if changed 415 if ( Diff.rightDiffStart !== ui.values[1] ) 416 Diff.reloadLeft(); 408 417 409 } 410 self.resetTicks(); 411 return self; 418 break; 412 419 } 413 } ),420 }, 414 421 415 // primary revision diff view 416 View: Backbone.View.extend({ 417 el: $('#backbonerevisionsdiff')[0], 418 tagName: 'revisionvview', 419 className: 'revisionview-container', 420 template: wp.template('revision'), 421 comparetwochecked: '', 422 draggingLeft: false, 422 addTooltip: function() { 423 // Own view? 424 }, 423 425 424 // render the revisions 425 render: function() { 426 var addHtml = ''; 427 var thediff; 428 // compare two revisions mode? 426 width: function() { 427 return $( '#slider' ).width(); 428 }, 429 429 430 if ( 2 === REVAPP._compareOneOrTwo ) { 430 setWidth: function( width ) { 431 return $( '#slider' ).width( width ); 432 }, 431 433 432 this.comparetwochecked = 'checked'; 433 if ( this.draggingLeft ) { 434 thediff = REVAPP._leftDiff -1; 435 if ( this.model.at( thediff ) ) { 436 addHtml = this.template( _.extend( 437 this.model.at( thediff ).toJSON(), 438 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 439 ) ); 440 } 441 } else { // dragging right handle 442 thediff = REVAPP._rightDiff -1; 443 if ( this.model.at( thediff ) ) { 444 addHtml = this.template( _.extend( 445 this.model.at( thediff ).toJSON(), 446 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 447 ) ); 448 } 449 } 450 } else { // end compare two revisions mode, eg only one slider handle 451 this.comparetwochecked = ''; 452 if ( this.model.at( REVAPP._rightDiff - 1 ) ) { 453 addHtml = this.template( _.extend( 454 this.model.at( REVAPP._rightDiff - 1 ).toJSON(), 455 { comparetwochecked: this.comparetwochecked } // keep the checkmark unchecked 456 ) ); 457 } 458 } 459 this.$el.html( addHtml ); 460 if ( this.model.length < 3 ) { 461 $( 'div#comparetworevisions' ).hide(); // don't allow compare two if fewer than three revisions 462 } 463 if ( this.model.length < 2 ) { 464 $( 'div#diffslider' ).hide(); // don't allow compare two if fewer than three revisions 465 $( 'div.diff-slider-ticks-wrapper' ).hide(); 466 } 434 refresh: function( options, slide ) { 435 $( '#slider' ).slider( 'option', options ); 467 436 468 // add tooltips to the handles 469 if ( 2 === REVAPP._compareOneOrTwo ) { 470 REVAPP.addTooltip ( $( 'a.ui-slider-handle.left-handle' ), 471 ( REVAPP._leftDiff < 0 ) ? '' : REVAPP._revisions.at( REVAPP._leftDiff - 1 ).get( 'revision_date_author_short' ) ); 472 REVAPP.addTooltip ( $( 'a.ui-slider-handle.right-handle' ), 473 ( REVAPP._rightDiff > REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._rightDiff - 1 ).get( 'revision_date_author_short' ) ); 474 } else { 475 REVAPP.addTooltip ( $( 'a.ui-slider-handle' ), 476 ( REVAPP._rightDiff > REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._rightDiff - 1 ).get( 'revision_date_author_short' ) ); 477 } 437 // Triggers the slide event 438 if ( slide ) 439 $( '#slider' ).trigger( 'slide' ); 440 }, 478 441 479 // hide the restore button when on the last sport/current post data 480 if ( REVAPP._rightDiff === REVAPP._revisions.length ){ 481 $( '.restore-button' ).hide(); 482 } else { 483 $( '.restore-button' ).show(); 484 } 442 option: function( key ) { 443 return $( '#slider' ).slider( 'option', key ); 444 }, 485 445 486 return this; 487 }, 446 render: function() { 447 var self = this; 448 // this.$el doesn't work, why? 449 $( '#slider' ).slider( { 450 slide: $.proxy( self.slide, self ), 451 start: $.proxy( self.start, self ), 452 stop: $.proxy( self.stop, self ) 453 } ); 488 454 489 // the compare two button is in this view, add the interaction here490 events: {491 'click #comparetwo': 'clickcomparetwo'492 },455 // Set options 456 this.refresh( this.options ); 457 } 458 }); 493 459 494 // turn on/off the compare two mmode 495 clickcomparetwo: function(){ 496 self = this; 460 /** 461 * wp.revisions.view.Tickmarks 462 * 463 * The slider tickmarks. 464 */ 465 revisions.view.Tickmarks = Backbone.View.extend({ 466 el: $('#diff-slider-ticks'), 467 template: wp.template('revision-ticks'), 468 model: Revision, 497 469 498 if ( $( 'input#comparetwo' ).is( ':checked' ) ) { // compare 2 mode 499 REVAPP._compareOneOrTwo = 2 ; 470 resetTicks: function() { 471 var sliderMax = Diff.slider.option( 'max' ); 472 var sliderWidth = Diff.slider.width(); 473 var adjustMax = Diff.singleRevision ? 0 : 1; 474 var tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); 500 475 501 if ( 1 === REVAPP._rightDiff ) 502 REVAPP._rightDiff = 2; 503 REVAPP._revisionView.draggingLeft = false; 476 // TODO: adjust right margins for wider ticks so they stay centered on handle stop point 504 477 505 wpRevisionsSettings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision506 REVAPP.reloadLeftRight();507 REVAPP._revisionView.model = REVAPP._rightHandleRevisions;478 // set minimum and maximum widths for tick marks 479 tickWidth = (tickWidth > 50 ) ? 50 : tickWidth; 480 tickWidth = (tickWidth < 10 ) ? 10 : tickWidth; 508 481 509 } else { // compare one mode 510 REVAPP._compareOneOrTwo = 1 ; 511 REVAPP._revisionView.draggingLeft = false; 512 // REVAPP._leftDiff = 0; 513 // REVAPP._rightDiff = (REVAPP._revisions.length <= REVAPP._rightDiff ) ? REVAPP._rightDiff + 1 : REVAPP._rightDiff + 1; 514 REVAPP.reloadModelSingle(); 515 } 516 // REVAPP._revisionView.render(); 517 REVAPP._revisionsInteractions.render(); 518 REVAPP._tickmarkView.render(); 482 sliderWidth = tickWidth * (sliderMax - adjustMax ) + 1; 519 483 520 } 521 }), 484 //$( '#slider' ).width( sliderWidth ); 485 Diff.slider.setWidth( sliderWidth ); 486 $( '.diff-slider-ticks-wrapper' ).width( sliderWidth ); 487 $( '#diffslider' ).width( sliderWidth ); 488 $( '#diff-slider-ticks' ).width( sliderWidth ); 522 489 523 // options view for show autosaves and show split view options 524 /* DISABLED for now 525 Options: Backbone.View.extend({ 526 el: $('#backbonerevisionsoptions')[0], 527 tagName: 'revisionoptionsview', 528 className: 'revisionoptions-container', 529 template: wp.template('revisionoptions'), 490 var aTickWidth = $( '.revision-tick' ).width(); 530 491 531 // render the options view 532 render: function() { 533 var addHtml = this.template; 534 this.$el.html( addHtml ); 535 return this; 536 }, 492 if ( tickWidth !== aTickWidth ) { // is the width already set correctly? 493 $( '.revision-tick' ).each( function( ) { 494 $(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin 495 }); 537 496 538 // add options interactions 539 events: { 540 'click #toggleshowautosaves': 'toggleshowautosaves', 541 'click #showsplitview': 'showsplitview' 542 }, 543 544 // toggle include autosaves 545 toggleshowautosaves: function() { 546 var self = this; 547 if ( $( '#toggleshowautosaves' ).is( ':checked' ) ) { 548 REVAPP._autosaves = true ; 549 } else { 550 REVAPP._autosaves = false ; 497 if( ! Diff.singleRevision ) { 498 $( '.revision-tick' ).first().remove(); // TODO - remove the check 551 499 } 500 $( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin 501 } 552 502 553 // refresh the model data 554 REVAPP.reloadModel(); 555 }, 503 }, 556 504 557 // toggle showing the split diffview558 showsplitview:function() {559 505 // render the tickmark view 506 render: function() { 507 var self = this; 560 508 561 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 562 REVAPP._showSplitView = 'true'; 563 $('.revisiondiffcontainer').addClass('diffsplit'); 564 } else { 565 REVAPP._showSplitView = ''; 566 $('.revisiondiffcontainer').removeClass('diffsplit'); 567 } 509 if ( null !== self.model ) { 510 var addHtml = ""; 511 _.each ( self.model.models, function( theModel ) { 512 addHtml = addHtml + self.template ( theModel.toJSON() ); 513 }); 514 self.$el.html( addHtml ); 568 515 569 REVAPP.reloadModel();570 516 } 571 }), 572 */ 573 // main interactions view 574 Interact: Backbone.View.extend({ 575 el: $('#backbonerevisionsinteract')[0], 576 tagName: 'revisionvinteract', 577 className: 'revisionvinteract-container', 578 template: wp.template('revisionvinteract'), 517 self.resetTicks(); 518 return self; 519 } 520 }); 579 521 580 initialize: function() { 581 }, 522 /** 523 * wp.revisions.view.Interact 524 * 525 * Next/Prev buttons and the slider 526 */ 527 // TODO: Change Interact to something else. 528 revisions.view.Interact = Backbone.View.extend({ 529 el: $('#backbonerevisionsinteract'), 530 template: wp.template('revision-interact'), 582 531 583 render: function() { 584 var self = this; 532 // next and previous buttons, only available in compare one mode 533 events: { 534 'click #next': 'nextRevision', 535 'click #previous': 'previousRevision' 536 }, 585 537 586 var addHtml = this.template;587 this.$el.html( addHtml );538 render: function() { 539 var self = this; 588 540 589 var modelcount = REVAPP._revisions.length; 541 var addHtml = this.template; 542 this.$el.html( addHtml ); 590 543 591 slider = $( "#slider" ); 592 if ( 1 === REVAPP._compareOneOrTwo ) { 593 // set up the slider with a single handle 594 slider.slider({ 595 value: REVAPP._rightDiff - 1, 596 min: 0, 597 max: modelcount - 1, 598 step: 1, 544 var modelcount = Diff.revisions.length; 599 545 546 Diff.slider.singleRevision = Diff.singleRevision; 547 Diff.slider.render(); 600 548 601 // slide interactions for one handles slider 602 slide: function( event, ui ) { 549 if ( Diff.singleRevision ) { 550 Diff.slider.refresh({ 551 value: Diff.rightDiff - 1, 552 min: 0, 553 max: modelcount - 1 554 }); 603 555 604 REVAPP._rightDiff = ( ui.value + 1 ); 605 REVAPP._revisionView.render(); 606 /* 607 $( 'a.ui-slider-handle' ).tooltip( { 608 content: REVAPP._revisions.at( ui.value ).get( 'revision_date_author_short' ), 609 position: { 610 my: "top-65", 611 using: function( position, feedback ) { 612 $( this ).css( position ); 613 $( "<div>" ) 614 .addClass( "arrow" ) 615 .addClass( feedback.vertical ) 616 .addClass( feedback.horizontal ) 617 .appendTo( this ); 618 } 619 } 620 });// .trigger( 'close' ).trigger( 'open' ); 621 */ 622 } 623 }); 624 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); 556 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); 625 557 626 } else { // comparing more than one, eg 2 627 // set up the slider with two handles 628 slider.slider({ 629 values: [ REVAPP._leftDiff, REVAPP._rightDiff + 1 ], 630 min: 1, 631 max: modelcount + 1, 632 step: 1, 633 range: true, 558 } else { 559 Diff.slider.refresh({ 560 values: [ Diff.leftDiff, Diff.rightDiff + 1 ], 561 min: 1, 562 max: modelcount + 1, 563 range: true 564 }); 634 565 635 // in two handled mode when user starts dragging, swap in precalculated diff for handle 636 start: function(event, ui ) { 637 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 638 switch ( index ) { 639 case 1: // left handle drag 640 if ( REVAPP._leftModelLoading ) // left model still loading, prevent sliding left handle 641 return false; 566 $( '.revisiondiffcontainer' ).addClass( 'comparetwo' ); 567 $( '#diffslider a.ui-slider-handle' ).first().addClass( 'left-handle' ).next().addClass( 'right-handle' ); 642 568 643 REVAPP._revisionView.draggingLeft = true;569 } 644 570 645 if ( REVAPP._revisionView.model !== REVAPP._leftHandleRevisions && 646 null !== REVAPP._leftHandleRevisions ) { 647 REVAPP._revisionView.model = REVAPP._leftHandleRevisions; 648 REVAPP._tickmarkView.model = REVAPP._leftHandleRevisions; 649 REVAPP._tickmarkView.render(); 650 } 571 return this; 572 }, 651 573 652 REVAPP._leftDiffStart = ui.values[ 0 ]; 653 break; 574 // go to the next revision 575 nextRevision: function() { 576 if ( Diff.rightDiff < this.model.length ) // unless at right boundry 577 Diff.rightDiff = Diff.rightDiff + 1 ; 654 578 655 case 2: // right 656 if ( REVAPP._rightModelLoading || 0 === REVAPP._rightHandleRevisions.length) // right model still loading, prevent sliding right handle 657 return false; 579 Diff.revisionView.render(); 658 580 659 if ( REVAPP._revisionView.model !== REVAPP._rightHandleRevisions && 660 null !== REVAPP._rightHandleRevisions ) { 661 REVAPP._revisionView.model = REVAPP._rightHandleRevisions; 662 REVAPP._tickmarkView.model = REVAPP._rightHandleRevisions; 663 REVAPP._tickmarkView.render(); 664 } 581 Diff.slider.refresh({ 582 value: Diff.rightDiff - 1 583 }, true ); 584 }, 665 585 666 REVAPP._revisionView.draggingLeft = false; 667 REVAPP._rightDiffStart = ui.values[1]; 668 break; 669 } 670 }, 586 // go the the previous revision 587 previousRevision: function() { 588 if ( Diff.rightDiff > 1 ) // unless at left boundry 589 Diff.rightDiff = Diff.rightDiff - 1 ; 671 590 672 // when sliding in two handled mode change appropriate value 673 slide: function( event, ui ) { 674 if ( ui.values[0] === ui.values[1] ) // prevent compare to self 675 return false; 591 Diff.revisionView.render(); 676 592 677 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 593 Diff.slider.refresh({ 594 value: Diff.rightDiff - 1 595 }, true ); 596 } 597 }); 678 598 679 switch ( index ) { 680 case 1: // left 681 if ( REVAPP._leftModelLoading ) // left model still loading, prevent sliding left handle 682 return false; 599 /** 600 * wp.revisions.view.Diff 601 * 602 * Next/Prev buttons and the slider 603 */ 604 revisions.view.Diff = Backbone.View.extend({ 605 el: $('#backbonerevisionsdiff'), 606 template: wp.template('revision'), 607 comparetwochecked: '', 608 draggingLeft: false, 683 609 684 REVAPP._leftDiff = ui.values[0]; 685 break; 610 // the compare two button is in this view, add the interaction here 611 events: { 612 'click #comparetwo': 'compareTwo', 613 'click #restore': 'restore' 614 }, 686 615 687 case 2: // right 688 if ( REVAPP._rightModelLoading ) // right model still loading, prevent sliding right handle 689 return false; 616 // render the revisions 617 render: function() { 618 var addHtml = ''; 619 var thediff; 690 620 691 REVAPP._rightDiff = ui.values[1]; 692 break; 693 } 621 // compare two revisions mode? 622 if ( ! Diff.singleRevision ) { 623 this.comparetwochecked = 'checked'; 624 if ( this.draggingLeft ) { 625 thediff = Diff.leftDiff - 1; 626 if ( this.model.at( thediff ) ) { 627 addHtml = this.template( _.extend( 628 this.model.at( thediff ).toJSON(), 629 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 630 ) ); 631 } 632 } else { // dragging right handle 633 thediff = Diff.rightDiff -1; 634 if ( this.model.at( thediff ) ) { 635 addHtml = this.template( _.extend( 636 this.model.at( thediff ).toJSON(), 637 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 638 ) ); 639 } 640 } 641 } else { // end compare two revisions mode, eg only one slider handle 642 this.comparetwochecked = ''; 643 if ( this.model.at( Diff.rightDiff - 1 ) ) { 644 addHtml = this.template( _.extend( 645 this.model.at( Diff.rightDiff - 1 ).toJSON(), 646 { comparetwochecked: this.comparetwochecked } // keep the checkmark unchecked 647 ) ); 648 } 649 } 650 this.$el.html( addHtml ); 651 if ( this.model.length < 3 ) { 652 $( 'div#comparetworevisions' ).hide(); // don't allow compare two if fewer than three revisions 653 } 654 if ( this.model.length < 2 ) { 655 $( 'div#diffslider' ).hide(); // don't allow compare two if fewer than three revisions 656 $( 'div.diff-slider-ticks-wrapper' ).hide(); 657 } 694 658 695 if ( 0 === REVAPP._leftDiff ) { 696 $( '.revisiondiffcontainer' ).addClass( 'currentversion' ); 659 // add tooltips to the handles 660 if ( ! Diff.singleRevision ) { 661 Diff.addTooltip ( $( 'a.ui-slider-handle.left-handle' ), 662 ( Diff.leftDiff < 0 ) ? '' : Diff.revisions.at( Diff.leftDiff - 1 ).get( 'revision_date_author_short' ) ); 663 Diff.addTooltip ( $( 'a.ui-slider-handle.right-handle' ), 664 ( Diff.rightDiff > Diff.revisions.length ) ? '' : Diff.revisions.at( Diff.rightDiff - 1 ).get( 'revision_date_author_short' ) ); 665 } else { 666 Diff.addTooltip ( $( 'a.ui-slider-handle' ), 667 ( Diff.rightDiff > Diff.revisions.length ) ? '' : Diff.revisions.at( Diff.rightDiff - 1 ).get( 'revision_date_author_short' ) ); 668 } 697 669 698 } else { 699 $( '.revisiondiffcontainer' ).removeClass( 'currentversion' ); 700 } 670 // hide the restore button when on the last sport/current post data 671 if ( Diff.rightDiff === Diff.revisions.length ){ 672 $( '#restore' ).hide(); 673 } else { 674 $( '#restore' ).show(); 675 } 701 676 702 REVAPP._revisionView.render(); 677 return this; 678 }, 703 679 704 }, 680 // turn on/off the compare two mmode 681 compareTwo: function() { 682 self = this; 705 683 706 // when the user stops sliding in 2 handle mode, recalculate diffs 707 stop: function( event, ui ) { 708 if ( 2 === REVAPP._compareOneOrTwo ) { 709 // calculate and generate a diff for comparing to the left handle 710 // and the right handle, swap out when dragging 684 if ( $( 'input#comparetwo' ).is( ':checked' ) ) { // compare 2 mode 685 Diff.singleRevision = false ; 711 686 712 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 687 if ( 1 === Diff.rightDiff ) 688 Diff.rightDiff = 2; 713 689 714 switch ( index ) { 715 case 1: // left 690 Diff.revisionView.draggingLeft = false; 716 691 717 // left handle dragged & changed, reload right handle model718 if ( REVAPP._leftDiffStart !== ui.values[0] )719 REVAPP.reloadRight();692 revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 693 Diff.reloadLeftRight(); 694 Diff.revisionView.model = Diff.rightHandleRevisions; 720 695 721 break; 696 } else { // compare one mode 697 Diff.singleRevision = true; 698 Diff.revisionView.draggingLeft = false; 699 Diff.reloadModelSingle(); 700 } 701 Diff.revisionsInteractions.render(); 702 Diff.tickmarkView.render(); 703 }, 722 704 723 case 2: // right 724 // REVAPP._rightDiff = ( 1 >= REVAPP._rightDiff ) ? 1 : REVAPP._rightDiff - 1; 725 // right handle dragged & changed, reload left handle model if changed 726 if ( REVAPP._rightDiffStart !== ui.values[1] ) 727 REVAPP.reloadLeft(); 705 restore: function() { 706 document.location = $( '#restore' ).data( 'link' ); 707 } 708 }); 728 709 729 break;730 }731 }732 }733 });734 $( '.revisiondiffcontainer' ).addClass( 'comparetwo' );735 $( '#diffslider a.ui-slider-handle' ).first().addClass( 'left-handle' ).next().addClass( 'right-handle' );736 }737 710 738 return this; 739 }, 711 /** 712 * ======================================================================== 713 * MODELS 714 * ======================================================================== 715 */ 740 716 741 // next and previous buttons, only available in compare one mode 742 events: { 743 'click #next': 'nextRevision', 744 'click #previous': 'previousRevision' 745 }, 717 /** 718 * wp.revisions.Revision 719 */ 720 Revision = revisions.model.Revision = Backbone.Model.extend({ 721 idAttribute: 'ID', 722 urlRoot: ajaxurl + '?action=revisions-data' + 723 '&show_autosaves=true&show_split_view=true&nonce=' + revisions.model.settings.nonce, 724 defaults: { 725 ID: 0, 726 revision_date_author: '', 727 revision_date_author_short: '', 728 revisiondiff: '<div class="diff-loading"><div class="spinner"></div></div>', 729 restoreaction: '', 730 revision_from_date_author: '', 731 revision_toload: false, 732 lines_added: 0, 733 lines_deleted: 0, 734 scope_of_changes: 'none', 735 previous_revision_id: 0 736 }, 746 737 747 // go to the next revision 748 nextRevision: function() { 749 if ( REVAPP._rightDiff < this.model.length ) // unless at right boundry 750 REVAPP._rightDiff = REVAPP._rightDiff + 1 ; 738 url: function() { 739 if ( Diff.singleRevision ) { 740 return this.urlRoot + 741 '&single_revision_id=' + this.id + 742 '&compare_to=' + this.get( 'previous_revision_id' ) + 743 '&post_id=' + revisions.model.settings.post_id; 744 } else { 745 return this.urlRoot + '&single_revision_id=' + this.id; 746 } 751 747 752 REVAPP._revisionView.render(); 748 } 749 }); 753 750 754 $( '#slider' ).slider( 'value', REVAPP._rightDiff - 1 ).trigger( 'slide' ); 755 }, 751 /** 752 * wp.revisions.Revisions 753 */ 754 Revisions = revisions.Revisions = Backbone.Collection.extend({ 755 model: Revision, 756 urlRoot: ajaxurl + '?action=revisions-data', 756 757 757 // go the the previous revision 758 previousRevision: function() { 759 if ( REVAPP._rightDiff > 1 ) // unless at left boundry 760 REVAPP._rightDiff = REVAPP._rightDiff - 1 ; 758 initialize: function( models, options ) { 759 this.options = _.defaults( options || {}, { 760 'compareTo': revisions.model.settings.post_id, 761 'post_id': revisions.model.settings.post_id, 762 'showAutosaves': true, 763 'showSplitView': true, 764 'rightHandleAt': 0, 765 'nonce': revisions.model.settings.nonce 766 }); 767 }, 761 768 762 REVAPP._revisionView.render(); 769 url: function() { 770 return this.urlRoot + 771 '&compare_to=' + this.options.compareTo + 772 '&post_id=' + this.options.post_id + 773 '&show_autosaves=' + this.options.showAutosaves + 774 '&show_split_view=' + this.options.showSplitView + 775 '&right_handle_at=' + this.options.rightHandleAt + 776 '&nonce=' + this.options.nonce; 777 }, 763 778 764 $( '#slider' ).slider( 'value', REVAPP._rightDiff - 1 ).trigger( 'slide' ); 765 } 766 }) 767 }); 779 reload: function( options ) { 780 this.options = _.defaults( options || {}, this.options ); 768 781 769 // instantiate Revision Application 770 REVAPP = new wp.revisions.App(); 782 // TODO 783 //this.fetch(); 784 } 771 785 786 } ); 787 788 $( wp.revisions ); 789 772 790 }(jQuery)); -
wp-admin/revision.php
79 79 80 80 require_once( './admin-header.php' ); 81 81 82 //TODO - Some of the translations below split things into multiple strings that are contextually related and this makes it pretty impossible for RTL translation. 83 //TODO can we pass the context in a better way 84 $wpRevisionsSettings = array( 'post_id' => $post->ID, 85 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 86 'revision_id' => $revision_id ); 87 wp_localize_script( 'revisions', 'wpRevisionsSettings', $wpRevisionsSettings ); 82 $strings = array( 83 'diffFromTitle' => _x( 'From: %s', 'revision from title' ), 84 'diffToTitle' => _x( 'To: %s', 'revision to title' ) 85 ); 88 86 87 $settings = array( 88 'post_id' => $post->ID, 89 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 90 'revision_id' => $revision_id 91 ); 92 93 $strings['settings'] = $settings; 94 95 wp_localize_script( 'revisions', 'wpRevisionsL10n', $strings ); 96 89 97 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 90 98 ?> 91 99 … … 126 134 <div class="diff-to-title"><?php _e( 'To:' ); ?></div>{{{ data.revision_date_author }}} 127 135 </div> 128 136 <div id="diffrestore"> 129 <input class="button button-primary restore-button" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore This Revision' )?>" />137 <input class="button button-primary" data-link="{{{ data.restoreaction }}}" type="button" id="restore" value="<?php esc_attr_e( 'Restore This Revision' )?>" /> 130 138 </div> 131 139 <div id="comparetworevisions"> 132 140 <input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> … … 141 149 <div>{{{ data.revisiondiff }}}</div> 142 150 </script> 143 151 144 <script id="tmpl-revision vinteract" type="text/html">152 <script id="tmpl-revision-interact" type="text/html"> 145 153 <div id="diffheader"> 146 154 <div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /> 147 155 </div> … … 153 161 </div> 154 162 </div> 155 163 </script> 164 156 165 <script id="tmpl-revision-ticks" type="text/html"> 157 166 <div class="revision-tick revision-toload{{{ data.revision_toload }}} revision-scopeofchanges-{{{ data.scope_of_changes }}}"> 158 167 </div> 159 168 </script> 160 169 <?php 161 /* 162 TODO Convert these into screen options 163 <script id="tmpl-revisionoptions" type="text/html"> 164 <div id="revisionoptions"> 165 <div id="showsplitviewoption"> 166 <input type='checkbox' id="show_split_view" checked="checked" value="1" /> <?php _e( 'Show split diff view' ); ?> 167 </div> 168 <div id="toggleshowautosavesoption"> 169 <input type='checkbox' id="toggleshowautosaves" value="1" /> <?php _e( 'Show autosaves' ); ?> 170 </div> 171 </div> 172 </script> 173 */ 174 require_once( './admin-footer.php' ); 175 No newline at end of file 170 require_once( './admin-footer.php' );