Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { uniqueId } from 'lodash';
import { NEW_NOTICE, REMOVE_NOTICE } from '../action-types';

/**
* Creates a remove notice action.
*
* @param {string} noticeId - Notice ID.
* @return {object} Action object.
*/
export function removeNotice( noticeId ) {
return {
noticeId: noticeId,
type: REMOVE_NOTICE,
};
}

/**
* Creates a new notice action.
*
* @param {string} status - Notice status.
* @param {string} text - Notice text.
* @param {object} options - Notice options.
* @return {object} Action object.
*/
export function createNotice( status, text, options = {} ) {
const notice = {
noticeId: options.id || uniqueId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { combineReducers } from 'redux';
import { NEW_NOTICE, REMOVE_NOTICE } from '../action-types';

/**
* Reducer for global notices.
*
* @param {Array} state - Current state.
* @param {object} action - Action object.
* @return {Array} Updated state.
*/
export function globalNotices( state = [], action ) {
switch ( action.type ) {
case NEW_NOTICE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ let preventCloseFlag = false;

import './style.scss';

/**
* Prevents any modals from closing until {@link allowClose} is called.
*/
function preventClose() {
preventCloseFlag = true;
}

/**
* Allows modals to close again after {@link preventClose} was called.
*/
function allowClose() {
preventCloseFlag = false;
}
Expand Down
44 changes: 39 additions & 5 deletions projects/plugins/jetpack/_inc/client/components/popover/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import debugFactory from 'debug';
const debug = debugFactory( 'calypso:popover:util' );

// inspired by https://github.com/jkroso/viewport

/**
* Updates and returns the current viewport dimensions.
*
* @return {object} Viewport object with top, left, width, height, right, and bottom.
*/
function updateViewport() {
const viewport = {};
viewport.top = window.scrollY;
Expand Down Expand Up @@ -38,6 +44,9 @@ const adjacent = {

let viewport = updateViewport();

/**
* Updates the cached viewport on window resize or scroll.
*/
function onViewportChange() {
viewport = updateViewport();
}
Expand Down Expand Up @@ -95,6 +104,13 @@ const suggested = ( pos, el, target ) => {
return chooseSecondary( primary, pos1, el, target, w, h ) || pos;
};

/**
* Chooses the primary popover position based on available room.
*
* @param {string} prefered - Preferred position.
* @param {object} room - Available room in each direction.
* @return {string|undefined} Best primary position.
*/
function choosePrimary( prefered, room ) {
// top, bottom, left, right in order of preference
const order = [
Expand Down Expand Up @@ -125,6 +141,17 @@ function choosePrimary( prefered, room ) {
return bestPos;
}

/**
* Chooses the secondary popover position based on visible area.
*
* @param {string} primary - Primary position.
* @param {string|null} prefered - Preferred secondary position.
* @param {HTMLElement} el - Tip element.
* @param {HTMLElement} target - Target element.
* @param {number} w - Tip width.
* @param {number} h - Tip height.
* @return {string|undefined} Best position string.
*/
function chooseSecondary( primary, prefered, el, target, w, h ) {
// top, top left, top right in order of preference
const order = prefered
Expand Down Expand Up @@ -170,6 +197,14 @@ function chooseSecondary( primary, prefered, el, target, w, h ) {
return bestPos;
}

/**
* Calculates the offset for a popover position.
*
* @param {string} pos - Position string.
* @param {HTMLElement} el - Tip element.
* @param {HTMLElement} target - Target element.
* @return {object} Offset with top and left properties.
*/
function offset( pos, el, target ) {
const pad = 15;
const tipRect = getBoundingClientRect( el );
Expand Down Expand Up @@ -290,14 +325,13 @@ function offset( pos, el, target ) {

/**
* Extracted from `timoxley/offset`, but directly using a
* TextRectangle instead of getting another version.
* DOMRect instead of getting another version.
*
* @param {TextRectangle} box - result from a `getBoundingClientRect()` call
* @param {Document} doc - Document instance to use
* @return {object} an object with `top` and `left` Number properties
* @param {DOMRect} box - Result from a `getBoundingClientRect()` call.
* @param {Document} doc - Document instance to use.
* @return {object} An object with `top` and `left` number properties.
* @private
*/

function _offset( box, doc ) {
const body = doc.body || doc.getElementsByTagName( 'body' )[ 0 ];
const docEl = doc.documentElement || body.parentNode;
Expand Down
8 changes: 8 additions & 0 deletions projects/plugins/jetpack/_inc/client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const data = {
google_analytics_enabled: false,
google_analytics_key: null,
};

/**
* Returns a configuration value.
*
* @param {string} key - Configuration key.
* @return {*} Configuration value.
* @throws {Error} If the key does not exist.
*/
function config( key ) {
if ( key in data ) {
return data[ key ];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const keyboardNavigationKeycodes = [ 9, 32, 37, 38, 39, 40 ]; // keyCodes for tab, space, left, up, right, down respectively
let keyboardNavigation = false;

/**
* Enables accessible focus styles when navigating via keyboard.
*/
function accessibleFocus() {
document.addEventListener( 'keydown', function ( event ) {
if ( keyboardNavigation ) {
Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/_inc/client/mixins/emitter/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { EventEmitter } from 'events';

/**
* Adds EventEmitter methods to a prototype.
*
* @param {object} prototype - Prototype to extend.
*/
export default function ( prototype ) {
Object.assign( prototype, EventEmitter.prototype );
prototype.emitChange = function () {
Expand Down
6 changes: 6 additions & 0 deletions projects/plugins/jetpack/_inc/client/my-plan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import MyPlanBody from './my-plan-body';
import MyPlanHeader from './my-plan-header';
import MyPlanPartnerCoupon from './my-plan-partner-coupon';

/**
* My Plan page component.
*
* @param {object} props - Component props.
* @return {import('react').ReactElement} React element.
*/
export function MyPlan( props ) {
let sitePlan = props.sitePlan.product_slug || '',
availableFeatures = props.availableFeatures,
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/twitter-timeline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! ( function ( d, s, id ) {
void ( function ( d, s, id ) {
var js,
fjs = d.getElementsByTagName( s )[ 0 ],
p = /^http:/.test( d.location ) ? 'http' : 'https';
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-eslint-fixes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other
Comment: Fix ESLint issues in legacy Jetpack admin client files.

12 changes: 1 addition & 11 deletions tools/eslint-excludelist.json
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
[
"projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/actions.js",
"projects/plugins/jetpack/_inc/client/components/global-notices/state/notices/reducer.js",
"projects/plugins/jetpack/_inc/client/components/modal/index.jsx",
"projects/plugins/jetpack/_inc/client/components/popover/util.js",
"projects/plugins/jetpack/_inc/client/config.js",
"projects/plugins/jetpack/_inc/client/lib/accessible-focus/index.js",
"projects/plugins/jetpack/_inc/client/mixins/emitter/index.js",
"projects/plugins/jetpack/_inc/client/my-plan/index.jsx",
"projects/plugins/jetpack/_inc/twitter-timeline.js"
]
[]
Loading