forked from Tencent/vConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.html
114 lines (105 loc) · 3.45 KB
/
plugin.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Test: Plugin</title>
<link href="../example/lib/weui.min.css" rel="stylesheet"/>
<link href="../example/lib/demo.css" rel="stylesheet"/>
<script src="../example/lib/zepto.min.js"></script>
<script src="../example/lib/zepto.touch.min.js"></script>
<script src="../dist/vconsole.min.js"></script>
</head>
<body ontouchstart>
<div class="page">
<a onclick="newTab()" href="javascript:;" class="weui_btn weui_btn_default">newTab</a>
<a onclick="newTabWithTool()" href="javascript:;" class="weui_btn weui_btn_default">newTabWithTool</a>
<a onclick="newGlobalToolButton()" href="javascript:;" class="weui_btn weui_btn_default">newGlobalToolButton</a>
<a onclick="newTabUseJQuery()" href="javascript:;" class="weui_btn weui_btn_default">newTabUseJQuery</a>
<a onclick="newTabUseDOM()" href="javascript:;" class="weui_btn weui_btn_default">newTabUseDOM</a>
</div>
</body>
</html>
<script>
function newTab() {
console.info('newTab() Start');
var tab = new vConsole.VConsolePlugin('tab1', 'Tab1');
tab
.on('init', function() { console.log(this.id, 'init'); })
.on('renderTab', function(cb) {
console.log(this.id, 'renderTab');
cb('<div>I am ' + this.id+'</div>');
})
.on('ready', function() { console.log(this.id, 'ready'); })
.on('show', function() { console.log(this.id, 'show'); })
.on('hide', function() { console.log(this.id, 'hide'); })
.on('showConsole', function() { console.log(this.id, 'showConsole'); })
.on('hideConsole', function() { console.log(this.id, 'hideConsole'); });
vConsole.addPlugin(tab);
console.info('newTab() End');
}
function newTabWithTool() {
console.info('newTabWithTool() Start');
var tab = new vConsole.VConsolePlugin('tab2', 'Tab2');
tab.on('renderTab', function(cb) {
console.log(this.id, 'renderTab');
cb('<div>I am ' + this.id+'</div>');
})
.on('addTool', function(cb) {
console.log(this.id, 'addTool');
cb([
{
name: 'Alert',
global: false,
onClick: function(e) {
alert('I am a tool button!');
}
}
]);
});
vConsole.addPlugin(tab);
console.info('newTabWithTool() End');
}
function newGlobalToolButton() {
console.info('newGlobalToolButton() Start');
var plugin = new vConsole.VConsolePlugin('plugin3', 'Plugin3');
plugin.on('addTool', function(cb) {
console.log(this.id, 'addTool');
cb([
{
name: 'Global',
global: true,
onClick: function(e) {
alert('I am a global tool button!');
}
}
]);
});
vConsole.addPlugin(plugin);
console.info('newGlobalToolButton() End');
}
function newTabUseJQuery() {
console.info('newTabUseJQuery() Start');
var tab = new vConsole.VConsolePlugin('tab4', 'Tab4');
var $html = $('<div><a href="javascript:;">Alert</a></div>');
$html.find('a').click(function() {
alert('OK');
});
tab.on('renderTab', function(cb) {
cb($html);
});
vConsole.addPlugin(tab);
console.info('newTabUseJQuery() End');
}
function newTabUseDOM() {
console.info('newTabUseDOM() Start');
var tab = new vConsole.VConsolePlugin('tab5', 'Tab5');
var $elm = document.createElement('DIV');
$elm.innerHTML = '<p>It works</p>';
tab.on('renderTab', function(cb) {
cb($elm);
});
vConsole.addPlugin(tab);
console.info('newTabUseDOM() End');
}
</script>