Skip to content

Commit

Permalink
Deprecates the historyService along with broadcast.init, `broadca…
Browse files Browse the repository at this point in the history
…st.propagateAjax`, `broadcast.pageLoad` (#12363)

* deprecates broadcast.propagateAjax()

* make overlay js independed from history service and some broadcast methods

* deprecates historyService alogn with some broadcast methods

* make popovers work in widgetized dashboard without history service

* do not update overlay page/sidebar when iframe url didn't change

prevents reloading data when opening a popover
  • Loading branch information
sgiehl authored and diosmosis committed Jun 17, 2018
1 parent e2969c8 commit eb18603
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -60,6 +60,12 @@ Piwik is now Matomo. Read more about this change in the [official announcement](

* New HTTP API `API.getMatomoVersion` was introduced. The previous HTTP API `API.getPiwikVersion` will still work but will now be hidden from the API reference page.

## Piwik 3.2.2

### Breaking Changes
* The `historyService` along with `broadcast.init`, `broadcast.propagateAjax`, `broadcast.pageLoad` have been deprecated and will be removed in Piwik 4.


## Piwik 3.2.1

### New APIs
Expand Down
2 changes: 2 additions & 0 deletions plugins/CoreHome/angularjs/history/history.service.js
Expand Up @@ -12,6 +12,8 @@
* This service replaces the previously used jQuery history extension.
*
* Should only be used by the broadcast object.
*
* @deprecated in 3.2.2, will be removed in Piwik 4
*/
(function (window, $, broadcast) {
angular.module('piwikApp').service('historyService', historyService);
Expand Down
14 changes: 7 additions & 7 deletions plugins/CoreHome/javascripts/broadcast.js
Expand Up @@ -52,6 +52,9 @@ var broadcast = {

/**
* Initializes broadcast object
*
* @deprecated in 3.2.2, will be removed in Piwik 4
*
* @return {void}
*/
init: function (noLoadingMessage) {
Expand All @@ -78,6 +81,8 @@ var broadcast = {
*
* * Note: the method is manipulated in Overlay/javascripts/Piwik_Overlay.js - keep this in mind when making changes.
*
* @deprecated since 3.2.2, will be removed in Piwik 4
*
* @param {string} hash to load page with
* @return {void}
*/
Expand Down Expand Up @@ -185,7 +190,6 @@ var broadcast = {
},

/**
* ONLY USED BY OVERLAY
* propagateAjax -- update hash values then make ajax calls.
* example :
* 1) <a href="javascript:broadcast.propagateAjax('module=Referrers&action=getKeywords')">View keywords report</a>
Expand All @@ -195,6 +199,8 @@ var broadcast = {
*
* NOTE: this method will only make ajax call and replacing main content.
*
* @deprecated in 3.2.2, will be removed in Piwik 4.
*
* @param {string} ajaxUrl querystring with parameters to be updated
* @param {boolean} [disableHistory] the hash change won't be available in the browser history
* @return {void}
Expand Down Expand Up @@ -292,8 +298,6 @@ var broadcast = {
* 1) We want to update idSite to both search query and hash then reload the page,
* 2) update period to both search query and hash then reload page.
*
* ** If you'd like to make ajax call with new values then use propagateAjax ** *
*
* Expecting:
* str = "param1=newVal1&param2=newVal2";
*
Expand Down Expand Up @@ -442,10 +446,6 @@ var broadcast = {
* handler.
*/
propagateNewPopoverParameter: function (handlerName, value) {
// init broadcast if not already done (it is required to make popovers work in widgetize mode)
if (broadcast.isWidgetizedDashboard()) {
broadcast.init(true);
}

var $location = angular.element(document).injector().get('$location');

Expand Down
1 change: 1 addition & 0 deletions plugins/Dashboard/templates/_header.twig
Expand Up @@ -16,3 +16,4 @@
{% include "_jsCssIncludes.twig" %}
</head>
<body id="standalone" ng-app="app">
<div piwik-popover-handler></div>
44 changes: 25 additions & 19 deletions plugins/Overlay/javascripts/Piwik_Overlay.js
Expand Up @@ -140,6 +140,10 @@ var Piwik_Overlay = (function () {
var location = getOverlayLocationFromHash(urlHash);
location = Overlay_Helper.decodeFrameUrl(location);

if (location == iframeCurrentPageNormalized) {
return;
}

if (!updateComesFromInsideFrame) {
var iframeUrl = iframeSrcBase;
if (location) {
Expand Down Expand Up @@ -186,26 +190,19 @@ var Piwik_Overlay = (function () {
}, 50);

// handle window resize
// we manipulate broadcast.pageload because it unbinds all resize events on window
var originalPageload = broadcast.pageload;
broadcast.pageload = function (hash) {
originalPageload(hash);
$(window).resize(function () {
adjustDimensions();
});
};
$(window).resize(function () {
adjustDimensions();
});

// handle hash change
broadcast.loadAjaxContent = hashChangeCallback;
angular.element(document).injector().invoke(function ($rootScope) {
$rootScope.$on('$locationChangeSuccess', function () {
hashChangeCallback(broadcast.getHash());
});

broadcast._isInit = false;
broadcast.init();
hashChangeCallback(broadcast.getHash());
});

if (window.location.href.split('#').length == 1) {
// if there's no hash, broadcast won't trigger the callback - we have to do it here
hashChangeCallback('');
}

Expand Down Expand Up @@ -270,14 +267,23 @@ var Piwik_Overlay = (function () {
currentLocation = getOverlayLocationFromHash(locationParts[1]);
}

var newLocation = Overlay_Helper.encodeFrameUrl(currentUrl);
var newFrameLocation = Overlay_Helper.encodeFrameUrl(currentUrl);

if (newLocation != currentLocation) {
if (newFrameLocation != currentLocation) {
updateComesFromInsideFrame = true;
// put the current iframe url in the main url to enable refresh and deep linking.
// use disableHistory=true to make sure that the back and forward buttons can be
// used on the iframe (which in turn notifies the parent about the location change)
broadcast.propagateAjax('l=' + newLocation, true);

// available in global scope
var currentHashStr = broadcast.getHash();

if (currentHashStr.charAt(0) == '?') {
currentHashStr = currentHashStr.substr(1);
}

currentHashStr = broadcast.updateParamValue('l=' + newFrameLocation, currentHashStr);

var newLocation = window.location.href.split('#')[0] + '#?' + currentHashStr;
// window.location.replace changes the current url without pushing it on the browser's history stack
window.location.replace(newLocation);
} else {
// happens when the url is changed by hand or when the l parameter is there on page load
loadSidebar(currentUrl);
Expand Down

0 comments on commit eb18603

Please sign in to comment.