Skip to content

Instantly share code, notes, and snippets.

@astronomersiva
Last active March 26, 2019 14:47
Show Gist options
  • Save astronomersiva/2e230805a23b7e34a235074fa999fd81 to your computer and use it in GitHub Desktop.
Save astronomersiva/2e230805a23b7e34a235074fa999fd81 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Component.extend({
progressBar: service(),
didInsertElement() {
this._super(...arguments);
}
});
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
progressBar: service(),
actions: {
showProgress() {
this.get('progressBar').startLoading();
},
endProgress() {
this.get('progressBar').endLoading();
}
}
});
import Ember from 'ember';
import { later } from '@ember/runloop';
export default Ember.Service.extend({
start() {
let interval = (1000/60); // 16fps
let ratio = .1;
let progress = 0;
let timer = setInterval(() => {
progress = progress + ((progress || 20) * ratio);
if (ratio < 0.0005) {
ratio = ratio * .999;
} else {
ratio = ratio * .97;
}
this.set('width', `${progress}%`);
if (progress > 100) {
this.set('width', `100%`);
clearInterval(timer);
}
}, interval);
this.timer = timer;
},
startLoading() {
this.set('width', 0);
this.set('canShow', true);
this.start();
},
endLoading() {
clearInterval(this.timer);
this.set('width', `100%`);
this.set('complete', true);
later(() => {
this.set('width', 0);
this.set('complete', false);
this.set('canShow', false);
}, 300);
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.progress-complete {
transition: width linear .15s;
}
.progress {
position: absolute;
height: 3px;
background: #0eb477;
top: 0;
left: 0;
}
.progress-lead {
position: absolute;
right: 0;
top: 0;
height: 100%;
width: 40px;
box-shadow: #0eb477ff 0px 0px 10px;
transform: rotate(3deg) translate(0px,-4px);
translate: -10%;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component}}
<button {{action "showProgress"}}>heel</button>
<button {{action "endProgress"}}>stop</button>
{{outlet}}
<br>
<br>
{{# if progressBar.canShow}}
<div class="progress {{if progressBar.complete 'progress-complete'}}" style="width:{{progressBar.width}}">
<div class="progress-lead"></div>
</div>
{{/if}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment