/*! * Matomo - free/libre analytics platform * * @link https://matomo.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) { if (that.options.replaceContent) { $(that.element).html(r); if (that.options.fadeInSpeed) { $(that.element).effect("highlight", {}, that.options.fadeInSpeed); } } else { that._parseResponse(r); } that.options.interval = parseInt(that.options.interval, 10); // 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.length && $.contains(document, that.element[0])) { that.updateInterval = window.setTimeout(function() { that._update() }, that.currentInterval); } } }); ajaxRequest.send(); }, /** * 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.visit', $(data)); for (var i = items.length; i--;) { this._parseItem(items[i]); } this._initTooltips(); }, /** * Initializes the icon tooltips */ _initTooltips: function() { $('li.visit').tooltip({ items: '.visitorLogIconWithDetails', track: true, show: false, hide: false, content: function() { return $('