| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.dm.MWGalleryNode = function VeDmMWGalleryNode() { |
| 19 |
|
| 20 |
ve.dm.MWGalleryNode.super.apply( this, arguments ); |
| 21 |
|
| 22 |
|
| 23 |
ve.dm.FocusableNode.call( this ); |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.inheritClass( ve.dm.MWGalleryNode, ve.dm.BranchNode ); |
| 29 |
|
| 30 |
OO.mixinClass( ve.dm.MWGalleryNode, ve.dm.FocusableNode ); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
ve.dm.MWGalleryNode.static.name = 'mwGallery'; |
| 35 |
|
| 36 |
ve.dm.MWGalleryNode.static.matchRdfaTypes = [ 'mw:Extension/gallery' ]; |
| 37 |
|
| 38 |
ve.dm.MWGalleryNode.static.matchTagNames = [ 'ul' ]; |
| 39 |
|
| 40 |
ve.dm.MWGalleryNode.static.childNodeTypes = [ 'mwGalleryCaption', 'mwGalleryImage' ]; |
| 41 |
|
| 42 |
ve.dm.MWGalleryNode.static.disallowedAnnotationTypes = [ 'link' ]; |
| 43 |
|
| 44 |
ve.dm.MWGalleryNode.static.cloneElement = function () { |
| 45 |
|
| 46 |
const clone = ve.dm.LeafNode.static.cloneElement.apply( this, arguments ); |
| 47 |
delete clone.attributes.originalMw; |
| 48 |
return clone; |
| 49 |
}; |
| 50 |
|
| 51 |
ve.dm.MWGalleryNode.static.getHashObject = function ( dataElement ) { |
| 52 |
return { |
| 53 |
type: dataElement.type, |
| 54 |
mw: ve.copy( dataElement.attributes.mw ) |
| 55 |
}; |
| 56 |
}; |
| 57 |
|
| 58 |
ve.dm.MWGalleryNode.static.toDataElement = function ( domElements ) { |
| 59 |
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ), |
| 60 |
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {}; |
| 61 |
|
| 62 |
return { |
| 63 |
type: this.name, |
| 64 |
attributes: { |
| 65 |
mw: mwData, |
| 66 |
originalMw: mwDataJSON |
| 67 |
} |
| 68 |
}; |
| 69 |
}; |
| 70 |
|
| 71 |
ve.dm.MWGalleryNode.static.toDomElements = function ( data, doc ) { |
| 72 |
const ul = doc.createElement( 'ul' ); |
| 73 |
|
| 74 |
|
| 75 |
ul.setAttribute( 'typeof', 'mw:Extension/gallery' ); |
| 76 |
ul.setAttribute( 'data-mw', JSON.stringify( data.attributes.mw ) ); |
| 77 |
|
| 78 |
return [ ul ]; |
| 79 |
}; |
| 80 |
|
| 81 |
ve.dm.MWGalleryNode.static.describeChanges = function ( attributeChanges, attributes, element ) { |
| 82 |
|
| 83 |
if ( attributeChanges.mw ) { |
| 84 |
return ve.dm.MWGalleryNode.super.static.describeChanges.call( |
| 85 |
this, |
| 86 |
ve.ui.DiffElement.static.compareAttributes( attributeChanges.mw.from.attrs || {}, attributeChanges.mw.to.attrs || {} ), |
| 87 |
attributes, |
| 88 |
element |
| 89 |
); |
| 90 |
} |
| 91 |
return []; |
| 92 |
}; |
| 93 |
|
| 94 |
ve.dm.MWGalleryNode.static.describeChange = function ( key ) { |
| 95 |
|
| 96 |
if ( key === 'caption' ) { |
| 97 |
return null; |
| 98 |
} |
| 99 |
|
| 100 |
return ve.dm.MWGalleryNode.super.static.describeChange.apply( this, arguments ); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.dm.MWGalleryNode.prototype.isDiffedAsDocument = function () { |
| 106 |
return true; |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.dm.MWGalleryNode.prototype.getCaptionNode = function () { |
| 115 |
const node = this.children[ 0 ]; |
| 116 |
return node instanceof ve.dm.MWGalleryCaptionNode ? node : null; |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
ve.dm.MWGalleryNode.prototype.getImageNodes = function () { |
| 125 |
const images = this.children.filter( ( child ) => child instanceof ve.dm.MWGalleryImageNode ); |
| 126 |
return images; |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.dm.modelRegistry.register( ve.dm.MWGalleryNode ); |