textcircle.js 789 B

1234567891011121314151617181920212223242526272829
  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. docid: function () {
  6. let doc = Documents.findOne();
  7. return doc ? doc._id : undefined;
  8. },
  9. config: function () {
  10. return function (editor) {
  11. editor.on("change", function (cm_editor, info) {
  12. let $preview = $("#viewer_iframe");
  13. $preview.contents().find("html").html(cm_editor.getValue());
  14. });
  15. };
  16. }
  17. });
  18. }
  19. if (Meteor.isServer) {
  20. Meteor.startup(function () {
  21. // startup code that creates a document in case there isn't one yet.
  22. if (!Documents.findOne()) {
  23. Documents.insert({ title: "my new document" });
  24. }
  25. });
  26. }