meteor-ionic/components/ionLoading/ionLoading.js
2015-02-18 13:09:51 -06:00

48 lines
1.2 KiB
JavaScript

IonLoading = {
show: function (userOptions) {
var userOptions = userOptions || {};
var options = _.extend({
delay: 0,
duration: null,
customTemplate: null,
backdrop: false
}, userOptions);
if (options.backdrop) {
IonBackdrop.retain();
$('.backdrop').addClass('backdrop-loading');
}
Meteor.setTimeout(function () {
this.template = Template['ionLoading'];
this.view = Blaze.renderWithData(this.template, {template: options.customTemplate}, $('.ionic-body').get(0));
var $loadingEl = $(this.view.firstNode());
$loadingEl.addClass('visible');
Meteor.setTimeout(function () {
$loadingEl.addClass('active');
}, 10);
}.bind(this), options.delay);
if (options.duration) {
Meteor.setTimeout(function () {
this.hide();
}.bind(this), options.duration);
}
},
hide: function () {
if (this.view) {
var $loadingEl = $(this.view.firstNode());
$loadingEl.removeClass('active');
Meteor.setTimeout(function () {
IonBackdrop.release();
$loadingEl.removeClass('visible');
Blaze.remove(this.view);
this.view = null;
}.bind(this), 400);
}
}
};