diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index 3fc71ddd53065ec6346cf75a42276a94001a0636..a73c83bd6c2e07869e9aecdde6d6f8650e526189 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -145,6 +145,8 @@ class CoreHome extends \Piwik\Plugin $jsFiles[] = "plugins/CoreHome/angularjs/anchorLinkFix.js"; $jsFiles[] = "plugins/CoreHome/angularjs/http404check.js"; + $jsFiles[] = "plugins/CoreHome/angularjs/history/history.service.js"; + $jsFiles[] = "plugins/CoreHome/angularjs/siteselector/siteselector-model.service.js"; $jsFiles[] = "plugins/CoreHome/angularjs/siteselector/siteselector.controller.js"; $jsFiles[] = "plugins/CoreHome/angularjs/siteselector/siteselector.directive.js"; diff --git a/plugins/CoreHome/angularjs/history/history.service.js b/plugins/CoreHome/angularjs/history/history.service.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b75b9b3b37f88f5e124b88b22e244773f8e339 --- /dev/null +++ b/plugins/CoreHome/angularjs/history/history.service.js @@ -0,0 +1,47 @@ +/*! + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * TODO + */ +(function (window, $, broadcast) { + angular.module('piwikApp').service('historyService', historyService); + + historyService.$inject = ['$location', '$rootScope']; + + function historyService($location, $rootScope) { + var service = {}; + service.load = load; + service.init = init; + return service; + + function init() { + $rootScope.$on('$locationChangeSuccess', function () { + loadCurrentPage(); + }); + + loadCurrentPage(); + } + + function loadCurrentPage() { + // the location hash will have a #? prefix, which broadcast.pageload doesn't want + broadcast.pageload(window.location.hash.substring(2)); + } + + function load(hash) { + // make sure the hash is just the query parameter values, w/o a starting #, / or ? char. broadcast.pageload & $location.search should get neither + ['#', '/', '?'].forEach(function (char) { + if (hash.charAt(0) == char) { + hash = hash.substring(1); + } + }); + + $location.search(hash); + broadcast.pageload(hash); + } + } +})(window, jQuery, broadcast); \ No newline at end of file diff --git a/plugins/CoreHome/javascripts/broadcast.js b/plugins/CoreHome/javascripts/broadcast.js index aaad2bd70878d98cc80a410de92193fa54caf47d..5ada120a6bb738a0946dfa969a3a944458bef7eb 100644 --- a/plugins/CoreHome/javascripts/broadcast.js +++ b/plugins/CoreHome/javascripts/broadcast.js @@ -54,9 +54,9 @@ var broadcast = { } broadcast._isInit = true; - // Initialize history plugin. - // The callback is called at once by present location.hash - $.history.init(broadcast.pageload, {unescape: true}); + angular.element(document).injector().invoke(function (historyService) { + historyService.init(); + }); if(noLoadingMessage != true) { piwikHelper.showAjaxLoading(); @@ -222,7 +222,9 @@ var broadcast = { else { // Let history know about this new Hash and load it. broadcast.forceReload = true; - $.history.load(currentHashStr); + angular.element(document).injector().invoke(function (historyService) { + historyService.load(currentHashStr); + }); } }, @@ -378,7 +380,9 @@ var broadcast = { } broadcast.forceReload = false; - $.history.load(newHash); + angular.element(document).injector().invoke(function (historyService) { + historyService.load(newHash); + }); }, /**