$( document ).ready(() => { var counter = 0; let url_string = window.location.href; let url = new URL(url_string); let r = url.searchParams.get('r'); if(r){ init(r.split('|')); } function init(arr) { let blocks = ['r4', 'r3', 'r2', 'r1']; for(let i = 0; i< arr.length; i++){ if(blocks.length > 0 ){ let id = blocks.pop(); let panel = generatePanel(counter); $( '#' + id ).append( panel + '' ); bindEvents(counter); counter++; } else { break; } } } function generatePanel(i) { return '
'; } // add event listeners function bindEvents(id) { $( '#close' + id)[0].addEventListener('click', streamClose); $( '#reload' + id)[0].addEventListener('click', streamReload); $( '#full' + id)[0].addEventListener('click', streamFull); } // close frame with stream function streamClose(e) { e.preventDefault(); e.stopPropagation(); $(this)[0].removeEventListener('click', streamClose); let parent = $(this).parent('.dashboard--elem--panel').parent('.dashboard--elem'); parent.empty(); if(parent.hasClass('fullscreen')){ parent.removeClass('fullscreen'); $('.dashboard--elem').removeClass('hide'); } } // reload stream function streamReload(e) { e.preventDefault(); e.stopPropagation(); let elem = $(this).parent('.dashboard--elem--panel').parent('.dashboard--elem'); let idStr = $(this).attr('id'); let id = parseInt(idStr.match(/(\d+)$/)[0]); let html = elem.html(); elem.empty(); elem.html(html); bindEvents(id); } function streamFull(e) { e.preventDefault(); e.stopPropagation(); let parent = $(this).parent('.dashboard--elem--panel').parent('.dashboard--elem'); if(parent.hasClass('fullscreen')){ parent.removeClass('fullscreen'); $('.dashboard--elem').removeClass('hide'); } else { $('.dashboard--elem').addClass('hide'); parent.addClass('fullscreen'); } } $('.dashboard--elem').on('drop', function (e) { console.log('drop'); e.preventDefault(); let target = e.target; let url = e.originalEvent.dataTransfer.getData('URL'); if(!url || url.indexOf('https://gto.to/?r=') === -1){ return false; } $(target).empty(); let panel = generatePanel(counter); $( this ).append( panel + '' ); bindEvents(counter); counter++; return false; }); });