-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtmpl.html
127 lines (119 loc) · 4.66 KB
/
tmpl.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<title><?php echo config()->title ?></title>
<link rel="stylesheet" href="<?php echo get_baseurl()?>/asset/pure-min.css">
<style>
html, body {height: 100%; padding: 0; }
html {width: 100%; overflow: hidden; margin: 0; }
body {position: relative; }
#scrollContainer {overflow: auto; position:absolute; top: 0; bottom: 2em; width: 100%; }
body{background: #111;color: #999;margin: 0;font: 16px/1.3 Menlo, Monaco, Consolas, "Courier New", monospace}
#ctrl_bar{position: fixed;width: 100%;bottom: 0;background: #000;}
#ctrl_bar input{height: 2em;color: #fff;background: #000;font: 16px/1.8 Menlo, Monaco, Consolas, "Courier New", monospace}
#line_recv{margin: 0;border: 0;display: block;width: 100%;outline: none}
p.error{color: #800000}
#content p {margin: 0;word-break: break-all;}
#content {padding: 0.3em}
#load_more, #load_more:visited{display: block;text-align: center;text-decoration: none;padding: 0.3em;color: #fff}
#load_more:hover{text-decoration: underline}
@media screen and (max-width: 480px) {
body{font: 12px/1.3}
}
</style>
</head>
<body>
<div id="scrollContainer">
<div>
<?php if (!empty($logs) && !$last_page): ?>
<a id="load_more" href="#" data-page="0">Load More...</a>
<?php endif; ?>
</div>
<div id="content">
<?php if(!empty($logs)) foreach($logs as $l): ?>
<p><?php echo $l; ?></p>
<?php endforeach; ?>
</div>
<div id="bottom"></div>
</div>
<div id="ctrl_bar">
<form id="write_log">
<input type="text" id="line_recv" maxlength="300" placeholder="Input Here~" name="log_line">
</form>
</div>
<script type="text/javascript" src="<?php echo get_baseurl() ?>/asset/zepto.min.js"></script>
<script type="text/javascript">
$(function() {
//滚到最低
var scrollBottom = function() {
$('#bottom').get(0).scrollIntoView(true);
}
//提交过程
var lock = false;
$('#write_log').submit(function(){
if ($.trim($('#line_recv').val()) == "") {
return false;
}
if (lock) {
return false;
} else {
lock = true;
}
$.post('<?php echo get_baseurl() ?>/index.php?m=save',
$('#write_log').serialize(),
function(resp){
if(resp !== null){
if(resp.ok) {
//$('#content').append('<p>'+resp.info+'</p>'); 自己发的内容通过广播接收
$('#line_recv').val('');
} else {
$('#content').append('<p class="error">'+resp.info+'</p>');
}
}
scrollBottom();
}, 'json');
lock = false;
return false;
});
//回车键提交
$('#line_recv').keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
$("form").submit();
}
});
//分页加载
$('#load_more').click(function(){
var btn = $(this);
var pos = $('#content p').first();
$.getJSON('<?php echo get_baseurl() ?>/index.php?m=load',
{p: parseInt(btn.data('page')) + 1},
function(data) {
for(var i in data.data) { //新一页数据填充
$('#content').prepend('<p>'+data.data[data.data.length - i - 1]+'</p>'); //反序
}
btn.data('page', btn.data('page')+1); //更新页码状态
if (data.last_page) { //最后一页去掉加载下一页按钮
$('#load_more').remove();
}
//滚动
pos.get(0).scrollIntoView(false);
}
);
return false;
});
//自动更新
(function poll(){
$.ajax({ url: "<?php echo get_baseurl() ?>:8421/sub", success: function(data){
$('#content').append('<p>'+data+'</p>');
scrollBottom();
}, complete: poll, timeout: 30000 });
})();
//默认滚到底部
scrollBottom();
});
</script>
</body>
</html>