textcircle.js 914 B

1234567891011121314151617181920212223242526272829303132
  1. // This collection stores all the documents.
  2. // Note: not Documents, but this.Documents, because of the editing package (?)
  3. this.Documents = new Mongo.Collection("documents");
  4. if (Meteor.isClient) {
  5. Template.editor.helpers({
  6. // Return the id of the first document you can find.
  7. docid: function () {
  8. const doc = Documents.findOne();
  9. return doc ? doc._id : undefined;
  10. },
  11. // Configure the CodeMirror editor.
  12. config: function () {
  13. return function (editor) {
  14. editor.on("change", function (cm_editor, info) {
  15. let $preview = $("#viewer_iframe");
  16. $preview.contents().find("html").html(cm_editor.getValue());
  17. });
  18. };
  19. },
  20. });
  21. }
  22. if (Meteor.isServer) {
  23. Meteor.startup(function () {
  24. // Insert a document if there isn't one already.
  25. if (!Documents.findOne()) {
  26. Documents.insert({ title: "my new document" });
  27. }
  28. });
  29. }