FloatButton_wev8.js
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
define(['mUtil', "Component"],function(mUtil, Component) {
var comp = function(options) {
Component.super(this, options);
this.type = "FloatButton";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var goTopFn = function(){
$(".page-content").scrollTop(0);
};
var isGoTopFn = true;
var vm = this.viewModel = {
position:{
top: "auto",
right: "auto",
bottom: "auto",
left: "auto"
},
img: "",
text: "",
remind: false,
badge: null,
click: goTopFn
};
this.beforeMount = function(){
var compStyle = "";
for(var key in vm.position){
var value = vm.position[key];
if(value && value != "auto"){
compStyle += key + ":" + value + ";";
}
}
isGoTopFn = vm.click && (vm.click.toString() == goTopFn.toString());
if(isGoTopFn){
compStyle += "display:none;";
}
vm.compStyle = compStyle;
if(vm.badge === true){
vm.badge = mUtil.getActionUrl(this.type, {action:"getBadge", "mec_id": this.id}, this.pageid);
}
if(vm.text){
if(vm.text.length == 4){
vm.wordsClass = "fourletters";
}else if(vm.text.length > 4){
vm.wordsClass = "wordsLoop";
}
}
};
var $comp;
this.mounted = function(){
var that = this;
$comp = that.$el.children(".wev-comp-"+that.type);
that.$container.append($comp);
$comp.css("visibility", "visible");
if(isGoTopFn){
var $pageContent = that.$container.children(".page-content");
$pageContent.scroll(function(){
var h = $(window).height();
var t = $pageContent.scrollTop();
if(t > h){
$comp.show();
}else{
$comp.hide();
}
});
}
$comp.on("click", function(){
mUtil.eval(vm.click, that.pageid);
});
//绑定插件内部的pageChange方法
this.$on('pageChange', function(isPageIn){
if(!isGoTopFn){
$comp.toggle(isPageIn);
}
});
_floatButton.loadBadge();
};
this.refreshBadge = function(){
_floatButton.loadBadge();
};
var _floatButton = {
loadBadge: function(){
if(!vm.remind){
return;
}
var $badges = $(".wev-badge", $comp);
require(["remindHelper"], function(helper){
helper.renderBadge(vm.badge, $badges, vm.remindapi);
});
}
};
_floatButton.loadBadge = _floatButton.loadBadge.bind(this);
};
return Component.init(comp);
});