| 1 |
'use strict'; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
( function () { |
| 11 |
function fixTarget( target ) { |
| 12 |
const toolGroups = target.static.toolbarGroups; |
| 13 |
|
| 14 |
if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { |
| 15 |
for ( let i = 0; i < toolGroups.length; i++ ) { |
| 16 |
const toolGroup = toolGroups[ i ]; |
| 17 |
if ( toolGroup.name === 'insert' && ( !toolGroup.demote || toolGroup.demote.indexOf( 'reference' ) === -1 ) ) { |
| 18 |
toolGroup.demote = toolGroup.demote || []; |
| 19 |
toolGroup.demote.push( { group: 'cite' }, 'reference', 'reference/existing' ); |
| 20 |
} |
| 21 |
} |
| 22 |
} else { |
| 23 |
|
| 24 |
for ( let i = 0; i < toolGroups.length; i++ ) { |
| 25 |
if ( toolGroups[ i ].name === 'reference' ) { |
| 26 |
const group = { |
| 27 |
|
| 28 |
name: 'cite', |
| 29 |
type: 'list', |
| 30 |
indicator: 'down', |
| 31 |
include: [ { group: 'cite' }, 'reference', 'reference/existing' ], |
| 32 |
demote: [ 'reference', 'reference/existing' ] |
| 33 |
}; |
| 34 |
const label = OO.ui.deferMsg( 'cite-ve-toolbar-group-label' ); |
| 35 |
|
| 36 |
if ( target === ve.init.mw.MobileArticleTarget ) { |
| 37 |
group.header = label; |
| 38 |
group.title = label; |
| 39 |
group.icon = 'reference'; |
| 40 |
} else { |
| 41 |
group.label = label; |
| 42 |
} |
| 43 |
toolGroups[ i ] = group; |
| 44 |
break; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
for ( const n in ve.init.mw.targetFactory.registry ) { |
| 51 |
fixTarget( ve.init.mw.targetFactory.lookup( n ) ); |
| 52 |
} |
| 53 |
|
| 54 |
ve.init.mw.targetFactory.on( 'register', ( name, target ) => { |
| 55 |
fixTarget( target ); |
| 56 |
} ); |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
( function () { |
| 79 |
const deprecatedIcons = { |
| 80 |
'ref-cite-book': 'book', |
| 81 |
'ref-cite-journal': 'journal', |
| 82 |
'ref-cite-news': 'newspaper', |
| 83 |
'ref-cite-web': 'browser', |
| 84 |
'reference-existing': 'referenceExisting' |
| 85 |
}, |
| 86 |
defaultIcons = { |
| 87 |
book: 'book', |
| 88 |
journal: 'journal', |
| 89 |
news: 'newspaper', |
| 90 |
web: 'browser' |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.mwCitationTools = ve.ui.mwCitationTools || []; |
| 96 |
|
| 97 |
ve.ui.mwCitationTools.forEach( ( item ) => { |
| 98 |
const hasOwn = Object.prototype.hasOwnProperty; |
| 99 |
const data = { template: item.template, title: item.title }; |
| 100 |
|
| 101 |
if ( !item.icon && hasOwn.call( defaultIcons, item.name ) ) { |
| 102 |
item.icon = defaultIcons[ item.name ]; |
| 103 |
} |
| 104 |
|
| 105 |
if ( hasOwn.call( deprecatedIcons, item.icon ) ) { |
| 106 |
item.icon = deprecatedIcons[ item.icon ]; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
const name = 'cite-' + item.name; |
| 111 |
if ( !ve.ui.toolFactory.lookup( name ) ) { |
| 112 |
const tool = function GeneratedMWCitationDialogTool() { |
| 113 |
ve.ui.MWCitationDialogTool.apply( this, arguments ); |
| 114 |
}; |
| 115 |
OO.inheritClass( tool, ve.ui.MWCitationDialogTool ); |
| 116 |
tool.static.group = 'cite'; |
| 117 |
tool.static.name = name; |
| 118 |
tool.static.icon = item.icon; |
| 119 |
if ( mw.config.get( 'wgCiteVisualEditorOtherGroup' ) ) { |
| 120 |
tool.static.title = mw.msg( 'cite-ve-othergroup-item', item.title ); |
| 121 |
} else { |
| 122 |
tool.static.title = item.title; |
| 123 |
} |
| 124 |
tool.static.commandName = name; |
| 125 |
tool.static.template = item.template; |
| 126 |
tool.static.autoAddToCatchall = false; |
| 127 |
tool.static.autoAddToGroup = true; |
| 128 |
tool.static.associatedWindows = [ name ]; |
| 129 |
ve.ui.toolFactory.register( tool ); |
| 130 |
ve.ui.commandRegistry.register( |
| 131 |
new ve.ui.Command( |
| 132 |
name, 'mwcite', 'open', { args: [ data ], supportedSelections: [ 'linear' ] } |
| 133 |
) |
| 134 |
); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
if ( !ve.ui.contextItemFactory.lookup( name ) ) { |
| 139 |
const contextItem = function GeneratedMWCitationContextItem() { |
| 140 |
|
| 141 |
ve.ui.MWCitationContextItem.apply( this, arguments ); |
| 142 |
}; |
| 143 |
OO.inheritClass( contextItem, ve.ui.MWCitationContextItem ); |
| 144 |
contextItem.static.name = name; |
| 145 |
contextItem.static.icon = item.icon; |
| 146 |
contextItem.static.label = item.title; |
| 147 |
contextItem.static.commandName = name; |
| 148 |
contextItem.static.template = item.template; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
contextItem.static.suppresses = [ 'reference' ]; |
| 155 |
ve.ui.contextItemFactory.register( contextItem ); |
| 156 |
} |
| 157 |
} ); |
| 158 |
}() ); |
| 159 |
|
| 160 |
}() ); |