Skip to content

Instantly share code, notes, and snippets.

@3AHAT0P
Last active December 10, 2016 15:30
Show Gist options
  • Save 3AHAT0P/82838dbf90847f89eebc2c62ba46dc8f to your computer and use it in GitHub Desktop.
Save 3AHAT0P/82838dbf90847f89eebc2c62ba46dc8f to your computer and use it in GitHub Desktop.
Ember 2.10.0 #14704 workaround
import Ember from 'ember';
const {
String: { htmlSafe }
} = Ember;
export default Ember.Component.extend({
attributeBindings: 'style'.w(),
style: '',
getStyle(propName) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
console.log('123', style);
return style.match(regexp);
},
setStyle(propName, value) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
if (regexp.test(style)) {
console.log('1', style);
this.set('style', htmlSafe(style.replace(regexp, `${propName}:${value};`)));
console.log('12', this.get('style'));
} else {
console.log('2', style);
this.set('style', Ember.String.htmlSafe(`${style}${propName}:${value};`));
console.log('22', this.get('style'));
}
return value;
},
init() {
this._super(...arguments);
this.set('style', htmlSafe(this.get('style')));
Ember.run.later(this, () => {
this.set('isVisible', true);
}, 5000);
},
didInsertElement() {
this._super(...arguments);
this.setStyle('color', 'blue');
}
});
import Ember from 'ember';
const {
String: { htmlSafe }
} = Ember;
export default Ember.Component.extend({
isVisible: false,
attributeBindings: 'style'.w(),
style: '',
getStyle(propName) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
console.log('123', style);
return style.match(regexp);
},
setStyle(propName, value) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
if (regexp.test(style)) {
console.log('1', style);
this.set('style', htmlSafe(style.replace(regexp, `${propName}:${value};`)));
console.log('12', this.get('style'));
} else {
console.log('2', style);
this.set('style', Ember.String.htmlSafe(`${style}${propName}:${value};`));
console.log('22', this.get('style'));
}
return value;
},
init() {
this._super(...arguments);
this.set('style', htmlSafe(this.get('style')));
Ember.run.later(this, () => {
this.set('isVisible', true);
}, 5000);
},
didInsertElement() {
this._super(...arguments);
this.setStyle('color', 'red');
}
});
import Ember from 'ember';
const {
String: { htmlSafe }
} = Ember;
export default Ember.Component.extend({
attributeBindings: 'style'.w(),
style: '',
getStyle(propName) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
console.log('123', style);
return style.match(regexp);
},
setStyle(propName, value) {
let style = this.get('style.string'),
regexp = new RegExp(`${propName}\\:[\\w\\s\\d]*\\;`, 'ig');
if (regexp.test(style)) {
console.log('1', style);
this.set('style', htmlSafe(style.replace(regexp, `${propName}:${value};`)));
console.log('12', this.get('style'));
} else {
console.log('2', style);
this.set('style', Ember.String.htmlSafe(`${style}${propName}:${value};`));
console.log('22', this.get('style'));
}
return value;
},
init() {
this._super(...arguments);
this.set('style', htmlSafe(this.get('style')));
Ember.run.later(this, () => {
this.set('isVisible', false);
}, 5000);
Ember.run.later(this, () => {
this.set('isVisible', true);
}, 10000);
},
didInsertElement() {
this._super(...arguments);
this.setStyle('color', 'red');
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
textAreaVisible: true,
actions: {
toggleVisibilityTextArea() {
this.toggleProperty('textAreaVisible');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<div>{{test-one}}</div>
<div>{{test-two}}</div>
<div>{{test-three}}</div>
<div>{{textarea isVisible=textAreaVisible}}</div>
<button type='button' {{action 'toggleVisibilityTextArea'}}> Toggle visibility TextArea</button>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "release",
"ember-data": "2.9.0",
"ember-template-compiler": "release",
"ember-testing": "release"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment