/* Copyright 2012-2020 OpenBroadcaster, Inc. This file is part of OpenBroadcaster Server. OpenBroadcaster Server is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenBroadcaster Server is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with OpenBroadcaster Server. If not, see . */ OB.UI = new Object(); OB.UI.htmlCache = new Array(); OB.UI.init = function() { // watch for changes to DOM and then do things. new MutationObserver(function(mutations) { OB.UI.domChangeCallback(); }).observe(document.querySelector('html'), { attributes: false, childList: true, characterData: false, subtree: true }); OB.Callbacks.add('ready',-50,OB.UI.initLayout); // add drag helper html $('body').append('
'); $('body').on('mousemove',OB.UI.dragHelperMove); } OB.UI.initLayout = function() { OB.API.post('ui','html',{},function(response) { OB.UI.htmlCache = response.data; $('#main_container').html(OB.UI.getHTML('layout.html')); $('#sidebar_player').html(OB.UI.getHTML('sidebar/player.html')); $('#sidebar_search').html(OB.UI.getHTML('sidebar/search.html')); },'sync'); // we might need to adjust things if window resizes. $(window).resize(OB.UI.domChangeCallback); } OB.UI.dragHelperOn = function(html) { $('#drag_helper').html(html).addClass('active'); } OB.UI.dragHelperOff = function() { $('#drag_helper').removeClass('active'); $('#drag_helper').css({ 'left': '-1000px', 'top': '-1000px' }); } OB.UI.dragHelperMove = function(e) { if(!$('#drag_helper').hasClass('active')) return; var left = e.pageX - $('#drag_helper').outerWidth()/2; var top = e.pageY - $('#drag_helper').outerHeight()/2; $('#drag_helper').css({ 'left': left+'px', 'top': top+'px' }); } // TODO fix this with better html/css, shouldn't be necessary. OB.UI.sidebarSearchResultsHeight = function() { if($('#sidebar_search_media_container').is(':visible')) { $('#sidebar_search_media_results_container').css('height',0); var mediaResultsHeight = $('#sidebar_search_media_container').height() - 20; $('#sidebar_search_media_container > *').each(function() { if($(this).attr('id')!='sidebar_search_media_results_container') mediaResultsHeight -= $(this).outerHeight(); }); $('#sidebar_search_media_results_container').css('height',Math.max(0,mediaResultsHeight)+'px'); } if($('#sidebar_search_playlist_container').is(':visible')) { $('#sidebar_search_playlist_results_container').css('height',0); var playlistResultsHeight = $('#sidebar_search_playlist_container').height() - 20; $('#sidebar_search_playlist_container > *').each(function() { if($(this).attr('id')!='sidebar_search_playlist_results_container') playlistResultsHeight -= $(this).outerHeight(); }); $('#sidebar_search_playlist_results_container').css('height',Math.max(0,playlistResultsHeight)+'px'); } } OB.UI.domChangeCallback = function() { OB.UI.sidebarSearchResultsHeight(); $('ob-tabs').each(function (index, container) { OB.UI.tabsInit(container); }); $('ob-duration-input').each(function(index, input) { OB.UI.durationInputInit(input); }); $('ob-datetime-input').each(function(index, input) { OB.UI.datetimeInputInit(input); }); $('ob-date-input').each(function(index, input) { OB.UI.dateInputInit(input); }); $('ob-time-input').each(function(index, input) { OB.UI.timeInputInit(input); }); $('ob-tag-input').each(function(index,tag) { OB.UI.tagInputInit(tag); }); $('ob-user-input').each(function(index,input) { OB.UI.userInputInit(input); }); $('ob-group-input').each(function(index,input) { OB.UI.groupInputInit(input); }); $('ob-html-input').each(function (index, input) { OB.UI.htmlInputInit(input); }) $('ob-media-input').each(function (index, input) { OB.UI.mediaInputInit(input); }); $('ob-playlist-input').each(function (index, input) { OB.UI.playlistInputInit(input); }); OB.UI.translateHTML(); } OB.UI.tabsInit = function (container) { if($(container).attr('data-ready')) return true; var tabs = $(container).find('> ob-tab'); var $select = $(''); $(tabs).each(function(index, tab) { var name = $(tab).attr('data-name'); if(!name) name = 'Untitled'; $select.append( $('