Skip to content

Commit

Permalink
Async content rerendering and in demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan Graham Walker committed May 22, 2016
1 parent aca1a53 commit 0ad21b8
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 4 deletions.
27 changes: 27 additions & 0 deletions addon/components/tooltip-on-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export default EmberTetherComponent.extend({
tooltipIsVisible: false,
keepInWindow: true,

/*
When this property changes it repositions the tooltip.
This isn't actually used in the code anywhere - it just
needs to be passed as an attribute so didUpdate is
triggered.
@property updateFor
*/

updateFor: null,

/* Actions */

onTooltipDestroy: null,
Expand Down Expand Up @@ -322,6 +334,21 @@ export default EmberTetherComponent.extend({
this.set('offset', offset);
},

/*
Repositions the tooltip if new attributes or content are
passed to the tooltip.
@method didUpdate
*/

didUpdate() {
this._super(...arguments);

run.later(() => {
this.positionTether();
}, 1000);
},

/*
We use an observer so the user can set tooltipIsVisible
as a attribute.
Expand Down
16 changes: 14 additions & 2 deletions tests/dummy/app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ import Ember from 'ember';
const { run } = Ember;

export default Ember.Controller.extend({
asyncContent: null,
showTooltips: false,

actions: {
setAsyncContent() {
return new Ember.RSVP.Promise((resolve) => {
run.later(() => {
this.set('asyncContent', 'Some model');
resolve();
}, 2000);
});
},
},

init() {
run.scheduleOnce('afterRender', () => {
run.later(() => {
this.set('showTooltips', true);
this.set('showLogoTooltip', true);
}, 1000);
});
}
},

});
46 changes: 46 additions & 0 deletions tests/dummy/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,49 @@ hr {
input {
@include rem(padding, 0.4, 0.6);
}

/* Async spinner */

.spinner {
margin: 5px 0;
width: 70px;
text-align: center;
}

.spinner > div {
width: 6px;
height: 6px;
background-color: #fff;

border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}

.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}

.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}

@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0) }
40% { -webkit-transform: scale(1.0) }
}

@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}

/* End of async spinner */
30 changes: 28 additions & 2 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class='logo-tooltip'
event='none'
target='#ember-logo'
tooltipIsVisible=showTooltips
tooltipIsVisible=showLogoTooltip
side='right'
spacing=15
}}
Expand Down Expand Up @@ -109,7 +109,7 @@

{{!-- BEGIN-SNIPPET using-with-duration --}}
{{#some-component}}
Tooltip wil disappear after 1000ms
Tooltip will disappear after 1000ms

{{#tooltip-on-component duration=1000}}
Here is the info!
Expand Down Expand Up @@ -144,3 +144,29 @@
{{code-snippet name='custom-styling.hbs'}}

</div>

<div class="page-content">
<h3>Using async content</h3>

{{!-- BEGIN-SNIPPET async-content --}}
{{#some-component}}
Tooltip has async content

{{#tooltip-on-component onTooltipShow='setAsyncContent' updateFor=asyncContent}}
{{#if asyncContent}}
{{asyncContent}}
{{else}}
{{!-- Some custom spinner --}}
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
{{/if}}
{{/tooltip-on-component}}
{{/some-component}}
{{!-- END-SNIPPET --}}

{{code-snippet name='async-content.hbs'}}

</div>

0 comments on commit 0ad21b8

Please sign in to comment.