wp/wp-admin/js/revisions.js
author ymh <ymh.work@gmail.com>
Mon, 08 Sep 2025 19:44:41 +0200
changeset 23 417f20492bf7
parent 22 8c2e4d02f4ef
permissions -rw-r--r--
Update Docker configuration and plugin versions - Upgrade MariaDB from 10.6 to 11 with auto-upgrade support - Add WordPress debug environment variable to FPM container - Update PHP-FPM Dockerfile base image - Update Include Mastodon Feed plugin with bug fixes and improvements - Update Portfolio plugin (v2.58) with latest translations and demo data enhancements - Remove old README.md from Mastodon Feed plugin 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   598
			// Add the checkbox view.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   599
			this.views.add( new revisions.view.Checkbox({
0
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
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   603
			// Add the button view.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   604
			this.views.add( new revisions.view.Buttons({
0
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
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   631
			// Add the visually hidden slider help view.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   632
			this.views.add( new revisions.view.SliderHelp() );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   633
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   634
			// Add the slider view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
			this.views.add( new revisions.view.Slider({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
				model: slider
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   639
			// Add the Metabox view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
			this.views.add( new revisions.view.Metabox({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
			this.top = this.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
			this.window = $(window);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
			this.window.on( 'scroll.wp.revisions', {controls: this}, function(e) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
				var controls  = e.data.controls,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
					container = controls.$el.parent(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
					scrolled  = controls.window.scrollTop(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
					frame     = controls.views.parent;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
				if ( scrolled >= controls.top ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
					if ( ! frame.$el.hasClass('pinned') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
						controls.setWidth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
						container.css('height', container.height() + 'px' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
						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
   659
							e.data.controls.setWidth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
					frame.$el.addClass('pinned');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
				} else if ( frame.$el.hasClass('pinned') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
					controls.window.off('.wp.revisions.pinning');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					controls.$el.css('width', 'auto');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
					frame.$el.removeClass('pinned');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
					container.css('height', 'auto');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
					controls.top = controls.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
					controls.top = controls.$el.offset().top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
		setWidth: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
			this.$el.css('width', this.$el.parent().width() + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   680
	// The tickmarks view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	revisions.view.Tickmarks = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		className: 'revisions-tickmarks',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
		direction: isRtl ? 'right' : 'left',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
			this.listenTo( this.model, 'change:revision', this.reportTickPosition );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		reportTickPosition: function( model, revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
			var offset, thisOffset, parentOffset, tick, index = this.model.revisions.indexOf( revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			thisOffset = this.$el.allOffsets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			parentOffset = this.$el.parent().allOffsets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			if ( index === this.model.revisions.length - 1 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   694
				// Last one.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
				offset = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
					rightPlusWidth: thisOffset.left - parentOffset.left + 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
					leftPlusWidth: thisOffset.right - parentOffset.right + 1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   700
				// Normal tick.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
				tick = this.$('div:nth-of-type(' + (index + 1) + ')');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
				offset = tick.allPositions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
				_.extend( offset, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
					left: offset.left + thisOffset.left - parentOffset.left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
					right: offset.right + thisOffset.right - parentOffset.right
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
				_.extend( offset, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
					leftPlusWidth: offset.left + tick.outerWidth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
					rightPlusWidth: offset.right + tick.outerWidth()
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
			this.model.set({ offset: offset });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
			var tickCount, tickWidth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
			tickCount = this.model.revisions.length - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
			tickWidth = 1 / tickCount;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
			this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			_(tickCount).times( function( index ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
				this.$el.append( '<div style="' + this.direction + ': ' + ( 100 * tickWidth * index ) + '%"></div>' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   727
	// The metabox view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	revisions.view.Metabox = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
		className: 'revisions-meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
		initialize: function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   732
			// Add the 'from' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
			this.views.add( new revisions.view.MetaFrom({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
				model: this.model,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
				className: 'diff-meta diff-meta-from'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   738
			// Add the 'to' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
			this.views.add( new revisions.view.MetaTo({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
				model: this.model
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
			}) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   745
	// The revision meta view (to be extended).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	revisions.view.Meta = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
		template: wp.template('revisions-meta'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
			'click .restore-revision': 'restoreRevision'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
			this.listenTo( this.model, 'update:revisions', this.render );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
		prepare: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
			return _.extend( this.model.toJSON()[this.type] || {}, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
				type: this.type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		restoreRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
			document.location = this.model.get('to').attributes.restoreUrl;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   768
	// The revision meta 'from' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	revisions.view.MetaFrom = revisions.view.Meta.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		className: 'diff-meta diff-meta-from',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		type: 'from'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   774
	// The revision meta 'to' view.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	revisions.view.MetaTo = revisions.view.Meta.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
		className: 'diff-meta diff-meta-to',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		type: 'to'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	// The checkbox view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
	revisions.view.Checkbox = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		className: 'revisions-checkbox',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
		template: wp.template('revisions-checkbox'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
			'click .compare-two-revisions': 'compareTwoToggle'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
			this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		ready: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
			if ( this.model.revisions.length < 3 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
				$('.revision-toggle-compare-mode').hide();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
		updateCompareTwoMode: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
			this.$('.compare-two-revisions').prop( 'checked', this.model.get('compareTwoMode') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		// 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
   804
		compareTwoToggle: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
			// Activate compare two mode?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			this.model.set({ compareTwoMode: $('.compare-two-revisions').prop('checked') });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   810
	// The slider visually hidden help view.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   811
 	revisions.view.SliderHelp = wp.Backbone.View.extend({
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   812
		className: 'revisions-slider-hidden-help',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   813
		template:  wp.template( 'revisions-slider-hidden-help' )
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   814
	});
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   815
   
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	// The tooltip view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	// Encapsulates the tooltip.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	revisions.view.Tooltip = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
		className: 'revisions-tooltip',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
		template: wp.template('revisions-meta'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
		initialize: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
			this.listenTo( this.model, 'change:offset', this.render );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
			this.listenTo( this.model, 'change:hovering', this.toggleVisibility );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
			this.listenTo( this.model, 'change:scrubbing', this.toggleVisibility );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
		prepare: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
			if ( _.isNull( this.model.get('revision') ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
				return _.extend( { type: 'tooltip' }, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
					attributes: this.model.get('revision').toJSON()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
		render: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
			var otherDirection,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
				direction,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
				directionVal,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
				flipped,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
				css      = {},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
				position = this.model.revisions.indexOf( this.model.get('revision') ) + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
			flipped = ( position / this.model.revisions.length ) > 0.5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
			if ( isRtl ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
				direction = flipped ? 'left' : 'right';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
				directionVal = flipped ? 'leftPlusWidth' : direction;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
				direction = flipped ? 'right' : 'left';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
				directionVal = flipped ? 'rightPlusWidth' : direction;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
			otherDirection = 'right' === direction ? 'left': 'right';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
			wp.Backbone.View.prototype.render.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
			css[direction] = this.model.get('offset')[directionVal] + 'px';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
			css[otherDirection] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			this.$el.toggleClass( 'flipped', flipped ).css( css );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
		visible: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
			return this.model.get( 'scrubbing' ) || this.model.get( 'hovering' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
		toggleVisibility: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
			if ( this.visible() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
				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
   868
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
				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
   870
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
	// The buttons view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	// Encapsulates all of the configuration for the previous/next buttons.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	revisions.view.Buttons = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		className: 'revisions-buttons',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		template: wp.template('revisions-buttons'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
			'click .revisions-next .button': 'nextRevision',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
			'click .revisions-previous .button': 'previousRevision'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
			this.listenTo( this.model, 'update:revisions', this.disabledButtonCheck );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
			this.disabledButtonCheck();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   894
		// Go to a specific model index.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
		gotoModel: function( toIndex ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
			var attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
				to: this.model.revisions.at( toIndex )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
			// If we're at the first revision, unset 'from'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
			if ( toIndex ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
				attributes.from = this.model.revisions.at( toIndex - 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
				this.model.unset('from', { silent: true });
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
			this.model.set( attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   909
		// Go to the 'next' revision.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		nextRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
			var toIndex = this.model.revisions.indexOf( this.model.get('to') ) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
			this.gotoModel( toIndex );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   915
		// Go to the 'previous' revision.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
		previousRevision: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
			var toIndex = this.model.revisions.indexOf( this.model.get('to') ) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			this.gotoModel( toIndex );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		// 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
   922
		disabledButtonCheck: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
			var maxVal   = this.model.revisions.length - 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
				minVal   = 0,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
				next     = $('.revisions-next .button'),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
				previous = $('.revisions-previous .button'),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
				val      = this.model.revisions.indexOf( this.model.get('to') );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
			// Disable "Next" button if you're on the last node.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
			next.prop( 'disabled', ( maxVal === val ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
			// Disable "Previous" button if you're on the first node.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
			previous.prop( 'disabled', ( minVal === val ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
	});
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
	// The slider view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	revisions.view.Slider = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
		className: 'wp-slider',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
		direction: isRtl ? 'right' : 'left',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		events: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
			'mousemove' : 'mouseMove'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		initialize: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
			_.bindAll( this, 'start', 'slide', 'stop', 'mouseMove', 'mouseEnter', 'mouseLeave' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
			this.listenTo( this.model, 'update:slider', this.applySliderSettings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
		ready: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
			this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
			this.$el.slider( _.extend( this.model.toJSON(), {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
				start: this.start,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
				slide: this.slide,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
				stop:  this.stop
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
			this.$el.hoverIntent({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
				over: this.mouseEnter,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
				out: this.mouseLeave,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
				timeout: 800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
			this.applySliderSettings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   969
		accessibilityHelper: function() {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   970
			var handles = $( '.ui-slider-handle' );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   971
			handles.first().attr( {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   972
					role: 'button',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   973
					'aria-labelledby': 'diff-title-from diff-title-author',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   974
					'aria-describedby': 'revisions-slider-hidden-help',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   975
			} );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   976
			handles.last().attr( {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   977
					role: 'button',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   978
					'aria-labelledby': 'diff-title-to diff-title-author',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   979
					'aria-describedby': 'revisions-slider-hidden-help',
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   980
			} );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   981
		},
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   982
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
		mouseMove: function( e ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   984
			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
   985
				sliderFrom        = this.$el.allOffsets()[this.direction], // "From" edge of slider.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   986
				sliderWidth       = this.$el.width(),                      // Width of slider.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   987
				tickWidth         = sliderWidth / zoneCount,               // Calculated width of zone.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   988
				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
   989
				currentModelIndex = Math.floor( ( actualX  + ( tickWidth / 2 )  ) / tickWidth );    // Calculate the model index.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
			// Ensure sane value for currentModelIndex.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
			if ( currentModelIndex < 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
				currentModelIndex = 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
			} else if ( currentModelIndex >= this.model.revisions.length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
				currentModelIndex = this.model.revisions.length - 1;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   996
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   998
			// Update the tooltip mode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
			this.model.set({ hoveredRevision: this.model.revisions.at( currentModelIndex ) });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		mouseLeave: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
			this.model.set({ hovering: false });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		mouseEnter: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			this.model.set({ hovering: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
		applySliderSettings: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
			this.$el.slider( _.pick( this.model.toJSON(), 'value', 'values', 'range' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			var handles = this.$('a.ui-slider-handle');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
			if ( this.model.get('compareTwoMode') ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1015
				// 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
  1016
				handles.first()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
					.toggleClass( 'to-handle', !! isRtl )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
					.toggleClass( 'from-handle', ! isRtl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
				handles.last()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
					.toggleClass( 'from-handle', !! isRtl )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
					.toggleClass( 'to-handle', ! isRtl );
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1022
				this.accessibilityHelper();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
				handles.removeClass('from-handle to-handle');
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1025
				this.accessibilityHelper();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			}
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1027
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		start: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
			this.model.set({ scrubbing: true });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
			// Track the mouse position to enable smooth dragging,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
			// overrides default jQuery UI step behavior.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
			$( window ).on( 'mousemove.wp.revisions', { view: this }, function( e ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
				var handles,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
					view              = e.data.view,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
					leftDragBoundary  = view.$el.offset().left,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
					sliderOffset      = leftDragBoundary,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
					sliderRightEdge   = leftDragBoundary + view.$el.width(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
					rightDragBoundary = sliderRightEdge,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
					leftDragReset     = '0',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
					rightDragReset    = '100%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
					handle            = $( ui.handle );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
				// In two handle mode, ensure handles can't be dragged past each other.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
				// Adjust left/right boundaries and reset points.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
				if ( view.model.get('compareTwoMode') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
					handles = handle.parent().find('.ui-slider-handle');
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1050
					if ( handle.is( handles.first() ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1051
						// We're the left handle.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
						rightDragBoundary = handles.last().offset().left;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
						rightDragReset    = rightDragBoundary - sliderOffset;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1054
					} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1055
						// We're the right handle.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
						leftDragBoundary = handles.first().offset().left + handles.first().width();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
						leftDragReset    = leftDragBoundary - sliderOffset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
				// Follow mouse movements, as long as handle remains inside slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
				if ( e.pageX < leftDragBoundary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
					handle.css( 'left', leftDragReset ); // Mouse to left of slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
				} else if ( e.pageX > rightDragBoundary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
					handle.css( 'left', rightDragReset ); // Mouse to right of slider.
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
					handle.css( 'left', e.pageX - sliderOffset ); // Mouse in slider.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
			} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
		getPosition: function( position ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
			return isRtl ? this.model.revisions.length - position - 1: position;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1076
		// Responds to slide events.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		slide: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
			var attributes, movedRevision;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1079
			// Compare two revisions mode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
			if ( this.model.get('compareTwoMode') ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1081
				// Prevent sliders from occupying same spot.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
				if ( ui.values[1] === ui.values[0] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1085
				if ( isRtl ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
					ui.values.reverse();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
				attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
					from: this.model.revisions.at( this.getPosition( ui.values[0] ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
					to: this.model.revisions.at( this.getPosition( ui.values[1] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
				attributes = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
					to: this.model.revisions.at( this.getPosition( ui.value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
				// If we're at the first revision, unset 'from'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
				if ( this.getPosition( ui.value ) > 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
					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
  1099
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
					attributes.from = undefined;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1101
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
			movedRevision = this.model.revisions.at( this.getPosition( ui.value ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1105
			// 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
  1106
			if ( this.model.get('scrubbing') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
				attributes.hoveredRevision = movedRevision;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
			this.model.set( attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
		stop: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
			$( window ).off('mousemove.wp.revisions');
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1115
			this.model.updateSliderSettings(); // To snap us back to a tick mark.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
			this.model.set({ scrubbing: false });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
	// The diff view.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
	// This is the view for the current active diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
	revisions.view.Diff = wp.Backbone.View.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
		className: 'revisions-diff',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
		template:  wp.template('revisions-diff'),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
		// Generate the options to be passed to the template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
		prepare: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
			return _.extend({ fields: this.model.fields.toJSON() }, this.options );
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
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
	// The revisions router.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1133
	// Maintains the URL routes so browser URL matches state.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	revisions.Router = Backbone.Router.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
		initialize: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
			this.model = options.model;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1138
			// Maintain state and history when navigating.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
			this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
			this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
		baseUrl: function( url ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
			return this.model.get('baseUrl') + url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
		updateUrl: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
			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
  1149
				to   = this.model.get('to').id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
			if ( this.model.get('compareTwoMode' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
				this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ), { replace: true } );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
				this.navigate( this.baseUrl( '?revision=' + to ), { replace: true } );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
		handleRoute: function( a, b ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1158
			var compareTwo = _.isUndefined( b );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
			if ( ! compareTwo ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
				b = this.model.revisions.get( a );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
				a = this.model.revisions.prev( b );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
				b = b ? b.id : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
				a = a ? a.id : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1170
	 * Initialize the revisions UI for revision.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	revisions.init = function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
		var state;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
		// Bail if the current page is not revision.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1176
		if ( ! window.adminpage || 'revision-php' !== window.adminpage ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1177
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1178
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
		state = new revisions.model.FrameState({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
			initialDiffState: {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
				// wp_localize_script doesn't stringifies ints, so cast them.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
				to: parseInt( revisions.settings.to, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
				from: parseInt( revisions.settings.from, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
				// 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
  1186
				compareTwoMode: ( revisions.settings.compareTwoMode === '1' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
			diffData: revisions.settings.diffData,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
			baseUrl: revisions.settings.baseUrl,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
			postId: parseInt( revisions.settings.postId, 10 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
		}, {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
			revisions: new revisions.model.Revisions( revisions.settings.revisionData )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
		revisions.view.frame = new revisions.view.Frame({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
			model: state
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
		}).render();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
	$( revisions.init );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
}(jQuery));