mediawiki-extensions-Popups/src/ui/templates/preview/preview.js
Thiemo Kreuz c35715bdec Make all render functions return jQuery objects instead of strings
This gets rid of a little bit of code duplication, and makes the
interfaces all conform to one standard again after I05ed4b8 left them
in a little inconsistent (but properly documented) state.

Bug: T214970
Change-Id: If8407c1a48aff1cb31fc2e74b3c2b846e79a3cb5
2019-02-01 12:49:53 +01:00

37 lines
958 B
JavaScript

/**
* @module preview
*/
import { renderPopup } from '../popup/popup';
import { escapeHTML } from '../templateUtil';
/**
* @param {ext.popups.PreviewModel} model
* @param {boolean} showTitle
* @param {string} extractMsg
* @param {string} linkMsg
* @return {jQuery}
*/
export function renderPreview(
model, showTitle, extractMsg, linkMsg
) {
const title = escapeHTML( model.title ),
url = escapeHTML( model.url ),
type = escapeHTML( model.type );
extractMsg = escapeHTML( extractMsg );
linkMsg = escapeHTML( linkMsg );
return renderPopup( model.type,
`
<div class='mw-ui-icon mw-ui-icon-element mw-ui-icon-preview-${ type }'></div>
${ showTitle ? `<strong class='mwe-popups-title'>${ title }</strong>` : '' }
<a href='${ url }' class='mwe-popups-extract'>
<span class='mwe-popups-message'>${ extractMsg }</span>
</a>
<footer>
<a href='${ url }' class='mwe-popups-read-link'>${ linkMsg }</a>
</footer>
`
);
}