Skip to content

Instantly share code, notes, and snippets.

@tehmaestro
Last active October 3, 2016 01:55
Show Gist options
  • Save tehmaestro/0dcbef3316252a48d4129b9902f28478 to your computer and use it in GitHub Desktop.
Save tehmaestro/0dcbef3316252a48d4129b9902f28478 to your computer and use it in GitHub Desktop.
My twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
items: [],
i: 1,
isAnimating: false,
actions: {
addItem: function() {
this.get('items').pushObject({id: this.get('i')});
Ember.run.next(this, this.animate);
}
},
animate: function() {
var self = this;
this.set('isAnimating', true);
let $item = Ember.$('#image-' + this.get('i'));
Ember.$.Velocity($item, {
translateX: ["0px", "50px"],
opacity: 1
}).then(function() {
self.incrementProperty('i');
self.set('isAnimating', false);
});
}
});
import Ember from 'ember';
export function myHelper([item]/*, hash*/) {
return Ember.String.htmlSafe('<div id="image-'+ item.id +'" class="image"></div>');
}
export default Ember.Helper.helper(myHelper);
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.image {
width: 30px;
height: 30px;
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.5/assets/png/1f603.png");
background-size: 100% 100%;
display: inline-block;
opacity: 0;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button {{action "addItem"}} disabled={{isAnimating}}>Add item to array</button>
<br>
<br>
{{#each items as |item|}}
{{my-helper item}}
{{/each}}
<br>
<br>
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "1.13.13",
"ember-data": "1.13.15",
"ember-template-compiler": "1.13.13",
"ember-testing": "1.13.13"
},
"addons": {
"liquid-fire": "0.23.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment