2020-06-25 13:36:59 +00:00
|
|
|
/**
|
|
|
|
* Get the URL params.
|
|
|
|
*
|
|
|
|
* @param {string} locationSearch - Querystring part of a URL, including the question mark (?).
|
|
|
|
* @return {Object} - URL params.
|
|
|
|
*/
|
2020-06-05 16:07:28 +00:00
|
|
|
export function getUrlParams( locationSearch ) {
|
|
|
|
if ( locationSearch ) {
|
|
|
|
return locationSearch
|
|
|
|
.substr( 1 )
|
|
|
|
.split( '&' )
|
|
|
|
.reduce( ( params, query ) => {
|
|
|
|
const chunks = query.split( '=' );
|
|
|
|
const key = chunks[ 0 ];
|
|
|
|
let value = decodeURIComponent( chunks[ 1 ] );
|
|
|
|
value = isNaN( Number( value ) ) ? value : Number( value );
|
|
|
|
return ( params[ key ] = value ), params;
|
|
|
|
}, {} );
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
2020-06-25 13:36:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current screen name.
|
|
|
|
*
|
|
|
|
* @return {string} - Screen name.
|
|
|
|
*/
|
|
|
|
export function getScreenName() {
|
|
|
|
let screenName = '';
|
|
|
|
const { page, path, post_type: postType } = getUrlParams(
|
|
|
|
window.location.search
|
|
|
|
);
|
|
|
|
if ( page ) {
|
|
|
|
const currentPage = page === 'wc-admin' ? 'home_screen' : page;
|
|
|
|
screenName = path
|
|
|
|
? path.replace( /\//g, '_' ).substring( 1 )
|
|
|
|
: currentPage;
|
|
|
|
} else if ( postType ) {
|
|
|
|
screenName = postType;
|
|
|
|
}
|
|
|
|
return screenName;
|
|
|
|
}
|