blob: ea15f025b091a6537f972fd49b150f0a6c32435b (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*!
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
/**
* When present in the page it listens to a popover URL parameter.
*
* If present it will try to load the related content in a popover or if the URL is empty it will close an
* opened popover.
*
* Example:
* <div piwik-popover-handler></div>
*/
(function () {
angular.module('piwikApp').directive('piwikPopoverHandler', piwikPopoverHandler);
piwikPopoverHandler.$inject = ['$location', '$rootScope', 'piwik'];
function piwikPopoverHandler($location, $rootScope, piwik){
return {
restrict: 'A',
scope: {},
controller: function () {
function close()
{
Piwik_Popover.close();
}
function open(popoverParam)
{
// in case the $ was encoded (e.g. when using copy&paste on urls in some browsers)
popoverParam = decodeURIComponent(popoverParam);
// revert special encoding from broadcast.propagateNewPopoverParameter()
popoverParam = popoverParam.replace(/\$/g, '%');
popoverParam = decodeURIComponent(popoverParam);
var popoverParamParts = popoverParam.split(':');
var handlerName = popoverParamParts[0];
popoverParamParts.shift();
var param = popoverParamParts.join(':');
if (typeof piwik.broadcast.popoverHandlers[handlerName] != 'undefined'
&& !piwik.broadcast.isLoginPage()) {
piwik.broadcast.popoverHandlers[handlerName](param);
}
}
function openOrClose()
{
// should be rather done by routing
var popoverParam = $location.search().popover;
if (popoverParam) {
open(popoverParam);
} else {
close();
}
}
$rootScope.$on('$locationChangeSuccess', function () {
// should be rather done by routing
$(function () {
// make sure all popover handles were registered
openOrClose();
});
});
}
};
}
})();
|