| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ce.MWGalleryNode = function VeCeMWGalleryNode() { |
| 20 |
|
| 21 |
ve.ce.MWGalleryNode.super.apply( this, arguments ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
⋮ |
| 29 |
|
| 30 |
|
| 31 |
ve.ce.FocusableNode.call( this, this.getFocusableElement() ); |
| 32 |
|
| 33 |
this.onUpdateDebounced = ve.debounce( this.onUpdate.bind( this ) ); |
| 34 |
|
| 35 |
|
| 36 |
this.model.connect( this, { |
| 37 |
update: 'onUpdateDebounced', |
| 38 |
|
| 39 |
splice: 'onUpdateDebounced', |
| 40 |
attributeChange: 'onAttributeChange' |
| 41 |
} ); |
| 42 |
|
| 43 |
|
| 44 |
this.$element.addClass( 'gallery' ); |
| 45 |
this.onUpdate(); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
OO.inheritClass( ve.ce.MWGalleryNode, ve.ce.BranchNode ); |
| 51 |
|
| 52 |
OO.mixinClass( ve.ce.MWGalleryNode, ve.ce.FocusableNode ); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
ve.ce.MWGalleryNode.static.name = 'mwGallery'; |
| 57 |
|
| 58 |
ve.ce.MWGalleryNode.static.tagName = 'ul'; |
| 59 |
|
| 60 |
ve.ce.MWGalleryNode.static.iconWhenInvisible = 'imageGallery'; |
| 61 |
|
| 62 |
ve.ce.MWGalleryNode.static.primaryCommandName = 'gallery'; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
ve.ce.MWGalleryNode.prototype.onUpdate = function () { |
| 70 |
const mwAttrs = this.model.getAttribute( 'mw' ).attrs; |
| 71 |
const defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions; |
| 72 |
const mode = mwAttrs.mode || defaults.mode; |
| 73 |
|
| 74 |
e. |
| 75 |
|
| 76 |
this.$element.attr( 'style', mwAttrs.style || null ); |
| 77 |
|
| 78 |
if ( mwAttrs.perrow && ( mode === 'traditional' || mode === 'nolines' ) ) { |
| 79 |
|
| 80 |
const imageWidth = parseInt( mwAttrs.widths || defaults.imageWidth ); |
| 81 |
const imagePadding = ( mode === 'traditional' ? 30 : 0 ); |
| 82 |
this.$element.css( 'max-width', mwAttrs.perrow * ( imageWidth + imagePadding + 8 ) ); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
if ( this.live ) { |
| 87 |
this.emit( 'teardown' ); |
| 88 |
} |
| 89 |
this.$focusable = this.getFocusableElement(); |
| 90 |
this.$bounding = this.$focusable; |
| 91 |
if ( this.live ) { |
| 92 |
this.emit( 'setup' ); |
| 93 |
} |
| 94 |
|
| 95 |
this.updateInvisibleIcon(); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.ce.MWGalleryNode.prototype.onAttributeChange = function ( key, from, to ) { |
| 106 |
const defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions; |
| 107 |
|
| 108 |
if ( key !== 'mw' ) { |
| 109 |
return; |
| 110 |
} |
| 111 |
|
| 112 |
if ( from.attrs.class !== to.attrs.class ) { |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
this.$element |
| 117 |
.removeClass( from.attrs.class ) |
| 118 |
.addClass( to.attrs.class ); |
| 119 |
} |
| 120 |
|
| 121 |
if ( from.attrs.mode !== to.attrs.mode ) { |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
this.$element |
| 130 |
.removeClass( 'mw-gallery-' + ( from.attrs.mode || defaults.mode ) ) |
| 131 |
.addClass( 'mw-gallery-' + ( to.attrs.mode || defaults.mode ) ); |
| 132 |
} |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
ve.ce.MWGalleryNode.prototype.getFocusableElement = function () { |
| 144 |
return this.$element.find( '.gallerybox .thumb' ); |
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
ve.ce.nodeFactory.register( ve.ce.MWGalleryNode ); |