var
H5ComponentBase =
function
( name, cfg ) {
var
cfg = cfg || {};
var
id = (
'h5_c_'
+Math.random() ).replace(
'.'
,
'_'
) ;
var
cls =
' h5_component_'
+cfg.type;
var
component = $(
'<div class="h5_component '
+cls+
' h5_component_name_'
+name+
'" id="'
+id+
'">'
);
cfg.text && component.text(cfg.text);
cfg.width && component.width(cfg.width/2);
cfg.height && component.height(cfg.height/2);
cfg.css && component.css( cfg.css );
cfg.bg && component.css(
'backgroundImage'
,
'url('
+cfg.bg+
')'
);
if
( cfg.center ===
true
){
component.css({
marginLeft : ( cfg.width/4 * -1) +
'px'
,
left:
'50%'
})
}
if
(
typeof
cfg.onclick ===
'function'
){
component.on(
'click'
,cfg.onclick);
}
component.on(
'onLoad'
,
function
(){
setTimeout(
function
(){
component.addClass(cls+
'_load'
).removeClass(cls+
'_leave'
);
cfg.animateIn && component.animate( cfg.animateIn );
},cfg.delay || 0)
return
false
;
})
component.on(
'onLeave'
,
function
(){
setTimeout(
function
(){
component.addClass(cls+
'_leave'
).removeClass(cls+
'_load'
);
cfg.animateOut && component.animate( cfg.animateOut );
},cfg.delay || 0)
return
false
;
})
this
.cfg = cfg;
this
.id = id;
this
.el = component;
return
this
;
}
var
H5ComponentBar =
function
( name, cfg ) {
H5ComponentBase.apply(
this
,[name,cfg])
var
component =
this
.el;
$.each(cfg.data,
function
(idx,item){
var
line = $(
'<div class="line">'
);
var
name = $(
'<div class="name">'
);
var
rate = $(
'<div class="rate">'
);
var
per = $(
'<div class="per">'
);
var
width = item[1]*100 +
'%'
;
var
bgStyle =
''
;
if
( item[2] ){
bgStyle =
'style="background-color:'
+item[2]+
'"'
;
}
rate.html(
'<div class="bg" '
+bgStyle+
'></div>'
);
rate.css(
'width'
,width);
name.text( item[0]);
per.text(width);
line.append( name ).append( rate ).append( per );
component.append(line);
});
this
.cfg = cfg;
this
.el = component;
return
this
;
}