| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
ve.ce.MWExtensionNode = function VeCeMWExtensionNode() { |
| 24 |
|
| 25 |
ve.ce.MWExtensionNode.super.apply( this, arguments ); |
| 26 |
|
| 27 |
|
| 28 |
ve.ce.FocusableNode.call( this, this.getFocusableElement() ); |
| 29 |
ve.ce.GeneratedContentNode.call( this ); |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
OO.inheritClass( ve.ce.MWExtensionNode, ve.ce.LeafNode ); |
| 35 |
OO.mixinClass( ve.ce.MWExtensionNode, ve.ce.FocusableNode ); |
| 36 |
OO.mixinClass( ve.ce.MWExtensionNode, ve.ce.GeneratedContentNode ); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ve.ce.MWExtensionNode.static.rendersEmpty = false; |
| 48 |
|
| 49 |
ve.ce.MWExtensionNode.static.iconWhenInvisible = 'markup'; |
| 50 |
|
| 51 |
ve.ce.MWExtensionNode.static.getDescription = function ( model ) { |
| 52 |
const body = ve.getProp( model.getAttribute( 'mw' ), 'body', 'extsrc' ) || ''; |
| 53 |
return body.slice( 0, 100 ) + ( body.length > 100 ? '…' : '' ); |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ce.MWExtensionNode.prototype.generateContents = function ( config ) { |
| 62 |
const deferred = ve.createDeferred(), |
| 63 |
mwData = ve.copy( this.getModel().getAttribute( 'mw' ) ), |
| 64 |
extsrc = config && config.extsrc !== undefined ? config.extsrc : ( ve.getProp( mwData, 'body', 'extsrc' ) || '' ), |
| 65 |
attrs = config && config.attrs || mwData.attrs, |
| 66 |
tagName = this.getModel().getExtensionName(); |
| 67 |
|
| 68 |
|
| 69 |
for ( const attr in attrs ) { |
| 70 |
if ( attrs[ attr ] === undefined ) { |
| 71 |
delete attrs[ attr ]; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
const wikitext = mw.html.element( tagName, attrs, new mw.html.Raw( extsrc ) ); |
| 77 |
|
| 78 |
if ( this.constructor.static.rendersEmpty || extsrc.trim() !== '' ) { |
| 79 |
const xhr = ve.init.target.parseWikitextFragment( wikitext, false, this.getModel().getDocument() ) |
| 80 |
.done( this.onParseSuccess.bind( this, deferred ) ) |
| 81 |
.fail( this.onParseError.bind( this, deferred ) ); |
| 82 |
return deferred.promise( { abort: xhr.abort } ); |
| 83 |
} else { |
| 84 |
deferred.resolve( $( '<span>' ).text( '\u00a0' ).get() ); |
| 85 |
return deferred.promise(); |
| 86 |
} |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ce.MWExtensionNode.prototype.getRenderedDomElements = function () { |
| 93 |
|
| 94 |
const elements = ve.ce.GeneratedContentNode.prototype.getRenderedDomElements.apply( this, arguments ); |
| 95 |
|
| 96 |
if ( this.getModelHtmlDocument() ) { |
| 97 |
ve.init.platform.linkCache.styleParsoidElements( |
| 98 |
$( elements ), |
| 99 |
this.getModelHtmlDocument() |
| 100 |
); |
| 101 |
} |
| 102 |
return elements; |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
ve.ce.MWExtensionNode.prototype.onParseSuccess = function ( deferred, response ) { |
| 112 |
const data = response.visualeditor, |
| 113 |
contentNodes = $( data.content ).get(); |
| 114 |
deferred.resolve( contentNodes ); |
| 115 |
}; |
| 116 |
|
| 117 |
ve.ce.MWExtensionNode.prototype.afterRender = function () { |
| 118 |
const $images = this.$element |
| 119 |
.find( 'img:not([width]),img:not([height])' ) |
| 120 |
.addBack( 'img:not([width]),img:not([height])' ); |
| 121 |
|
| 122 |
|
| 123 |
ve.ce.GeneratedContentNode.prototype.afterRender.call( this ); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
if ( $images.length ) { |
| 128 |
$images.on( 'load', () => { |
| 129 |
|
| 130 |
ve.ce.GeneratedContentNode.prototype.afterRender.call( this ); |
| 131 |
} ); |
| 132 |
} |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.ce.MWExtensionNode.prototype.onParseError = function ( deferred ) { |
| 142 |
deferred.reject(); |
| 143 |
}; |