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
|
/*!
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
/**
* Controller for the piwikDialogToggler directive. Adds a couple methods to the
* scope allowing elements to open and close dialogs.
*/
(function () {
angular.module('piwikApp').controller('DialogTogglerController', DialogTogglerController);
DialogTogglerController.$inject = ['$scope', 'piwik', 'ngDialog', 'piwikDialogtogglerUrllistener'];
function DialogTogglerController($scope, piwik, ngDialog, piwikDialogtogglerUrllistener) {
/**
* Open a new dialog window using ngDialog.
*
* @param {object|string} contentsInfo If an object, it is assumed to be ngDialog open(...) config and is
* passed to ngDialog.open unaltered.
* If a string that beings with '#', we assume it is an ID of an element
* with the dialog contents. (Note: ngDialog doesn't appear to support arbitrary
* selectors).
* If a string that ends with .html, we assume it is a link to a an angular
* template.
* Otherwise we assume it is a raw angular
* @return {object} Returns the result of ngDialog.open. Can be used to close the dialog or listen for
* when the dialog is closed.
*/
$scope.open = function (contentsInfo) {
var ngDialogInfo;
if (typeof(contentsInfo) == 'object') { // is info to pass directly to ngDialog
ngDialogInfo = contentsInfo;
} else if (contentsInfo.substr(0, 1) == '#') { // is ID of an element
ngDialogInfo = {template: contentsInfo.substr(1)};
} else if (contentsInfo.substr(-4) == '.html') { // is a link to an .html file
ngDialogInfo = {template: contentsInfo};
} else { // is a raw HTML string
ngDialogInfo = {template: contentsInfo, plain: true};
}
return ngDialog.open(ngDialogInfo);
};
/**
* Opens a persisted dialog. Persisted dialogs are dialogs that will be launched on reload
* of the current URL. They are accomplished by modifying the URL and adding a 'popover'
* query parameter.
*
* @param {string} directive The denormalized name of an angularjs directive. An element with
* this directive will be the contents of the dialog.
* @param {object} attributes Key value mapping of the HTML attributes to add to the dialog's
* contents element.
*/
$scope.persist = function (directive, attributes) {
piwikDialogtogglerUrllistener.propagatePersistedDialog(directive, attributes);
};
/**
* Closes the currently open dialog window.
*/
$scope.close = function () {
ngDialog.close();
};
}
})();
|