Skip to content

Instantly share code, notes, and snippets.

@edygar
Last active December 23, 2015 15:01
Show Gist options
  • Save edygar/778f5970cdf38952c3c2 to your computer and use it in GitHub Desktop.
Save edygar/778f5970cdf38952c3c2 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
init() {
setTimeout(()=>{
this.set('value',
`
<h2>Permito qualquer tag?</h2>
entende pq Michael?
`);
}, 2000);
}
});
Meu "input":
{{meu-input value=value}}
<h2>Valor livre de HTML </h2>
substitui as &lt;br/&gt; por \n e &amp;nbsp; por ' ':
<pre>{{value}}</pre>
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['meu-input'],
attributeBindings: [ 'contentEditable' ],
contentEditable: true,
valueDidChange: Ember.observer('value', function() {
this.element.innerHTML = Ember.Handlebars.Utils.escapeExpression(this.value)
.replace(/\n/g, '<br/>')
.replace(/ {2}/g, ' &nbsp;');
}),
input(event) {
console.log(this.element.innerHTML);
const value = this.element.innerHTML
.replace(/&nbsp;/g, ' ')
.replace(/<\/?div.*?>/g, '\n')
.replace(/<br\s*\/?>/g, '\n');
this.removeObserver('value', this, this.valueDidChange);
this.set('value', value);
this.addObserver('value', this, this.valueDidChange);
},
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.meu-input {
border: 1px solid #999;
border-radius: 6px;
min-height: 1em;
padding: 6px;
}
{
"version": "0.4.17",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment