| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ce.MWSignatureNode = function VeCeMWSignatureNode() { |
| 20 |
|
| 21 |
ve.ce.MWSignatureNode.super.apply( this, arguments ); |
| 22 |
|
| 23 |
|
| 24 |
ve.ce.GeneratedContentNode.call( this ); |
| 25 |
ve.ce.FocusableNode.call( this ); |
| 26 |
|
| 27 |
|
| 28 |
this.$element.addClass( 've-ce-mwSignatureNode' ); |
| 29 |
|
| 30 |
if ( this.isGenerating() ) { |
| 31 |
|
| 32 |
|
| 33 |
this.$element.text( '~~~~' ); |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
OO.inheritClass( ve.ce.MWSignatureNode, ve.ce.LeafNode ); |
| 40 |
OO.mixinClass( ve.ce.MWSignatureNode, ve.ce.GeneratedContentNode ); |
| 41 |
OO.mixinClass( ve.ce.MWSignatureNode, ve.ce.FocusableNode ); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.ce.MWSignatureNode.static.name = 'mwSignature'; |
| 46 |
|
| 47 |
ve.ce.MWSignatureNode.static.tagName = 'span'; |
| 48 |
|
| 49 |
ve.ce.MWSignatureNode.static.primaryCommandName = 'mwSignature'; |
| 50 |
|
| 51 |
ve.ce.MWSignatureNode.static.liveSignatures = []; |
| 52 |
|
| 53 |
|
| 54 |
ve.ce.MWSignatureNode.static.getDescription = function () { |
| 55 |
return ve.msg( 'visualeditor-mwsignature-tool' ); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
setInterval( () => { |
| 60 |
const liveSignatures = ve.ce.MWSignatureNode.static.liveSignatures; |
| 61 |
|
| 62 |
const updatedSignatures = []; |
| 63 |
for ( let i = 0; i < liveSignatures.length; i++ ) { |
| 64 |
const sig = liveSignatures[ i ]; |
| 65 |
try { |
| 66 |
sig.forceUpdate(); |
| 67 |
updatedSignatures.push( sig ); |
| 68 |
} catch ( er ) { |
| 69 |
|
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
ve.ce.MWSignatureNode.static.liveSignatures = updatedSignatures; |
| 74 |
}, 60 * 1000 ); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
ve.ce.MWSignatureNode.prototype.onSetup = function () { |
| 82 |
|
| 83 |
ve.ce.MWSignatureNode.super.prototype.onSetup.call( this ); |
| 84 |
|
| 85 |
|
| 86 |
this.constructor.static.liveSignatures.push( this ); |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ce.MWSignatureNode.prototype.onTeardown = function () { |
| 93 |
const liveSignatures = this.constructor.static.liveSignatures; |
| 94 |
|
| 95 |
|
| 96 |
ve.ce.MWSignatureNode.super.prototype.onTeardown.call( this ); |
| 97 |
|
| 98 |
|
| 99 |
const index = liveSignatures.indexOf( this ); |
| 100 |
if ( index !== -1 ) { |
| 101 |
liveSignatures.splice( index, 1 ); |
| 102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ce.MWSignatureNode.prototype.generateContents = function () { |
| 109 |
const doc = this.getModel().getDocument(); |
| 110 |
let abortable, aborted; |
| 111 |
const abortedPromise = ve.createDeferred().reject( 'http', |
| 112 |
{ textStatus: 'abort', exception: 'abort' } ).promise(); |
| 113 |
|
| 114 |
function abort() { |
| 115 |
aborted = true; |
| 116 |
if ( abortable && abortable.abort ) { |
| 117 |
abortable.abort(); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
return mw.user.acquireTempUserName() |
| 124 |
.then( () => { |
| 125 |
if ( aborted ) { |
| 126 |
return abortedPromise; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
const wikitext = '<span>~~~~</span>'; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
return ( abortable = ve.init.target.getContentApi( doc ).post( { |
| 137 |
action: 'parse', |
| 138 |
text: wikitext, |
| 139 |
contentmodel: 'wikitext', |
| 140 |
prop: 'text', |
| 141 |
onlypst: true |
| 142 |
} ) ); |
| 143 |
} ) |
| 144 |
.then( ( pstResponse ) => { |
| 145 |
if ( aborted ) { |
| 146 |
return abortedPromise; |
| 147 |
} |
| 148 |
const wikitext = ve.getProp( pstResponse, 'parse', 'text' ); |
| 149 |
if ( !wikitext ) { |
| 150 |
return ve.createDeferred().reject(); |
| 151 |
} |
| 152 |
return ( abortable = ve.init.target.parseWikitextFragment( wikitext, true, doc ) ); |
| 153 |
} ) |
| 154 |
.then( ( parseResponse ) => { |
| 155 |
if ( aborted ) { |
| 156 |
return abortedPromise; |
| 157 |
} |
| 158 |
if ( ve.getProp( parseResponse, 'visualeditor', 'result' ) !== 'success' ) { |
| 159 |
return ve.createDeferred().reject(); |
| 160 |
} |
| 161 |
|
| 162 |
return $( parseResponse.visualeditor.content ).contents().toArray(); |
| 163 |
} ) |
| 164 |
.promise( { abort: abort } ); |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
ve.ce.nodeFactory.register( ve.ce.MWSignatureNode ); |