bt/README.md

77 lines
1.6 KiB
Markdown
Raw Normal View History

2015-12-11 12:00:28 +00:00
# bt
manage communication between browser tabs
### require
2015-12-13 01:20:07 +00:00
html5 localStorage
2015-12-11 12:00:28 +00:00
### Initialize
2015-12-13 01:20:07 +00:00
$v(document).ready(function() {
2015-12-11 12:00:28 +00:00
$bt.init();
}
2015-12-13 02:53:48 +00:00
2015-12-11 12:00:28 +00:00
### Internal Commands
// append data on node to other browser tabs
2015-12-13 02:53:48 +00:00
$bt.append('#test', "<b>it's cool to append</b>");
2015-12-11 12:00:28 +00:00
// rewrite content on node to other browser tabs
2015-12-13 02:53:48 +00:00
$bt.html('#test', "<b>it's cool to rewrite</b>");
// rewrite content to specific browser tabs
$bt.html('#test', "<b>it's cool to rewrite</b>", '1449974562012');
// perform a node synchro to other browser tabs
$bt.sync('#test');
// reload other browser tabs
$bt.reload();
// reload other browser tabs to specific url
$bt.reload(window.location.path+"?reloaded=1");
// get browser tab list
$bt.list;
// current browser tab id
$bt.id;
2015-12-11 12:00:28 +00:00
### Custom Commands
// 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 `'+cmd.customKey+'`');
break;
}
}
// send a custom command to other browser tabs
$bt.send({ name : $bt.CMD_CUSTOM, customKey : 'customValue' });
### Bonus
// alias localStorage : clear|rem|get|set
$l;
// alias json : str|obj
$j
// minimal vanilla jquery style : ready|on|html|append|attr|val|foreach
$v
2015-12-11 12:00:28 +00:00
### Demo
2015-12-13 01:20:07 +00:00
on chromium/chrome browser make sure to test on a web server (not directly file://)
2015-12-11 12:00:28 +00:00
enjoy !