diff --git a/js/glowingbear.js b/js/glowingbear.js index a1ac3d8..0efde02 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -1343,6 +1343,12 @@ weechat.directive('plugin', function($rootScope) { * Actual plugin content is only fetched when * 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(); + } $scope.displayedContent = $scope.plugin.content; $scope.plugin.visible = true; diff --git a/js/plugins.js b/js/plugins.js index afd31af..16a4545 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -60,8 +60,14 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) { if (num) { pluginName += " " + num; } + + // If content isn't a callback, it's HTML + if (!(content instanceof Function)) { + content = $sce.trustAsHtml(content); + } + message.metadata.push({ - 'content': $sce.trustAsHtml(content), + 'content': content, 'nsfw': nsfw, 'name': pluginName });