/home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/stories/story.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/stories/story.js

  1. /**
  2. A **Story** defines a panel of text generated from markdown.
  3.  
  4. Story is the base class for:
  5.  
  6. * {{#crossLink "AnnotationStory"}}{{/crossLink}} - a list of
  7. {{#crossLink "Annotation"}}Annotations{{/crossLink}} accompanied by a panel of text containing links
  8. that activate them.
  9.  
  10. @class Story
  11. @module xeogl
  12. @submodule stories
  13. @constructor
  14. @param [scene] {Scene} Parent {{#crossLink "Scene"}}Scene{{/crossLink}} - creates this Story in the default
  15. {{#crossLink "Scene"}}Scene{{/crossLink}} when omitted.
  16. @param [cfg] {*} Configs
  17. @param [cfg.id] {String} Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}},
  18. generated automatically when omitted.
  19. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this Story.
  20. @param [cfg.text=""] {String} Story text in markdown format.
  21. @extends Component
  22. */
  23. {
  24. var converter = new showdown.Converter();
  25.  
  26. function idToString(id) {
  27. return xeogl._isNumeric(id) ? id : ("'" + id + "'");
  28. }
  29.  
  30. xeogl.Story = class xeoglStory extends xeogl.Component {
  31.  
  32. init(cfg) {
  33. this._container = document.createElement("div");
  34. this._container.className = "xeogl-story";
  35. document.body.appendChild(this._container);
  36. this._actions = cfg.actions || {};
  37. this.text = cfg.text;
  38. }
  39.  
  40. set text(value) {
  41. this._text = value || [];
  42. this._updateText();
  43. }
  44.  
  45. get text() {
  46. return this._text;
  47. }
  48.  
  49. _updateText() {
  50. var text = this._text.join("\n");
  51. for (var action in this._actions) {
  52. if (this._actions.hasOwnProperty(action)) {
  53. text = text.split(action + "(").join("javascript:xeogl.scenes[" +
  54. idToString(this.scene.id) + "].components[" + idToString(this.id) + "]._actions." + action + ".call(xeogl.scenes[" +
  55. idToString(this.scene.id) + "].components[" + idToString(this.id) + "],");
  56. }
  57. }
  58. this._container.innerHTML = converter.makeHtml(text);
  59. }
  60.  
  61. _clear() {
  62. this._text = [];
  63. this._container.innerHTML = "";
  64. }
  65.  
  66. _getJSON() {
  67. return {
  68. text: this._text.slice()
  69. };
  70. }
  71.  
  72. destroy() {
  73. super.destroy();
  74. this._container.parentNode.removeChild(this._container);
  75. }
  76. }
  77. }
  78.