25 |
26 | {{> froalaReactive getFEContext}}
27 |
28 |
29 | ```
30 |
31 | ```javascript
32 | Template.myTemplate.helpers({
33 | getFEContext: function () {
34 | var self = this;
35 | self.myDoc.myHTMLField = 'Hello World !';
36 | return {
37 | // Set html content
38 | _value: self.myDoc.myHTMLField,
39 | // Preserving cursor markers
40 | _keepMarkers: true,
41 | // Override wrapper class
42 | _className: "froala-reactive-meteorized-override",
43 |
44 | // Set some FE options
45 | // toolbarInline: true,
46 | initOnClick: false,
47 | tabSpaces: false,
48 |
49 | // FE save.before event handler function:
50 | "_onsave.before": function ( editor) {
51 | // Get edited HTML from Froala-Editor
52 | var newHTML = editor.html.get(true /* keep_markers */);
53 | // Do something to update the edited value provided by the Froala-Editor plugin, if it has changed:
54 | if (!_.isEqual(newHTML, self.myDoc.myHTMLField)) {
55 | console.log("onSave HTML is :"+newHTML);
56 | myCollection.update({_id: self.myDoc._id}, {
57 | $set: {myHTMLField: newHTML}
58 | });
59 | }
60 | return false; // Stop Froala Editor from POSTing to the Save URL
61 | },
62 | }
63 | },
64 | })
65 | ```
66 |
67 | Where:
68 |
69 | * The "myTemplate" template has a data context that contains a 'myDoc' property, which itself contains '_id' and 'myHTMLField' properties.
70 | * We use a helper to build the data context object to pass to the froalalReactive template.
71 | * We set some [Froala Editor options](https://www.froala.com/wysiwyg-editor/docs/options)
72 | * The `"_onsave.before"` property provides a callback function to handle the Froala-Editor [save.before](https://www.froala.com/wysiwyg-editor/docs/events#save.before) event.
73 | * The `_value` argument provides the HTML string that you want to display and edit
74 |
75 | Here, we are triggering the update of the underlying 'myDoc' document record in the 'myCollection' collection when the Froala Editor 'beforeSave' event triggers. We could easily have used the 'blur' or 'contentChanged' events instead.
76 |
77 | The final line in the callback stops Froala Editor from generating its own AJAX call to post the updated HTML contents, because we have used the awesomeness of Meteor to do that for us instead.
78 |
79 | Note that Froala-Reactive *does not* automatically update the edited `_value`, you
80 | have to provide your own Froala-Editor event handler(s) to do that.
81 |
82 | However, Froala-Reactive *will* reactively update the displayed `_value` HTML immediately if you have assigned it to a data context property or template helper function which changes its value any time after the template has rendered (e.g. if the underlying collection document is updated from the server, or another action on the client).
83 |
84 |
85 | ## Events
86 |
87 | You can provide callbacks for any of the Froala-Editor [events](https://froala.com/wysiwyg-editor/docs/events) by specifying `_on