Changeset 23813
- Timestamp:
- 03/27/2013 12:59:41 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/revisions.js
r23769 r23813 4 4 wp.revisions = { 5 5 6 views 7 8 Model 9 idAttribute 10 urlRoot 6 views: {}, 7 8 Model: Backbone.Model.extend({ 9 idAttribute: 'ID', 10 urlRoot: ajaxurl + '?action=revisions-data' + 11 11 '&show_autosaves=true&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 12 12 defaults: { 13 ID 14 revision_date_author 13 ID: 0, 14 revision_date_author: '', 15 15 revision_date_author_short: '', 16 revisiondiff 17 restoreaction 18 revision_from_date_author 19 revision_toload 20 lines_added 21 lines_deleted 22 scope_of_changes 23 previous_revision_id 24 }, 25 26 url 27 if ( 1 === REVAPP._compare oneortwo ) {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 }, 25 26 url: function() { 27 if ( 1 === REVAPP._compareOneOrTwo ) { 28 28 return this.urlRoot + 29 29 '&single_revision_id=' + this.id + … … 41 41 app: _.extend({}, Backbone.Events), 42 42 43 App : Backbone.Router.extend({ 44 _revisionDifflView : null, 45 _revisions : null, 46 _left_handle_revisions : null, 47 _right_handle_revisions : null, 48 _revisionsInteractions : null, 49 _revisionsOptions : null, 50 _left_diff : 1, 51 _right_diff : 1, 52 _autosaves : true, 53 _show_split_view : true, 54 _compareoneortwo : 1, 55 _left_model_loading : false, //keep track of model loads 56 _right_model_loading : false, //disallow slider interaction, also repeat loads, while loading 57 _tickmarkView : null, //the slider tickmarks 58 _has_tooltip : false, 59 60 routes : { 61 }, 62 63 reload_toload_revisions : function( model_collection, reverse_direction ) { 64 var self = this; 65 var revisions_to_load = model_collection.where( { revision_toload : true } ); 66 var delay=0; 67 //match slider to passed revision_id 68 _.each( revisions_to_load, function( the_model ) { 69 if ( the_model.get( 'ID' ) == wpRevisionsSettings.revision_id ) { 70 self._right_diff = self._revisions.indexOf( the_model ) + 1; 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 57 58 routes: { 59 }, 60 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; 71 69 } 72 70 73 71 }); 74 _.each( revisions _to_load, function( the_model ) {75 the _model.urlRoot = model_collection.url;72 _.each( revisionsToLoad, function( theModel ) { 73 theModel.urlRoot = model_collection.url; 76 74 _.delay( function() { 77 the _model.fetch( {78 update 79 add 80 remove 81 success 75 theModel.fetch( { 76 update: true, 77 add: false, 78 remove: false, 79 success: function( model ) { 82 80 model.set( 'revision_toload', 'false' ); 83 81 84 // stop spinner when all models are loaded85 if ( 0 === model_collection.where( { revision_toload 86 self.stop _model_loading_spinner();82 // stop spinner when all models are loaded 83 if ( 0 === model_collection.where( { revision_toload: true } ).length ) 84 self.stopModelLoadingSpinner(); 87 85 88 86 self._tickmarkView.render(); 89 87 90 var total_changes = model.get( 'lines_added' ) + model.get( 'lines_deleted') ;91 varscope_of_changes = 'vsmall';88 var total_changes = model.get( 'lines_added' ) + model.get( 'lines_deleted'), 89 scope_of_changes = 'vsmall'; 92 90 93 91 // Note: hard coded scope of changes … … 103 101 } 104 102 model.set( 'scope_of_changes', scope_of_changes ); 105 if ( 0 !== self._right _diff &&106 model.get( 'ID' ) === self._revisions.at( self._right _diff - 1 ).get( 'ID' ) ) {107 // reload if current model refreshed103 if ( 0 !== self._rightDiff && 104 model.get( 'ID' ) === self._revisions.at( self._rightDiff - 1 ).get( 'ID' ) ) { 105 // reload if current model refreshed 108 106 self._revisionView.render(); 109 107 } … … 112 110 } ); 113 111 }, delay ) ; 114 delay = delay + 150; // stagger model loads to avoid hammering server with requests112 delay = delay + 150; // stagger model loads to avoid hammering server with requests 115 113 } 116 114 ); 117 115 }, 118 116 119 start _left_model_loading: function() {120 this._left _model_loading = true;117 startLeftModelLoading: function() { 118 this._leftModelLoading = true; 121 119 $('.revisiondiffcontainer').addClass('leftmodelloading'); 122 120 }, 123 121 124 stop _left_model_loading: function() {125 this._left _model_loading = false;126 }, 127 128 start _right_model_loading: function() {129 this._right _model_loading = true;122 stopLeftModelLoading: function() { 123 this._leftModelLoading = false; 124 }, 125 126 startRightModelLoading: function() { 127 this._rightModelLoading = true; 130 128 $('.revisiondiffcontainer').addClass('rightmodelloading'); 131 129 }, 132 130 133 stop _right_model_loading: function() {134 this._right _model_loading = false;135 }, 136 137 stop _model_loading_spinner: function() {131 stopRightModelLoading: function() { 132 this._rightModelLoading = false; 133 }, 134 135 stopModelLoadingSpinner: function() { 138 136 $('.revisiondiffcontainer').removeClass('rightmodelloading'); 139 137 $('.revisiondiffcontainer').removeClass('leftmodelloading'); 140 138 }, 141 139 142 reload model: function() {143 if ( 2 === this._compare oneortwo ) {144 this.reload leftright();140 reloadModel: function() { 141 if ( 2 === this._compareOneOrTwo ) { 142 this.reloadLeftRight(); 145 143 } else { 146 this.reload modelsingle();147 } 148 }, 149 150 // load the models for the single handle mode151 reload modelsingle: function() {144 this.reloadModelSingle(); 145 } 146 }, 147 148 // load the models for the single handle mode 149 reloadModelSingle: function() { 152 150 var self = this; 153 151 self._revisions.url = ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 154 152 '&show_autosaves=' + self._autosaves + 155 '&show_split_view=' + self._show _split_view +153 '&show_split_view=' + self._showSplitView + 156 154 '&nonce=' + wpRevisionsSettings.nonce; 157 self.start _right_model_loading();158 self._revisions.fetch({ // reload revision data159 success 155 self.startRightModelLoading(); 156 self._revisions.fetch({ // reload revision data 157 success: function() { 160 158 console.log('loaded'); 161 // self.stop_right_model_loading();162 // REVAPP._right_diff -= 1;163 var revision count = self._revisions.length;159 // self.stopRightModelLoading(); 160 // REVAPP._rightDiff -= 1; 161 var revisionCount = self._revisions.length; 164 162 self._revisionView.model = self._revisions; 165 163 self._revisionView.render(); 166 self.reload _toload_revisions( self._revisions );164 self.reloadToLoadRevisions( self._revisions ); 167 165 self._tickmarkView.model = self._revisions; 168 166 self._tickmarkView.render(); 169 $( '#slider' ).slider( 'option', 'max', revision count-1 ); //TODO test this, if autsave option changed170 $( '#slider' ).slider( 'value', self._right _diff - 1 ).trigger( 'slide' );167 $( '#slider' ).slider( 'option', 'max', revisionCount - 1 ); // TODO: test this, if autosave option changed 168 $( '#slider' ).slider( 'value', self._rightDiff - 1 ).trigger( 'slide' ); 171 169 172 170 }, 173 171 174 error : function() {175 self.stop _right_model_loading();172 error: function() { 173 self.stopRightModelLoading(); 176 174 } 177 175 … … 179 177 }, 180 178 181 // load the models for the left handle182 reload left: function() {179 // load the models for the left handle 180 reloadLeft: function() { 183 181 var self = this; 184 self.start _left_model_loading();185 self._left _handle_revisions = new wp.revisions.Collection();186 187 self._left _handle_revisions.url =182 self.startLeftModelLoading(); 183 self._leftHandleRevisions = new wp.revisions.Collection(); 184 185 self._leftHandleRevisions.url = 188 186 ajaxurl + 189 '?action=revisions-data&compare_to=' + self._revisions.at( self._right _diff - 1 ).get( 'ID' ) +187 '?action=revisions-data&compare_to=' + self._revisions.at( self._rightDiff - 1 ).get( 'ID' ) + 190 188 '&post_id=' + wpRevisionsSettings.post_id + 191 189 '&show_autosaves=' + REVAPP._autosaves + 192 '&show_split_view=' + REVAPP._show _split_view +190 '&show_split_view=' + REVAPP._showSplitView + 193 191 '&nonce=' + wpRevisionsSettings.nonce + 194 '&right_handle_at=' + ( self._right _diff );195 196 self._left _handle_revisions.fetch({197 198 success 199 self.stop _left_model_loading();200 self.reload _toload_revisions( self._left_handle_revisions );201 self._tickmarkView.model = self._left _handle_revisions;192 '&right_handle_at=' + ( self._rightDiff ); 193 194 self._leftHandleRevisions.fetch({ 195 196 success: function(){ 197 self.stopLeftModelLoading(); 198 self.reloadToLoadRevisions( self._leftHandleRevisions ); 199 self._tickmarkView.model = self._leftHandleRevisions; 202 200 $( '#slider' ).slider( 'option', 'max', self._revisions.length ); 203 201 // ensure right handle not beyond length, in particular if viewing autosaves is switched from on to off 204 202 // the number of models in the collection might get shorter, this ensures right handle is not beyond last model 205 if ( self._right _diff > self._revisions.length )206 self._right _diff = self._revisions.length;203 if ( self._rightDiff > self._revisions.length ) 204 self._rightDiff = self._revisions.length; 207 205 }, 208 206 209 error : function() {210 self.stop _left_model_loading();207 error: function() { 208 self.stopLeftModelLoading(); 211 209 } 212 210 }); 213 211 }, 214 212 215 // load the models for the right handle216 reload right: function() {213 // load the models for the right handle 214 reloadRight: function() { 217 215 var self = this; 218 self.start _right_model_loading();219 self._right _handle_revisions = new wp.revisions.Collection();220 221 self._right _handle_revisions.url =216 self.startRightModelLoading(); 217 self._rightHandleRevisions = new wp.revisions.Collection(); 218 219 self._rightHandleRevisions.url = 222 220 ajaxurl + 223 '?action=revisions-data&compare_to=' + ( self._revisions.at( self._left _diff ).get( 'ID' ) -1)+221 '?action=revisions-data&compare_to=' + ( self._revisions.at( self._leftDiff ).get( 'ID' ) - 1 )+ 224 222 '&post_id=' + wpRevisionsSettings.post_id + 225 223 '&show_autosaves=' + REVAPP._autosaves + 226 '&show_split_view=' + REVAPP._show _split_view +224 '&show_split_view=' + REVAPP._showSplitView + 227 225 '&nonce=' + wpRevisionsSettings.nonce; 228 226 229 self._right _handle_revisions.fetch({230 231 success 232 self.stop _right_model_loading();233 self.reload _toload_revisions( self._right_handle_revisions );234 self._tickmarkView.model = self._right _handle_revisions;227 self._rightHandleRevisions.fetch({ 228 229 success: function(){ 230 self.stopRightModelLoading(); 231 self.reloadToLoadRevisions( self._rightHandleRevisions ); 232 self._tickmarkView.model = self._rightHandleRevisions; 235 233 $( '#slider' ).slider( 'option', 'max', self._revisions.length ); 236 $( '#slider' ).slider( 'values', [ REVAPP._left _diff, REVAPP._right_diff] ).trigger( 'slide' );237 238 // REVAPP._revisionView.render();234 $( '#slider' ).slider( 'values', [ REVAPP._leftDiff, REVAPP._rightDiff] ).trigger( 'slide' ); 235 236 // REVAPP._revisionView.render(); 239 237 240 238 }, 241 239 242 error : function( response ) {243 self.stop _right_model_loading();240 error: function( response ) { 241 self.stopRightModelLoading(); 244 242 } 245 243 }); … … 247 245 }, 248 246 249 reload leftright: function() {250 this.start _right_model_loading();251 this.start _left_model_loading();252 this.reload left();253 this.reload right();247 reloadLeftRight: function() { 248 this.startRightModelLoading(); 249 this.startLeftModelLoading(); 250 this.reloadLeft(); 251 this.reloadRight(); 254 252 }, 255 253 … … 257 255 * initialize the revision application 258 256 */ 259 initialize 260 var self = this; // store the application instance257 initialize: function( options ) { 258 var self = this; // store the application instance 261 259 if (this._revisions === null) { 262 self._revisions = new wp.revisions.Collection(); // set up collection263 self.start _right_model_loading();264 self._revisions.fetch({ // load revision data265 266 success 267 self.stop _right_model_loading();268 // self._right_handle_revisions = self._revisions;260 self._revisions = new wp.revisions.Collection(); // set up collection 261 self.startRightModelLoading(); 262 self._revisions.fetch({ // load revision data 263 264 success: function() { 265 self.stopRightModelLoading(); 266 // self._rightHandleRevisions = self._revisions; 269 267 self.completeApplicationSetup(); 270 268 } … … 274 272 }, 275 273 276 addTooltip 274 addTooltip: function( handle, message ) { 277 275 278 276 handle.attr( 'title', '' ).tooltip({ … … 301 299 /**/ 302 300 303 completeApplicationSetup 301 completeApplicationSetup: function() { 304 302 this._revisionView = new wp.revisions.views.View({ 305 model 303 model: this._revisions 306 304 }); 307 305 this._revisionView.render(); 308 306 $( '#slider' ).slider( 'option', 'max', this._revisions.length - 1 ); 309 307 310 this.reload _toload_revisions( this._revisions );308 this.reloadToLoadRevisions( this._revisions ); 311 309 312 310 this._revisionsInteractions = new wp.revisions.views.Interact({ 313 model 311 model: this._revisions 314 312 }); 315 313 this._revisionsInteractions.render(); 316 314 317 315 this._tickmarkView = new wp.revisions.views.Tickmarks({ 318 model 316 model: this._revisions 319 317 }); 320 318 this._tickmarkView.render(); 321 this._tickmarkView.reset ticks();319 this._tickmarkView.resetTicks(); 322 320 323 321 … … 334 332 */ 335 333 /* 336 // Options hidden for now, moving to screen options334 // Options hidden for now, moving to screen options 337 335 this._revisionsOptions = new wp.revisions.views.Options({ 338 model 336 model: this._revisions 339 337 }); 340 338 this._revisionsOptions.render(); … … 346 344 347 345 wp.revisions.Collection = Backbone.Collection.extend({ 348 model 349 url 346 model: wp.revisions.Model, 347 url: ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 350 348 '&show_autosaves=true&show_split_view=true&nonce=' + wpRevisionsSettings.nonce, 351 349 352 initialize 350 initialize: function() { 353 351 } 354 352 } ); … … 356 354 _.extend(wp.revisions.views, { 357 355 358 //Ticks inside slider view 359 // 360 Tickmarks : Backbone.View.extend({ 361 el : $('#diff-slider-ticks')[0], 362 tagName : 'diff-slider-ticks-view', 363 className : 'diff-slider-ticks-container', 364 template : wp.template('revision-ticks'), 365 model : wp.revisions.Model, 366 367 resetticks : function() { 368 var slider_max = $( '#slider' ).slider( 'option', 'max'); 369 var slider_width = $( '#slider' ).width(); 370 var adjust_max = ( 2 === REVAPP._compareoneortwo ) ? 1 : 0; 371 var tick_width = Math.floor( slider_width / ( slider_max - adjust_max ) ); 372 373 //TODO: adjust right margins for wider ticks so they stay centered on handle stop point 374 375 //set minimum and maximum widths for tick marks 376 tick_width = (tick_width > 50 ) ? 50 : tick_width; 377 tick_width = (tick_width < 10 ) ? 10 : tick_width; 378 379 slider_width = tick_width * (slider_max - adjust_max ) +1; 380 381 $( '#slider' ).width( slider_width ); 382 $( '.diff-slider-ticks-wrapper' ).width( slider_width ); 383 $( '#diffslider' ).width( slider_width ); 384 $( '#diff-slider-ticks' ).width( slider_width ); 385 386 var a_tick_width = $( '.revision-tick' ).width(); 387 388 if ( tick_width !== a_tick_width ) { // is the width already set correctly? 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, 363 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 ) ); 369 370 // TODO: adjust right margins for wider ticks so they stay centered on handle stop point 371 372 // set minimum and maximum widths for tick marks 373 tickWidth = (tickWidth > 50 ) ? 50 : tickWidth; 374 tickWidth = (tickWidth < 10 ) ? 10 : tickWidth; 375 376 sliderWidth = tickWidth * (sliderMax - adjustMax ) + 1; 377 378 $( '#slider' ).width( sliderWidth ); 379 $( '.diff-slider-ticks-wrapper' ).width( sliderWidth ); 380 $( '#diffslider' ).width( sliderWidth ); 381 $( '#diff-slider-ticks' ).width( sliderWidth ); 382 383 var aTickWidth = $( '.revision-tick' ).width(); 384 385 if ( tickWidth !== aTickWidth ) { // is the width already set correctly? 389 386 $( '.revision-tick' ).each( function( ) { 390 $(this).css( 'margin-right', tick _width - 1 + 'px'); //space the ticks out using right margin387 $(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin 391 388 }); 392 389 393 if( 2 === REVAPP._compare oneortwo ) {394 $( '.revision-tick' ).first().remove(); // TODO - remove the check390 if( 2 === REVAPP._compareOneOrTwo ) { 391 $( '.revision-tick' ).first().remove(); // TODO - remove the check 395 392 } 396 393 $( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin … … 399 396 }, 400 397 401 // render the tickmark view402 render 398 // render the tickmark view 399 render: function() { 403 400 var self = this; 404 401 405 402 if ( null !== self.model ) { 406 var add html = "";407 _.each ( self.model.models, function ( the_model ) {408 add html = addhtml + self.template ( the_model.toJSON() );403 var addHtml = ""; 404 _.each ( self.model.models, function( theModel ) { 405 addHtml = addHtml + self.template ( theModel.toJSON() ); 409 406 }); 410 self.$el.html( add html );411 412 } 413 self.reset ticks();407 self.$el.html( addHtml ); 408 409 } 410 self.resetTicks(); 414 411 return self; 415 412 } 416 413 }), 417 414 418 // 419 //primary revision diff view 420 // 421 View : Backbone.View.extend({ 422 el : $('#backbonerevisionsdiff')[0], 423 tagName : 'revisionvview', 424 className : 'revisionview-container', 425 template : wp.template('revision'), 426 comparetwochecked : '', 427 draggingleft : false, 428 429 // 430 //render the revisions 431 // 432 render : function() { 433 var addhtml = ''; 434 //compare two revisions mode? 435 436 if ( 2 === REVAPP._compareoneortwo ) { 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, 423 424 // render the revisions 425 render: function() { 426 var addHtml = ''; 427 // compare two revisions mode? 428 429 if ( 2 === REVAPP._compareOneOrTwo ) { 437 430 this.comparetwochecked = 'checked'; 438 if ( this.dragging left ) {439 if ( this.model.at( REVAPP._left _diff ) ) {440 add html = this.template( _.extend(441 this.model.at( REVAPP._left _diff ).toJSON(),442 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked431 if ( this.draggingLeft ) { 432 if ( this.model.at( REVAPP._leftDiff ) ) { 433 addHtml = this.template( _.extend( 434 this.model.at( REVAPP._leftDiff ).toJSON(), 435 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 443 436 ) ); 444 437 } 445 } else { // dragging right handle446 var thediff = REVAPP._right _diff;438 } else { // dragging right handle 439 var thediff = REVAPP._rightDiff; 447 440 if ( this.model.at( thediff ) ) { 448 add html = this.template( _.extend(441 addHtml = this.template( _.extend( 449 442 this.model.at( thediff ).toJSON(), 450 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked443 { comparetwochecked: this.comparetwochecked } // keep the checkmark checked 451 444 ) ); 452 445 } 453 446 } 454 } else { // end compare two revisions mode, eg only one slider handle447 } else { // end compare two revisions mode, eg only one slider handle 455 448 this.comparetwochecked = ''; 456 if ( this.model.at( REVAPP._right _diff - 1 ) ) {457 add html = this.template( _.extend(458 this.model.at( REVAPP._right _diff - 1 ).toJSON(),459 { comparetwochecked : this.comparetwochecked } //keep the checkmark unchecked449 if ( this.model.at( REVAPP._rightDiff - 1 ) ) { 450 addHtml = this.template( _.extend( 451 this.model.at( REVAPP._rightDiff - 1 ).toJSON(), 452 { comparetwochecked: this.comparetwochecked } // keep the checkmark unchecked 460 453 ) ); 461 454 } 462 455 } 463 this.$el.html( add html );456 this.$el.html( addHtml ); 464 457 if ( this.model.length < 3 ) { 465 $( 'div#comparetworevisions' ).hide(); // don't allow compare two if fewer than three revisions458 $( 'div#comparetworevisions' ).hide(); // don't allow compare two if fewer than three revisions 466 459 } 467 460 if ( this.model.length < 2 ) { 468 $( 'div#diffslider' ).hide(); // don't allow compare two if fewer than three revisions461 $( 'div#diffslider' ).hide(); // don't allow compare two if fewer than three revisions 469 462 $( 'div.diff-slider-ticks-wrapper' ).hide(); 470 463 } 471 464 472 //473 465 // add tooltips to the handles 474 // 475 if ( 2 === REVAPP._compareoneortwo ) { 466 if ( 2 === REVAPP._compareOneOrTwo ) { 476 467 REVAPP.addTooltip ( $( 'a.ui-slider-handle.left-handle' ), 477 ( REVAPP._right _diff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._left_diff ).get( 'revision_date_author_short' ) );468 ( REVAPP._rightDiff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._leftDiff ).get( 'revision_date_author_short' ) ); 478 469 REVAPP.addTooltip ( $( 'a.ui-slider-handle.right-handle' ), 479 ( REVAPP._right _diff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._right_diff ).get( 'revision_date_author_short' ) );470 ( REVAPP._rightDiff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._rightDiff ).get( 'revision_date_author_short' ) ); 480 471 } else { 481 472 REVAPP.addTooltip ( $( 'a.ui-slider-handle' ), 482 ( REVAPP._right_diff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._right_diff ).get( 'revision_date_author_short' ) ); 483 } 484 485 // 473 ( REVAPP._rightDiff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._rightDiff ).get( 'revision_date_author_short' ) ); 474 } 475 486 476 // hide the restore button when on the last sport/current post data 487 // 488 if ( REVAPP._right_diff === REVAPP._revisions.length ){ 477 if ( REVAPP._rightDiff === REVAPP._revisions.length ){ 489 478 $( '.restore-button' ).hide(); 490 479 } else { … … 495 484 }, 496 485 497 //the compare two button is in this view, add the interaction here 498 events : { 499 'click #comparetwo' : 'clickcomparetwo' 500 }, 501 502 // 503 //turn on/off the compare two mmode 504 // 505 clickcomparetwo : function(){ 486 // the compare two button is in this view, add the interaction here 487 events: { 488 'click #comparetwo': 'clickcomparetwo' 489 }, 490 491 // turn on/off the compare two mmode 492 clickcomparetwo: function(){ 506 493 self = this; 507 494 508 if ( $( 'input#comparetwo' ).is( ':checked' ) ) { // compare 2 mode509 REVAPP._compare oneortwo = 2 ;510 511 if ( 1 === REVAPP._right _diff )512 REVAPP._right _diff = 2;513 REVAPP._revisionView.dragging left = false;495 if ( $( 'input#comparetwo' ).is( ':checked' ) ) { // compare 2 mode 496 REVAPP._compareOneOrTwo = 2 ; 497 498 if ( 1 === REVAPP._rightDiff ) 499 REVAPP._rightDiff = 2; 500 REVAPP._revisionView.draggingLeft = false; 514 501 515 502 wpRevisionsSettings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 516 REVAPP.reload leftright();517 REVAPP._revisionView.model = REVAPP._right _handle_revisions;518 519 } else { // compare one mode520 REVAPP._compare oneortwo = 1 ;521 REVAPP._revisionView.dragging left = false;522 // REVAPP._left_diff = 0;523 // REVAPP._right_diff = (REVAPP._revisions.length <= REVAPP._right_diff ) ? REVAPP._right_diff + 1 : REVAPP._right_diff + 1;524 REVAPP.reload modelsingle();525 } 526 // REVAPP._revisionView.render();503 REVAPP.reloadLeftRight(); 504 REVAPP._revisionView.model = REVAPP._rightHandleRevisions; 505 506 } else { // compare one mode 507 REVAPP._compareOneOrTwo = 1 ; 508 REVAPP._revisionView.draggingLeft = false; 509 // REVAPP._leftDiff = 0; 510 // REVAPP._rightDiff = (REVAPP._revisions.length <= REVAPP._rightDiff ) ? REVAPP._rightDiff + 1 : REVAPP._rightDiff + 1; 511 REVAPP.reloadModelSingle(); 512 } 513 // REVAPP._revisionView.render(); 527 514 REVAPP._revisionsInteractions.render(); 528 515 REVAPP._tickmarkView.render(); … … 531 518 }), 532 519 533 // 534 //options view for show autosaves and show split view options 535 // 520 // options view for show autosaves and show split view options 536 521 /* DISABLED for now 537 Options 538 el 539 tagName 540 className 541 template 542 543 // render the options view544 render 545 var add html = this.template;546 this.$el.html( add html );522 Options: Backbone.View.extend({ 523 el: $('#backbonerevisionsoptions')[0], 524 tagName: 'revisionoptionsview', 525 className: 'revisionoptions-container', 526 template: wp.template('revisionoptions'), 527 528 // render the options view 529 render: function() { 530 var addHtml = this.template; 531 this.$el.html( addHtml ); 547 532 return this; 548 533 }, 549 534 550 //add options interactions 551 events : { 552 'click #toggleshowautosaves' : 'toggleshowautosaves', 553 'click #showsplitview' : 'showsplitview' 554 }, 555 556 // 557 //toggle include autosaves 558 // 559 toggleshowautosaves : function() { 535 // add options interactions 536 events: { 537 'click #toggleshowautosaves': 'toggleshowautosaves', 538 'click #showsplitview': 'showsplitview' 539 }, 540 541 // toggle include autosaves 542 toggleshowautosaves: function() { 560 543 var self = this; 561 544 if ( $( '#toggleshowautosaves' ).is( ':checked' ) ) { … … 565 548 } 566 549 567 //refresh the model data 568 REVAPP.reloadmodel(); 569 }, 570 571 // 572 //toggle showing the split diff view 573 // 574 showsplitview : function() { 550 // refresh the model data 551 REVAPP.reloadModel(); 552 }, 553 554 // toggle showing the split diff view 555 showsplitview: function() { 575 556 var self = this; 576 557 577 558 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 578 REVAPP._show _split_view = 'true';559 REVAPP._showSplitView = 'true'; 579 560 $('.revisiondiffcontainer').addClass('diffsplit'); 580 561 } else { 581 REVAPP._show _split_view = '';562 REVAPP._showSplitView = ''; 582 563 $('.revisiondiffcontainer').removeClass('diffsplit'); 583 564 } 584 565 585 REVAPP.reload model();566 REVAPP.reloadModel(); 586 567 } 587 568 }), 588 569 */ 589 // 590 //main interactions view 591 // 592 Interact : Backbone.View.extend({ 593 el : $('#backbonerevisionsinteract')[0], 594 tagName : 'revisionvinteract', 595 className : 'revisionvinteract-container', 596 template : wp.template('revisionvinteract'), 597 598 initialize : function() { 599 }, 600 601 render : function() { 570 // main interactions view 571 Interact: Backbone.View.extend({ 572 el: $('#backbonerevisionsinteract')[0], 573 tagName: 'revisionvinteract', 574 className: 'revisionvinteract-container', 575 template: wp.template('revisionvinteract'), 576 577 initialize: function() { 578 }, 579 580 render: function() { 602 581 var self = this; 603 582 604 var add html = this.template;605 this.$el.html( add html );583 var addHtml = this.template; 584 this.$el.html( addHtml ); 606 585 607 586 var modelcount = REVAPP._revisions.length; 608 587 609 588 slider = $( "#slider" ); 610 if ( 1 === REVAPP._compare oneortwo ) {611 // set up the slider with a single handle589 if ( 1 === REVAPP._compareOneOrTwo ) { 590 // set up the slider with a single handle 612 591 slider.slider({ 613 value: REVAPP._right _diff-1,592 value: REVAPP._rightDiff - 1, 614 593 min: 0, 615 max: modelcount -1,594 max: modelcount - 1, 616 595 step: 1, 617 596 618 597 619 // slide interactions for one handles slider620 slide 621 622 REVAPP._right _diff = ( ui.value + 1 );598 // slide interactions for one handles slider 599 slide: function( event, ui ) { 600 601 REVAPP._rightDiff = ( ui.value + 1 ); 623 602 REVAPP._revisionView.render(); 624 603 /* … … 636 615 } 637 616 } 638 });// .trigger( 'close' ).trigger( 'open' );617 });// .trigger( 'close' ).trigger( 'open' ); 639 618 */ 640 619 } … … 642 621 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); 643 622 644 } else { // comparing more than one, eg 2645 // set up the slider with two handles623 } else { // comparing more than one, eg 2 624 // set up the slider with two handles 646 625 slider.slider({ 647 values : [ REVAPP._left_diff, REVAPP._right_diff + 1 ],648 min 649 max : modelcount+1,650 step 626 values: [ REVAPP._leftDiff, REVAPP._rightDiff + 1 ], 627 min: 1, 628 max: modelcount + 1, 629 step: 1, 651 630 range: true, 652 631 653 // in two handled mode when user starts dragging, swap in precalculated diff for handle654 start : function(event, ui ) {655 var index = $( ui.handle ).index(); // 0 (left) or 1 (right)632 // in two handled mode when user starts dragging, swap in precalculated diff for handle 633 start: function(event, ui ) { 634 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 656 635 switch ( index ) { 657 case 1: // left handle drag658 if ( REVAPP._left _model_loading ) //left model still loading, prevent sliding left handle636 case 1: // left handle drag 637 if ( REVAPP._leftModelLoading ) // left model still loading, prevent sliding left handle 659 638 return false; 660 639 661 REVAPP._revisionView.dragging left = true;662 663 if ( REVAPP._revisionView.model !== REVAPP._left _handle_revisions &&664 null !== REVAPP._left _handle_revisions ) {665 REVAPP._revisionView.model = REVAPP._left _handle_revisions;666 REVAPP._tickmarkView.model = REVAPP._left _handle_revisions;640 REVAPP._revisionView.draggingLeft = true; 641 642 if ( REVAPP._revisionView.model !== REVAPP._leftHandleRevisions && 643 null !== REVAPP._leftHandleRevisions ) { 644 REVAPP._revisionView.model = REVAPP._leftHandleRevisions; 645 REVAPP._tickmarkView.model = REVAPP._leftHandleRevisions; 667 646 REVAPP._tickmarkView.render(); 668 647 } 669 648 670 REVAPP._left _diff_start = ui.values[ 0 ];649 REVAPP._leftDiffStart = ui.values[ 0 ]; 671 650 break; 672 651 673 case 2: // right674 if ( REVAPP._right _model_loading || 0 === REVAPP._right_handle_revisions.length) //right model still loading, prevent sliding right handle652 case 2: // right 653 if ( REVAPP._rightModelLoading || 0 === REVAPP._rightHandleRevisions.length) // right model still loading, prevent sliding right handle 675 654 return false; 676 655 677 if ( REVAPP._revisionView.model !== REVAPP._right _handle_revisions &&678 null !== REVAPP._right _handle_revisions ) {679 REVAPP._revisionView.model = REVAPP._right _handle_revisions;680 REVAPP._tickmarkView.model = REVAPP._right _handle_revisions;656 if ( REVAPP._revisionView.model !== REVAPP._rightHandleRevisions && 657 null !== REVAPP._rightHandleRevisions ) { 658 REVAPP._revisionView.model = REVAPP._rightHandleRevisions; 659 REVAPP._tickmarkView.model = REVAPP._rightHandleRevisions; 681 660 REVAPP._tickmarkView.render(); 682 661 } 683 662 684 REVAPP._revisionView.dragging left = false;685 REVAPP._right _diff_start = ui.values[ 1];663 REVAPP._revisionView.draggingLeft = false; 664 REVAPP._rightDiffStart = ui.values[1]; 686 665 break; 687 666 } 688 667 }, 689 668 690 // when sliding in two handled mode change appropriate value691 slide 692 if ( ui.values[ 0 ] === ui.values[ 1 ] ) //prevent compare to self669 // when sliding in two handled mode change appropriate value 670 slide: function( event, ui ) { 671 if ( ui.values[0] === ui.values[1] ) // prevent compare to self 693 672 return false; 694 673 695 var index = $( ui.handle ).index(); // 0 (left) or 1 (right)674 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 696 675 697 676 switch ( index ) { 698 case 1: // left699 if ( REVAPP._left _model_loading ) //left model still loading, prevent sliding left handle677 case 1: // left 678 if ( REVAPP._leftModelLoading ) // left model still loading, prevent sliding left handle 700 679 return false; 701 680 702 REVAPP._left _diff = ui.values[ 0];681 REVAPP._leftDiff = ui.values[0]; 703 682 break; 704 683 705 case 2: // right706 if ( REVAPP._right _model_loading ) //right model still loading, prevent sliding right handle684 case 2: // right 685 if ( REVAPP._rightModelLoading ) // right model still loading, prevent sliding right handle 707 686 return false; 708 687 709 REVAPP._right _diff = ui.values[ 1];688 REVAPP._rightDiff = ui.values[1]; 710 689 break; 711 690 } 712 691 713 if ( 0 === REVAPP._left _diff ) {692 if ( 0 === REVAPP._leftDiff ) { 714 693 $( '.revisiondiffcontainer' ).addClass( 'currentversion' ); 715 694 … … 722 701 }, 723 702 724 // when the user stops sliding in 2 handle mode, recalculate diffs725 stop 726 if ( 2 === REVAPP._compare oneortwo ) {727 // calculate and generate a diff for comparing to the left handle728 // and the right handle, swap out when dragging729 730 var index = $( ui.handle ).index(); // 0 (left) or 1 (right)703 // when the user stops sliding in 2 handle mode, recalculate diffs 704 stop: function( event, ui ) { 705 if ( 2 === REVAPP._compareOneOrTwo ) { 706 // calculate and generate a diff for comparing to the left handle 707 // and the right handle, swap out when dragging 708 709 var index = $( ui.handle ).index(); // 0 (left) or 1 (right) 731 710 732 711 switch ( index ) { 733 case 1: // left734 735 // left handle dragged & changed, reload right handle model736 if ( REVAPP._left _diff_start !== ui.values[ 0] )737 REVAPP.reload right();712 case 1: // left 713 714 // left handle dragged & changed, reload right handle model 715 if ( REVAPP._leftDiffStart !== ui.values[0] ) 716 REVAPP.reloadRight(); 738 717 739 718 break; 740 719 741 case 2: // right742 // REVAPP._right_diff = ( 1 >= REVAPP._right_diff ) ? 1 : REVAPP._right_diff-1;743 // right handle dragged & changed, reload left handle model if changed744 if ( REVAPP._right _diff_start !== ui.values[ 1] )745 REVAPP.reload left();720 case 2: // right 721 // REVAPP._rightDiff = ( 1 >= REVAPP._rightDiff ) ? 1 : REVAPP._rightDiff - 1; 722 // right handle dragged & changed, reload left handle model if changed 723 if ( REVAPP._rightDiffStart !== ui.values[1] ) 724 REVAPP.reloadLeft(); 746 725 747 726 break; … … 757 736 }, 758 737 759 // next and previous buttons, only available in compare one mode760 events 761 'click #next' : 'nextrevision',762 'click #previous' : 'previousrevision'763 }, 764 765 // go to the next revision766 next revision: function() {767 if ( REVAPP._right _diff < this.model.length ) //unless at right boundry768 REVAPP._right _diff = REVAPP._right_diff + 1 ;738 // next and previous buttons, only available in compare one mode 739 events: { 740 'click #next': 'nextRevision', 741 'click #previous': 'previousRevision' 742 }, 743 744 // go to the next revision 745 nextRevision: function() { 746 if ( REVAPP._rightDiff < this.model.length ) // unless at right boundry 747 REVAPP._rightDiff = REVAPP._rightDiff + 1 ; 769 748 770 749 REVAPP._revisionView.render(); 771 750 772 $( '#slider' ).slider( 'value', REVAPP._right _diff - 1 ).trigger( 'slide' );773 }, 774 775 // go the the previous revision776 previous revision: function() {777 if ( REVAPP._right _diff > 1 ) //unless at left boundry778 REVAPP._right_diff = REVAPP._right_diff - 1 ;751 $( '#slider' ).slider( 'value', REVAPP._rightDiff - 1 ).trigger( 'slide' ); 752 }, 753 754 // go the the previous revision 755 previousRevision: function() { 756 if ( REVAPP._rightDiff > 1 ) // unless at left boundry 757 REVAPP._rightDiff = REVAPP._rightDiff - 1 ; 779 758 780 759 REVAPP._revisionView.render(); 781 760 782 $( '#slider' ).slider( 'value', REVAPP._right _diff - 1 ).trigger( 'slide' );761 $( '#slider' ).slider( 'value', REVAPP._rightDiff - 1 ).trigger( 'slide' ); 783 762 } 784 763 }) 785 764 }); 786 765 787 // instantiate Revision Application766 // instantiate Revision Application 788 767 REVAPP = new wp.revisions.App(); 789 768
Note: See TracChangeset
for help on using the changeset viewer.