(win, target)
| 294 | * @return {string} |
| 295 | */ |
| 296 | export function getExtraParamsUrl(win, target) { |
| 297 | // Get an array with extra params that needs to append. |
| 298 | const url = parseUrlDeprecated(WindowInterface.getLocation(win).href); |
| 299 | const params = parseQueryString(url.search); |
| 300 | const appendParams = []; |
| 301 | for (let i = 0; i < DEFAULT_APPEND_URL_PARAM.length; i++) { |
| 302 | const param = DEFAULT_APPEND_URL_PARAM[i]; |
| 303 | if (typeof params[param] !== 'undefined') { |
| 304 | appendParams.push(param); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // Check if the param already exists |
| 309 | const additionalUrlParams = target.getAttribute('data-amp-addparams'); |
| 310 | let {href} = target; |
| 311 | if (additionalUrlParams) { |
| 312 | href = addParamsToUrl(href, parseQueryString(additionalUrlParams)); |
| 313 | } |
| 314 | const loc = parseUrlDeprecated(href); |
| 315 | const existParams = parseQueryString(loc.search); |
| 316 | for (let i = appendParams.length - 1; i >= 0; i--) { |
| 317 | const param = appendParams[i]; |
| 318 | if (typeof existParams[param] !== 'undefined') { |
| 319 | appendParams.splice(i, 1); |
| 320 | } |
| 321 | } |
| 322 | return getQueryParamUrl(appendParams); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Helper method to convert an query param array to string |
no test coverage detected