Easy browser tab events fireing and receiving.
Basic features are:
- callback will be fired
only onceacross all tabs - one tab emit event, other tabs received
remind:this project requires jquery !!
var hub = tabHub('event1', function (emit) {
// this callback will no longer be fired if other tab already fired this
$.get('/api').done(function(data){
emit(data);
});
});
hub.onValue(function(data) {
if(data == 'sync'){
//do something
}
});
//any where else need to brocast through tabs
$('xxx').click(function(){
hub.emit('sync')
})register cross tabs events.
eventsNamemust be unique.- once the emit function called, callback will
no longerbe fired. - you should call emit with
string, because it will go to localstorage. - your emit should not containg
:, because i use:to seperate.
- this callback will be fired
morethan you think - hub.onValue(cb) returned a function for deregister events
- emit a cross tab events
- emit function inside calback is also the same
get the lastValue that emited
remove all this instance listeners.
var hub = tabHub('myVal_spec1', function (emit) {
});
hub.onValue(function(data) {
});
Contributions are very very welcome!!!