Last active
May 24, 2016 17:07
-
-
Save senica/7c57aa21f586eaca700ae91e12f60c87 to your computer and use it in GitHub Desktop.
RiotJS wrapper for the Trix text editor
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
<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