module.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. /*global Showdown:false */
  4. /*
  5. ## Text
  6. A simple panel of static content
  7. ### Parameters
  8. * mode :: 'text', 'html', 'markdown'
  9. * content :: Content of the panel
  10. * style :: Hash containing css properties
  11. */
  12. 'use strict';
  13. angular.module('kibana.text', [])
  14. .controller('text', function($scope, $rootScope) {
  15. // Set and populate defaults
  16. var _d = {
  17. status : "Stable",
  18. group : "default",
  19. mode : "markdown",
  20. content : "",
  21. style: {},
  22. };
  23. _.defaults($scope.panel,_d);
  24. $scope.init = function() {
  25. $scope.ready = false;
  26. };
  27. }).directive('markdown', function() {
  28. return {
  29. restrict: 'E',
  30. link: function(scope, element, attrs) {
  31. scope.$on('render', function() {
  32. render_panel();
  33. });
  34. function render_panel() {
  35. var scripts = $LAB.script("panels/text/lib/showdown.js");
  36. scripts.wait(function(){
  37. scope.ready = true;
  38. var converter = new Showdown.converter();
  39. var text = scope.panel.content.replace(/&/g, '&')
  40. .replace(/>/g, '>')
  41. .replace(/</g, '&lt;');
  42. var htmlText = converter.makeHtml(text);
  43. element.html(htmlText);
  44. // For whatever reason, this fixes chrome. I don't like it, I think
  45. // it makes things slow?
  46. if(!scope.$$phase) {
  47. scope.$apply();
  48. }
  49. });
  50. }
  51. render_panel();
  52. }
  53. };
  54. })
  55. .filter('newlines', function(){
  56. return function (input) {
  57. return input.replace(/\n/g, '<br/>');
  58. };
  59. })
  60. .filter('striphtml', function () {
  61. return function(text) {
  62. return text
  63. .replace(/&/g, '&amp;')
  64. .replace(/>/g, '&gt;')
  65. .replace(/</g, '&lt;');
  66. };
  67. });