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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 03:39:59 +0400
committerBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 03:39:59 +0400
commit6d884e19f5d870c8c0647ec2bac68fa546115578 (patch)
tree1e1dbda09d046cf06e1644dba48e47159fc52722 /plugins/CoreHome
parent94eff35d47c5be86d88b51e933bec3fb8ee450cd (diff)
Refs #3089, #4116, display visitor profile popup when visit in realtime map is clicked.
Notes: - Includes new UIControl base type. - Fixes cleanup bugs in realtime map and popover closing. - Refactored realtime map so as little JavaScript as possible is included in HTML fragments. - Allow more than one realtime map to exist on a single page.
Diffstat (limited to 'plugins/CoreHome')
-rw-r--r--plugins/CoreHome/CoreHome.php1
-rw-r--r--plugins/CoreHome/javascripts/broadcast.js3
-rw-r--r--plugins/CoreHome/javascripts/popover.js1
-rw-r--r--plugins/CoreHome/javascripts/uiControl.js75
4 files changed, 80 insertions, 0 deletions
diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php
index 64fe4b56dd..5ed00a718a 100644
--- a/plugins/CoreHome/CoreHome.php
+++ b/plugins/CoreHome/CoreHome.php
@@ -72,6 +72,7 @@ class CoreHome extends \Piwik\Plugin
$jsFiles[] = "plugins/Zeitgeist/javascripts/piwikHelper.js";
$jsFiles[] = "plugins/Zeitgeist/javascripts/ajaxHelper.js";
$jsFiles[] = "plugins/CoreHome/javascripts/require.js";
+ $jsFiles[] = "plugins/CoreHome/javascripts/uiControl.js";
$jsFiles[] = "plugins/CoreHome/javascripts/dataTable.js";
$jsFiles[] = "plugins/CoreHome/javascripts/dataTable_rowactions.js";
$jsFiles[] = "plugins/CoreHome/javascripts/popover.js";
diff --git a/plugins/CoreHome/javascripts/broadcast.js b/plugins/CoreHome/javascripts/broadcast.js
index fe30534120..19aeb74bbc 100644
--- a/plugins/CoreHome/javascripts/broadcast.js
+++ b/plugins/CoreHome/javascripts/broadcast.js
@@ -130,6 +130,9 @@ var broadcast = {
// make sure the "Widgets & Dashboard" is deleted on reload
$('#dashboardSettings').remove();
$('#dashboardWidgetsArea').dashboard('destroy');
+
+ // remove unused controls
+ require('piwik/UI').UIControl.cleanupUnusedControls();
}
}
diff --git a/plugins/CoreHome/javascripts/popover.js b/plugins/CoreHome/javascripts/popover.js
index e3ff6d9326..22b23eab38 100644
--- a/plugins/CoreHome/javascripts/popover.js
+++ b/plugins/CoreHome/javascripts/popover.js
@@ -45,6 +45,7 @@ var Piwik_Popover = (function () {
$('.ui-widget-overlay').off('click.popover');
isOpen = false;
broadcast.propagateNewPopoverParameter(false);
+ require('piwik/UI').UIControl.cleanupUnusedControls();
if (typeof closeCallback == 'function') {
closeCallback();
closeCallback = false;
diff --git a/plugins/CoreHome/javascripts/uiControl.js b/plugins/CoreHome/javascripts/uiControl.js
new file mode 100644
index 0000000000..58d9662acb
--- /dev/null
+++ b/plugins/CoreHome/javascripts/uiControl.js
@@ -0,0 +1,75 @@
+/**
+ * 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');
+
+ /**
+ * Base type for Piwik UI controls. Provides functionality that all controls need (such as
+ * cleanup on destruction).
+ *
+ * @param {Element} element The root element of the control.
+ */
+ var UIControl = function (element) {
+ this._controlIndex = UIControl._controls.length;
+ UIControl._controls.push(this);
+
+ var $element = this.$element = $(element);
+ $element.data('uiControlObject', this);
+ };
+
+ /**
+ * Contains all active control instances.
+ */
+ UIControl._controls = [];
+
+ /**
+ * Utility method that will clean up all piwik UI controls whose elements are not attached
+ * to the DOM.
+ *
+ * TODO: instead of having other pieces of the UI manually calling cleanupUnusedControls,
+ * MutationObservers should be called
+ */
+ UIControl.cleanupUnusedControls = function () {
+ var controls = UIControl._controls;
+
+ for (var i = 0; i != controls.length; ++i) {
+ var control = controls[i];
+ if (control.$element
+ && !$.contains(document.documentElement, control.$element[0])
+ ) {
+ controls[i] = null;
+ control._destroy();
+
+ if (!control._baseDestroyCalled) {
+ throw new Error("Error: " + control.constructor.name + "'s destroy method does not call " +
+ "UIControl.destroy. You may have a memory leak.");
+ }
+ }
+ }
+ };
+
+ UIControl.prototype = {
+
+ /**
+ * Perform cleanup. Called when the control has been removed from the DOM. Derived
+ * classes should overload this function to perform their own cleanup.
+ */
+ _destroy: function () {
+ this.$element.removeData('uiControlObject');
+ delete this.$element;
+
+ this._baseDestroyCalled = true;
+ },
+ };
+
+ exports.UIControl = UIControl;
+
+})(jQuery, require); \ No newline at end of file