2018-12-12 18:37:19 +00:00
|
|
|
/**
|
|
|
|
* @module referencePreview
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { renderPopup } from '../popup/popup';
|
|
|
|
import { escapeHTML } from '../templateUtil';
|
|
|
|
|
2019-02-16 09:13:23 +00:00
|
|
|
// Known citation type strings currently supported with icons and messages.
|
|
|
|
const KNOWN_TYPES = [ 'book', 'journal', 'news', 'web' ],
|
|
|
|
mw = mediaWiki;
|
2019-01-24 15:33:29 +00:00
|
|
|
|
2018-12-12 18:37:19 +00:00
|
|
|
/**
|
|
|
|
* @param {ext.popups.PreviewModel} model
|
2019-01-26 09:56:08 +00:00
|
|
|
* @return {jQuery}
|
2018-12-12 18:37:19 +00:00
|
|
|
*/
|
|
|
|
export function renderReferencePreview(
|
|
|
|
model
|
|
|
|
) {
|
2019-02-16 09:13:23 +00:00
|
|
|
const type = KNOWN_TYPES.indexOf( model.referenceType ) < 0 ? 'generic' : model.referenceType,
|
|
|
|
titleMsg = `popups-refpreview-${ type === 'generic' ? 'footnote' : type }`,
|
|
|
|
title = escapeHTML( mw.msg( titleMsg ) ),
|
2019-01-28 07:54:49 +00:00
|
|
|
url = escapeHTML( model.url ),
|
2019-02-11 17:44:04 +00:00
|
|
|
linkMsg = escapeHTML( mw.msg( 'popups-refpreview-jump-to-footnote' ) );
|
2018-12-12 18:37:19 +00:00
|
|
|
|
2019-01-30 18:53:50 +00:00
|
|
|
const $el = renderPopup( model.type,
|
2018-12-12 18:37:19 +00:00
|
|
|
`
|
2019-01-24 17:48:13 +00:00
|
|
|
<strong class='mwe-popups-title'>
|
2019-02-16 09:13:23 +00:00
|
|
|
<span class='mw-ui-icon mw-ui-icon-element mw-ui-icon-reference-${ type }'></span>
|
2019-01-24 17:48:13 +00:00
|
|
|
${ title }
|
|
|
|
</strong>
|
2019-01-30 14:16:32 +00:00
|
|
|
<div class='mwe-popups-extract mw-parser-output'>${ model.extract }</div>
|
2018-12-12 18:37:19 +00:00
|
|
|
<footer>
|
2019-01-28 07:54:49 +00:00
|
|
|
<a href='${ url }' class='mwe-popups-read-link'>${ linkMsg }</a>
|
2018-12-12 18:37:19 +00:00
|
|
|
</footer>
|
|
|
|
`
|
2019-01-30 18:53:50 +00:00
|
|
|
);
|
2019-01-26 09:56:08 +00:00
|
|
|
|
|
|
|
// Make sure to not destroy existing targets, if any
|
|
|
|
$el.find( '.mwe-popups-extract a[href]:not([target])' ).each( ( i, a ) => {
|
|
|
|
a.target = '_blank';
|
|
|
|
// Don't let the external site access and possibly manipulate window.opener.location
|
|
|
|
a.rel = `${ a.rel ? `${ a.rel } ` : '' }noopener`;
|
|
|
|
} );
|
|
|
|
|
2019-02-04 12:08:36 +00:00
|
|
|
if ( model.sourceElementId ) {
|
|
|
|
$el.find( '.mwe-popups-read-link' ).on( 'click', ( event ) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
$( `#${ model.sourceElementId } > a` ).trigger( 'click' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-01-26 09:56:08 +00:00
|
|
|
return $el;
|
2018-12-12 18:37:19 +00:00
|
|
|
}
|