mediawiki-extensions-Popups/resources/ext.popups/renderChangeListener.js
Sam Smith 5e2d8ae8d4 Render previews
Extract core rendering functionality from the mw.popups.renderer and
mw.popups.renderer.article objects.

For now, render and show the preview when the user dwells on and
abandons a link respectively.

Supporting changes:
* Add mw.popups.wait, which is sugar around window.setTimeout.
* action.response -> action.result in the FETCH_END case of the preview
  reducer.

Change-Id: I14b437e7c2f55b988837fcb2800dd61a23c29a01
2016-11-24 18:07:03 +00:00

25 lines
587 B
JavaScript

( function ( mw ) {
/**
* Creates an instance of the render change listener.
*
* @return {ext.popups.ChangeListener}
*/
mw.popups.changeListeners.render = function () {
var preview;
return function ( prevState, state ) {
if ( state.preview.fetchResponse && !preview ) {
preview = mw.popups.renderer.render( state.preview.fetchResponse );
preview.show( state.preview.activeEvent );
} else if ( prevState && prevState.preview.fetchResponse ) {
preview.hide()
.done( function () {
preview = undefined;
} );
}
};
};
}( mediaWiki ) );