mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-04 20:18:23 +00:00
20e7564bed
boot.js is renamed to index.js and popups is now bundled up inside popups.js To support qunit tests, the library is still exposed as mw.popups with a FIXME to remove later when it is no longer necessary Bug: T156333 Change-Id: Ieb6b4b0344af2701f99ef0fcc786d2378fd2fceb
96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
var actionTypes = require( './../actionTypes' ),
|
|
nextState = require( './nextState' );
|
|
|
|
/**
|
|
* Reducer for actions that modify the state of the preview model
|
|
*
|
|
* @param {Object} state before action
|
|
* @param {Object} action Redux action that modified state.
|
|
* Must have `type` property.
|
|
* @return {Object} state after action
|
|
*/
|
|
module.exports = function ( state, action ) {
|
|
if ( state === undefined ) {
|
|
state = {
|
|
enabled: undefined,
|
|
activeLink: undefined,
|
|
activeEvent: undefined,
|
|
activeToken: '',
|
|
shouldShow: false,
|
|
isUserDwelling: false
|
|
};
|
|
}
|
|
|
|
switch ( action.type ) {
|
|
case actionTypes.BOOT:
|
|
return nextState( state, {
|
|
enabled: action.isEnabled
|
|
} );
|
|
case actionTypes.SETTINGS_CHANGE:
|
|
return nextState( state, {
|
|
enabled: action.enabled
|
|
} );
|
|
case actionTypes.LINK_DWELL:
|
|
// New interaction
|
|
if ( action.el !== state.activeLink ) {
|
|
return nextState( state, {
|
|
activeLink: action.el,
|
|
activeEvent: action.event,
|
|
activeToken: action.token,
|
|
|
|
// When the user dwells on a link with their keyboard, a preview is
|
|
// renderered, and then dwells on another link, the ABANDON_END
|
|
// action will be ignored.
|
|
//
|
|
// Ensure that all the preview is hidden.
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: true
|
|
} );
|
|
} else {
|
|
// Dwelling back into the same link
|
|
return nextState( state, {
|
|
isUserDwelling: true
|
|
} );
|
|
}
|
|
|
|
case actionTypes.ABANDON_END:
|
|
if ( action.token === state.activeToken && !state.isUserDwelling ) {
|
|
return nextState( state, {
|
|
activeLink: undefined,
|
|
activeToken: undefined,
|
|
activeEvent: undefined,
|
|
fetchResponse: undefined,
|
|
shouldShow: false
|
|
} );
|
|
}
|
|
return state;
|
|
|
|
case actionTypes.PREVIEW_DWELL:
|
|
return nextState( state, {
|
|
isUserDwelling: true
|
|
} );
|
|
|
|
case actionTypes.ABANDON_START:
|
|
return nextState( state, {
|
|
isUserDwelling: false
|
|
} );
|
|
|
|
case actionTypes.FETCH_START:
|
|
return nextState( state, {
|
|
fetchResponse: undefined
|
|
} );
|
|
case actionTypes.FETCH_END:
|
|
if ( action.el === state.activeLink ) {
|
|
return nextState( state, {
|
|
fetchResponse: action.result,
|
|
shouldShow: true
|
|
} );
|
|
}
|
|
|
|
/* falls through */
|
|
default:
|
|
return state;
|
|
}
|
|
};
|