-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
148 lines (133 loc) · 3.23 KB
/
demo.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="offline/bootstrap.min.css">
<style type="text/css">
table{
border:solid 1px #eee;
width: 500px;
}
li{
list-style-type:none;
}
li span{
width: 80px;
text-align: right;
display: inline-block;
margin-right: 10px;
}
.left{
margin-left: 90px;
}
.div{
padding: 10px 0 20px 50px;
}
</style>
</head>
<body>
<h1>
</h1>
<ul>
<li><span>key:</span><input id="J_a"></li>
<li><span>value:</span><input id="J_b"></li>
<li><span>过期时间:</span><input id="J_c"></li>
<li><input type="button" id="J_Save" class="btn left" value="保存"></li>
</ul>
<script type="text/javascript" src="http://a.tbcdn.cn/s/kissy/1.2.0/kissy.js"></script>
<script type="text/javascript">
KISSY.config({
packages: [{
name: "offline",
path: "./",
charset: "utf-8"
}]
});
</script>
<div class="div">
<input id="J_ShowAll" type="hidden" class="btn" value="显示全部">
<input type="button" class="btn" id="J_Clear" value="清空">
<input type="button" class="btn" id="J_Used" value="使用字节">
</div>
<table border="1">
<thead>
<tr>
<th>
key
</th>
<th>
value
</th>
<th>
操作
</th>
<th>
查看
</th>
</tr>
</thead>
<tbody id="J_Tbody">
<tr class="J_List">
</tr>
</tbody>
</table>
<script type="text/javascript">
//alert(document.addBehavior);
KISSY.use('offline/index',function (S,Offiline) {
var a = new Offiline();
var $ = S.all;
var TEMPLATE = '<tr class="J_List">'+
'<td>{key}</td>'+
'<td>{value}</td>'+
'<td><a class="J_Delete" href="javascript:void(0)" item-name="{key}">删除</a></td>'+
'<td><a class="J_Remain" href="javascript:void(0)" item-name="{key}">剩余时间</a></td>'+
'</tr>';
/**
Template('Hello, <b color="{{_ks_value.color}}">{{_ks_value.user}}</b>{{/each}})')
.render({users: [{name: 'Frank', color: 'red'}, {name: 'yyfrankyy', color: 'green']});
*/
$('#J_ShowAll').on('click',function(){
var o = a.getAll(true),
arr = [];
for(var i in o){
if(o.hasOwnProperty(i)){
arr.push(S.substitute(TEMPLATE,{
key:i,
value:o[i]
}));
}
}
$('.J_List').remove();
$('#J_Tbody').append($(arr.join('')));
});
S.later(function(){
$('#J_ShowAll').fire('click');
},1000);
$('#J_Save').on('click',function(){
a.setItem($('#J_a').val(),$('#J_b').val(),$('#J_c').val());
$('#J_ShowAll').fire('click');
});
//删除
S.Event.delegate(document,'click','.J_Delete',function(e){
a.removeItem($(e.currentTarget).attr('item-name'));
$('#J_ShowAll').fire('click');
});
//剩余时间
S.Event.delegate(document,'click','.J_Remain',function(e){
var time = a.timeRemain($(e.currentTarget).attr('item-name'));
alert(time===-1?'没有限制':time);
});
//清空
$('#J_Clear').on('click',function(){
a.clear();
$('#J_ShowAll').fire('click');
});
//统计
$('#J_Used').on('click',function(){
alert(a.usedByte());
});
});
</script>
</body>
</html>