Skip to content

Instantly share code, notes, and snippets.

@guido4000
Created April 21, 2014 06:00
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 guido4000/11133569 to your computer and use it in GitHub Desktop.
Save guido4000/11133569 to your computer and use it in GitHub Desktop.
/* Put your CSS here */
html, body {
margin: 20px;
}
.wysiwyg-editor {
width: 100%
}
.wysiwyg-preview {
margin-top: 24px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ember wysiwyg" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="http://hbrysiewicz.github.io/assets/css/summernote.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.5.0/ember.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" />
<script src='http://hbrysiewicz.github.io/assets/js/summernote.js'></script>
</head>
<body>
<script type="text/x-handlebars">
<div class='wysiwyg-container'>
{{wysiwyg-editor content=postContent header="Example"}}
</div>
<div class='wysiwyg-preview'>
{{{postContent}}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="components/wysiwyg-editor">
{{textarea classNames='wysiwyg-textarea form-control' value=content}}
</script>
</body>
</html>
App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
postContent: 'Hello, world!'
});
App.WysiwygEditorComponent = Ember.Component.extend({
classNames: ['wysiwyg-editor'],
btnSize: 'btn-xs',
height: 120,
willDestroyElement: function() {
this.$('textarea').destroy();
},
didInsertElement: function() {
var _this = this;
var btnSize = this.get('btnSize');
var height = this.get('height');
this.$('textarea').summernote({
height: height,
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['insert', ['link']],
['table', ['table']],
['help', ['help']]
]
});
var content = this.get('content');
this.$('textarea').code(content);
this.$('.btn').addClass(btnSize);
},
keyUp: function() {
this.doUpdate();
},
click: function() {
this.doUpdate();
},
doUpdate: function() {
var content = this.$('.note-editable').html();
this.set('content', content);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment