| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.dm.example.StubReferenceNode = function VeDmStubReferenceNode() { |
| 17 |
|
| 18 |
ve.dm.example.StubReferenceNode.super.apply( this, arguments ); |
| 19 |
|
| 20 |
|
| 21 |
ve.dm.FocusableNode.call( this ); |
| 22 |
|
| 23 |
|
| 24 |
this.connect( this, { |
| 25 |
root: 'onRoot', |
| 26 |
unroot: 'onUnroot', |
| 27 |
attributeChange: 'onAttributeChange' |
| 28 |
} ); |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
OO.inheritClass( ve.dm.example.StubReferenceNode, ve.dm.LeafNode ); |
| 34 |
|
| 35 |
OO.mixinClass( ve.dm.example.StubReferenceNode, ve.dm.FocusableNode ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
ve.dm.example.StubReferenceNode.static.name = 'stubReference'; |
| 40 |
|
| 41 |
ve.dm.example.StubReferenceNode.static.matchTagNames = [ 'ref' ]; |
| 42 |
|
| 43 |
ve.dm.example.StubReferenceNode.static.isContent = true; |
| 44 |
|
| 45 |
ve.dm.example.StubReferenceNode.static.handlesOwnChildren = true; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
ve.dm.example.StubReferenceNode.static.listKeyRegex = /^(auto|literal)\/([\s\S]*)$/; |
| 57 |
|
| 58 |
ve.dm.example.StubReferenceNode.static.toDataElement = function ( domElements, converter ) { |
| 59 |
const refElement = domElements[ 0 ]; |
| 60 |
const body = refElement.innerHTML; |
| 61 |
const refGroup = refElement.getAttribute( 'group' ) || ''; |
| 62 |
const listGroup = this.name + '/' + refGroup; |
| 63 |
const name = refElement.getAttribute( 'name' ); |
| 64 |
const listKey = name ? |
| 65 |
'literal/' + name : |
| 66 |
'auto/' + converter.internalList.getNextUniqueNumber(); |
| 67 |
const queueResult = converter.internalList.queueItemHtml( listGroup, listKey, body ); |
| 68 |
const listIndex = queueResult.index; |
| 69 |
const contentsUsed = ( body !== '' && queueResult.isNew ); |
| 70 |
|
| 71 |
const dataElement = { |
| 72 |
type: this.name, |
| 73 |
attributes: { |
| 74 |
listIndex: listIndex, |
| 75 |
listGroup: listGroup, |
| 76 |
listKey: listKey, |
| 77 |
refGroup: refGroup, |
| 78 |
contentsUsed: contentsUsed |
| 79 |
} |
| 80 |
}; |
| 81 |
return dataElement; |
| 82 |
}; |
| 83 |
|
| 84 |
ve.dm.example.StubReferenceNode.static.toDomElements = function ( dataElements, doc ) { |
| 85 |
return [ doc.createElement( 'ref' ) ]; |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ve.dm.example.StubReferenceNode.prototype.onRoot = function () { |
| 92 |
this.addToInternalList(); |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
ve.dm.example.StubReferenceNode.prototype.onUnroot = function ( oldRoot ) { |
| 101 |
if ( this.getDocument().getDocumentNode() === oldRoot ) { |
| 102 |
this.removeFromInternalList(); |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
ve.dm.example.StubReferenceNode.prototype.addToInternalList = function () { |
| 110 |
if ( this.getRoot() === this.getDocument().getDocumentNode() ) { |
| 111 |
this.registeredListGroup = this.element.attributes.listGroup; |
| 112 |
this.registeredListKey = this.element.attributes.listKey; |
| 113 |
this.registeredListIndex = this.element.attributes.listIndex; |
| 114 |
this.getDocument().getInternalList().addNode( |
| 115 |
this.registeredListGroup, |
| 116 |
this.registeredListKey, |
| 117 |
this.registeredListIndex, |
| 118 |
this |
| 119 |
); |
| 120 |
} |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
ve.dm.example.StubReferenceNode.prototype.removeFromInternalList = function () { |
| 127 |
if ( !this.registeredListGroup ) { |
| 128 |
|
| 129 |
return; |
| 130 |
} |
| 131 |
this.getDocument().getInternalList().removeNode( |
| 132 |
this.registeredListGroup, |
| 133 |
this.registeredListKey, |
| 134 |
this.registeredListIndex, |
| 135 |
this |
| 136 |
); |
| 137 |
}; |
| 138 |
|
| 139 |
ve.dm.example.StubReferenceNode.prototype.onAttributeChange = function ( key, from, to ) { |
| 140 |
if ( |
| 141 |
( key !== 'listGroup' && key !== 'listKey' ) || |
| 142 |
( key === 'listGroup' && this.registeredListGroup === to ) || |
| 143 |
( key === 'listKey' && this.registeredListKey === to ) |
| 144 |
) { |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
this.removeFromInternalList(); |
| 151 |
this.addToInternalList(); |
| 152 |
}; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
ve.dm.modelRegistry.register( ve.dm.example.StubReferenceNode ); |