Add support for asynchronous / lazy plugins

Fixes #253
This commit is contained in:
Lorenz Hübschle-Schneider 2014-08-08 14:39:50 +01:00
parent 7ad1974d12
commit 703fcb1668
2 changed files with 13 additions and 1 deletions

View file

@ -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;

View file

@ -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
});