diff options
Diffstat (limited to 'plugins/CoreHome/angularjs/common/services/piwik-url.js')
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-url.js | 43 |
1 files changed, 6 insertions, 37 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/piwik-url.js b/plugins/CoreHome/angularjs/common/services/piwik-url.js index b7e4e52f14..dc45b7e390 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-url.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-url.js @@ -7,12 +7,12 @@ (function () { angular.module('piwikApp.service').service('piwikUrl', piwikUrl); - piwikUrl.$inject = ['$location', 'piwik']; + piwikUrl.$inject = ['$location', 'piwik', '$window']; /** * Similar to angulars $location but works around some limitation. Use it if you need to access search params */ - function piwikUrl($location, piwik) { + function piwikUrl($location, piwik, $window) { var model = { getSearchParam: getSearchParam @@ -22,42 +22,11 @@ function getSearchParam(paramName) { - if (paramName === 'segment') { - var hash = window.location.href.split('#'); - if (hash && hash[1]) { - return piwik.broadcast.getValueFromHash(paramName, hash[1]); - } - - return broadcast.getValueFromUrl(paramName); - } - - // available in global scope - var search = $location.search(); - - if (!search[paramName]) { - // see https://github.com/angular/angular.js/issues/7239 (issue is resolved but problem still exists) - var paramUrlValue = piwik.broadcast.getValueFromUrl(paramName); - if (paramUrlValue !== false - && paramUrlValue !== '' - && paramUrlValue !== null - && paramUrlValue !== undefined - && paramName !== 'token_auth') { - search[paramName] = paramUrlValue; - } else { - return paramUrlValue; - } - } - - if (search[paramName]) { - var value = search[paramName]; - - if (angular.isArray(search[paramName])) { - // use last one. Eg when having period=day&period=year angular would otherwise return ['day', 'year'] - return value[value.length - 1]; - } - - return value; + var hash = $window.location.href.split('#'); + if (hash && hash[1] && (new RegExp(paramName + '(\\[]|=)')).test(decodeURIComponent(hash[1]))) { + return broadcast.getValueFromHash(paramName, $window.location.href); } + return broadcast.getValueFromUrl(paramName, $window.location.search); } } })(); |