IP : 3.131.142.67Hostname : server86.web-hosting.comKernel : Linux server86.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
servlmvm/
public_html/
ad917/
./
../
wp-admin/
js/
revisions.js/
/
/** * @file Revisions interface functions, Backbone classes and * the revisions.php document.ready bootstrap. * * @output wp-admin/js/revisions.js */
/* global isRtl */
window.wp = window.wp || {};
(function($) { var revisions; /** * Expose the module in window.wp.revisions. */ revisions = wp.revisions = { model: {}, view: {}, controller: {} };
// Link post revisions data served from the back end. revisions.settings = window._wpRevisionsSettings || {};
// For debugging. revisions.debug = false;
/** * wp.revisions.log * * A debugging utility for revisions. Works only when a * debug flag is on and the browser supports it. */ revisions.log = function() { if ( window.console && revisions.debug ) { window.console.log.apply( window.console, arguments ); } };
// Listen for changes to the revisions or mode from outside. this.listenTo( this.frame, 'update:revisions', this.receiveRevisions ); this.listenTo( this.frame, 'change:compareTwoMode', this.updateMode );
// Called when a revision is hovered. hoverRevision: function( model, value ) { this.trigger( 'hovered:revision', value ); },
// Called when `compareTwoMode` changes. updateMode: function( model, value ) { this.set({ compareTwoMode: value }); },
// Called when `from` or `to` changes in the local model. handleLocalChanges: function() { this.frame.set({ from: this.get('from'), to: this.get('to') }); },
// Receives revisions changes from outside the model. receiveRevisions: function( from, to ) { // Bail if nothing changed. if ( this.get('from') === from && this.get('to') === to ) { return; }
this.set({ from: from, to: to }, { silent: true }); this.trigger( 'update:revisions', from, to ); }
});
revisions.model.Tooltip = Backbone.Model.extend({ defaults: { revision: null, offset: {}, hovering: false, // Whether the mouse is hovering. scrubbing: false // Whether the mouse is scrubbing. },
ensure: function( id, context ) { var diff = this.get( id ), request = this.requests[ id ], deferred = $.Deferred(), ids = {}, from = id.split(':')[0], to = id.split(':')[1]; ids[id] = true;
wp.revisions.log( 'ensure', id );
this.trigger( 'ensure', ids, from, to, deferred.promise() );
if ( diff ) { deferred.resolveWith( context, [ diff ] ); } else { this.trigger( 'ensure:load', ids, from, to, deferred.promise() ); _.each( ids, _.bind( function( id ) { // Remove anything that has an ongoing request. if ( this.requests[ id ] ) { delete ids[ id ]; } // Remove anything we already have. if ( this.get( id ) ) { delete ids[ id ]; } }, this ) ); if ( ! request ) { // Always include the ID that started this ensure. ids[ id ] = true; request = this.load( _.keys( ids ) ); }
var deferred = wp.ajax.send( options ), requests = this.requests;
// Record that we're requesting each diff. if ( options.data.compare ) { _.each( options.data.compare, function( id ) { requests[ id ] = deferred; }); }
// When the request completes, clear the stored request. deferred.always( function() { if ( options.data.compare ) { _.each( options.data.compare, function( id ) { delete requests[ id ]; }); } });
return deferred;
// Otherwise, fall back to `Backbone.sync()`. } else { return Backbone.Model.prototype.sync.apply( this, arguments ); } } });
/** * wp.revisions.model.FrameState * * The frame state. * * @see wp.revisions.view.Frame * * @param {object} attributes Model attributes - none are required. * @param {object} options Options for the model. * @param {revisions.model.Revisions} options.revisions A collection of revisions. */ revisions.model.FrameState = Backbone.Model.extend({ defaults: { loading: false, error: false, compareTwoMode: false },
changeMode: function( model, value ) { var toIndex = this.revisions.indexOf( this.get( 'to' ) );
// If we were on the first revision before switching to two-handled mode, // bump the 'to' position over one. if ( value && 0 === toIndex ) { this.set({ from: this.revisions.at( toIndex ), to: this.revisions.at( toIndex + 1 ) }); }
// When switching back to single-handled mode, reset 'from' model to // one position before the 'to' model. if ( ! value && 0 !== toIndex ) { // '! value' means switching to single-handled mode. this.set({ from: this.revisions.at( toIndex - 1 ), to: this.revisions.at( toIndex ) }); } },
// Fetch the currently loaded diff. diff: function() { return this.diffs.get( this._diffId ); },
/* * So long as `from` and `to` are changed at the same time, the diff * will only be updated once. This is because Backbone updates all of * the changed attributes in `set`, and then fires the `change` events. */ updateDiff: function( options ) { var from, to, diffId, diff;
options = options || {}; from = this.get('from'); to = this.get('to'); diffId = ( from ? from.id : 0 ) + ':' + to.id;
// Check if we're actually changing the diff id. if ( this._diffId === diffId ) { return $.Deferred().reject().promise(); }
this._diffId = diffId; this.trigger( 'update:revisions', from, to );
diff = this.diffs.get( diffId );
// If we already have the diff, then immediately trigger the update. if ( diff ) { this.receiveDiff( diff ); return $.Deferred().resolve().promise(); // Otherwise, fetch the diff. } else { if ( options.immediate ) { return this._ensureDiff(); } else { this._debouncedEnsureDiff(); return $.Deferred().reject().promise(); } } },
// A simple wrapper around `updateDiff` to prevent the change event's // parameters from being passed through. changeRevisionHandler: function() { this.updateDiff(); },
receiveDiff: function( diff ) { // Did we actually get a diff? if ( _.isUndefined( diff ) || _.isUndefined( diff.id ) ) { this.set({ loading: false, error: true }); } else if ( this._diffId === diff.id ) { // Make sure the current diff didn't change. this.trigger( 'update:diff', diff ); } },
/** * wp.revisions.view.Frame * * Top level frame that orchestrates the revisions experience. * * @param {object} options The options hash for the view. * @param {revisions.model.FrameState} options.model The frame state model. */ revisions.view.Frame = wp.Backbone.View.extend({ className: 'revisions', template: wp.template('revisions-frame'),
/** * wp.revisions.view.Controls * * The controls view. * * Contains the revision slider, previous/next buttons, the meta info and the compare checkbox. */ revisions.view.Controls = wp.Backbone.View.extend({ className: 'revisions-controls',
// Toggle the compare two mode feature when the compare two checkbox is checked. compareTwoToggle: function() { // Activate compare two mode? this.model.set({ compareTwoMode: $('.compare-two-revisions').prop('checked') }); } });
// The slider visually hidden help view. revisions.view.SliderHelp = wp.Backbone.View.extend({ className: 'revisions-slider-hidden-help', template: wp.template( 'revisions-slider-hidden-help' ) });
// The tooltip view. // Encapsulates the tooltip. revisions.view.Tooltip = wp.Backbone.View.extend({ className: 'revisions-tooltip', template: wp.template('revisions-meta'),
// The buttons view. // Encapsulates all of the configuration for the previous/next buttons. revisions.view.Buttons = wp.Backbone.View.extend({ className: 'revisions-buttons', template: wp.template('revisions-buttons'),
// Go to a specific model index. gotoModel: function( toIndex ) { var attributes = { to: this.model.revisions.at( toIndex ) }; // If we're at the first revision, unset 'from'. if ( toIndex ) { attributes.from = this.model.revisions.at( toIndex - 1 ); } else { this.model.unset('from', { silent: true }); }
this.model.set( attributes ); },
// Go to the 'next' revision. nextRevision: function() { var toIndex = this.model.revisions.indexOf( this.model.get('to') ) + 1; this.gotoModel( toIndex ); },
// Go to the 'previous' revision. previousRevision: function() { var toIndex = this.model.revisions.indexOf( this.model.get('to') ) - 1; this.gotoModel( toIndex ); },
// Check to see if the Previous or Next buttons need to be disabled or enabled. disabledButtonCheck: function() { var maxVal = this.model.revisions.length - 1, minVal = 0, next = $('.revisions-next .button'), previous = $('.revisions-previous .button'), val = this.model.revisions.indexOf( this.model.get('to') );
// Disable "Next" button if you're on the last node. next.prop( 'disabled', ( maxVal === val ) );
// Disable "Previous" button if you're on the first node. previous.prop( 'disabled', ( minVal === val ) ); } });
// Track the mouse position to enable smooth dragging, // overrides default jQuery UI step behavior. $( window ).on( 'mousemove.wp.revisions', { view: this }, function( e ) { var handles, view = e.data.view, leftDragBoundary = view.$el.offset().left, sliderOffset = leftDragBoundary, sliderRightEdge = leftDragBoundary + view.$el.width(), rightDragBoundary = sliderRightEdge, leftDragReset = '0', rightDragReset = '100%', handle = $( ui.handle );
// In two handle mode, ensure handles can't be dragged past each other. // Adjust left/right boundaries and reset points. if ( view.model.get('compareTwoMode') ) { handles = handle.parent().find('.ui-slider-handle'); if ( handle.is( handles.first() ) ) { // We're the left handle. rightDragBoundary = handles.last().offset().left; rightDragReset = rightDragBoundary - sliderOffset; } else { // We're the right handle. leftDragBoundary = handles.first().offset().left + handles.first().width(); leftDragReset = leftDragBoundary - sliderOffset; } }
// Follow mouse movements, as long as handle remains inside slider. if ( e.pageX < leftDragBoundary ) { handle.css( 'left', leftDragReset ); // Mouse to left of slider. } else if ( e.pageX > rightDragBoundary ) { handle.css( 'left', rightDragReset ); // Mouse to right of slider. } else { handle.css( 'left', e.pageX - sliderOffset ); // Mouse in slider. } } ); },
getPosition: function( position ) { return isRtl ? this.model.revisions.length - position - 1: position; },
// Responds to slide events. slide: function( event, ui ) { var attributes, movedRevision; // Compare two revisions mode. if ( this.model.get('compareTwoMode') ) { // Prevent sliders from occupying same spot. if ( ui.values[1] === ui.values[0] ) { return false; } if ( isRtl ) { ui.values.reverse(); } attributes = { from: this.model.revisions.at( this.getPosition( ui.values[0] ) ), to: this.model.revisions.at( this.getPosition( ui.values[1] ) ) }; } else { attributes = { to: this.model.revisions.at( this.getPosition( ui.value ) ) }; // If we're at the first revision, unset 'from'. if ( this.getPosition( ui.value ) > 0 ) { attributes.from = this.model.revisions.at( this.getPosition( ui.value ) - 1 ); } else { attributes.from = undefined; } } movedRevision = this.model.revisions.at( this.getPosition( ui.value ) );
// If we are scrubbing, a scrub to a revision is considered a hover. if ( this.model.get('scrubbing') ) { attributes.hoveredRevision = movedRevision; }
this.model.set( attributes ); },
stop: function() { $( window ).off('mousemove.wp.revisions'); this.model.updateSliderSettings(); // To snap us back to a tick mark. this.model.set({ scrubbing: false }); } });
// The diff view. // This is the view for the current active diff. revisions.view.Diff = wp.Backbone.View.extend({ className: 'revisions-diff', template: wp.template('revisions-diff'),
// Generate the options to be passed to the template. prepare: function() { return _.extend({ fields: this.model.fields.toJSON() }, this.options ); } });
// The revisions router. // Maintains the URL routes so browser URL matches state. revisions.Router = Backbone.Router.extend({ initialize: function( options ) { this.model = options.model;
// Maintain state and history when navigating. this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) ); this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl ); },