bt/demo.html

57 lines
1.5 KiB
HTML
Raw Normal View History

2015-12-11 11:54:06 +00:00
<!doctype>
<html>
<head>
<title>pluie.org bt demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#test { border: 1px dashed #ccc; }
</style>
</head>
<body>
<input type="text" value="" id="data"/><br/>
<button class="cmd-append">dom append</button><br/>
<button class="cmd-html">dom html</button><br/>
<button class="cmd-custom">custom</button><br/>
<h2>demo bt : </h2>
<div id="test"></div>
<script type="text/javascript" src="src/bt.js"></script>
<script type="text/javascript">
// define a new custom cmd
$bt.CMD_CUSTOM = "customCmd";
// treat custom command to other browser tabs
$bt.on = function(cmd) {
switch (cmd.name) {
case $bt.CMD_CUSTOM :
// do stuff
$bt.log('custom command `'+cmd.name+'` with value `'+cmd.customKey+'`');
break;
}
}
//
2015-12-13 01:20:07 +00:00
$v(document).ready(function() {
2015-12-11 11:54:06 +00:00
$bt.init();
var bind = function(call) {
2015-12-13 01:20:07 +00:00
var html = $v('#data').val();
2015-12-11 11:54:06 +00:00
if (html.length > 0) call(html)
2015-12-13 01:20:07 +00:00
else $v('#data').attr('placeholder', 'insert data first !');
2015-12-11 11:54:06 +00:00
}
2015-12-13 01:20:07 +00:00
$v('.cmd-append').on('click', function(){
2015-12-11 11:54:06 +00:00
bind(function(data) {
$bt.append('#test', data);
});
});
2015-12-13 01:20:07 +00:00
$v('.cmd-html').on('click', function(){
2015-12-11 11:54:06 +00:00
bind(function(data) {
$bt.html('#test', data);
});
});
2015-12-13 01:20:07 +00:00
$v('.cmd-custom').on('click', function(){
2015-12-11 11:54:06 +00:00
bind(function(data) {
$bt.send({ name : $bt.CMD_CUSTOM, customKey : data });
});
});
});
</script>
</body>
</html>