2016-11-30 13:40:08 +00:00
|
|
|
( function ( mw, Redux, ReduxThunk ) {
|
2016-11-09 11:57:24 +00:00
|
|
|
var BLACKLISTED_LINKS = [
|
|
|
|
'.extiw',
|
|
|
|
'.image',
|
|
|
|
'.new',
|
|
|
|
'.internal',
|
|
|
|
'.external',
|
|
|
|
'.oo-ui-buttonedElement-button',
|
|
|
|
'.cancelLink a'
|
|
|
|
];
|
2016-11-08 10:05:40 +00:00
|
|
|
|
2016-11-16 19:45:10 +00:00
|
|
|
/**
|
|
|
|
* Creates a gateway with sensible values for the dependencies.
|
|
|
|
*
|
|
|
|
* See `mw.popups.createGateway`.
|
|
|
|
*
|
|
|
|
* @return {ext.popups.Gateway}
|
|
|
|
*/
|
|
|
|
function createGateway() {
|
|
|
|
return mw.popups.createGateway( new mw.Api() );
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:18:13 +00:00
|
|
|
/**
|
|
|
|
* Subscribes the registered change listeners to the
|
|
|
|
* [store](http://redux.js.org/docs/api/Store.html#store).
|
|
|
|
*
|
|
|
|
* Change listeners are registered by setting a property on
|
|
|
|
* `mw.popups.changeListeners`.
|
|
|
|
*
|
2016-11-16 19:45:10 +00:00
|
|
|
* @param {Redux.Store} store
|
2016-11-30 13:40:08 +00:00
|
|
|
* @param {Object} actions
|
|
|
|
* @param {mw.eventLog.Schema} schema
|
2016-12-05 11:56:51 +00:00
|
|
|
* @param {ext.popups.UserSettings} userSettings
|
2016-12-12 19:26:55 +00:00
|
|
|
* @param {Function} settingsDialog
|
2016-11-15 18:18:13 +00:00
|
|
|
*/
|
2016-12-12 19:26:55 +00:00
|
|
|
function registerChangeListeners( store, actions, schema, userSettings, settingsDialog ) {
|
2016-11-15 18:18:13 +00:00
|
|
|
|
2016-11-30 13:40:08 +00:00
|
|
|
// Sugar.
|
|
|
|
var changeListeners = mw.popups.changeListeners,
|
|
|
|
registerChangeListener = mw.popups.registerChangeListener;
|
|
|
|
|
|
|
|
registerChangeListener( store, changeListeners.footerLink( actions ) );
|
|
|
|
registerChangeListener( store, changeListeners.linkTitle() );
|
|
|
|
registerChangeListener( store, changeListeners.render( actions ) );
|
|
|
|
registerChangeListener( store, changeListeners.eventLogging( actions, schema ) );
|
2016-12-14 11:12:55 +00:00
|
|
|
registerChangeListener( store, changeListeners.syncUserSettings( userSettings ) );
|
2016-12-12 19:26:55 +00:00
|
|
|
registerChangeListener( store, changeListeners.settings( actions, settingsDialog ) );
|
2016-11-15 18:18:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 19:37:11 +00:00
|
|
|
/**
|
|
|
|
* Binds the actions (or "action creators") to the
|
|
|
|
* [store](http://redux.js.org/docs/api/Store.html#store).
|
|
|
|
*
|
2016-11-16 19:45:10 +00:00
|
|
|
* @param {Redux.Store} store
|
2016-11-14 19:37:11 +00:00
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
function createBoundActions( store ) {
|
|
|
|
return Redux.bindActionCreators( mw.popups.actions, store.dispatch );
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:00:33 +00:00
|
|
|
/**
|
2016-12-13 10:25:17 +00:00
|
|
|
* Creates the reducer for all actions.
|
2016-11-16 17:00:33 +00:00
|
|
|
*
|
2016-12-13 10:25:17 +00:00
|
|
|
* @return {Redux.Reducer}
|
2016-11-16 17:00:33 +00:00
|
|
|
*/
|
2016-12-13 10:25:17 +00:00
|
|
|
function createRootReducer() {
|
|
|
|
return Redux.combineReducers( mw.popups.reducers );
|
|
|
|
}
|
2016-11-16 17:00:33 +00:00
|
|
|
|
2016-12-02 11:14:02 +00:00
|
|
|
/*
|
|
|
|
* Initialize the application by:
|
|
|
|
* 1. Creating the state store
|
|
|
|
* 2. Binding the actions to such store
|
|
|
|
* 3. Trigger the boot action to bootstrap the system
|
|
|
|
* 4. When the page content is ready:
|
|
|
|
* - Process the eligible links for page previews
|
|
|
|
* - Initialize the renderer
|
|
|
|
* - Bind hover and click events to the eligible links to trigger actions
|
|
|
|
*/
|
2016-11-08 10:05:40 +00:00
|
|
|
mw.requestIdleCallback( function () {
|
2016-11-08 19:42:21 +00:00
|
|
|
var compose = Redux.compose,
|
|
|
|
store,
|
2016-11-14 19:37:11 +00:00
|
|
|
actions,
|
2016-11-30 13:40:08 +00:00
|
|
|
|
|
|
|
// So-called "services".
|
2016-11-16 19:45:10 +00:00
|
|
|
generateToken = mw.user.generateRandomSessionId,
|
2016-11-30 13:40:08 +00:00
|
|
|
gateway = createGateway(),
|
|
|
|
userSettings,
|
2016-12-12 19:26:55 +00:00
|
|
|
settingsDialog,
|
2016-11-30 13:40:08 +00:00
|
|
|
isUserInCondition,
|
|
|
|
schema;
|
|
|
|
|
|
|
|
userSettings = mw.popups.createUserSettings( mw.storage, mw.user );
|
2016-12-12 19:26:55 +00:00
|
|
|
settingsDialog = mw.popups.createSettingsDialogRenderer();
|
2016-11-30 13:40:08 +00:00
|
|
|
isUserInCondition = mw.popups.createExperiment( mw.config, mw.user, userSettings );
|
|
|
|
schema = mw.popups.createSchema( mw.config, window );
|
2016-11-08 11:06:19 +00:00
|
|
|
|
|
|
|
// If debug mode is enabled, then enable Redux DevTools.
|
|
|
|
if ( mw.config.get( 'debug' ) === true ) {
|
2016-12-16 11:11:54 +00:00
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
2016-11-08 11:06:19 +00:00
|
|
|
compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
|
|
|
}
|
|
|
|
|
2016-11-08 19:42:21 +00:00
|
|
|
store = Redux.createStore(
|
2016-12-13 10:25:17 +00:00
|
|
|
createRootReducer(),
|
2016-11-08 11:06:19 +00:00
|
|
|
compose( Redux.applyMiddleware(
|
|
|
|
ReduxThunk.default
|
|
|
|
) )
|
2016-11-08 10:05:40 +00:00
|
|
|
);
|
2016-11-14 19:37:11 +00:00
|
|
|
actions = createBoundActions( store );
|
2016-12-12 19:26:55 +00:00
|
|
|
registerChangeListeners( store, actions, schema, userSettings, settingsDialog );
|
2016-11-08 19:42:21 +00:00
|
|
|
|
2016-11-14 19:37:11 +00:00
|
|
|
actions.boot(
|
2016-11-30 13:40:08 +00:00
|
|
|
isUserInCondition,
|
|
|
|
mw.user,
|
2016-12-01 14:56:46 +00:00
|
|
|
userSettings,
|
2016-11-30 13:40:08 +00:00
|
|
|
generateToken,
|
|
|
|
mw.config
|
2016-11-14 19:37:11 +00:00
|
|
|
);
|
2016-11-09 11:57:24 +00:00
|
|
|
|
|
|
|
mw.hook( 'wikipage.content' ).add( function ( $container ) {
|
|
|
|
var previewLinks =
|
|
|
|
mw.popups.processLinks(
|
|
|
|
$container,
|
2016-11-30 12:06:30 +00:00
|
|
|
BLACKLISTED_LINKS,
|
|
|
|
mw.config
|
2016-11-09 11:57:24 +00:00
|
|
|
);
|
2016-11-08 19:42:21 +00:00
|
|
|
|
2016-11-21 12:07:23 +00:00
|
|
|
mw.popups.renderer.init();
|
|
|
|
|
2016-11-09 11:57:24 +00:00
|
|
|
previewLinks
|
2016-11-21 11:08:06 +00:00
|
|
|
.on( 'mouseover focus', function ( event ) {
|
2016-12-06 14:02:13 +00:00
|
|
|
actions.linkDwell( this, event, gateway, generateToken );
|
2016-11-09 11:57:24 +00:00
|
|
|
} )
|
|
|
|
.on( 'mouseout blur', function () {
|
|
|
|
actions.linkAbandon( this );
|
2016-11-10 12:05:38 +00:00
|
|
|
} )
|
|
|
|
.on( 'click', function () {
|
|
|
|
actions.linkClick( this );
|
2016-11-09 11:57:24 +00:00
|
|
|
} );
|
2016-11-10 12:05:38 +00:00
|
|
|
|
2016-11-09 11:57:24 +00:00
|
|
|
} );
|
2016-11-08 10:05:40 +00:00
|
|
|
} );
|
|
|
|
|
2016-11-30 13:40:08 +00:00
|
|
|
}( mediaWiki, Redux, ReduxThunk ) );
|