| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ce.MWEntityNode = function VeCeMWEntityNode() { |
| 18 |
|
| 19 |
ve.ce.MWEntityNode.super.apply( this, arguments ); |
| 20 |
|
| 21 |
|
| 22 |
this.$element.addClass( 've-ce-mwEntityNode' ); |
| 23 |
|
| 24 |
this.$element.prop( 'contentEditable', 'false' ); |
| 25 |
|
| 26 |
|
| 27 |
this.model.connect( this, { update: 'onUpdate' } ); |
| 28 |
|
| 29 |
|
| 30 |
this.onUpdate(); |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
OO.inheritClass( ve.ce.MWEntityNode, ve.ce.LeafNode ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
ve.ce.MWEntityNode.static.name = 'mwEntity'; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
ve.ce.MWEntityNode.prototype.onUpdate = function () { |
| 47 |
const whitespaceHtmlChars = ve.visibleWhitespaceCharacters, |
| 48 |
significantWhitespace = this.getModel().getParent().hasSignificantWhitespace(); |
| 49 |
|
| 50 |
let chr = this.model.getAttribute( 'character' ); |
| 51 |
if ( chr === '\u00a0' ) { |
| 52 |
|
| 53 |
this.$element |
| 54 |
.addClass( 've-ce-mwEntityNode-nbsp' ) |
| 55 |
.attr( 'title', mw.msg( 'visualeditor-tooltip-non-breaking-space' ) ); |
| 56 |
} else { |
| 57 |
this.$element |
| 58 |
.removeClass( 've-ce-mwEntityNode-nbsp' ) |
| 59 |
.removeAttr( 'title' ); |
| 60 |
} |
| 61 |
|
| 62 |
if ( !significantWhitespace && Object.prototype.hasOwnProperty.call( whitespaceHtmlChars, chr ) ) { |
| 63 |
chr = whitespaceHtmlChars[ chr ]; |
| 64 |
} |
| 65 |
|
| 66 |
this.$element.text( chr ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
ve.ce.nodeFactory.register( ve.ce.MWEntityNode ); |