| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.dm.ListNode = function VeDmListNode() { |
| 18 |
|
| 19 |
ve.dm.ListNode.super.apply( this, arguments ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.dm.ListNode, ve.dm.BranchNode ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ve.dm.ListNode.static.name = 'list'; |
| 29 |
|
| 30 |
ve.dm.ListNode.static.childNodeTypes = [ 'listItem' ]; |
| 31 |
|
| 32 |
ve.dm.ListNode.static.defaultAttributes = { |
| 33 |
style: 'bullet' |
| 34 |
}; |
| 35 |
|
| 36 |
ve.dm.ListNode.static.matchTagNames = [ 'ul', 'ol' ]; |
| 37 |
|
| 38 |
ve.dm.ListNode.static.isDiffedAsList = true; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.dm.ListNode.static.createItem = function () { |
| 46 |
return { type: 'listItem' }; |
| 47 |
}; |
| 48 |
|
| 49 |
ve.dm.ListNode.static.toDataElement = function ( domElements ) { |
| 50 |
const style = domElements[ 0 ].nodeName.toLowerCase() === 'ol' ? 'number' : 'bullet'; |
| 51 |
return { type: this.name, attributes: { style: style } }; |
| 52 |
}; |
| 53 |
|
| 54 |
ve.dm.ListNode.static.toDomElements = function ( dataElement, doc ) { |
| 55 |
const tag = dataElement.attributes && dataElement.attributes.style === 'number' ? 'ol' : 'ul'; |
| 56 |
return [ doc.createElement( tag ) ]; |
| 57 |
}; |
| 58 |
|
| 59 |
ve.dm.ListNode.static.describeChanges = function ( attributeChanges, attributes, element ) { |
| 60 |
attributeChanges = ve.copy( attributeChanges ); |
| 61 |
if ( 'listType' in attributeChanges ) { |
| 62 |
let mapped = false; |
| 63 |
[ 'from', 'to' ].forEach( ( fromOrTo ) => { |
| 64 |
if ( attributeChanges.listType[ fromOrTo ] === 'definitionList' ) { |
| 65 |
attributeChanges.style[ fromOrTo ] = 'indent'; |
| 66 |
mapped = true; |
| 67 |
} |
| 68 |
} ); |
| 69 |
if ( mapped ) { |
| 70 |
delete attributeChanges.listType; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return ve.dm.ListNode.super.static.describeChanges.call( this, attributeChanges, attributes, element ); |
| 75 |
}; |
| 76 |
|
| 77 |
ve.dm.ListNode.static.describeChange = function ( key, change ) { |
| 78 |
const messageKeys = { |
| 79 |
bullet: 'visualeditor-listbutton-bullet-tooltip', |
| 80 |
number: 'visualeditor-listbutton-number-tooltip', |
| 81 |
indent: 'visualeditor-changedesc-list-style-indent' |
| 82 |
}; |
| 83 |
if ( key === 'style' && change.from in messageKeys && change.to in messageKeys ) { |
| 84 |
return ve.htmlMsg( 'visualeditor-changedesc-no-key', |
| 85 |
|
| 86 |
|
| 87 |
this.wrapText( 'del', ve.msg( messageKeys[ change.from ] ) ), |
| 88 |
|
| 89 |
this.wrapText( 'ins', ve.msg( messageKeys[ change.to ] ) ) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
return ve.dm.ListNode.super.static.describeChange.apply( this, arguments ); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
ve.dm.ListNode.prototype.canHaveSlugAfter = function () { |
| 99 |
|
| 100 |
return false; |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.dm.modelRegistry.register( ve.dm.ListNode ); |