bricks/bricks/running.js
2024-03-21 18:12:24 +08:00

48 lines
1.1 KiB
JavaScript

var bricks = window.bricks || {};
bricks.Running = class extends bricks.BaseModal {
/*
{
target:
icon:
}
*/
constructor(opts){
opts.auto_open = true;
opts.archor = 'cc';
opts.width='96px';
super(opts);
this.icon_w = new bricks.Icon({
url:opts.icon || bricks_resource('imgs/running.gif')
});
this.time_w = new bricks.Text({
text:'test123',
color:'#222',
wrap:false,
width:'50px',
i18n:false
});
this.time_start = new Date().getTime();
var box = new bricks.FHBox({width:'auto'});
box.add_widget(this.icon_w);
box.add_widget(this.time_w);
this.add_widget(box);
this.showtime_task = schedule_once(this.show_timepass.bind(this), 0.05);
}
show_timepass(){
var t = new Date().getTime() - this.time_start;
var txt = bricks.formatMs(t, 1);
this.time_w.set_text(txt);
this.showtime_task = schedule_once(this.show_timepass.bind(this), 0.05);
}
dismiss(){
if (this.showtime_task){
this.showtime_task.cancel();
this.showtime_task = null;
}
bricks.BaseModal.prototype.dismiss.bind(this)();
}
}
bricks.Factory.register('Running', bricks.Running);