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:
|
Add reading depth
Use schema revision 16163887.
Add the 'checkin' action, which is accompanied by the 'checkin'
property. The action is logged at the following seconds
(Fibonacci numbers) after the page loads: 1, 2, 3, 5, 8, 13, 21,
34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765.
The `checkin` property contains the values listed above.
Bug: T147314
Change-Id: Ib9ec7bd0e60aa34a04e32222b025347f6ee31794
2016-12-13 22:52:20 +00:00
|
|
|
* - Setup `checkin` actions
|
2016-12-02 11:14:02 +00:00
|
|
|
* - 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-12-14 13:48:20 +00:00
|
|
|
isEnabled,
|
2016-11-30 13:40:08 +00:00
|
|
|
schema;
|
|
|
|
|
2016-12-14 14:13:52 +00:00
|
|
|
userSettings = mw.popups.createUserSettings( mw.storage );
|
2016-12-12 19:26:55 +00:00
|
|
|
settingsDialog = mw.popups.createSettingsDialogRenderer();
|
2016-11-30 13:40:08 +00:00
|
|
|
schema = mw.popups.createSchema( mw.config, window );
|
2016-11-08 11:06:19 +00:00
|
|
|
|
2016-12-14 13:48:20 +00:00
|
|
|
isEnabled = mw.popups.isEnabled( mw.user, userSettings );
|
|
|
|
|
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-12-14 13:48:20 +00:00
|
|
|
isEnabled,
|
2016-11-30 13:40:08 +00:00
|
|
|
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
|
|
|
|
Add reading depth
Use schema revision 16163887.
Add the 'checkin' action, which is accompanied by the 'checkin'
property. The action is logged at the following seconds
(Fibonacci numbers) after the page loads: 1, 2, 3, 5, 8, 13, 21,
34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765.
The `checkin` property contains the values listed above.
Bug: T147314
Change-Id: Ib9ec7bd0e60aa34a04e32222b025347f6ee31794
2016-12-13 22:52:20 +00:00
|
|
|
mw.popups.checkin.setupActions( actions.checkin );
|
|
|
|
|
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 () {
|
2017-01-11 23:33:27 +00:00
|
|
|
actions.abandon( 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 ) );
|