Welcome to mirror list, hosted at ThFree Co, Russian Federation.

popover.js « templates « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4704233a635efc3332b959e3c7bacfced9345e33 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*!
 * Piwik - Web Analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

var Piwik_Popover = (function() {

	var container = false;
	var isOpen = false;
	var closeCallback = false;

	var createContainer = function() {
		if (container === false) {
			container = $(document.createElement('div')).attr('id', 'Piwik_Popover');
		}
	};
	
	var openPopover = function(title) {
		createContainer();
		
		container.dialog({
			title: title,
			modal: true,
			width: '950px',
			position: ['center', 'center'],
			resizable: false,
			autoOpen: true,
			open: function(event, ui) {
				$('.ui-widget-overlay').on('click.popover', function() {
					container.dialog('close');
				});
			},
			close: function(event, ui) {
				container.find('div.jqplot-target').trigger('piwikDestroyPlot');
				container[0].innerHTML = ''; // IE8 fix
				container.dialog('destroy').remove();
				globalAjaxQueue.abort();
				$('.ui-widget-overlay').off('click.popover');
				isOpen = false;
				broadcast.propagateNewPopoverParameter(false);
				if (typeof closeCallback == 'function') {
					closeCallback();
					closeCallback = false;
				}
			}
		});
		
		isOpen = true;
	};
	
	var centerPopover = function() {
		if (container !== false) {
			container.dialog({position: ['center', 'center']});
		}
	};

	return {

		/**
		 * Open the popover with a loading message
		 *
		 * @param popoverName        string    name of the popover
		 * @param popoverSubject    string    subject of the popover (e.g. url, optional)
		 * @param height            int        height of the popover in px (optional)
		 */
		showLoading: function(popoverName, popoverSubject, height) {
			var loading = $(document.createElement('div')).addClass('Piwik_Popover_Loading');

			var loadingMessage = popoverSubject ? translations.General_LoadingPopoverFor_js :
				translations.General_LoadingPopover_js;

			loadingMessage = loadingMessage.replace(/%s/, popoverName);
			
			var p1 = $(document.createElement('p')).addClass('Piwik_Popover_Loading_Name');
			loading.append(p1.text(loadingMessage));

			var p2;
			if (popoverSubject) {
				popoverSubject = piwikHelper.addBreakpointsToUrl(popoverSubject);
				p1.addClass('Piwik_Popover_Loading_NameWithSubject');
				p2 = $(document.createElement('p')).addClass('Piwik_Popover_Loading_Subject');
				loading.append(p2.html(popoverSubject));
			}

			if (height) {
				loading.height(height);
			}

			if (!isOpen) {
				openPopover();
			}
				
			this.setContent(loading);
			this.setTitle('');

			if (height) {
				var offset = loading.height() - p1.outerHeight();
				if (popoverSubject) {
					offset -= p2.outerHeight();
				}
				var spacingEl = $(document.createElement('div'));
				spacingEl.height(Math.round(offset / 2));
				loading.prepend(spacingEl);
			}

			return container;
		},
		
		/** Add a help button to the current popover */
		addHelpButton: function(helpUrl) {
			if (!isOpen) {
				return;
			}
			
			var titlebar = container.parent().find('.ui-dialog-titlebar');
			
			var button = $(document.createElement('a')).addClass('ui-dialog-titlebar-help');
			button.attr({href: helpUrl, target: '_blank'});
			
			titlebar.append(button);
		},

		/** Set the title of the popover */
		setTitle: function(titleHtml) {
			container.dialog({title: titleHtml});
		},
		
		/** Set inner HTML of the popover */
		setContent: function(html) {
			if (typeof closeCallback == 'function') {
				closeCallback();
				closeCallback = false;
			}
			
			container[0].innerHTML = ''; // IE8 fix
			container.html(html);
			centerPopover();
		},
		
		/** Show an error message. All params are HTML! */
		showError: function(title, message, backLabel) {
			var error = $(document.createElement('div')).addClass('Piwik_Popover_Error');
			
			var p = $(document.createElement('p')).addClass('Piwik_Popover_Error_Title');
			error.append(p.html(title));

			if (message) {
				p = $(document.createElement('p')).addClass('Piwik_Popover_Error_Message');
				error.append(p.html(message));
			}
			
			if (backLabel) {
				var back = $(document.createElement('a')).addClass('Piwik_Popover_Error_Back');
				back.attr('href', '#').click(function() {
					history.back();
					return false;
				});
				error.append(back.html(backLabel));
			}

			if (!isOpen) {
				openPopover();
			}
				
			this.setContent(error);
		},
		
		/** Add a callback for the next time the popover is closed or the content changes */
		onClose: function(callback) {
			closeCallback = callback;
		},

		/** Close the popover */
		close: function() {
			if (isOpen) {
				container.dialog('close');
			}
		},

    /**
     * Create a Popover and load the specified URL in it
     * @param url
     */
    createPopupAndLoadUrl: function(url, loadingName) {
      // open the popover
      var box = Piwik_Popover.showLoading(loadingName);

      var callback = function(html) {
        function setPopoverTitleIfOneFoundInContainer() {
          var title = $('h1,h2', container);
          if (title.length == 1) {
            Piwik_Popover.setTitle(title.text());
            $(title).hide();
          }
        }
        Piwik_Popover.setContent(html);
        setPopoverTitleIfOneFoundInContainer();
      }
      var ajaxRequest = new ajaxHelper();
      ajaxRequest.addParams(piwikHelper.getArrayFromQueryString(url), 'get');
      ajaxRequest.setCallback(callback);
      ajaxRequest.setFormat('html');
      ajaxRequest.send(false);
    }
	};

})();