2015-11-08 17:05:33 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWSignatureNode class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2015-11-08 17:05:33 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki signature node. This defines the behavior of the signature node
|
|
|
|
* inserted into the ContentEditable document.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ce.MWTransclusionInlineNode
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWSignatureNode} model Model to observe
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ce.MWSignatureNode = function VeCeMWSignatureNode() {
|
2015-11-08 17:05:33 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ce.MWSignatureNode.super.apply( this, arguments );
|
2015-11-08 17:05:33 +00:00
|
|
|
|
|
|
|
// DOM changes
|
|
|
|
this.$element.addClass( 've-ce-mwSignatureNode' );
|
|
|
|
|
|
|
|
if ( this.isGenerating() ) {
|
|
|
|
// Use an initial rendering of '~~~~' as a placeholder to avoid
|
|
|
|
// the width changing when using the Sequence.
|
|
|
|
this.$element.text( '~~~~' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ce.MWSignatureNode, ve.ce.MWTransclusionInlineNode );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ce.MWSignatureNode.static.name = 'mwSignature';
|
|
|
|
|
|
|
|
ve.ce.MWSignatureNode.static.tagName = 'span';
|
|
|
|
|
|
|
|
ve.ce.MWSignatureNode.static.primaryCommandName = 'mwSignature';
|
|
|
|
|
2017-04-29 11:37:28 +00:00
|
|
|
ve.ce.MWSignatureNode.static.liveSignatures = [];
|
|
|
|
|
|
|
|
// Update the timestamp on inserted signatures every minute.
|
|
|
|
setInterval( function () {
|
|
|
|
var updatedSignatures, i, sig,
|
|
|
|
liveSignatures = ve.ce.MWSignatureNode.static.liveSignatures;
|
|
|
|
|
|
|
|
updatedSignatures = [];
|
|
|
|
for ( i = 0; i < liveSignatures.length; i++ ) {
|
|
|
|
sig = liveSignatures[ i ];
|
|
|
|
try {
|
|
|
|
sig.forceUpdate();
|
|
|
|
updatedSignatures.push( sig );
|
|
|
|
} catch ( er ) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
liveSignatures = updatedSignatures;
|
|
|
|
}, 60 * 1000 );
|
|
|
|
|
2015-11-08 17:05:33 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2017-04-29 11:37:28 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ce.MWSignatureNode.prototype.onSetup = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ce.MWSignatureNode.super.prototype.onSetup.call( this );
|
|
|
|
|
|
|
|
// Keep track for regular updating of timestamp
|
|
|
|
this.constructor.static.liveSignatures.push( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ce.MWSignatureNode.prototype.onTeardown = function () {
|
|
|
|
var index,
|
|
|
|
liveSignatures = this.constructor.static.liveSignatures;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ce.MWSignatureNode.super.prototype.onTeardown.call( this );
|
|
|
|
|
|
|
|
// Stop tracking
|
|
|
|
index = liveSignatures.indexOf( this );
|
|
|
|
if ( index !== -1 ) {
|
|
|
|
liveSignatures.splice( index, 1 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-08 17:05:33 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ce.MWSignatureNode.prototype.generateContents = function () {
|
2018-05-04 13:30:10 +00:00
|
|
|
var wikitext, signatureNode, deferred, xhr;
|
2015-11-08 17:05:33 +00:00
|
|
|
// Parsoid doesn't support pre-save transforms. PHP parser doesn't support Parsoid's
|
|
|
|
// meta attributes (that may or may not be required).
|
|
|
|
|
|
|
|
// We could try hacking up one (or even both) of these, but just calling the two parsers
|
|
|
|
// in order seems slightly saner.
|
|
|
|
|
|
|
|
// We must have only one top-level node, this is the easiest way.
|
|
|
|
wikitext = '<span>~~~~</span>';
|
|
|
|
signatureNode = this;
|
|
|
|
|
2019-11-02 05:06:28 +00:00
|
|
|
deferred = ve.createDeferred();
|
2018-05-04 13:30:10 +00:00
|
|
|
xhr = ve.init.target.getContentApi( this.getModel().getDocument() ).post( {
|
2015-11-08 17:05:33 +00:00
|
|
|
action: 'parse',
|
|
|
|
text: wikitext,
|
|
|
|
contentmodel: 'wikitext',
|
|
|
|
prop: 'text',
|
|
|
|
onlypst: true
|
|
|
|
} )
|
|
|
|
.done( function ( resp ) {
|
2019-08-27 15:15:07 +00:00
|
|
|
var wikitext = ve.getProp( resp, 'parse', 'text' );
|
2015-11-08 17:05:33 +00:00
|
|
|
if ( wikitext ) {
|
|
|
|
// Call parent method with the wikitext with PST applied.
|
|
|
|
ve.ce.MWSignatureNode.parent.prototype.generateContents.call(
|
|
|
|
signatureNode,
|
|
|
|
{ wikitext: wikitext }
|
|
|
|
).done( function ( nodes ) {
|
|
|
|
deferred.resolve( nodes );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
signatureNode.onParseError( deferred );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.fail( this.onParseError.bind( this, deferred ) );
|
|
|
|
|
|
|
|
return deferred.promise( { abort: xhr.abort } );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWSignatureNode );
|