2014-08-24 18:53:55 +02:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2014-08-28 18:25:40 +02:00
|
|
|
var weechat = angular.module('weechat');
|
|
|
|
|
|
|
|
weechat.directive('plugin', ['$rootScope', function($rootScope) {
|
|
|
|
/*
|
|
|
|
* Plugin directive
|
|
|
|
* Shows additional plugin content
|
|
|
|
*/
|
|
|
|
return {
|
|
|
|
templateUrl: 'directives/plugin.html',
|
|
|
|
|
|
|
|
scope: {
|
|
|
|
plugin: '=data'
|
|
|
|
},
|
|
|
|
|
|
|
|
controller: ['$scope', function($scope) {
|
|
|
|
|
|
|
|
$scope.displayedContent = "";
|
|
|
|
|
|
|
|
$scope.plugin.visible = $rootScope.auto_display_embedded_content;
|
|
|
|
|
|
|
|
$scope.hideContent = function() {
|
|
|
|
$scope.plugin.visible = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showContent = function() {
|
|
|
|
/*
|
|
|
|
* Shows the plugin content.
|
|
|
|
* displayedContent is bound to the DOM.
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
// Scroll embed content into view
|
|
|
|
var scroll = function() {
|
|
|
|
var embed = document.querySelector(".embed_" + $scope.plugin.$$hashKey);
|
2014-08-27 10:53:57 +02:00
|
|
|
if (embed && embed.scrollIntoViewIfNeeded !== undefined) {
|
2014-08-28 18:25:40 +02:00
|
|
|
embed.scrollIntoViewIfNeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setTimeout(scroll, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($scope.plugin.visible) {
|
|
|
|
$scope.showContent();
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}]);
|
2014-08-24 18:53:55 +02:00
|
|
|
})();
|