-
-
Save phongjalvn/2642270 to your computer and use it in GitHub Desktop.
Meteor wysiwyg livedata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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