From 3c34ab223a89a305a698e399ac28a08595159b10 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 13 Nov 2015 11:18:53 +0100 Subject: [PATCH] Prevent assigning to the htmlcollection. --- js/h5p.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 355360f..24d9846 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -540,11 +540,13 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) { before('h5p-semi-fullscreen'); var $disable = H5P.jQuery('
').appendTo($container.find('.h5p-content-controls')); var keyup, disableSemiFullscreen = H5P.exitFullScreen = function () { - if (lastViewport) { - metaTags[i].content = lastViewport; + if (prevViewportContent) { + // Use content from the previous viewport tag + h5pViewport.content = prevViewportContent; } else { - head.removeChild(metaTags[i]); + // Remove viewport tag + head.removeChild(h5pViewport); } $disable.remove(); $body.unbind('keyup', keyup); @@ -559,23 +561,26 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) { $body.keyup(keyup); // Disable zoom - var lastViewport; + var prevViewportContent, h5pViewport; var metaTags = document.getElementsByTagName('meta'); for (var i = 0; i < metaTags.length; i++) { if (metaTags[i].name === 'viewport') { - lastViewport = metaTags[i].content; + // Use the existing viewport tag + h5pViewport = metaTags[i]; + prevViewportContent = h5pViewport.content; break; } } - if (!lastViewport) { - // Create tag - metaTags[i] = document.createElement('meta'); - metaTags[i].name = 'viewport'; + if (!prevViewportContent) { + // Create a new viewport tag + h5pViewport = document.createElement('meta'); + h5pViewport.name = 'viewport'; } - metaTags[i].content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'; - if (!lastViewport) { + h5pViewport.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'; + if (!prevViewportContent) { + // Insert the new viewport tag var head = document.getElementsByTagName('head')[0]; - head.appendChild(metaTags[i]); + head.appendChild(h5pViewport); } entered();