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

widgetize.js « templates « Widgetize « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e6d79daa97b9651bd209560b99b07ac2ee54386e (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
function widgetize()
{
	var self = this;
	
	this.getInputFormWithHtml = function(inputId, htmlEmbed)
	{
		return '<input class="formEmbedCode" id="'+inputId+'" value="'+ htmlEmbed.replace(/"/g, '&quot;') +'" onclick="javascript:document.getElementById(\''+inputId+'\').focus();document.getElementById(\''+inputId+'\').select();" readonly="true" type="text">';
	}
	
	this.getEmbedUrl = function( parameters, exportFormat )
	{
		copyParameters = new Object();
		for(var variableName in parameters) {
			copyParameters[variableName] = parameters[variableName];
		}
		copyParameters['moduleToWidgetize'] = parameters['module'];
		copyParameters['actionToWidgetize'] = parameters['action'];
		delete copyParameters['action'];
		delete copyParameters['module'];
		var sourceUrl;
		sourceUrl = document.location.protocol + '//' + document.location.hostname + document.location.pathname + '?';
		sourceUrl += 	"module=Widgetize" +
						"&action="+exportFormat+
						"&"+piwikHelper.getQueryStringFromParameters(copyParameters)+
						"&idSite="+piwik.idSite+
						"&period="+piwik.period+
						"&date="+piwik.currentDateString+
						"&disableLink=1";
		return sourceUrl;
	}
	
	this.deleteEmbedElements = function()
	{
		$('#exportButtons').remove();
	}
	
	this.htmlentities = function(s)
	{
		return s.replace( /[<>&]/g, function(m) { return "&" + m.charCodeAt(0) + ";"; });
	}
	
	this.callbackAddExportButtonsUnderWidget = function (	widgetUniqueId, 
															loadedWidgetElement)
	{
		widget = widgetsHelper.getWidgetObjectFromUniqueId(widgetUniqueId);
		widgetName = widget["name"];
		widgetParameters = widget['parameters'];
	
		self.deleteEmbedElements();
		var exportButtonsElement = $('<span id="exportButtons">');

		// We first build the HTML code that will load the widget in an IFRAME
		var widgetIframeHtml = '<div id="widgetIframe">'+
								'<iframe width="100%" height="350" src="'+
									self.getEmbedUrl(widgetParameters, "iframe")+ 
									'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0">'+
								'</iframe>'+
							'</div>';

		// Add the input field containing the widget in an Iframe 
		$(exportButtonsElement).append(
			'<div id="embedThisWidgetIframe">'+
				'<label for="embedThisWidgetIframeInput">&rsaquo; Embed Iframe</label>'+
				'<span id="embedThisWidgetIframeInput">'+
					self.getInputFormWithHtml('iframeEmbed', widgetIframeHtml)+
				'</span>'+
			'</div>'
		);
		
		// Add the Flash Export if a flash <embed> is found in the widget 
		$(loadedWidgetElement)
			.find('embed,object')
			.each(function() {
				var htmlEmbed = $(this).parent().html();

				$(exportButtonsElement).append(
					'<div id="embedThisWidgetFlash">'+
						'<label for="embedThisWidgetFlashInput">&rsaquo; Embed Flash</label>'+
						'<span id="embedThisWidgetFlashInput">'+
							self.getInputFormWithHtml('flashEmbed', htmlEmbed) +
						'</span>'+
					'</div>'
				);
			});
		
		// Add the Clearspring Export 
		$(exportButtonsElement).append(
			'<div id="embedThisWidgetEverywhere">'+
				'<div id="exportThisWidget">'+
					'<label for="flashEmbed">&rsaquo; Export anywhere!</label>'+
					'<img src="http://cdn.clearspring.com/launchpad/static/cs_button_share1.gif">'+
				'</div>'+
				'<div id="exportThisWidgetMenu"></div>'+
			'</div>'
		);

		// We then replace the div iframeDivToExport with the actual Iframe html
		// Clearspring will then build a widget that has the same html as this div
		$('#iframeDivToExport')
			.html(widgetIframeHtml);

		// Finally we append the content to the parent widget DIV 
		$(loadedWidgetElement)
			.parent()
			.append(exportButtonsElement);
		
		// Call clearspring
		$Launchpad.ShowButton({
								actionElement : "exportThisWidget",
								targetElement : "exportThisWidgetMenu",
								userId : "4797da88692e4fe9",
								widgetName : widgetName + " - Piwik",
								source : "iframeDivToExport"
		});

		// JS is buggy at least on IE
		//var widgetJS = '<script type="text/javascript" src="'+ getEmbedUrl(pluginId, actionId, "js") +'"></scr'+'ipt>';
		//divEmbedThisWidget.append('<br/>Embed JS: '+ getInputFormWithHtml('javascriptEmbed', widgetJS));
	}
}