2014-01-15 03:04:58 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWGalleryNode class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2014-01-15 03:04:58 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki gallery node.
|
|
|
|
*
|
|
|
|
* @class
|
2016-11-19 23:11:06 +00:00
|
|
|
* @extends ve.ce.BranchNode
|
|
|
|
* @mixins ve.ce.FocusableNode
|
2014-01-15 03:04:58 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWGalleryNode} model Model to observe
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-11-12 19:02:57 +00:00
|
|
|
ve.ce.MWGalleryNode = function VeCeMWGalleryNode() {
|
2014-01-15 03:04:58 +00:00
|
|
|
// Parent constructor
|
2014-11-12 19:02:57 +00:00
|
|
|
ve.ce.MWGalleryNode.super.apply( this, arguments );
|
2016-11-19 23:11:06 +00:00
|
|
|
|
|
|
|
// DOM hierarchy for MWGalleryNode:
|
|
|
|
// <ul> this.$element (gallery mw-gallery-{mode})
|
|
|
|
// <li> ve.ce.MWGalleryCaptionNode (gallerycaption)
|
|
|
|
// <li> ve.ce.MWGalleryImageNode (gallerybox)
|
|
|
|
// <li> ve.ce.MWGalleryImageNode (gallerybox)
|
|
|
|
// ⋮
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.ce.FocusableNode.call( this, this.$element );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.connect( this, { update: 'updateInvisibleIcon' } );
|
|
|
|
this.model.connect( this, { update: 'onUpdate' } );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.onUpdate();
|
2014-01-15 03:04:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
OO.inheritClass( ve.ce.MWGalleryNode, ve.ce.BranchNode );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.ce.MWGalleryNode, ve.ce.FocusableNode );
|
2014-01-15 03:04:58 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ce.MWGalleryNode.static.name = 'mwGallery';
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
ve.ce.MWGalleryNode.static.tagName = 'ul';
|
|
|
|
|
|
|
|
ve.ce.MWGalleryNode.static.iconWhenInvisible = 'imageGallery';
|
2014-01-15 03:04:58 +00:00
|
|
|
|
2013-12-20 23:25:24 +00:00
|
|
|
ve.ce.MWGalleryNode.static.primaryCommandName = 'gallery';
|
|
|
|
|
2014-06-16 10:52:37 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2016-11-19 23:11:06 +00:00
|
|
|
* Handle model update events.
|
|
|
|
*
|
2017-11-03 22:29:25 +00:00
|
|
|
* @method
|
|
|
|
*/
|
2016-11-19 23:11:06 +00:00
|
|
|
ve.ce.MWGalleryNode.prototype.onUpdate = function () {
|
|
|
|
var mwAttrs, defaults, mode, imageWidth, imagePadding;
|
|
|
|
|
|
|
|
mwAttrs = this.model.getAttribute( 'mw' ).attrs;
|
|
|
|
defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions;
|
|
|
|
mode = mwAttrs.mode || defaults.mode;
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.attr( 'class', mwAttrs.class )
|
|
|
|
.attr( 'style', mwAttrs.style )
|
|
|
|
.addClass( 'gallery mw-gallery-' + mode );
|
|
|
|
|
|
|
|
if ( mwAttrs.perrow && ( mode === 'traditional' || mode === 'nolines' ) ) {
|
|
|
|
// Magic 30 and 8 matches the code in ve.ce.MWGalleryImageNode
|
|
|
|
imageWidth = parseInt( mwAttrs.widths || defaults.imageWidth );
|
|
|
|
imagePadding = ( mode === 'traditional' ? 30 : 0 );
|
|
|
|
this.$element.css( 'max-width', mwAttrs.perrow * ( imageWidth + imagePadding + 8 ) );
|
|
|
|
}
|
|
|
|
};
|
2017-11-03 22:29:25 +00:00
|
|
|
|
2014-01-15 03:04:58 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWGalleryNode );
|