From de6ea98c72963204513191e8d79caef633d757d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Thu, 25 Sep 2014 18:00:54 +0200 Subject: [PATCH] Rerun async plugins after buffer switch TODO: cache result. This is necessary at the moment because currently, they just stop working after a buffer switch --- js/plugin-directive.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/plugin-directive.js b/js/plugin-directive.js index 7006a3e..d843d6e 100644 --- a/js/plugin-directive.js +++ b/js/plugin-directive.js @@ -33,17 +33,22 @@ weechat.directive('plugin', ['$rootScope', function($rootScope) { * content is shown. */ - // If the plugin is asynchronous / lazy, execute it now and store - // the result. This ensures that the callback is executed only once - if ($scope.plugin.content instanceof Function) { - $scope.plugin.content = $scope.plugin.content(); + var embed = document.querySelector(".embed_" + $scope.plugin.$$hashKey); + + // If the plugin is asynchronous / lazy, execute it now and let it insert itself + // TODO store the result between channel switches + if ($scope.plugin.content instanceof Function){ + // Don't rerun if the result is already there + if (embed.innerHTML === "") { + $scope.plugin.content(); + } + } else { + $scope.displayedContent = $scope.plugin.content; } - $scope.displayedContent = $scope.plugin.content; $scope.plugin.visible = true; // Scroll embed content into view var scroll = function() { - var embed = document.querySelector(".embed_" + $scope.plugin.$$hashKey); if (embed && embed.scrollIntoViewIfNeeded !== undefined) { embed.scrollIntoViewIfNeeded(); }