| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ui.MWPopupTool = function VeUiMWPopupTool( title, toolGroup, config ) { |
| 21 |
|
| 22 |
config = ve.extendObject( { popup: { head: true, label: title, width: config && config.width } }, config ); |
| 23 |
|
| 24 |
|
| 25 |
ve.ui.MWPopupTool.super.call( this, toolGroup, config ); |
| 26 |
|
| 27 |
this.popup.connect( this, { |
| 28 |
ready: 'onPopupOpened', |
| 29 |
closing: 'onPopupClosing' |
| 30 |
} ); |
| 31 |
|
| 32 |
this.$element.addClass( 've-ui-mwPopupTool' ); |
| 33 |
|
| 34 |
this.$link.on( 'click', this.onToolLinkClick.bind( this ) ); |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
OO.inheritClass( ve.ui.MWPopupTool, OO.ui.PopupTool ); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
ve.ui.MWPopupTool.prototype.onPopupOpened = function () { |
| 45 |
this.popup.closeButton.focus(); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
ve.ui.MWPopupTool.prototype.onPopupClosing = function () { |
| 52 |
this.$link.trigger( 'focus' ); |
| 53 |
}; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
ve.ui.MWPopupTool.prototype.onToolLinkClick = function () { |
| 61 |
if ( this.popup.isVisible() ) { |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.track( 'activity.' + this.constructor.static.name + 'Popup', { action: 'show' } ); |
| 66 |
} |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
ve.ui.MWNoticesPopupTool = function VeUiMWNoticesPopupTool( toolGroup, config ) { |
| 79 |
|
| 80 |
ve.ui.MWNoticesPopupTool.super.call( |
| 81 |
this, |
| 82 |
ve.msg( 'visualeditor-editnotices-tooltip' ), |
| 83 |
toolGroup, |
| 84 |
ve.extendObject( config, { width: 380 } ) |
| 85 |
); |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
OO.inheritClass( ve.ui.MWNoticesPopupTool, ve.ui.MWPopupTool ); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
ve.ui.MWNoticesPopupTool.static.name = 'notices'; |
| 95 |
ve.ui.MWNoticesPopupTool.static.group = 'notices'; |
| 96 |
ve.ui.MWNoticesPopupTool.static.icon = 'alert'; |
| 97 |
ve.ui.MWNoticesPopupTool.static.title = OO.ui.deferMsg( 'visualeditor-editnotices-tooltip' ); |
| 98 |
ve.ui.MWNoticesPopupTool.static.autoAddToCatchall = false; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
ve.ui.MWNoticesPopupTool.prototype.setNotices = function ( notices ) { |
| 108 |
const count = notices.length; |
| 109 |
|
| 110 |
this.popup.setLabel( ve.msg( |
| 111 |
'visualeditor-editnotices-tool', |
| 112 |
mw.language.convertNumber( count ) |
| 113 |
) ); |
| 114 |
|
| 115 |
if ( this.$items ) { |
| 116 |
this.$items.remove(); |
| 117 |
} |
| 118 |
|
| 119 |
this.$items = $( '<div>' ).addClass( 've-ui-mwNoticesPopupTool-items' ); |
| 120 |
this.noticeItems = []; |
| 121 |
|
| 122 |
notices.forEach( ( item ) => { |
| 123 |
|
| 124 |
const $element = $( '<div>' ) |
| 125 |
.addClass( 've-ui-mwNoticesPopupTool-item' ) |
| 126 |
.html( typeof item === 'string' ? item : item.message ); |
| 127 |
ve.targetLinksToNewWindow( $element[ 0 ] ); |
| 128 |
|
| 129 |
this.noticeItems.push( { |
| 130 |
$element: $element, |
| 131 |
type: item.type |
| 132 |
} ); |
| 133 |
|
| 134 |
this.$items.append( $element ); |
| 135 |
} ); |
| 136 |
|
| 137 |
this.popup.$body.append( this.$items ); |
| 138 |
|
| 139 |
mw.hook( 'wikipage.content' ).fire( this.popup.$body ); |
| 140 |
|
| 141 |
ve.track( 'activity.notices', { action: 'show' } ); |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
ve.ui.MWNoticesPopupTool.prototype.getTitle = function () { |
| 150 |
const items = this.toolbar.getTarget().getEditNotices(); |
| 151 |
|
| 152 |
|
| 153 |
return ve.msg( this.constructor.static.title, items.length ); |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
ve.ui.toolFactory.register( ve.ui.MWNoticesPopupTool ); |