wp/wp-admin/js/revisions.js
author ymh <ymh.work@gmail.com>
Tue, 15 Dec 2020 13:49:49 +0100
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 22 8c2e4d02f4ef
permissions -rw-r--r--
update enmi-conf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     2
 * @file Revisions interface functions, Backbone classes and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     3
 * the revisions.php document.ready bootstrap.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     4
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
 * @output wp-admin/js/revisions.js
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     8
/* global isRtl */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     9
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
window.wp = window.wp || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
(function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	var revisions;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	 * Expose the module in window.wp.revisions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	revisions = wp.revisions = { model: {}, view: {}, controller: {} };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	// Link post revisions data served from the back end.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	revisions.settings = window._wpRevisionsSettings || {};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    22
	// For debugging.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	revisions.debug = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	 * wp.revisions.log
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	 * A debugging utility for revisions. Works only when a
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
	 * debug flag is on and the browser supports it.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	revisions.log = function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
		if ( window.console && revisions.debug ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
			window.console.log.apply( window.console, arguments );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    37
	// Handy functions to help with positioning.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	$.fn.allOffsets = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		var offset = this.offset() || {top: 0, left: 0}, win = $(window);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		return _.extend( offset, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			right:  win.width()  - offset.left - this.outerWidth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
			bottom: win.height() - offset.top  - this.outerHeight()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	$.fn.allPositions = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		var position = this.position() || {top: 0, left: 0}, parent = this.parent();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		return _.extend( position, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
			right:  parent.outerWidth()  - position.left - this.outerWidth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			bottom: parent.outerHeight() - position.top  - this.outerHeight()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 * ========================================================================
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 * MODELS
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * ========================================================================
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	revisions.model.Slider = Backbone.Model.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		defaults: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			value: null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			values: null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
			min: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			max: 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			step: 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			range: false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			compareTwoMode: false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		initialize: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			this.frame = options.frame;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			this.revisions = options.revisions;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    74
			// Listen for changes to the revisions or mode from outside.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			this.listenTo( this.frame, 'update:revisions', this.receiveRevisions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			this.listenTo( this.frame, 'change:compareTwoMode', this.updateMode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    78
			// Listen for internal changes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			this.on( 'change:from', this.handleLocalChanges );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
			this.on( 'change:to', this.handleLocalChanges );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			this.on( 'change:compareTwoMode', this.updateSliderSettings );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
			this.on( 'update:revisions', this.updateSliderSettings );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    84
			// Listen for changes to the hovered revision.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
			this.on( 'change:hoveredRevision', this.hoverRevision );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
			this.set({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
				max:   this.revisions.length - 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
				compareTwoMode: this.frame.get('compareTwoMode'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
				from: this.frame.get('from'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
				to: this.frame.get('to')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
			this.updateSliderSettings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		getSliderValue: function( a, b ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			return isRtl ? this.revisions.length - this.revisions.indexOf( this.get(a) ) - 1 : this.revisions.indexOf( this.get(b) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		updateSliderSettings: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			if ( this.get('compareTwoMode') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
				this.set({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
					values: [
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
						this.getSliderValue( 'to', 'from' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
						this.getSliderValue( 'from', 'to' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
					],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
					value: null,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   108
					range: true // Ensures handles cannot cross.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
				this.set({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
					value: this.getSliderValue( 'to', 'to' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
					values: null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
					range: false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			this.trigger( 'update:slider' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   120
		// Called when a revision is hovered.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		hoverRevision: function( model, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
			this.trigger( 'hovered:revision', value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   125
		// Called when `compareTwoMode` changes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		updateMode: function( model, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
			this.set({ compareTwoMode: value });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   130
		// Called when `from` or `to` changes in the local model.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		handleLocalChanges: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
			this.frame.set({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
				from: this.get('from'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
				to: this.get('to')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   138
		// Receives revisions changes from outside the model.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		receiveRevisions: function( from, to ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   140
			// Bail if nothing changed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
			if ( this.get('from') === from && this.get('to') === to ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			this.set({ from: from, to: to }, { silent: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			this.trigger( 'update:revisions', from, to );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	revisions.model.Tooltip = Backbone.Model.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		defaults: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
			revision: null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			offset: {},
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   155
			hovering: false, // Whether the mouse is hovering.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   156
			scrubbing: false // Whether the mouse is scrubbing.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		initialize: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			this.frame = options.frame;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
			this.revisions = options.revisions;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			this.slider = options.slider;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			this.listenTo( this.slider, 'hovered:revision', this.updateRevision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			this.listenTo( this.slider, 'change:hovering', this.setHovering );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			this.listenTo( this.slider, 'change:scrubbing', this.setScrubbing );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		updateRevision: function( revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
			this.set({ revision: revision });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		setHovering: function( model, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
			this.set({ hovering: value });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
		setScrubbing: function( model, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
			this.set({ scrubbing: value });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	revisions.model.Revision = Backbone.Model.extend({});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
	 * wp.revisions.model.Revisions
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	 * A collection of post revisions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	revisions.model.Revisions = Backbone.Collection.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
		model: revisions.model.Revision,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
			_.bindAll( this, 'next', 'prev' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		next: function( revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			var index = this.indexOf( revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
			if ( index !== -1 && index !== this.length - 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
				return this.at( index + 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		prev: function( revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			var index = this.indexOf( revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
			if ( index !== -1 && index !== 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
				return this.at( index - 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	revisions.model.Field = Backbone.Model.extend({});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	revisions.model.Fields = Backbone.Collection.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		model: revisions.model.Field
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	revisions.model.Diff = Backbone.Model.extend({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
		initialize: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			var fields = this.get('fields');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			this.unset('fields');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			this.fields = new revisions.model.Fields( fields );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	revisions.model.Diffs = Backbone.Collection.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		initialize: function( models, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			_.bindAll( this, 'getClosestUnloaded' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			this.loadAll = _.once( this._loadAll );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			this.revisions = options.revisions;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   234
			this.postId = options.postId;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			this.requests  = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		model: revisions.model.Diff,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		ensure: function( id, context ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
			var diff     = this.get( id ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
				request  = this.requests[ id ],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
				deferred = $.Deferred(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
				ids      = {},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
				from     = id.split(':')[0],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
				to       = id.split(':')[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			ids[id] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			wp.revisions.log( 'ensure', id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			this.trigger( 'ensure', ids, from, to, deferred.promise() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
			if ( diff ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
				deferred.resolveWith( context, [ diff ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
				this.trigger( 'ensure:load', ids, from, to, deferred.promise() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
				_.each( ids, _.bind( function( id ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   258
					// Remove anything that has an ongoing request.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
					if ( this.requests[ id ] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
						delete ids[ id ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   262
					// Remove anything we already have.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
					if ( this.get( id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
						delete ids[ id ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
				}, this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				if ( ! request ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   268
					// Always include the ID that started this ensure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
					ids[ id ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
					request   = this.load( _.keys( ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				request.done( _.bind( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
					deferred.resolveWith( context, [ this.get( id ) ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
				}, this ) ).fail( _.bind( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
					deferred.reject();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
				}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			return deferred.promise();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   283
		// Returns an array of proximal diffs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		getClosestUnloaded: function( ids, centerId ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			var self = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			return _.chain([0].concat( ids )).initial().zip( ids ).sortBy( function( pair ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
				return Math.abs( centerId - pair[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			}).map( function( pair ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				return pair.join(':');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			}).filter( function( diffId ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
				return _.isUndefined( self.get( diffId ) ) && ! self.requests[ diffId ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			}).value();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		_loadAll: function( allRevisionIds, centerId, num ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
			var self = this, deferred = $.Deferred(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
				diffs = _.first( this.getClosestUnloaded( allRevisionIds, centerId ), num );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
			if ( _.size( diffs ) > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
				this.load( diffs ).done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
					self._loadAll( allRevisionIds, centerId, num ).done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
						deferred.resolve();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
				}).fail( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
					if ( 1 === num ) { // Already tried 1. This just isn't working. Give up.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
						deferred.reject();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   306
					} else { // Request fewer diffs this time.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
						self._loadAll( allRevisionIds, centerId, Math.ceil( num / 2 ) ).done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
							deferred.resolve();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
				deferred.resolve();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
			return deferred;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		load: function( comparisons ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			wp.revisions.log( 'load', comparisons );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   320
			// Our collection should only ever grow, never shrink, so `remove: false`.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
			return this.fetch({ data: { compare: comparisons }, remove: false }).done( function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
				wp.revisions.log( 'load:complete', comparisons );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		sync: function( method, model, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
			if ( 'read' === method ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
				options = options || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
				options.context = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
				options.data = _.extend( options.data || {}, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
					action: 'get-revision-diffs',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
					post_id: this.postId
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
				var deferred = wp.ajax.send( options ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
					requests = this.requests;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				// Record that we're requesting each diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
				if ( options.data.compare ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
					_.each( options.data.compare, function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
						requests[ id ] = deferred;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
				// When the request completes, clear the stored request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
				deferred.always( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
					if ( options.data.compare ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
						_.each( options.data.compare, function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
							delete requests[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
				return deferred;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			// Otherwise, fall back to `Backbone.sync()`.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
				return Backbone.Model.prototype.sync.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	 * wp.revisions.model.FrameState
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	 * The frame state.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
	 * @see wp.revisions.view.Frame
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	 * @param {object}                    attributes        Model attributes - none are required.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
	 * @param {object}                    options           Options for the model.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	 * @param {revisions.model.Revisions} options.revisions A collection of revisions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
	revisions.model.FrameState = Backbone.Model.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
		defaults: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			loading: false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
			error: false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			compareTwoMode: false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		initialize: function( attributes, options ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
			var state = this.get( 'initialDiffState' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			_.bindAll( this, 'receiveDiff' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			this._debouncedEnsureDiff = _.debounce( this._ensureDiff, 200 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			this.revisions = options.revisions;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
			this.diffs = new revisions.model.Diffs( [], {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
				revisions: this.revisions,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
				postId: this.get( 'postId' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
			// Set the initial diffs collection.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
			this.diffs.set( this.get( 'diffData' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   397
			// Set up internal listeners.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			this.listenTo( this, 'change:from', this.changeRevisionHandler );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
			this.listenTo( this, 'change:to', this.changeRevisionHandler );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
			this.listenTo( this, 'change:compareTwoMode', this.changeMode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
			this.listenTo( this, 'update:revisions', this.updatedRevisions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			this.listenTo( this.diffs, 'ensure:load', this.updateLoadingStatus );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			this.listenTo( this, 'update:diff', this.updateLoadingStatus );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
			// Set the initial revisions, baseUrl, and mode as provided through attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
			this.set( {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
				to : this.revisions.get( state.to ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
				from : this.revisions.get( state.from ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
				compareTwoMode : state.compareTwoMode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
			} );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   413
			// Start the router if browser supports History API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			if ( window.history && window.history.pushState ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
				this.router = new revisions.Router({ model: this });
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
				if ( Backbone.History.started ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
					Backbone.history.stop();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
				Backbone.history.start({ pushState: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		updateLoadingStatus: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			this.set( 'error', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
			this.set( 'loading', ! this.diff() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		changeMode: function( model, value ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
			var toIndex = this.revisions.indexOf( this.get( 'to' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
			// If we were on the first revision before switching to two-handled mode,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   432
			// bump the 'to' position over one.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
			if ( value && 0 === toIndex ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
				this.set({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
					from: this.revisions.at( toIndex ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
					to:   this.revisions.at( toIndex + 1 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
				});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
			// When switching back to single-handled mode, reset 'from' model to
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   441
			// one position before the 'to' model.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   442
			if ( ! value && 0 !== toIndex ) { // '! value' means switching to single-handled mode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
				this.set({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
					from: this.revisions.at( toIndex - 1 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
					to:   this.revisions.at( toIndex )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
		updatedRevisions: function( from, to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			if ( this.get( 'compareTwoMode' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   452
				// @todo Compare-two loading strategy.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				this.diffs.loadAll( this.revisions.pluck('id'), to.id, 40 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		// Fetch the currently loaded diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		diff: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			return this.diffs.get( this._diffId );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   463
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   464
		 * So long as `from` and `to` are changed at the same time, the diff
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   465
		 * will only be updated once. This is because Backbone updates all of
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   466
		 * the changed attributes in `set`, and then fires the `change` events.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   467
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
		updateDiff: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			var from, to, diffId, diff;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			options = options || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			from = this.get('from');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
			to = this.get('to');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			diffId = ( from ? from.id : 0 ) + ':' + to.id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			// Check if we're actually changing the diff id.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
			if ( this._diffId === diffId ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
				return $.Deferred().reject().promise();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			this._diffId = diffId;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			this.trigger( 'update:revisions', from, to );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			diff = this.diffs.get( diffId );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			// If we already have the diff, then immediately trigger the update.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
			if ( diff ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
				this.receiveDiff( diff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
				return $.Deferred().resolve().promise();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
			// Otherwise, fetch the diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
				if ( options.immediate ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
					return this._ensureDiff();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
					this._debouncedEnsureDiff();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
					return $.Deferred().reject().promise();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		// A simple wrapper around `updateDiff` to prevent the change event's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		// parameters from being passed through.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
		changeRevisionHandler: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
			this.updateDiff();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		receiveDiff: function( diff ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			// Did we actually get a diff?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
			if ( _.isUndefined( diff ) || _.isUndefined( diff.id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
				this.set({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
					loading: false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
					error: true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
				});
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   514
			} else if ( this._diffId === diff.id ) { // Make sure the current diff didn't change.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
				this.trigger( 'update:diff', diff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		_ensureDiff: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
			return this.diffs.ensure( this._diffId, this ).always( this.receiveDiff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	 * ========================================================================
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 * VIEWS
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	 * ========================================================================
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
	 * wp.revisions.view.Frame
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
	 * Top level frame that orchestrates the revisions experience.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
	 * @param {object}                     options       The options hash for the view.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	 * @param {revisions.model.FrameState} options.model The frame state model.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	revisions.view.Frame = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		className: 'revisions',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
		template: wp.template('revisions-frame'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
			this.listenTo( this.model, 'update:diff', this.renderDiff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
			this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
			this.listenTo( this.model, 'change:loading', this.updateLoadingStatus );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
			this.listenTo( this.model, 'change:error', this.updateErrorStatus );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
			this.views.set( '.revisions-control-frame', new revisions.view.Controls({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
		render: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
			wp.Backbone.View.prototype.render.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
			$('html').css( 'overflow-y', 'scroll' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
			$('#wpbody-content .wrap').append( this.el );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
			this.updateCompareTwoMode();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
			this.renderDiff( this.model.diff() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
			this.views.ready();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
		renderDiff: function( diff ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
			this.views.set( '.revisions-diff-frame', new revisions.view.Diff({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
				model: diff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		updateLoadingStatus: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
			this.$el.toggleClass( 'loading', this.model.get('loading') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
		updateErrorStatus: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			this.$el.toggleClass( 'diff-error', this.model.get('error') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		updateCompareTwoMode: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
			this.$el.toggleClass( 'comparing-two-revisions', this.model.get('compareTwoMode') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
	 * wp.revisions.view.Controls
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	 * The controls view.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
	 * Contains the revision slider, previous/next buttons, the meta info and the compare checkbox.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	revisions.view.Controls = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
		className: 'revisions-controls',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
			_.bindAll( this, 'setWidth' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   598
			// Add the button view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
			this.views.add( new revisions.view.Buttons({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   603
			// Add the checkbox view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
			this.views.add( new revisions.view.Checkbox({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   608
			// Prep the slider model.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
			var slider = new revisions.model.Slider({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
				frame: this.model,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
				revisions: this.model.revisions
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
			}),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   614
			// Prep the tooltip model.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
			tooltip = new revisions.model.Tooltip({
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
				frame: this.model,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
				revisions: this.model.revisions,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
				slider: slider
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   621
			// Add the tooltip view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
			this.views.add( new revisions.view.Tooltip({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
				model: tooltip
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   626
			// Add the tickmarks view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
			this.views.add( new revisions.view.Tickmarks({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
				model: tooltip
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   631
			// Add the slider view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
			this.views.add( new revisions.view.Slider({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
				model: slider
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   636
			// Add the Metabox view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
			this.views.add( new revisions.view.Metabox({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			this.top = this.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
			this.window = $(window);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
			this.window.on( 'scroll.wp.revisions', {controls: this}, function(e) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
				var controls  = e.data.controls,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
					container = controls.$el.parent(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
					scrolled  = controls.window.scrollTop(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
					frame     = controls.views.parent;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
				if ( scrolled >= controls.top ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
					if ( ! frame.$el.hasClass('pinned') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
						controls.setWidth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
						container.css('height', container.height() + 'px' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
						controls.window.on('resize.wp.revisions.pinning click.wp.revisions.pinning', {controls: controls}, function(e) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
							e.data.controls.setWidth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
					frame.$el.addClass('pinned');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
				} else if ( frame.$el.hasClass('pinned') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
					controls.window.off('.wp.revisions.pinning');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
					controls.$el.css('width', 'auto');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
					frame.$el.removeClass('pinned');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
					container.css('height', 'auto');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					controls.top = controls.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
					controls.top = controls.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		setWidth: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
			this.$el.css('width', this.$el.parent().width() + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   677
	// The tickmarks view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	revisions.view.Tickmarks = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		className: 'revisions-tickmarks',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
		direction: isRtl ? 'right' : 'left',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
			this.listenTo( this.model, 'change:revision', this.reportTickPosition );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		reportTickPosition: function( model, revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
			var offset, thisOffset, parentOffset, tick, index = this.model.revisions.indexOf( revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
			thisOffset = this.$el.allOffsets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
			parentOffset = this.$el.parent().allOffsets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
			if ( index === this.model.revisions.length - 1 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   691
				// Last one.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
				offset = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
					rightPlusWidth: thisOffset.left - parentOffset.left + 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
					leftPlusWidth: thisOffset.right - parentOffset.right + 1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   697
				// Normal tick.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
				tick = this.$('div:nth-of-type(' + (index + 1) + ')');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
				offset = tick.allPositions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
				_.extend( offset, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
					left: offset.left + thisOffset.left - parentOffset.left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
					right: offset.right + thisOffset.right - parentOffset.right
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
				_.extend( offset, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
					leftPlusWidth: offset.left + tick.outerWidth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
					rightPlusWidth: offset.right + tick.outerWidth()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
			this.model.set({ offset: offset });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
			var tickCount, tickWidth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
			tickCount = this.model.revisions.length - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
			tickWidth = 1 / tickCount;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
			this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
			_(tickCount).times( function( index ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
				this.$el.append( '<div style="' + this.direction + ': ' + ( 100 * tickWidth * index ) + '%"></div>' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   724
	// The metabox view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	revisions.view.Metabox = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
		className: 'revisions-meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
		initialize: function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   729
			// Add the 'from' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
			this.views.add( new revisions.view.MetaFrom({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
				model: this.model,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
				className: 'diff-meta diff-meta-from'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   735
			// Add the 'to' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
			this.views.add( new revisions.view.MetaTo({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   742
	// The revision meta view (to be extended).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	revisions.view.Meta = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		template: wp.template('revisions-meta'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
			'click .restore-revision': 'restoreRevision'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
			this.listenTo( this.model, 'update:revisions', this.render );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
		prepare: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
			return _.extend( this.model.toJSON()[this.type] || {}, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
				type: this.type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		restoreRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
			document.location = this.model.get('to').attributes.restoreUrl;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   765
	// The revision meta 'from' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	revisions.view.MetaFrom = revisions.view.Meta.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
		className: 'diff-meta diff-meta-from',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		type: 'from'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   771
	// The revision meta 'to' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	revisions.view.MetaTo = revisions.view.Meta.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
		className: 'diff-meta diff-meta-to',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		type: 'to'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
	// The checkbox view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	revisions.view.Checkbox = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
		className: 'revisions-checkbox',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		template: wp.template('revisions-checkbox'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
			'click .compare-two-revisions': 'compareTwoToggle'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
		ready: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
			if ( this.model.revisions.length < 3 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
				$('.revision-toggle-compare-mode').hide();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		updateCompareTwoMode: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			this.$('.compare-two-revisions').prop( 'checked', this.model.get('compareTwoMode') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
		// Toggle the compare two mode feature when the compare two checkbox is checked.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
		compareTwoToggle: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
			// Activate compare two mode?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
			this.model.set({ compareTwoMode: $('.compare-two-revisions').prop('checked') });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
	// The tooltip view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
	// Encapsulates the tooltip.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	revisions.view.Tooltip = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
		className: 'revisions-tooltip',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		template: wp.template('revisions-meta'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
		initialize: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
			this.listenTo( this.model, 'change:offset', this.render );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
			this.listenTo( this.model, 'change:hovering', this.toggleVisibility );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			this.listenTo( this.model, 'change:scrubbing', this.toggleVisibility );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
		prepare: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
			if ( _.isNull( this.model.get('revision') ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
				return _.extend( { type: 'tooltip' }, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
					attributes: this.model.get('revision').toJSON()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
		render: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
			var otherDirection,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
				direction,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
				directionVal,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
				flipped,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
				css      = {},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
				position = this.model.revisions.indexOf( this.model.get('revision') ) + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
			flipped = ( position / this.model.revisions.length ) > 0.5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
			if ( isRtl ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
				direction = flipped ? 'left' : 'right';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
				directionVal = flipped ? 'leftPlusWidth' : direction;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
				direction = flipped ? 'right' : 'left';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
				directionVal = flipped ? 'rightPlusWidth' : direction;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
			otherDirection = 'right' === direction ? 'left': 'right';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
			wp.Backbone.View.prototype.render.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
			css[direction] = this.model.get('offset')[directionVal] + 'px';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
			css[otherDirection] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
			this.$el.toggleClass( 'flipped', flipped ).css( css );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
		visible: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
			return this.model.get( 'scrubbing' ) || this.model.get( 'hovering' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
		toggleVisibility: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
			if ( this.visible() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
				this.$el.stop().show().fadeTo( 100 - this.el.style.opacity * 100, 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
				this.$el.stop().fadeTo( this.el.style.opacity * 300, 0, function(){ $(this).hide(); } );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
	// The buttons view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
	// Encapsulates all of the configuration for the previous/next buttons.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
	revisions.view.Buttons = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
		className: 'revisions-buttons',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
		template: wp.template('revisions-buttons'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
			'click .revisions-next .button': 'nextRevision',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			'click .revisions-previous .button': 'previousRevision'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
			this.listenTo( this.model, 'update:revisions', this.disabledButtonCheck );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
			this.disabledButtonCheck();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   885
		// Go to a specific model index.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
		gotoModel: function( toIndex ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
			var attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
				to: this.model.revisions.at( toIndex )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
			// If we're at the first revision, unset 'from'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
			if ( toIndex ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
				attributes.from = this.model.revisions.at( toIndex - 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
				this.model.unset('from', { silent: true });
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
			this.model.set( attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   900
		// Go to the 'next' revision.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
		nextRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
			var toIndex = this.model.revisions.indexOf( this.model.get('to') ) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
			this.gotoModel( toIndex );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   906
		// Go to the 'previous' revision.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		previousRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
			var toIndex = this.model.revisions.indexOf( this.model.get('to') ) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
			this.gotoModel( toIndex );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
		// Check to see if the Previous or Next buttons need to be disabled or enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		disabledButtonCheck: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
			var maxVal   = this.model.revisions.length - 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
				minVal   = 0,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
				next     = $('.revisions-next .button'),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
				previous = $('.revisions-previous .button'),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
				val      = this.model.revisions.indexOf( this.model.get('to') );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
			// Disable "Next" button if you're on the last node.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
			next.prop( 'disabled', ( maxVal === val ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
			// Disable "Previous" button if you're on the first node.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
			previous.prop( 'disabled', ( minVal === val ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
	// The slider view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
	revisions.view.Slider = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		className: 'wp-slider',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
		direction: isRtl ? 'right' : 'left',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
			'mousemove' : 'mouseMove'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
			_.bindAll( this, 'start', 'slide', 'stop', 'mouseMove', 'mouseEnter', 'mouseLeave' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			this.listenTo( this.model, 'update:slider', this.applySliderSettings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
			this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
			this.$el.slider( _.extend( this.model.toJSON(), {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
				start: this.start,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
				slide: this.slide,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
				stop:  this.stop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			this.$el.hoverIntent({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
				over: this.mouseEnter,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
				out: this.mouseLeave,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
				timeout: 800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
			this.applySliderSettings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
		mouseMove: function( e ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   961
			var zoneCount         = this.model.revisions.length - 1,       // One fewer zone than models.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   962
				sliderFrom        = this.$el.allOffsets()[this.direction], // "From" edge of slider.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   963
				sliderWidth       = this.$el.width(),                      // Width of slider.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   964
				tickWidth         = sliderWidth / zoneCount,               // Calculated width of zone.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   965
				actualX           = ( isRtl ? $(window).width() - e.pageX : e.pageX ) - sliderFrom, // Flipped for RTL - sliderFrom.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   966
				currentModelIndex = Math.floor( ( actualX  + ( tickWidth / 2 )  ) / tickWidth );    // Calculate the model index.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
			// Ensure sane value for currentModelIndex.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   969
			if ( currentModelIndex < 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
				currentModelIndex = 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
			} else if ( currentModelIndex >= this.model.revisions.length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
				currentModelIndex = this.model.revisions.length - 1;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   973
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   975
			// Update the tooltip mode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
			this.model.set({ hoveredRevision: this.model.revisions.at( currentModelIndex ) });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
		mouseLeave: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
			this.model.set({ hovering: false });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
		mouseEnter: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
			this.model.set({ hovering: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		applySliderSettings: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
			this.$el.slider( _.pick( this.model.toJSON(), 'value', 'values', 'range' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
			var handles = this.$('a.ui-slider-handle');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
			if ( this.model.get('compareTwoMode') ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   992
				// In RTL mode the 'left handle' is the second in the slider, 'right' is first.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
				handles.first()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
					.toggleClass( 'to-handle', !! isRtl )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
					.toggleClass( 'from-handle', ! isRtl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
				handles.last()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
					.toggleClass( 'from-handle', !! isRtl )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
					.toggleClass( 'to-handle', ! isRtl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
				handles.removeClass('from-handle to-handle');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		start: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
			this.model.set({ scrubbing: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			// Track the mouse position to enable smooth dragging,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
			// overrides default jQuery UI step behavior.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
			$( window ).on( 'mousemove.wp.revisions', { view: this }, function( e ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
				var handles,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
					view              = e.data.view,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
					leftDragBoundary  = view.$el.offset().left,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
					sliderOffset      = leftDragBoundary,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1014
					sliderRightEdge   = leftDragBoundary + view.$el.width(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
					rightDragBoundary = sliderRightEdge,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
					leftDragReset     = '0',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
					rightDragReset    = '100%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1018
					handle            = $( ui.handle );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
				// In two handle mode, ensure handles can't be dragged past each other.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
				// Adjust left/right boundaries and reset points.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
				if ( view.model.get('compareTwoMode') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
					handles = handle.parent().find('.ui-slider-handle');
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1024
					if ( handle.is( handles.first() ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1025
						// We're the left handle.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
						rightDragBoundary = handles.last().offset().left;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
						rightDragReset    = rightDragBoundary - sliderOffset;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1028
					} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1029
						// We're the right handle.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
						leftDragBoundary = handles.first().offset().left + handles.first().width();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
						leftDragReset    = leftDragBoundary - sliderOffset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
				// Follow mouse movements, as long as handle remains inside slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
				if ( e.pageX < leftDragBoundary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
					handle.css( 'left', leftDragReset ); // Mouse to left of slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
				} else if ( e.pageX > rightDragBoundary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
					handle.css( 'left', rightDragReset ); // Mouse to right of slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
					handle.css( 'left', e.pageX - sliderOffset ); // Mouse in slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
			} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		getPosition: function( position ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
			return isRtl ? this.model.revisions.length - position - 1: position;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1050
		// Responds to slide events.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
		slide: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
			var attributes, movedRevision;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1053
			// Compare two revisions mode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
			if ( this.model.get('compareTwoMode') ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1055
				// Prevent sliders from occupying same spot.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
				if ( ui.values[1] === ui.values[0] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
				if ( isRtl ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
					ui.values.reverse();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
				attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
					from: this.model.revisions.at( this.getPosition( ui.values[0] ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
					to: this.model.revisions.at( this.getPosition( ui.values[1] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
				attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
					to: this.model.revisions.at( this.getPosition( ui.value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
				// If we're at the first revision, unset 'from'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
				if ( this.getPosition( ui.value ) > 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
					attributes.from = this.model.revisions.at( this.getPosition( ui.value ) - 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1073
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
					attributes.from = undefined;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
			movedRevision = this.model.revisions.at( this.getPosition( ui.value ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1079
			// If we are scrubbing, a scrub to a revision is considered a hover.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1080
			if ( this.model.get('scrubbing') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
				attributes.hoveredRevision = movedRevision;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
			this.model.set( attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
		stop: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
			$( window ).off('mousemove.wp.revisions');
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1089
			this.model.updateSliderSettings(); // To snap us back to a tick mark.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
			this.model.set({ scrubbing: false });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
	// The diff view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
	// This is the view for the current active diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
	revisions.view.Diff = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
		className: 'revisions-diff',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
		template:  wp.template('revisions-diff'),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
		// Generate the options to be passed to the template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
		prepare: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
			return _.extend({ fields: this.model.fields.toJSON() }, this.options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
	// The revisions router.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1107
	// Maintains the URL routes so browser URL matches state.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	revisions.Router = Backbone.Router.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
		initialize: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
			this.model = options.model;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1112
			// Maintain state and history when navigating.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
			this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
			this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
		baseUrl: function( url ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
			return this.model.get('baseUrl') + url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
		updateUrl: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
			var from = this.model.has('from') ? this.model.get('from').id : 0,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
				to   = this.model.get('to').id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
			if ( this.model.get('compareTwoMode' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
				this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ), { replace: true } );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
				this.navigate( this.baseUrl( '?revision=' + to ), { replace: true } );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
		handleRoute: function( a, b ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
			var compareTwo = _.isUndefined( b );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
			if ( ! compareTwo ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
				b = this.model.revisions.get( a );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
				a = this.model.revisions.prev( b );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
				b = b ? b.id : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
				a = a ? a.id : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
	 * Initialize the revisions UI for revision.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
	revisions.init = function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
		var state;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
		// Bail if the current page is not revision.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
		if ( ! window.adminpage || 'revision-php' !== window.adminpage ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
		state = new revisions.model.FrameState({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
			initialDiffState: {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
				// wp_localize_script doesn't stringifies ints, so cast them.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
				to: parseInt( revisions.settings.to, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1158
				from: parseInt( revisions.settings.from, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1159
				// wp_localize_script does not allow for top-level booleans so do a comparator here.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1160
				compareTwoMode: ( revisions.settings.compareTwoMode === '1' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1161
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1162
			diffData: revisions.settings.diffData,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1163
			baseUrl: revisions.settings.baseUrl,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
			postId: parseInt( revisions.settings.postId, 10 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
		}, {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
			revisions: new revisions.model.Revisions( revisions.settings.revisionData )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
		revisions.view.frame = new revisions.view.Frame({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1170
			model: state
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
		}).render();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
	$( revisions.init );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
}(jQuery));