| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
ve.ui.AuthorItemWidget = function VeUiAuthorItemWidget( synchronizer, $overlay, config ) { |
| 24 |
config = config || {}; |
| 25 |
|
| 26 |
|
| 27 |
ve.ui.AuthorItemWidget.super.call( this, config ); |
| 28 |
|
| 29 |
|
| 30 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 31 |
|
| 32 |
this.synchronizer = synchronizer; |
| 33 |
this.editable = !!config.editable; |
| 34 |
this.authorId = config.authorId; |
| 35 |
this.name = null; |
| 36 |
this.color = null; |
| 37 |
|
| 38 |
this.$color = $( '<div>' ).addClass( 've-ui-authorItemWidget-color' ); |
| 39 |
this.$element.append( this.$color ); |
| 40 |
|
| 41 |
if ( this.editable ) { |
| 42 |
this.input = new OO.ui.TextInputWidget( { |
| 43 |
classes: [ 've-ui-authorItemWidget-nameInput' ], |
| 44 |
placeholder: ve.msg( 'visualeditor-rebase-client-author-name' ) |
| 45 |
} ); |
| 46 |
|
| 47 |
this.input.on( 'change', this.emit.bind( this, 'change' ) ); |
| 48 |
|
| 49 |
this.colorPicker = new CP( this.$color[ 0 ] ); |
| 50 |
this.colorPicker.on( 'change', ( color ) => { |
| 51 |
this.color = color; |
| 52 |
this.$color.css( 'background-color', '#' + color ); |
| 53 |
} ); |
| 54 |
this.colorPicker.on( 'exit', () => { |
| 55 |
if ( this.color !== null ) { |
| 56 |
this.emit( 'changeColor', this.color ); |
| 57 |
} |
| 58 |
} ); |
| 59 |
|
| 60 |
this.colorPicker.picker.classList.add( 've-ui-authorItemWidget-colorPicker' ); |
| 61 |
this.colorPicker.fit = () => { |
| 62 |
this.colorPicker.picker.style.left = this.$element[ 0 ].offsetLeft + 'px'; |
| 63 |
this.colorPicker.picker.style.top = this.$element[ 0 ].offsetTop + 'px'; |
| 64 |
$overlay[ 0 ].appendChild( this.colorPicker.picker ); |
| 65 |
}; |
| 66 |
|
| 67 |
this.$element |
| 68 |
.addClass( 've-ui-authorItemWidget-editable' ) |
| 69 |
.append( this.input.$element ); |
| 70 |
} else { |
| 71 |
this.$element.append( this.$label ); |
| 72 |
} |
| 73 |
|
| 74 |
this.update(); |
| 75 |
|
| 76 |
this.$element.addClass( 've-ui-authorItemWidget' ); |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
OO.inheritClass( ve.ui.AuthorItemWidget, OO.ui.Widget ); |
| 82 |
|
| 83 |
OO.mixinClass( ve.ui.AuthorItemWidget, OO.ui.mixin.IconElement ); |
| 84 |
|
| 85 |
OO.mixinClass( ve.ui.AuthorItemWidget, OO.ui.mixin.LabelElement ); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ui.AuthorItemWidget.prototype.focus = function () { |
| 93 |
if ( this.editable ) { |
| 94 |
this.input.focus(); |
| 95 |
} |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ve.ui.AuthorItemWidget.prototype.getName = function () { |
| 104 |
if ( this.editable ) { |
| 105 |
return this.input.getValue(); |
| 106 |
} else { |
| 107 |
return this.name; |
| 108 |
} |
| 109 |
}; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
ve.ui.AuthorItemWidget.prototype.setAuthorId = function ( authorId ) { |
| 117 |
this.authorId = authorId; |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ve.ui.AuthorItemWidget.prototype.update = function () { |
| 124 |
const authorData = this.synchronizer.getAuthorData( this.authorId ); |
| 125 |
this.name = authorData.name; |
| 126 |
this.color = authorData.color; |
| 127 |
this.$color.css( 'background-color', '#' + this.color ); |
| 128 |
|
| 129 |
if ( this.editable ) { |
| 130 |
this.input.setValue( this.name ); |
| 131 |
this.colorPicker.set( '#' + this.color ); |
| 132 |
} else { |
| 133 |
|
| 134 |
this.setLabel( this.name || '…' ); |
| 135 |
} |
| 136 |
}; |