All files / ext.wikilambda.app/mixins urlUtils.js

100% Statements 33/33
100% Branches 6/6
100% Functions 4/4
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 347x 7x 7x 7x 7x 7x 7x 7x 7x 23x 23x 7x 7x 7x 7x 7x 2x 2x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 2x 7x 7x  
/*!
 * WikiLambda Vue URL manipulation utilities code
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
module.exports = exports = {
	methods: {
		getParameterByName: function ( name ) {
			const uri = mw.Uri();
			return uri.query[ name ] || null;
		},
		/**
		 * Function to remove the hash from the URL silently
		 */
		removeHashFromURL: function () {
			// Get the current URL without the hash
			const url = window.location.href.split( '#' )[ 0 ];
			// Use replaceState to update the URL
			history.replaceState( null, '', url );
		},
		/**
		 * Check if the link href is the current path
		 *
		 * @param {string} linkHref
		 * @return {boolean}
		 */
		isLinkCurrentPath: function ( linkHref ) {
			const linkUrl = new URL( linkHref, window.location.origin );
			return linkUrl.pathname === window.location.pathname;
		}
	}
};