| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ce.MWGalleryImageNode = function VeCeMWGalleryImageNode( model ) { |
| 19 |
|
| 20 |
ve.ce.MWGalleryImageNode.super.apply( this, arguments ); |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
const defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions; |
| 32 |
const attributes = model.getAttributes(); |
| 33 |
const galleryMwAttrs = model.parent.getAttribute( 'mw' ).attrs; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
const mode = galleryMwAttrs.mode || defaults.mode; |
| 41 |
let innerDivWidth, innerDivHeight, innerDivMargin, outerDivWidth; |
| 42 |
if ( mode === 'traditional' || mode === 'nolines' || mode === 'slideshow' ) { |
| 43 |
const imagePadding = ( mode === 'traditional' ? 30 : 0 ); |
| 44 |
innerDivWidth = parseInt( galleryMwAttrs.widths || defaults.imageWidth ) + imagePadding; |
| 45 |
innerDivHeight = parseInt( galleryMwAttrs.heights || defaults.imageHeight ) + imagePadding; |
| 46 |
if ( mode === 'traditional' ) { |
| 47 |
const imageHeight = parseInt( attributes.height ); |
| 48 |
innerDivMargin = ( ( innerDivHeight - imageHeight ) / 2 ) + 'px auto'; |
| 49 |
} else { |
| 50 |
innerDivMargin = 0; |
| 51 |
} |
| 52 |
outerDivWidth = innerDivWidth + 8; |
| 53 |
} else { |
| 54 |
innerDivWidth = parseInt( attributes.width ); |
| 55 |
innerDivHeight = parseInt( galleryMwAttrs.heights || defaults.imageHeight ); |
| 56 |
innerDivMargin = 0; |
| 57 |
outerDivWidth = innerDivWidth + 4; |
| 58 |
} |
| 59 |
|
| 60 |
const resourceTitle = mw.Title.newFromText( mw.libs.ve.normalizeParsoidResourceName( attributes.resource ) ); |
| 61 |
|
| 62 |
this.$element |
| 63 |
.addClass( 'gallerybox' ) |
| 64 |
.css( 'width', outerDivWidth + 'px' ); |
| 65 |
const $thumbDiv = $( '<div>' ) |
| 66 |
.addClass( 'thumb' ) |
| 67 |
.css( 'width', innerDivWidth + 'px' ) |
| 68 |
.css( 'height', innerDivHeight + 'px' ); |
| 69 |
const $innerDiv = $( '<span>' ) |
| 70 |
.css( 'margin', innerDivMargin ); |
| 71 |
const $a = $( '<a>' ).addClass( 'mw-file-description' ); |
| 72 |
|
| 73 |
let $img; |
| 74 |
if ( model.getAttribute( 'isError' ) ) { |
| 75 |
$img = $( '<span>' ) |
| 76 |
.addClass( 'mw-file-element mw-broken-media' ) |
| 77 |
.text( model.getAttribute( 'errorText' ) ); |
| 78 |
} else { |
| 79 |
$img = $( '<img>' ) |
| 80 |
.addClass( 'mw-file-element' ) |
| 81 |
.attr( 'resource', attributes.resource ) |
| 82 |
.attr( 'alt', attributes.altText ) |
| 83 |
.attr( 'src', attributes.src ) |
| 84 |
.attr( 'height', attributes.height ) |
| 85 |
.attr( 'width', attributes.width ); |
| 86 |
} |
| 87 |
|
| 88 |
this.$filenameA = $( '<a>' ) |
| 89 |
.attr( 'href', '#' ) |
| 90 |
.text( resourceTitle ? resourceTitle.getMainText() : attributes.resource ) |
| 91 |
.toggleClass( 'oo-ui-element-hidden', galleryMwAttrs.showfilename !== 'yes' ); |
| 92 |
|
| 93 |
this.$element.prepend( |
| 94 |
$thumbDiv.append( |
| 95 |
$innerDiv.append( |
| 96 |
$a.append( |
| 97 |
$img |
| 98 |
) |
| 99 |
) |
| 100 |
), |
| 101 |
this.$filenameA |
| 102 |
); |
| 103 |
|
| 104 |
this.model.parent.connect( this, { attributeChange: 'onGalleryAttributeChange' } ); |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
OO.inheritClass( ve.ce.MWGalleryImageNode, ve.ce.BranchNode ); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
ve.ce.MWGalleryImageNode.static.name = 'mwGalleryImage'; |
| 114 |
|
| 115 |
ve.ce.MWGalleryImageNode.static.tagName = 'li'; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
ve.ce.MWGalleryImageNode.prototype.onGalleryAttributeChange = function ( key, from, to ) { |
| 120 |
if ( key !== 'mw' ) { |
| 121 |
return; |
| 122 |
} |
| 123 |
|
| 124 |
this.$filenameA.toggleClass( 'oo-ui-element-hidden', to.attrs.showfilename !== 'yes' ); |
| 125 |
}; |
| 126 |
|
| 127 |
ve.ce.MWGalleryImageNode.prototype.getDomPosition = function () { |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
const domNode = this.$element.last()[ 0 ]; |
| 133 |
return { |
| 134 |
node: domNode, |
| 135 |
offset: domNode.childNodes.length |
| 136 |
}; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.ce.nodeFactory.register( ve.ce.MWGalleryImageNode ); |