2016-11-15 18:18:13 +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-09 11:57:24 +00:00
|
|
|
/**
|
2016-11-16 19:45:10 +00:00
|
|
|
* Creates an experiment with sensible values for the depenencies.
|
2016-11-09 11:57:24 +00:00
|
|
|
*
|
2016-11-16 19:45:10 +00:00
|
|
|
* See `mw.popups.createExperiment`.
|
|
|
|
*
|
|
|
|
* @return {Function}
|
2016-11-09 11:57:24 +00:00
|
|
|
*/
|
|
|
|
function isUserInCondition() {
|
|
|
|
var userSettings = mw.popups.createUserSettings( mw.storage, mw.user );
|
|
|
|
|
|
|
|
return mw.popups.createExperiment(
|
|
|
|
mw.config,
|
|
|
|
mw.user,
|
|
|
|
userSettings
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-15 18:18:13 +00:00
|
|
|
*/
|
|
|
|
function registerChangeListeners( store, actions ) {
|
|
|
|
$.each( mw.popups.changeListeners, function ( _, changeListenerFactory ) {
|
|
|
|
var changeListener = changeListenerFactory( actions );
|
|
|
|
|
|
|
|
mw.popups.registerChangeListener( store, changeListener );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Root reducer for all actions
|
|
|
|
*
|
|
|
|
* @param {Object} global state before action
|
|
|
|
* @param {Object} action Redux action that modified state.
|
|
|
|
* Must have `type` property.
|
|
|
|
* @return {Object} global state after action
|
|
|
|
*/
|
|
|
|
mw.popups.reducers.rootReducer = Redux.combineReducers( mw.popups.reducers );
|
|
|
|
|
|
|
|
// FIXME: Needs doc (or at least one comment line)
|
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-16 19:45:10 +00:00
|
|
|
generateToken = mw.user.generateRandomSessionId,
|
|
|
|
gateway = createGateway();
|
2016-11-08 11:06:19 +00:00
|
|
|
|
|
|
|
// If debug mode is enabled, then enable Redux DevTools.
|
|
|
|
if ( mw.config.get( 'debug' ) === true ) {
|
|
|
|
compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
|
|
|
}
|
|
|
|
|
2016-11-08 19:42:21 +00:00
|
|
|
store = Redux.createStore(
|
2016-11-10 18:02:29 +00:00
|
|
|
mw.popups.reducers.rootReducer,
|
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-11-15 18:18:13 +00:00
|
|
|
registerChangeListeners( store, actions );
|
2016-11-08 19:42:21 +00:00
|
|
|
|
2016-11-14 19:37:11 +00:00
|
|
|
actions.boot(
|
|
|
|
isUserInCondition(),
|
|
|
|
mw.user.sessionId(),
|
|
|
|
generateToken
|
|
|
|
);
|
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 ) {
|
|
|
|
actions.linkDwell( this, event, gateway );
|
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-15 18:18:13 +00:00
|
|
|
}( mediaWiki, Redux, ReduxThunk, jQuery ) );
|