From c6ac229c8e7d6cf032d50ae604f829933b11fd73 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 25 Feb 2013 22:04:50 +0000 Subject: [PATCH] Refs #1845, switch to async JS in other places and apply fixes to tracking code admin page & other pages. Notes: * Fix bug in Installation page that displays JS where newlines were not displayed and text would not be selected on click. * Modify piwik.js to make sure setTrackerUrl is called before _paq is processed. * Move _paq modifications in tracker code to global scope outside every anonymous function. * Fix bug in rewritten site selector widget where selecting the same site didn't fire an event (necessary for some uses). * Fix bug where change of site resulted in delay before site name in labels changed. * Fix bug where site name was double encoded in tracking code admin page. * Rewrite piwik_tag.tpl to use async tracking code. --- core/Piwik.php | 2 +- core/Tracker/javascriptCode.tpl | 25 ++++---- js/piwik.js | 13 ++++- .../templates/jsTrackingGenerator.js | 58 +++++++++---------- .../templates/jsTrackingGenerator.tpl | 4 +- plugins/CoreHome/templates/autocomplete.js | 34 +++++------ plugins/CoreHome/templates/piwik_tag.tpl | 44 ++++++++------ .../templates/DisplayJavascriptCode.tpl | 32 +++++++++- .../SitesManager/templates/SitesManager.tpl | 2 +- .../UsersManager/templates/UsersManager.js | 15 +++-- themes/default/styles.css | 4 ++ 11 files changed, 143 insertions(+), 90 deletions(-) diff --git a/core/Piwik.php b/core/Piwik.php index 9ad4eee9412..c0dba6bdcc6 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -1618,7 +1618,7 @@ static public function getPrettyNumber( $value ) static public function getJavascriptCode($idSite, $piwikUrl) { $jsCode = file_get_contents( PIWIK_INCLUDE_PATH . "/core/Tracker/javascriptCode.tpl"); - $jsCode = nl2br(htmlentities($jsCode)); + $jsCode = htmlentities($jsCode); $piwikUrl = preg_match('~^(http|https)://(.*)$~D', $piwikUrl, $matches); $piwikUrl = @$matches[2]; $jsCode = str_replace('{$idSite}', $idSite, $jsCode); diff --git a/core/Tracker/javascriptCode.tpl b/core/Tracker/javascriptCode.tpl index 1a7673c2ed4..51bbbd13ef7 100644 --- a/core/Tracker/javascriptCode.tpl +++ b/core/Tracker/javascriptCode.tpl @@ -1,11 +1,16 @@ - + + + diff --git a/js/piwik.js b/js/piwik.js index 310d9a510d0..e1fe744a573 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2882,9 +2882,20 @@ var Date.prototype.getTimeAlias = Date.prototype.getTime; asyncTracker = new Tracker(); + + // find the call to setTrackerUrl (if any) and call it first + for (i = 0; i < _paq.length; i++) { + if (_paq[i][0] == 'setTrackerUrl') { + apply(_paq[i]); + delete _paq[i]; + } + } + // apply the queue of actions for (i = 0; i < _paq.length; i++) { - apply(_paq[i]); + if (_paq[i]) { + apply(_paq[i]); + } } // replace initialization array with proxy object diff --git a/plugins/CoreAdminHome/templates/jsTrackingGenerator.js b/plugins/CoreAdminHome/templates/jsTrackingGenerator.js index 46e5a20afe8..017eb8959de 100644 --- a/plugins/CoreAdminHome/templates/jsTrackingGenerator.js +++ b/plugins/CoreAdminHome/templates/jsTrackingGenerator.js @@ -27,7 +27,7 @@ $(document).ready(function() { { var key = customVariables[i][0], value = customVariables[i][1]; - result += '_paq.push(["setCustomVariable", ' + (i + 1) + ', ' + JSON.stringify(key) + ', ' + result += ' _paq.push(["setCustomVariable", ' + (i + 1) + ', ' + JSON.stringify(key) + ', ' + JSON.stringify(value) + ', ' + JSON.stringify(scope) + ']);\n'; } } @@ -136,18 +136,17 @@ $(document).ready(function() { // resets the select options of a goal select using a site ID var resetGoalSelectItems = function (idsite, id) { - var newOptions = ''; + var selectElement = $('#' + id).html(''); + + selectElement.append($('').text(noneText)); var goals = allGoals[idsite] || []; for (var key in goals) { var goal = goals[key]; - newOptions += ''; + selectElement.append($('