Skip to content

Instantly share code, notes, and snippets.

View shubhank-srivastava's full-sized avatar

Shubhank Srivastava shubhank-srivastava

View GitHub Profile
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var dirs = json_file.split("/");
dirs.pop(); //if a directory path exists, remove the JSON file from dirs
var element = d3.select(to_select);
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var dirs = json_file.split("/");
dirs.pop(); //if a directory path exists, remove the JSON file from dirs
var element = d3.select(to_select);
@shubhank-srivastava
shubhank-srivastava / preventMultiTab.js
Created July 5, 2018 19:04
A JS function to detect multiple tabs or new tabs in the browser for the same domain (Works for Chrome/Firefox/UC).
function preventMultiTab(){
if(window.BroadcastChannel){
var tab_sid = (new Date()).getTime();
sessionStorage.setItem('tab_sid', tab_sid);
var channel = new BroadcastChannel('tab-connections');
channel.postMessage('ping:get_back_all_ids');
channel.onmessage = function(e) {
var message = e.data.split(':');
if(message[0]=='close'){
if(tab_sid > parseInt(message[1])){