module.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /** @scratch /panels/5
  2. * include::panels/text.asciidoc[]
  3. */
  4. /** @scratch /panels/text/0
  5. * == text
  6. * Status: *Stable*
  7. *
  8. * The text panel is used for displaying static text formated as markdown, sanitized html or as plain
  9. * text.
  10. *
  11. */
  12. define([
  13. 'angular',
  14. 'app',
  15. 'underscore',
  16. 'require'
  17. ],
  18. function (angular, app, _, require) {
  19. 'use strict';
  20. var module = angular.module('kibana.panels.text', []);
  21. app.useModule(module);
  22. module.controller('text', function($scope) {
  23. $scope.panelMeta = {
  24. description : "A static text panel that can use plain text, markdown, or (sanitized) HTML"
  25. };
  26. // Set and populate defaults
  27. var _d = {
  28. mode : "markdown", // 'html', 'markdown', 'text'
  29. content : "",
  30. style: {},
  31. };
  32. _.defaults($scope.panel,_d);
  33. $scope.init = function() {
  34. $scope.initBaseController(this, $scope);
  35. $scope.ready = false;
  36. };
  37. $scope.render = function() {
  38. $scope.$emit('render');
  39. };
  40. $scope.openEditor = function() {
  41. //$scope.$emit('open-modal','paneleditor');
  42. console.log('scope id', $scope.$id);
  43. };
  44. });
  45. module.directive('markdown', function() {
  46. return {
  47. restrict: 'E',
  48. link: function(scope, element) {
  49. scope.$on('render', function() {
  50. render_panel();
  51. });
  52. function render_panel() {
  53. require(['./lib/showdown'], function (Showdown) {
  54. scope.ready = true;
  55. var converter = new Showdown.converter();
  56. var text = scope.panel.content.replace(/&/g, '&')
  57. .replace(/>/g, '>')
  58. .replace(/</g, '&lt;');
  59. var htmlText = converter.makeHtml(text);
  60. element.html(htmlText);
  61. // For whatever reason, this fixes chrome. I don't like it, I think
  62. // it makes things slow?
  63. if(!scope.$$phase) {
  64. scope.$apply();
  65. }
  66. });
  67. }
  68. render_panel();
  69. }
  70. };
  71. });
  72. module.filter('newlines', function(){
  73. return function (input) {
  74. return input.replace(/\n/g, '<br/>');
  75. };
  76. });
  77. module.filter('striphtml', function () {
  78. return function(text) {
  79. return text
  80. .replace(/&/g, '&amp;')
  81. .replace(/>/g, '&gt;')
  82. .replace(/</g, '&lt;');
  83. };
  84. });
  85. });