textcircle.js 828 B

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