1234567891011121314151617181920212223242526272829303132 |
- // This collection stores all the documents.
- // Note: not Documents, but this.Documents, because of the editing package (?)
- this.Documents = new Mongo.Collection("documents");
- if (Meteor.isClient) {
- Template.editor.helpers({
- // Return the id of the first document you can find.
- docid: function () {
- const doc = Documents.findOne();
- return doc ? doc._id : undefined;
- },
- // Configure the CodeMirror editor.
- config: function () {
- return function (editor) {
- editor.on("change", function (cm_editor, info) {
- let $preview = $("#viewer_iframe");
- $preview.contents().find("html").html(cm_editor.getValue());
- });
- };
- },
- });
- }
- if (Meteor.isServer) {
- Meteor.startup(function () {
- // Insert a document if there isn't one already.
- if (!Documents.findOne()) {
- Documents.insert({ title: "my new document" });
- }
- });
- }
|