mediawiki-extensions-Popups/src/gateway/reference.js
Thiemo Kreuz bb60d5b716 Move default "Footnote" title from gateway to renderer
I guess both is fine: either having the default in the gateway (as it
was before), or in the renderer (as this patch proposes). I, personally,
feel better with having it closer to where it is needed. This way it's
not possible to accidentially deliver a model object with an empty title.
The renderer will catch this.

At the moment we don't know exactly how we will fetch other titles (e.g.
"Book").

This change is split from I15611a4 where it was a little misplaced.

It also includes a test for the default fallback title.

Bug: T213907
Change-Id: I8ec3ddc21a417da7f95feff7b080cbd60d5472e7
2019-01-29 11:37:47 +01:00

39 lines
854 B
JavaScript

/**
* @module gateway/reference
*/
import { previewTypes } from '../preview/model';
const $ = jQuery;
/**
* @return {Gateway}
*/
export default function createReferenceGateway() {
/**
* @param {mw.Title} title
* @returns {AbortPromise<PreviewModel>}
*/
function fetchPreviewForTitle( title ) {
const id = title.getFragment();
return $.Deferred().resolve( {
// TODO: Provide different titles depending on the type of reference (e.g. "Book")
// title: '',
url: `#${ id }`,
// TODO: Can probably be removed
// languageCode: 'en',
// languageDirection: 'ltr',
extract: $( `#${ $.escapeSelector( id ) } .reference-text` ).html(),
type: previewTypes.TYPE_REFERENCE
// TODO: Can probably be removed
// thumbnail: '',
// pageId: '0'
} ).promise( { abort() {} } );
}
return {
fetchPreviewForTitle
};
}