Newer
Older
var Piwik_Insight = (function() {
/** Load the sidebar for a url */
function loadSidebar(currentUrl) {
iframeDomain = currentUrl.match(/http(s)?:\/\/(www\.)?([^\/]*)/i)[3];
BeezyT
a validé
piwikHelper.ajaxCall('Insight', 'renderSidebar', {
currentUrl: currentUrl
}, function(response) {
var $response = $(response);
var $responseLocation = $response.find('.Insight_Location');
var $url = $responseLocation.find('span');
$url.html(piwikHelper.addBreakpointsToUrl($url.text()));
$responseLocation.remove();
$location.find('span').hover(function() {
if (iframeDomain) {
// use addBreakpointsToUrl because it also encoded html entities
Piwik_Tooltip.show('<b>' + Piwik_Insight_Translations.domain + ':</b> ' +
piwikHelper.addBreakpointsToUrl(iframeDomain), 'Insight_Tooltip');
}
}, function() {
Piwik_Tooltip.hide();
});
$sidebar.empty().append($response).show();
var $fullScreen = $sidebar.find('a.Insight_FullScreen');
$fullScreen.click(function() {
handleFullScreen();
return false;
});
}, 'html');
}
/** Adjust the height of the iframe */
function adjustHeight() {
height = Math.max(300, height);
$container.height(height);
/** Handle full screen */
function handleFullScreen() {
if (!isFullScreen) {
// open full screen
isFullScreen = true;
$container.addClass('Insight_FullScreen');
adjustHeight();
} else {
// close full screen
isFullScreen = false;
$container.removeClass('Insight_FullScreen');
adjustHeight();
}
}
return {
/** This method is called when insight loads (from index.tpl) */
init: function() {
$container = $('#Insight_Container');
$sidebar = $('#Insight_Sidebar');
$location = $('#Insight_Location');
$main = $('#Insight_Main');
BeezyT
a validé
adjustHeight();
window.setTimeout(function() {
// sometimes the frame is too high at first
adjustHeight();
}, 50);
BeezyT
a validé
// this callback is unbound in broadcast.pageload
$(window).resize(function() {
adjustHeight();
});
},
/** This callback is used from within the iframe */
setCurrentUrl: function(currentUrl) {
loadSidebar(currentUrl);
}
};
})();