From 94799537f84f0be7a3ad2da3bf289ed2783c3b27 Mon Sep 17 00:00:00 2001
From: Benaka Moorthi <benaka.moorthi@gmail.com>
Date: Wed, 11 Sep 2013 20:56:56 -0400
Subject: [PATCH] Refs #4116, move initElements code to utility function in
 UIControl.

---
 plugins/CoreHome/javascripts/uiControl.js          | 9 +++++++++
 plugins/Live/API.php                               | 3 ++-
 plugins/Live/javascripts/visitorProfile.js         | 9 +--------
 plugins/UserCountryMap/javascripts/realtime-map.js | 9 +--------
 plugins/UserCountryMap/templates/realtimeMap.twig  | 2 +-
 5 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/plugins/CoreHome/javascripts/uiControl.js b/plugins/CoreHome/javascripts/uiControl.js
index 58d9662acb..454b7134ff 100644
--- a/plugins/CoreHome/javascripts/uiControl.js
+++ b/plugins/CoreHome/javascripts/uiControl.js
@@ -56,6 +56,15 @@
         }
     };
 
+    UIControl.initElements = function (klass, selector) {
+        $(selector).each(function () {
+            if (!$(this).attr('data-inited')) {
+                var control = new klass(this);
+                $(this).attr('data-inited', 1);
+            }
+        });
+    };
+
     UIControl.prototype = {
 
         /**
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 0fa645f0ff..c58aefbed0 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -153,7 +153,8 @@ class API
      * @param bool $doNotFetchActions
      * @return DataTable
      */
-    public function getLastVisitsDetails($idSite, $period, $date, $segment = false, $filter_limit = false, $filter_offset = false, $minTimestamp = false, $flat = false, $doNotFetchActions = false)
+    public function getLastVisitsDetails($idSite, $period = false, $date = false, $segment = false, $filter_limit = false,
+                                         $filter_offset = false, $minTimestamp = false, $flat = false, $doNotFetchActions = false)
     {
         if (empty($filter_limit)) {
             $filter_limit = 10;
diff --git a/plugins/Live/javascripts/visitorProfile.js b/plugins/Live/javascripts/visitorProfile.js
index 112f2c0781..7c1aa9a301 100644
--- a/plugins/Live/javascripts/visitorProfile.js
+++ b/plugins/Live/javascripts/visitorProfile.js
@@ -31,14 +31,7 @@
      * if the element has not already been initialized.
      */
     VisitorProfileControl.initElements = function () {
-        $('.visitor-profile').each(function () {
-            if (!$(this).attr('data-inited')) {
-                var control = new VisitorProfileControl(this);
-
-                $(this).data('uiControlObject', control);
-                $(this).attr('data-inited', 1);
-            }
-        });
+        UIControl.initElements(this, '.visitor-profile');
     };
 
     /**
diff --git a/plugins/UserCountryMap/javascripts/realtime-map.js b/plugins/UserCountryMap/javascripts/realtime-map.js
index e4e4eef09f..2c35c56f25 100644
--- a/plugins/UserCountryMap/javascripts/realtime-map.js
+++ b/plugins/UserCountryMap/javascripts/realtime-map.js
@@ -19,14 +19,7 @@
     };
 
     RealtimeMap.initElements = function () {
-        $('.RealTimeMap').each(function () {
-            if (!$(this).attr('data-inited')) {
-                var control = new RealtimeMap(this);
-
-                $(this).data('uiControlObject', control);
-                $(this).attr('data-inited', 1);
-            }
-        });
+        UIControl.initElements(this, '.RealTimeMap');
     };
 
     $.extend(RealtimeMap.prototype, UIControl.prototype, {
diff --git a/plugins/UserCountryMap/templates/realtimeMap.twig b/plugins/UserCountryMap/templates/realtimeMap.twig
index 8e7d90e51a..6881700d13 100644
--- a/plugins/UserCountryMap/templates/realtimeMap.twig
+++ b/plugins/UserCountryMap/templates/realtimeMap.twig
@@ -21,4 +21,4 @@
     </div>
 
 </div>
-<script type="text/javascript">UserCountryMap.RealtimeMap.initElements();</script>
+<script type="text/javascript">UserCountryMap.RealtimeMap.initElements();</script>
\ No newline at end of file
-- 
GitLab