| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| var broadcast = { |
|
|
| |
| |
| |
| currentHashUrl: false, |
|
|
| |
| |
| |
| currentPopoverParameter: false, |
|
|
| |
| |
| |
| popoverHandlers: [], |
|
|
| |
| |
| |
| |
| popoverParamStack: [], |
|
|
| |
| |
| |
| forceReload: false, |
|
|
| |
| |
| |
| updateHashOnly: false, |
|
|
| isWidgetizedDashboard: function() { |
| return broadcast.getValueFromUrl('module') == 'Widgetize' && broadcast.getValueFromUrl('moduleToWidgetize') == 'Dashboard'; |
| }, |
|
|
| isWidgetizeRequestWithoutSession: function() { |
| |
| return broadcast.getValueFromUrl('token_auth') != '' && broadcast.getValueFromUrl('force_api_session') != '1'; |
| }, |
|
|
| |
| |
| |
| |
| isLoginPage: function() { |
| return !!$('body#loginPage').length; |
| }, |
|
|
| |
| |
| |
| |
| isNoDataPage: function() { |
| return !!$('body#site-without-data').length; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| buildReportingUrl: function (ajaxUrl) { |
|
|
| |
| var currentHashStr = broadcast.getHash(); |
|
|
| ajaxUrl = ajaxUrl.replace(/^\?|&#/, ''); |
|
|
| var params_vals = ajaxUrl.split("&"); |
| for (var i = 0; i < params_vals.length; i++) { |
| currentHashStr = broadcast.updateParamValue(params_vals[i], currentHashStr); |
| } |
|
|
| |
| |
| var action = broadcast.getParamValue('action', currentHashStr); |
| if (action != 'goalReport' && action != 'ecommerceReport' && action != 'products' && action != 'sales') { |
| currentHashStr = broadcast.updateParamValue('idGoal=', currentHashStr); |
| } |
| |
| var module = broadcast.getParamValue('module', currentHashStr); |
| if (module != 'Dashboard') { |
| currentHashStr = broadcast.updateParamValue('idDashboard=', currentHashStr); |
| } |
|
|
| return '#' + currentHashStr; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| propagateNewPage: function (str, showAjaxLoading, strHash, paramsToRemove, wholeNewUrl) { |
| |
| globalAjaxQueue.abort(); |
|
|
| paramsToRemove = paramsToRemove || []; |
|
|
| if (typeof showAjaxLoading === 'undefined' || showAjaxLoading) { |
| piwikHelper.showAjaxLoading(); |
| } |
|
|
| var params_vals = str.split("&"); |
|
|
| |
| var currentSearchStr = window.location.search; |
| var currentHashStr = broadcast.getHashFromUrl(); |
|
|
| if (!currentSearchStr) { |
| currentSearchStr = '?'; |
| } |
|
|
| var oldUrl = currentSearchStr + currentHashStr; |
| var newUrl; |
|
|
| if (!wholeNewUrl) { |
| |
| |
| params_vals.forEach(function (param) { |
| if (/\[]=/.test(decodeURIComponent(param))) { |
| var paramName = decodeURIComponent(param).split('[]=')[0]; |
| removeParam(paramName); |
| } |
| }); |
|
|
| |
| paramsToRemove.forEach(function (paramName) { |
| removeParam(paramName); |
| }); |
|
|
| |
| params_vals.forEach(function (param) { |
| if (!param.length) { |
| return; |
| } |
|
|
| if (/\[]=/.test(decodeURIComponent(param))) { |
| currentSearchStr = broadcast.addArrayParamValue(param, currentSearchStr); |
|
|
| if (currentHashStr.length !== 0) { |
| currentHashStr = broadcast.addArrayParamValue(param, currentHashStr); |
| } |
| } else { |
| |
| currentSearchStr = broadcast.updateParamValue(param, currentSearchStr); |
|
|
| if (currentHashStr.length !== 0) { |
| currentHashStr = broadcast.updateParamValue(param, currentHashStr); |
| } |
| } |
| }); |
|
|
| var updatedUrl = new RegExp('&updated=([0-9]+)'); |
| var updatedCounter = updatedUrl.exec(currentSearchStr); |
| if (!updatedCounter) { |
| currentSearchStr += '&updated=1'; |
| } else { |
| updatedCounter = 1 + parseInt(updatedCounter[1]); |
| currentSearchStr = currentSearchStr.replace(new RegExp('(&updated=[0-9]+)'), '&updated=' + updatedCounter); |
| } |
|
|
| if (strHash && currentHashStr.length != 0) { |
| var params_hash_vals = strHash.split("&"); |
| for (var i = 0; i < params_hash_vals.length; i++) { |
| currentHashStr = broadcast.updateParamValue(params_hash_vals[i], currentHashStr); |
| } |
| } |
|
|
| |
| newUrl = currentSearchStr + currentHashStr; |
| } else { |
| newUrl = wholeNewUrl; |
| } |
|
|
| if (oldUrl == newUrl) { |
| window.location.reload(); |
| } else { |
| this.forceReload = true; |
| window.location.href = newUrl; |
| } |
| return false; |
|
|
| function removeParam(paramName) { |
| var paramRegex = new RegExp(paramName + '(\\[]|%5B%5D)?=[^&?#]*&?', 'gi'); |
| currentSearchStr = currentSearchStr.replace(paramRegex, ''); |
| currentHashStr = currentHashStr.replace(paramRegex, ''); |
| } |
| }, |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| updateParamValue: function (newParamValue, urlStr) { |
| var p_v = newParamValue.split("="); |
|
|
| var paramName = p_v[0]; |
| var valFromUrl = broadcast.getParamValue(paramName, urlStr) || broadcast.getParamValue(encodeURIComponent(paramName), urlStr); |
| |
| var paramValue = p_v[1]; |
| if (paramValue == '') { |
| newParamValue = ''; |
| } |
| var getQuotedRegex = function(str) { |
| return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); |
| }; |
|
|
| if (valFromUrl != '' || urlStr.indexOf(paramName + '=') !== -1) { |
| |
| valFromUrl = getQuotedRegex(valFromUrl); |
| var regToBeReplace = new RegExp(paramName + '=' + valFromUrl, 'ig'); |
| if (newParamValue == '') { |
| |
| regToBeReplace = new RegExp('[\&]?(' + paramName + '|' + encodeURIComponent(paramName) + ')=' + valFromUrl, 'ig'); |
| } |
| urlStr = urlStr.replace(regToBeReplace, newParamValue); |
| } else if (newParamValue != '') { |
| urlStr += (urlStr == '') ? newParamValue : '&' + newParamValue; |
| } |
|
|
| return urlStr; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| addArrayParamValue: function (newParamValue, urlStr) { |
| if (urlStr.indexOf('?') === -1) { |
| urlStr += '?'; |
| } else { |
| urlStr += '&'; |
| } |
| return urlStr + newParamValue; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| propagateNewPopoverParameter: function (handlerName, value) { |
| var popover = ''; |
| if (handlerName && '' != value && 'undefined' != typeof value) { |
| popover = handlerName + ':' + value; |
|
|
| |
| |
| |
| popover = encodeURIComponent(popover); |
| popover = popover.replace(/%/g, '\$'); |
|
|
| broadcast.popoverParamStack.push(popover); |
| } else { |
| broadcast.popoverParamStack.pop(); |
| if (broadcast.popoverParamStack.length) { |
| popover = broadcast.popoverParamStack[broadcast.popoverParamStack.length - 1]; |
| } |
| } |
|
|
| var MatomoUrl = window.CoreHome.MatomoUrl; |
| MatomoUrl.updateHash( |
| Object.assign({}, MatomoUrl.hashParsed.value, { popover }), |
| ); |
| }, |
|
|
| |
| |
| |
| |
| resetPopoverStack: function () { |
| broadcast.popoverParamStack = []; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| addPopoverHandler: function (handlerName, callback) { |
| broadcast.popoverHandlers[handlerName] = callback; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| loadAjaxContent: function (urlAjax) { |
| if(broadcast.getParamValue('module', urlAjax) == 'API') { |
| broadcast.lastUrlRequested = null; |
| $('#content').html("Loading content from the API and displaying it within Matomo is not allowed."); |
| piwikHelper.hideAjaxLoading(); |
| return false; |
| } |
|
|
| piwikHelper.hideAjaxError('loadingError'); |
| piwikHelper.showAjaxLoading(); |
| $('#content').empty(); |
| $("object").remove(); |
|
|
| urlAjax = urlAjax.match(/^\?/) ? urlAjax : "?" + urlAjax; |
| broadcast.lastUrlRequested = urlAjax; |
|
|
| function sectionLoaded(content, status, request) { |
| if (request) { |
| var responseHeader = request.getResponseHeader('Content-Type'); |
| if (responseHeader && 0 <= responseHeader.toLowerCase().indexOf('json')) { |
| var message = 'JSON cannot be displayed for'; |
| if (this.getParams && this.getParams['module']) { |
| message += ' module=' + this.getParams['module']; |
| } |
| if (this.getParams && this.getParams['action']) { |
| message += ' action=' + this.getParams['action']; |
| } |
| $('#content').text(message); |
| piwikHelper.hideAjaxLoading(); |
| return; |
| } |
| } |
|
|
| |
| var htmlDocType = '<!DOCTYPE'; |
| if (content.substring(0, htmlDocType.length) == htmlDocType) { |
| |
| if ($(content).filter('title').text() == 'Piwik › Error') { |
| content = $(content).filter('#contentsimple'); |
| } else { |
| return; |
| } |
| } |
|
|
| if (urlAjax == broadcast.lastUrlRequested) { |
| $('#content').html(content).show(); |
| $(broadcast).trigger('locationChangeSuccess', {element: $('#content'), content: content}); |
| piwikHelper.hideAjaxLoading(); |
| broadcast.lastUrlRequested = null; |
|
|
| piwikHelper.compileVueDirectives('#content'); |
| } |
|
|
| initTopControls(); |
| } |
|
|
| var ajax = new ajaxHelper(); |
| ajax.setUrl(urlAjax); |
| ajax._getDefaultPostParams = function () { |
| return {}; |
| }; |
| ajax.setErrorCallback(broadcast.customAjaxHandleError); |
| ajax.setCallback(sectionLoaded); |
| ajax.setFormat('html'); |
| ajax.send(); |
|
|
| return false; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| customAjaxHandleError: function (deferred, status) { |
| broadcast.lastUrlRequested = null; |
|
|
| piwikHelper.hideAjaxLoading(); |
|
|
| |
| if(status == 'abort') { |
| return; |
| } |
|
|
| $('#loadingError').show(); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| isHashExists: function () { |
| var hashStr = broadcast.getHashFromUrl(); |
|
|
| if (hashStr != "") { |
| return hashStr; |
| } else { |
| return false; |
| } |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| getHashFromUrl: function (url) { |
| var hashStr = ""; |
| |
| if (url && url.match('#')) { |
| hashStr = url.substring(url.indexOf("#"), url.length); |
| } |
| else { |
| locationSplit = location.href.split('#'); |
| if(typeof locationSplit[1] != 'undefined') { |
| hashStr = '#' + locationSplit[1]; |
| } |
| } |
|
|
| return hashStr; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| getSearchFromUrl: function (url) { |
| var searchStr = ""; |
| |
| if (url && url.match(/\?/)) { |
| searchStr = url.substring(url.indexOf("?"), url.length); |
| } else { |
| searchStr = location.search; |
| } |
|
|
| return searchStr; |
| }, |
|
|
| |
| |
| |
| |
| |
| extractKeyValuePairsFromQueryString: function (queryString, decode) { |
| var pairs = queryString.replace(/%5B%5D/g, '[]').split('&'); |
| var result = {}; |
| for (var i = 0; i != pairs.length; ++i) { |
| if (pairs[i] === '') { |
| continue; |
| } |
|
|
| |
| |
| var pair = pairs[i].split('='); |
| var key = pair.shift(); |
| var value = pair.join('='); |
| if (decode) { |
| value = decodeURIComponent(value); |
| } |
| if (/\[.*?]$/.test(key)) { |
| key = key.replace(/\[.*?]$/, ''); |
| result[key] = result[key] || []; |
| result[key].push(value); |
| } else { |
| result[key] = value; |
| } |
| } |
| return result; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| getValuesFromUrl: function (url, decode) { |
| var searchString = this._removeHashFromUrl(url).split('?')[1] || ''; |
| return this.extractKeyValuePairsFromQueryString(searchString, decode); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| getValueFromUrl: function (param, url) { |
| var searchString = this._removeHashFromUrl(url); |
| return broadcast.getParamValue(param, searchString); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| getValueFromHash: function (param, url) { |
| var hashStr = broadcast.getHashFromUrl(url); |
| if (hashStr.slice(0, 1) == '#') { |
| hashStr = hashStr.slice(1); |
| } |
| hashStr = hashStr.split('#')[0]; |
|
|
| return broadcast.getParamValue(param, hashStr); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| getParamValue: function (param, url) { |
| var lookFor = param + '='; |
|
|
| if (url.indexOf('?') >= 0) { |
| url = url.slice(url.indexOf('?')+1); |
| } |
|
|
| var urlPieces = url.split('&'); |
|
|
| |
| for (var i=urlPieces.length-1; i>=0; i--) { |
| if (urlPieces[i].indexOf(lookFor) === 0) { |
| return getSingleValue(urlPieces[i]); |
| } |
| } |
|
|
| |
| lookFor = param + '[]='; |
| var result = []; |
| for (var j=0; j<urlPieces.length; j++) { |
| if (urlPieces[j].indexOf(lookFor) === 0) { |
| result.push(getSingleValue(urlPieces[j])); |
| } else if (decodeURIComponent(urlPieces[j]).indexOf(lookFor) === 0) { |
| result.push(getSingleValue(decodeURIComponent(urlPieces[j]))); |
| } |
| } |
| return result.length ? result : ''; |
|
|
| function getSingleValue(urlPart) { |
| var startPos = urlPart.indexOf("="); |
| if (startPos === -1) { |
| return ''; |
| } |
| var value = urlPart.substring(startPos+1); |
|
|
| |
| |
| if(param != 'segment' && param != 'popover' && param != 'compareSegments') { |
| value = value.replace(/[^_%~\*\+\-\<\>!@\$\.()=,;0-9a-zA-Z]/gi, ''); |
| } |
| return value; |
| } |
| }, |
|
|
| |
| |
| |
| |
| getHash: function () { |
| return broadcast.getHashFromUrl().replace(/^#/, '').split('#')[0]; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| _removeHashFromUrl: function (url) { |
| var searchString = ''; |
| if (url) { |
| var urlParts = url.split('#'); |
| searchString = urlParts[0]; |
| } else { |
| searchString = window.location.search; |
| } |
| return searchString; |
| } |
| }; |
|
|
| window.broadcast = broadcast; |
|
|