diff --git a/octoprint_uicustomizer/static/js/uicustomizer.js b/octoprint_uicustomizer/static/js/uicustomizer.js index 22d4927..9e18a5f 100644 --- a/octoprint_uicustomizer/static/js/uicustomizer.js +++ b/octoprint_uicustomizer/static/js/uicustomizer.js @@ -388,7 +388,7 @@ $(function() { containers = ['#webcam_hls_container','#IUCWebcamContainer > div']; // fix position of hls $('#webcam_hls_container').css('position','relative'); - $('#webcam_container img').attr('src',''); + $('#webcam_container img').attr('src','data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); $('#webcam_container').hide(); }else{ $('#webcam_hls_container video').attr('src',''); @@ -427,6 +427,11 @@ $(function() { $('body').append('
'); $('#UICWebCamShrink').hide(); + // Set top offset + if ($(window).scrollTop() > 0){ + $('#UICWebCamFull').css('top',$(window).scrollTop()+$('#UICWebCamFull').height()); + } + // Set source item if (hlsCam){ // Fix and setup video @@ -438,6 +443,13 @@ $(function() { // Add hls player var video = $('#UICWebCamFull video')[0]; self.startHLSstream(video,streamURL); + + // Tired of waiting + window.setTimeout(function(){ + $('#UICWebCamShrink').show(); + $('#UICWebCamFull div.nowebcam').remove(); + },5000); + }else{ var rotated = $('#webcam_rotator').hasClass('webcam_rotated'); var imgsrc = obj.find('img')[0]; @@ -450,41 +462,80 @@ $(function() { } var aspect = nWidth/nHeight; nWidth -= 100; - var wWidth = $(window).width()/1.5; - var wHeight = $(window).height()/1.5; + var fixed = false; + var wWidth = $(window).width(); + var wHeight = $(window).height(); + // Cam height than screen - then fit to screen height + if (nHeight > wHeight){ + fixed = true; + nHeight = (wHeight - 120); + nWidth = nHeight*aspect; + } // Cam wider than screen - then fit to screen width if (nWidth > wWidth){ - nWidth = (wWidth - 100); + fixed = true; + nWidth = (wWidth - 120); nHeight = nWidth/aspect; } - // Cam height than screen - then fit to screen height + // Cam height than screen - then fit to screen height * 2 if (nHeight > wHeight){ - nHeight = (wHeight - 50); + nHeight = (nHeight - 120); nWidth = nHeight*aspect; } + // Clone to fix rotation etc. var clone = $('#webcam_rotator').clone(); clone.find('>div:not(:first-child)').remove(); clone.attr('id','UICWebCamFullInnerDIV'); - clone.find('*').removeAttr('id'); - - $('#UICWebCamFull span.UICWebCamTarget').replaceWith(clone); + clone.find('*').removeAttr('id').removeAttr('data-bind'); + clone.find('img').off('load'); + clone.find('img').attr('src','data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); + $('#UICWebCamFull img').off('load'); + $('#UICWebCamFull span.UICWebCamTarget').html(clone.html()); + + // Tired of waiting + var timeoutLoad = window.setTimeout(function(){ + $('#UICWebCamFull img').trigger('load',[true]); + },5000); + + // Fixes and hacks for firefox $('#UICWebCamFull img').css({'width':nWidth}); $('#UICWebCamFull img').css({'height':nHeight}); - $('#UICWebCamFull img').off('load').on('load',function(){ + $('#UICWebCamFull img').off('load').on('load',function(event,forced){ + if (streamURL != $(this).attr('src')){ + if (forced){ + $(this).attr('src',streamURL); + }else{ + return false; + } + return false; + }else{ + $('#UICWebCamFull img').off('load'); + } + if (timeoutLoad != null){ + window.clearTimeout(timeoutLoad); + timeoutLoad = null; + }; $('#UICWebCamShrink').show(); $('#UICWebCamFull img').show(); $('#UICWebCamFull div.nowebcam').remove(); - $('#UICWebCamFull img').css({'width':''}); - $('#UICWebCamFull img').css({'height':''}); - $('#UICWebCamFull').css({'max-width':$(window).width()-60}); - $('#UICWebCamFull').css({'max-height':$(window).height()-60}); + if (fixed){ + $('#UICWebCamFull').css({'width':nWidth+10}); + $('#UICWebCamFull').css({'height':nHeight+10}); + }else{ + $('#UICWebCamFull img').css({'width':''}); + $('#UICWebCamFull img').css({'height':''}); + } + $('#UICWebCamFull').css({'max-width':$(window).width()-120}); + $('#UICWebCamFull').css({'max-height':$(window).height()-120}); }); $('#UICWebCamFull img').attr('src',streamURL); } // Fix on resize done $('#UICWebCamFull').off('mouseup').on('mouseup',function(){ + $('#UICWebCamFull img').css({'width':''}); + $('#UICWebCamFull img').css({'height':''}); $('#UICWebCamFull').css('height',''); }).off('dblclick').on('dblclick',function(){ $('#UICWebCamShrink').trigger('click'); @@ -497,7 +548,6 @@ $(function() { document.body.addEventListener('drop',drop,false); // Close again - window.setTimeout(function(){$('#UICWebCamShrink').show();},5000); $('#UICWebCamShrink').one('click',function(){ $('.UIWebcamZoomSrc').show(); $('#UICWebCamFull').remove(); @@ -637,8 +687,8 @@ $(function() { OctoPrint.coreui.viewmodels.controlViewModel.onWebcamLoaded = self.onWebCamOrg; // Clone it var clone = $('#webcam_hls').clone(); - clone.removeAttr('id'); - $('#IUCWebcamContainer > div').html(clone).find('*').removeAttr('id'); + clone.removeAttr('id').removeAttr('data-bind'); + $('#IUCWebcamContainer > div').html(clone).find('*').removeAttr('id').removeAttr('data-bind'); // Event handling on the main player $('#IUCWebcamContainer video').off('error').on('error',function(event){ @@ -714,34 +764,47 @@ $(function() { clone.find('>div:not(:first-child)').remove(); // Avoid any children added clone.find('>div:not(:first-child)').remove(); - $('#IUCWebcamContainer > div').append(clone).find('*').removeAttr('id'); + $('#IUCWebcamContainer > div').append(clone).find('*').removeAttr('id').removeAttr('data-bind'); clone.attr('id',"IUCWebcamContainerInner").hide(); // Error handling - var webcamLoader = function(){ + var webcamLoader = function(targetStreamURL){ + self.logToConsole("webcamLoader init"); $('#IUCWebcamContainerInner img').off('error').on('error',function(){ // Error loading + $('#webcam_image').data("isLoaded",false); $('#IUCWebcamContainerInner').hide(); $('.UICWebCamClick').hide(); $('#IUCWebcamContainer div.nowebcam').remove(); $('#IUCWebcamContainer > div').append($('