bt/demo.html

101 lines
3.4 KiB
HTML
Raw Normal View History

2015-12-11 11:54:06 +00:00
<!doctype>
<html>
<head>
<title>pluie.org bt demo - v0.4</title>
2015-12-11 11:54:06 +00:00
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
2015-12-13 02:53:48 +00:00
body { background-color:#888; color:white; font-family:arial; font-size:1.3rem; }
#test { border: 1px dashed #ccc; }
body > div { border-radius:20px; margin:40px; padding:20px; background-color: #ccc; color:black; }
body > span { font-size:0.8rem; }
button { padding:5px 15px; }
h3 { margin:35px 0 10px 0; }
h2 { margin:5px 0 0 0; }
textarea { padding:8px 5px; border-radius:10px; border-style:solid; width:100%; height:120px; font-size:1.2rem; }
2015-12-13 02:53:48 +00:00
#test { margin:20px; background-color:white; padding:20px; border: 1px dashed #aaa; }
2015-12-11 11:54:06 +00:00
</style>
</head>
<body>
2015-12-13 02:53:48 +00:00
<h2>pluie.org bt demo : </h2>
<span>author : a-sansara - version : 0.4</span>
2015-12-13 02:53:48 +00:00
<div>
<p>
this js lib can perform several actions on browser tabs.
</p>
<h3>Static actions</h3>
<button class="cmd-sta-append" title="$bt.append('#test', '<b>it\'s cool to append</b><br/>');">static dom append</button>
<button class="cmd-sta-html" title="$bt.html('#test', '<b>it\'s cool to rewrite</b><br/>')">static dom html</button>
<h3>Dynamic actions</h3>
enter txt or html : <br/>
<textarea id="data"></textarea>
<br/>select your action<br/>
<button class="cmd-append">dom append</button>
<button class="cmd-html">dom html</button>
<button class="cmd-sync">dom sync</button>
<button class="cmd-tarsync">target dom sync</button>
<button class="cmd-reload">tab reload</button>
<button class="cmd-custom">custom cmd</button>
<br/>then check other tabs
<h3>Target output</h3>
2015-12-11 11:54:06 +00:00
<div id="test"></div>
2015-12-13 02:53:48 +00:00
</div>
<script type="text/javascript" src="src/bt-min.js"></script>
2015-12-11 11:54:06 +00:00
<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+'`');
2015-12-13 02:53:48 +00:00
alert('FROM TAB '+$bt.id+' : \ncustom command `'+cmd.name+'` with value `'+cmd.customKey+'`');
2015-12-11 11:54:06 +00:00
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 });
});
});
2015-12-13 02:53:48 +00:00
$v('.cmd-sync').on('click', function(){
$v('h2').html('pluie.org bt demo (sync on '+(new Date).getTime()+') :');
$bt.sync('h2');
});
$v('.cmd-reload').on('click', function(){
$bt.reload(window.location.pathname+"?reload="+(new Date).getTime());
});
$v('.cmd-tarsync').on('click', function(){
$bt.sync('#test');
});
$v('.cmd-sta-append').on('click', function(){
eval(this.title);
});
$v('.cmd-sta-html').on('click', function(){
eval(this.title);
});
2015-12-11 11:54:06 +00:00
});
</script>
</body>
</html>