Skip to content

Instantly share code, notes, and snippets.

@senica
Last active May 24, 2016 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senica/7c57aa21f586eaca700ae91e12f60c87 to your computer and use it in GitHub Desktop.
Save senica/7c57aa21f586eaca700ae91e12f60c87 to your computer and use it in GitHub Desktop.
RiotJS wrapper for the Trix text editor
<trix>
<input id={'trix-'+_riot_id} value={opts.content} type="hidden" />
<trix-editor name="trix" class="trix-content" input={'trix-'+_riot_id} ></trix-editor>
<script>
/*
* <trix trix-change={changetext} content={content}></trix>
* You can bind to any of the trix events
*/
this.on('mount', function(){
jQuery(this.trix).on('trix-initialize trix-change trix-selection-change trix-focus trix-blur trix-file-accept trix-attachment-add trix-attachment-remove', function(e){
// opts are turned to camel case - match to that
e.type = e.type.replace(/-([a-z])/g, function (m, w) { return w.toUpperCase(); });
if(typeof this.opts[e.type] === 'function'){
this.opts[e.type].call(this, e, this.trix, this["{'trix-'+_riot_id}"].value);
}
}.bind(this));
})
this.on('before-unmount', function(){
this.original = null;
delete this.original;
jQuery(this.trix).off();
})
</script>
</trix>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment