This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| request.onload = function() { | |
| if(request.status === 200) { | |
| console.log("Response from server = ", request.response); | |
| } else { | |
| consle.log( request.status , ":", request.statusText ); // 500: Internal server error | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let isPiPSupported = 'pictureInPictureEnabled' in document, | |
| isPiPEnabled = document.pictureInPictureEnabled; | |
| if (!isPiPSupported) { | |
| console.log('The Picture-in-Picture Web API is not available.'); | |
| } | |
| else if (!isPiPEnabled) { | |
| console.log('The Picture-in-Picture Web API is disabled.'); | |
| } else { | |
| console.log("PiP supported"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pipWindow; | |
| video.addEventListener('enterpictureinpicture', function(event) { | |
| pipWindow = event.pictureInPictureWindow; | |
| console.log(`> Window size is ${pipWindow.width}x${pipWindow.height}`); | |
| pipWindow.addEventListener('resize', onPipWindowResize); | |
| }); | |
| video.addEventListener('leavepictureinpicture', function(event) { | |
| pipWindow.removeEventListener('resize', onPipWindowResize); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Picture-in-Picture</title> | |
| </head> | |
| <body> | |
| <video id="videoElement" controls="true" src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"> </video> | |
| <button id="PiP"> Enable Floating Video </button> | |
| <script> | |
| let video = document.getElementById('videoElement'); | |
| let toggleBtn = document.getElementById('PiP'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // image as dataURL | |
| let jpeg = canvas.toDataURL('image/jpg'); // 0.92 | |
| let webp = canvas.toDataURL('image/webp', 0.5); | |
| //zip | |
| let jsZip = new JSZip(); | |
| let folder = jsZip.folder("images"); | |
| let baseString = getBase64String(jpeg); | |
| folder.file("image1.jpeg", baseString, {base64 : true}); | |
| let baseString2 = getBase64String(webp); | |
| folder.file("image2.webp", baseString2, {base64 : true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getBase64String(dataURL) { | |
| var idx = dataURL.indexOf('base64,') + 'base64,'.length; | |
| return dataURL.substring(idx); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let jsZip = new JSZip(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let jpeg = canvas.toDataURL('image/jpg'); // 0.92 | |
| let webp = canvas.toDataURL('image/webp', 0.5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var download = function(href, name){ | |
| var link = document.createElement('a'); | |
| link.download = name; | |
| link.style.opacity = "0"; | |
| document.append(link); | |
| link.href = href; | |
| link.click(); | |
| link.remove(); | |
| } | |
| download(png, "image.png"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var download = function(href, name){ | |
| var link = document.createElement('a'); | |
| link.download = name; | |
| link.style.opacity = "0"; | |
| document.append(link); | |
| link.href = href; | |
| link.click(); | |
| link.remove(); | |
| } | |
| download(png, "image.png"); |