Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/widgets/ve.ui.MWGalleryItemWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface MWGalleryItemWidget class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Draggable item widget for the MWGalleryGroupWidget
10 *
11 * @class
12 * @extends OO.ui.Widget
13 * @mixes OO.ui.mixin.DraggableElement
14 *
15 * @constructor
16 * @param {Object} imageInfo Image information object
17 * @param {Object} [config] Configuration options
18 * @param {boolean} [config.isMobile=false]
19 * @param {boolean} [config.draggable=true]
20 */
21 ve.ui.MWGalleryItemWidget = function VeUiMWGalleryItemWidget( imageInfo, config ) {
22 this.resource = imageInfo.resource;
23 this.altText = imageInfo.altText || '';
24 this.altTextSame = imageInfo.altTextSame;
25 this.href = imageInfo.href;
26 // Keep the original value which may be null
27 this.originalAltText = imageInfo.altText;
28 this.src = imageInfo.src;
29 this.height = imageInfo.height;
30 this.width = imageInfo.width;
31 this.thumbUrl = imageInfo.thumbUrl;
32 this.captionDocument = imageInfo.captionDocument;
33 this.highlighted = false;
34 this.tagName = imageInfo.tagName;
35 this.isError = imageInfo.isError;
36 this.imageClassAttr = imageInfo.imageClassAttr;
37 this.imgWrapperClassAttr = imageInfo.imgWrapperClassAttr;
38 this.mw = imageInfo.mw;
39 this.mediaClass = imageInfo.mediaClass;
40 this.mediaTag = imageInfo.mediaTag;
41
42 // Configuration initialization
43 config = config || {};
44
45 // Parent constructor
46 ve.ui.MWGalleryItemWidget.super.call( this, config );
47
48 this.$element
49 .addClass( 've-ui-mwGalleryDialog-image-container mw-no-invert' ) // TODO: put in new CSS file?
50 .addClass( config.isMobile ?
51 've-ui-mwGalleryDialog-image-container-mobile' :
52 've-ui-mwGalleryDialog-image-container-desktop'
53 )
54 .css( 'background-image', 'url(' + this.thumbUrl + ')' );
55
56 // Mixin constructors
57 OO.ui.mixin.DraggableElement.call( this, ve.extendObject( { $handle: this.$element }, config ) );
58 OO.ui.mixin.TabIndexedElement.call( this, config );
59
60 this.$element.on( {
61 click: this.onItemClick.bind( this ),
62 keypress: this.onItemKeyPress.bind( this )
63 } );
64 };
65
66 /* Inheritance */
67
68 OO.inheritClass( ve.ui.MWGalleryItemWidget, OO.ui.Widget );
69
70 OO.mixinClass( ve.ui.MWGalleryItemWidget, OO.ui.mixin.DraggableElement );
71 OO.mixinClass( ve.ui.MWGalleryItemWidget, OO.ui.mixin.TabIndexedElement );
72
73 /* Events */
74
75 /**
76 * @event ve.ui.MWGalleryItemWidget#edit
77 */
78
79 /* Methods */
80
81 /**
82 * Handle clicking on an item
83 *
84 * @fires ve.ui.MWGalleryItemWidget#edit
85 */
86 ve.ui.MWGalleryItemWidget.prototype.onItemClick = function () {
87 this.emit( 'edit', this );
88 };
89
90 /**
91 * Handle key press events
92 *
93 * @param {jQuery.Event} e Key press event
94 * @return {boolean|undefined}
95 * @fires ve.ui.MWGalleryItemWidget#edit
96 */
97 ve.ui.MWGalleryItemWidget.prototype.onItemKeyPress = function ( e ) {
98 if ( e.which === OO.ui.Keys.ENTER ) {
99 this.emit( 'edit', this );
100 return false;
101 }
102 };
103
104 /**
105 * Set the captionDocument property
106 *
107 * @param {ve.dm.Document} captionDocument The caption document
108 */
109 ve.ui.MWGalleryItemWidget.prototype.setCaptionDocument = function ( captionDocument ) {
110 this.captionDocument = captionDocument;
111 };
112
113 /**
114 * Set the altText property
115 *
116 * @param {string} altText The altText
117 */
118 ve.ui.MWGalleryItemWidget.prototype.setAltText = function ( altText ) {
119 this.altText = altText;
120 };
121
122 /**
123 * Set the altTextSame property
124 *
125 * @param {boolean} same
126 */
127 ve.ui.MWGalleryItemWidget.prototype.setAltTextSame = function ( same ) {
128 this.altTextSame = same;
129 };
130
131 /**
132 * Toggle highlighted class
133 *
134 * @param {boolean} highlighted The item is highlighted
135 */
136 ve.ui.MWGalleryItemWidget.prototype.toggleHighlighted = function ( highlighted ) {
137 highlighted = highlighted !== undefined ? highlighted : !this.highlighted;
138 this.$element.toggleClass( 've-ui-mwGalleryDialog-image-container-highlighted', !!highlighted );
139 };