hide map for Character groups Quest Stations when there are no stations

This commit is contained in:
oliver 2016-04-09 13:44:37 +02:00
commit df14dfafc3
4371 changed files with 1220224 additions and 0 deletions

View file

@ -0,0 +1,288 @@
/*!
* Piwik - Web Analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
/**
* jQueryUI widget for Live visitors widget
*/
(function ($) {
$.widget('piwik.liveWidget', {
/**
* Default settings for widgetPreview
*/
options:{
// Maximum numbers of rows to display in widget
maxRows: 10,
// minimal time in microseconds to wait between updates
interval: 3000,
// maximum time to wait between requests
maxInterval: 300000,
// url params to use for data request
dataUrlParams: null,
// callback triggered on a successful update (content of widget changed)
onUpdate: null,
// speed for fade animation
fadeInSpeed: 'slow'
},
/**
* current updateInterval used
*/
currentInterval: null,
/**
* identifies if content has updated (eg new visits/views)
*/
updated: false,
/**
* window timeout interval
*/
updateInterval: null,
/**
* identifies if the liveWidget ist started or not
*/
isStarted: true,
/**
* Update the widget
*
* @return void
*/
_update: function () {
this.updated = false;
var that = this;
var ajaxRequest = new ajaxHelper();
ajaxRequest.addParams(this.options.dataUrlParams, 'GET');
ajaxRequest.setFormat('html');
ajaxRequest.setCallback(function (r) {
that._parseResponse(r);
// add default interval to last interval if not updated or reset to default if so
if (!that.updated) {
that.currentInterval += that.options.interval;
} else {
that.currentInterval = that.options.interval;
if (that.options.onUpdate) that.options.onUpdate();
}
// check new interval doesn't reach the defined maximum
if (that.options.maxInterval < that.currentInterval) {
that.currentInterval = that.options.maxInterval;
}
if (that.isStarted) {
window.clearTimeout(that.updateInterval);
if ($(that.element).closest('body').length) {
that.updateInterval = window.setTimeout(function() { that._update() }, that.currentInterval);
}
}
});
ajaxRequest.send(false);
},
/**
* Parses the given response and updates the widget if newer content is available
*
* @return void
*/
_parseResponse: function (data) {
if (!data || !data.length) {
this.updated = false;
return;
}
var items = $('li', $(data));
for (var i = items.length; i--;) {
this._parseItem(items[i]);
}
},
/**
* Parses the given item and updates or adds an entry to the list
*
* @param item to parse
* @return void
*/
_parseItem: function (item) {
var visitId = $(item).attr('id');
if ($('#' + visitId, this.element).length) {
if ($('#' + visitId, this.element).html() != $(item).html()) {
this.updated = true;
}
$('#' + visitId, this.element).remove();
$(this.element).prepend(item);
} else {
this.updated = true;
$(item).hide();
$(this.element).prepend(item);
$(item).fadeIn(this.options.fadeInSpeed);
}
// remove rows if there are more than the maximum
$('li:gt(' + (this.options.maxRows - 1) + ')', this.element).remove();
},
/**
* Constructor
*
* @return void
*/
_create: function () {
if (!this.options.dataUrlParams) {
console && console.error('liveWidget error: dataUrlParams needs to be defined in settings.');
return;
}
this.currentInterval = this.options.interval;
var self = this;
this.updateInterval = window.setTimeout(function() { self._update(); }, this.currentInterval);
},
/**
* Stops requests if widget is destroyed
*/
_destroy: function () {
this.stop();
},
/**
* Triggers an update for the widget
*
* @return void
*/
update: function () {
this._update();
},
/**
* Starts the automatic update cycle
*
* @return void
*/
start: function () {
this.isStarted = true;
this.currentInterval = 0;
this._update();
},
/**
* Stops the automatic update cycle
*
* @return void
*/
stop: function () {
this.isStarted = false;
window.clearTimeout(this.updateInterval);
},
/**
* Set the interval for refresh
*
* @param {int} interval new interval for refresh
* @return void
*/
setInterval: function (interval) {
this.currentInterval = interval;
}
});
})(jQuery);
$(function() {
var refreshWidget = function (element, refreshAfterXSecs) {
// if the widget has been removed from the DOM, abort
if ($(element).parent().length == 0) {
return;
}
var lastMinutes = $(element).attr('data-last-minutes') || 3,
translations = JSON.parse($(element).attr('data-translations'));
var ajaxRequest = new ajaxHelper();
ajaxRequest.addParams({
module: 'API',
method: 'Live.getCounters',
format: 'json',
lastMinutes: lastMinutes
}, 'get');
ajaxRequest.setFormat('json');
ajaxRequest.setCallback(function (data) {
data = data[0];
// set text and tooltip of visitors count metric
var visitors = data['visitors'];
if (visitors == 1) {
var visitorsCountMessage = translations['one_visitor'];
}
else {
var visitorsCountMessage = translations['visitors'].replace('%s', visitors);
}
$('.simple-realtime-visitor-counter', element)
.attr('title', visitorsCountMessage)
.find('div').text(visitors);
// set text of individual metrics spans
var metrics = $('.simple-realtime-metric', element);
var visitsText = data['visits'] == 1
? translations['one_visit'] : translations['visits'].replace('%s', data['visits']);
$(metrics[0]).text(visitsText);
var actionsText = data['actions'] == 1
? translations['one_action'] : translations['actions'].replace('%s', data['actions']);
$(metrics[1]).text(actionsText);
var lastMinutesText = lastMinutes == 1
? translations['one_minute'] : translations['minutes'].replace('%s', lastMinutes);
$(metrics[2]).text(lastMinutesText);
// schedule another request
setTimeout(function () { refreshWidget(element, refreshAfterXSecs); }, refreshAfterXSecs * 1000);
});
ajaxRequest.send(true);
};
var exports = require("piwik/Live");
exports.initSimpleRealtimeVisitorWidget = function () {
$('.simple-realtime-visitor-widget').each(function() {
var $this = $(this),
refreshAfterXSecs = $this.attr('data-refreshAfterXSecs');
if ($this.attr('data-inited')) {
return;
}
$this.attr('data-inited', 1);
setTimeout(function() { refreshWidget($this, refreshAfterXSecs ); }, refreshAfterXSecs * 1000);
});
};
});
var pauseImage = "plugins/Live/images/pause.gif";
var pauseDisabledImage = "plugins/Live/images/pause_disabled.gif";
var playImage = "plugins/Live/images/play.gif";
var playDisabledImage = "plugins/Live/images/play_disabled.gif";
function onClickPause() {
$('#pauseImage').attr('src', pauseImage);
$('#playImage').attr('src', playDisabledImage);
return $('#visitsLive').liveWidget('stop');
}
function onClickPlay() {
$('#playImage').attr('src', playImage);
$('#pauseImage').attr('src', pauseDisabledImage);
return $('#visitsLive').liveWidget('start');
}

View file

@ -0,0 +1,89 @@
/**
* Piwik - Web Analytics
*
* Visitor profile popup control.
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
(function ($, require) {
var exports = require('piwik/UI'),
DataTable = exports.DataTable,
dataTablePrototype = DataTable.prototype;
/**
* DataTable UI class for jqPlot graph datatable visualizations.
*
* @constructor
*/
exports.VisitorLog = function (element) {
DataTable.call(this, element);
};
$.extend(exports.VisitorLog.prototype, dataTablePrototype, {
/**
* Initializes this class.
*/
init: function () {
dataTablePrototype.init.call(this);
// Replace duplicated page views by a NX count instead of using too much vertical space
$("ol.visitorLog").each(function () {
var prevelement;
var prevhtml;
var counter = 0;
$(this).find("li").each(function () {
counter++;
$(this).val(counter);
var current = $(this).html();
if (current == prevhtml) {
var repeat = prevelement.find(".repeat");
if (repeat.length) {
repeat.html((parseInt(repeat.html()) + 1) + "x");
} else {
prevelement.append($("<em>2x</em>").attr({'class': 'repeat', 'title': _pk_translate('Live_PageRefreshed')}));
}
$(this).hide();
} else {
prevhtml = current;
prevelement = $(this);
}
var $this = $(this);
var tooltipIsOpened = false;
$('a', $this).on('focus', function () {
// see http://dev.piwik.org/trac/ticket/4099
if (tooltipIsOpened) {
$this.tooltip('close');
}
});
$this.tooltip({
track: true,
show: false,
hide: false,
content: function() {
var title = $(this).attr('title');
return $('<a>').text( title ).html().replace(/\n/g, '<br />');
},
tooltipClass: 'small',
open: function() { tooltipIsOpened = true; },
close: function() { tooltipIsOpened = false; }
});
});
});
// launch visitor profile on visitor profile link click
this.$element.on('click', '.visitor-log-visitor-profile-link', function (e) {
e.preventDefault();
broadcast.propagateNewPopoverParameter('visitorProfile', $(this).attr('data-visitor-id'));
return false;
});
}
});
})(jQuery, require);

View file

@ -0,0 +1,287 @@
/**
* Piwik - Web Analytics
*
* Visitor profile popup control.
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
(function ($, require) {
var piwik = require('piwik'),
exports = require('piwik/UI'),
UIControl = exports.UIControl;
/**
* Sets up and handles events for the visitor profile popup.
*
* @param {Element} element The HTML element returned by the Live.getVisitorLog controller
* action. Should have the CSS class 'visitor-profile'.
* @constructor
*/
var VisitorProfileControl = function (element) {
UIControl.call(this, element);
this._setupControl();
this._bindEventCallbacks();
};
/**
* Initializes all elements w/ the .visitor-profile CSS class as visitor profile popups,
* if the element has not already been initialized.
*/
VisitorProfileControl.initElements = function () {
UIControl.initElements(this, '.visitor-profile');
};
/**
* Shows the visitor profile popover for a visitor ID. This should not be called directly.
* Instead broadcast.propagateNewPopoverParameter('visitorProfile', visitorId) should be
* called. This would make sure the popover would be opened if the URL is copied and pasted
* in a new tab/window.
*
* @param {String} visitorId The string visitor ID.
*/
VisitorProfileControl.showPopover = function (visitorId) {
var url = 'module=Live&action=getVisitorProfilePopup&visitorId=' + encodeURIComponent(visitorId);
// if there is already a map shown on the screen, do not show the map in the popup. kartograph seems
// to only support showing one map at a time.
if ($('.RealTimeMap').length > 0) {
url += '&showMap=0';
}
Piwik_Popover.createPopupAndLoadUrl(url, _pk_translate('Live_VisitorProfile'), 'visitor-profile-popup');
};
$.extend(VisitorProfileControl.prototype, UIControl.prototype, {
_setupControl: function () {
// focus the popup so it will accept key events
this.$element.focus();
// highlight the first visit
$('.visitor-profile-visits>li:first-child', this.$element).addClass('visitor-profile-current-visit');
},
_bindEventCallbacks: function () {
var self = this,
$element = this.$element;
$element.on('click', '.visitor-profile-close', function (e) {
e.preventDefault();
Piwik_Popover.close();
return false;
});
$element.on('click', '.visitor-profile-more-info>a', function (e) {
e.preventDefault();
self._loadMoreVisits();
return false;
});
$element.on('click', '.visitor-profile-see-more-cvars>a', function (e) {
e.preventDefault();
$('.visitor-profile-extra-cvars', $element).slideToggle();
return false;
});
$element.on('click', '.visitor-profile-visit-title-row', function () {
self._loadIndividualVisitDetails($('h2', this));
});
$element.on('click', '.visitor-profile-prev-visitor', function (e) {
e.preventDefault();
self._loadPreviousVisitor();
return false;
});
$element.on('click', '.visitor-profile-next-visitor', function (e) {
e.preventDefault();
self._loadNextVisitor();
return false;
});
$element.on('keydown', function (e) {
if (e.which == 37) { // on <- key press, load previous visitor
self._loadPreviousVisitor();
} else if (e.which == 39) { // on -> key press, load next visitor
self._loadNextVisitor();
}
});
$element.on('click', '.visitor-profile-show-map', function (e) {
e.preventDefault();
self.toggleMap();
return false;
});
// append token_auth dynamically to export link
$element.on('mousedown', '.visitor-profile-export', function (e) {
var url = $(this).attr('href');
if (url.indexOf('&token_auth=') == -1) {
$(this).attr('href', url + '&token_auth=' + piwik.token_auth);
}
});
// on hover, show export link (chrome won't let me do this via css :( )
$element.on('mouseenter mouseleave', '.visitor-profile-id', function (e) {
var $exportLink = $(this).find('.visitor-profile-export');
if ($exportLink.css('visibility') == 'hidden') {
$exportLink.css('visibility', 'visible');
} else {
$exportLink.css('visibility', 'hidden');
}
});
},
toggleMap: function () {
var $element = this.$element,
$map = $('.visitor-profile-map', $element);
if (!$map.children().length) { // if the map hasn't been loaded, load it
this._loadMap($map);
return;
}
if ($map.is(':hidden')) { // show the map if it is hidden
if ($map.height() < 1) {
$map.resize();
}
$map.slideDown('slow');
var newLabel = 'Live_HideMap';
piwikHelper.lazyScrollTo($('.visitor-profile-location', $element)[0], 400);
} else { // hide the map if it is shown
$map.slideUp('slow');
var newLabel = 'Live_ShowMap';
}
newLabel = _pk_translate(newLabel).replace(' ', '\xA0');
$('.visitor-profile-show-map', $element).text('(' + newLabel + ')');
},
_loadMap: function ($map) {
var self = this;
var ajax = new ajaxHelper();
ajax.setUrl($map.attr('data-href'));
ajax.setCallback(function (response) {
$map.html(response);
self.toggleMap();
});
ajax.setFormat('html');
ajax.setLoadingElement($('.visitor-profile-location > p > .loadingPiwik', self.$element));
ajax.send();
},
_loadMoreVisits: function () {
var self = this,
$element = this.$element;
var loading = $('.visitor-profile-more-info > .loadingPiwik', $element);
loading.show();
var ajax = new ajaxHelper();
ajax.addParams({
module: 'Live',
action: 'getVisitList',
period: '',
date: '',
visitorId: $element.attr('data-visitor-id'),
filter_offset: $('.visitor-profile-visits>li', $element).length
}, 'GET');
ajax.setCallback(function (response) {
if (response == "") { // no more visits left
self._showNoMoreVisitsSpan();
} else {
response = $(response);
loading.hide();
$('.visitor-profile-visits', $element).append(response);
if (response.filter('li').length < 10) {
self._showNoMoreVisitsSpan();
}
piwikHelper.lazyScrollTo($(response)[0], 400, true);
}
});
ajax.setFormat('html');
ajax.send();
},
_showNoMoreVisitsSpan: function () {
var noMoreSpan = $('<span/>').text(_pk_translate('Live_NoMoreVisits')).addClass('visitor-profile-no-visits');
$('.visitor-profile-more-info', this.$element).html(noMoreSpan);
},
_loadIndividualVisitDetails: function ($visitElement) {
var self = this,
$element = this.$element,
visitId = $visitElement.attr('data-idvisit');
$('.visitor-profile-avatar .loadingPiwik', $element).css('display', 'inline-block');
piwikHelper.lazyScrollTo($('.visitor-profile-avatar', $element)[0], 400);
var ajax = new ajaxHelper();
ajax.addParams({
module: 'Live',
action: 'getSingleVisitSummary',
visitId: visitId,
idSite: piwik.idSite
}, 'GET');
ajax.setCallback(function (response) {
$('.visitor-profile-avatar .loadingPiwik', $element).hide();
$('.visitor-profile-current-visit', $element).removeClass('visitor-profile-current-visit');
$visitElement.closest('li').addClass('visitor-profile-current-visit');
var $latestVisitSection = $('.visitor-profile-latest-visit', $element);
$latestVisitSection
.html(response)
.parent()
.effect('highlight', {color: '#FFFFCB'}, 1200);
});
ajax.setFormat('html');
ajax.send();
},
_loadPreviousVisitor: function () {
this._gotoAdjacentVisitor(this.$element.attr('data-prev-visitor'));
},
_loadNextVisitor: function () {
this._gotoAdjacentVisitor(this.$element.attr('data-next-visitor'));
},
_gotoAdjacentVisitor: function (idVisitor) {
if (!idVisitor) {
return;
}
if (this._inPopover()) {
broadcast.propagateNewPopoverParameter('visitorProfile', idVisitor);
} else if (this._inWidget()) {
this.$element.closest('[widgetid]').dashboardWidget('reload', false, true, {visitorId: idVisitor});
}
},
_getFirstVisitId: function () {
return $('.visitor-profile-visits>li:first-child>h2', this.$element).attr('data-idvisit');
},
_inPopover: function () {
return !! this.$element.closest('#Piwik_Popover').length;
},
_inWidget: function () {
return !! this.$element.closest('.widget').length;
}
});
exports.VisitorProfileControl = VisitorProfileControl;
// add the popup handler that creates a visitor profile
broadcast.addPopoverHandler('visitorProfile', VisitorProfileControl.showPopover);
})(jQuery, require);