Skip to content

Instantly share code, notes, and snippets.

@phongjalvn
Forked from gabriel-dehan/edit.html
Created May 9, 2012 06:06
Show Gist options
  • Save phongjalvn/2642270 to your computer and use it in GitHub Desktop.
Save phongjalvn/2642270 to your computer and use it in GitHub Desktop.
Meteor wysiwyg livedata
<template name="editor">
<div class="well {{#if editor_mode}}editor-show{{/if}}" id="editor">
<textarea id="editor-area" placeholder="Enter your text ...">{{get_file}}</textarea>
</div>
</template>
Template.editor.get_file = function() {
var content = '';
if ( Session.get('edited_file') ) {
var file = File.findOne({ tree:Session.get('tree_id'), file_id:parseInt(Session.get('edited_file')) });
if ( file ) {
content = file.content;
}
}
return content;
};
Template.editor.events = {
'afterinsert' : function() {
if ( $("#editor-area") ) {
// Plugin that generates the wysiwyg editor, wrapping the textarea with the toolbar, and so on
$("#editor-area").markItUp(mySettings);
}
},
'keyup #editor-area' : function (e) {
// Should be server side, secured, and only accessible through meteor.calls but for testing, this is enough
File.update({ tree:Session.get('tree_id'), file_id:parseInt(Session.get('edited_file')) }, { $set : { content : $(e.target).val() }});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment