|
|
@ -71,15 +71,29 @@ module.exports = function (opts) { |
|
|
|
initSoftKeyboard(screen, input) |
|
|
|
initSoftKeyboard(screen, input) |
|
|
|
if (attachDebugScreen) attachDebugScreen(screen) |
|
|
|
if (attachDebugScreen) attachDebugScreen(screen) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fullscreenIcon = {} // dummy
|
|
|
|
let isFullscreen = false |
|
|
|
let isFullscreen = false |
|
|
|
|
|
|
|
let properFullscreen = false |
|
|
|
let fitScreen = false |
|
|
|
let fitScreen = false |
|
|
|
let screenPadding = screen.window.padding |
|
|
|
let screenPadding = screen.window.padding |
|
|
|
let fitScreenIfNeeded = function fitScreenIfNeeded () { |
|
|
|
let fitScreenIfNeeded = function fitScreenIfNeeded () { |
|
|
|
if (isFullscreen) { |
|
|
|
if (isFullscreen) { |
|
|
|
screen.window.fitIntoWidth = window.screen.width |
|
|
|
fullscreenIcon.className = 'icn-resize-small' |
|
|
|
screen.window.fitIntoHeight = window.screen.height |
|
|
|
if (properFullscreen) { |
|
|
|
screen.window.padding = 0 |
|
|
|
screen.window.fitIntoWidth = window.screen.width |
|
|
|
|
|
|
|
screen.window.fitIntoHeight = window.screen.height |
|
|
|
|
|
|
|
screen.window.padding = 0 |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
screen.window.fitIntoWidth = window.innerWidth |
|
|
|
|
|
|
|
if (qs('#term-nav').classList.contains('hidden')) { |
|
|
|
|
|
|
|
screen.window.fitIntoHeight = window.innerHeight |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
screen.window.fitIntoHeight = window.innerHeight - 24 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
screen.window.padding = 0 |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
fullscreenIcon.className = 'icn-resize-full' |
|
|
|
screen.window.fitIntoWidth = fitScreen ? window.innerWidth - 4 : 0 |
|
|
|
screen.window.fitIntoWidth = fitScreen ? window.innerWidth - 4 : 0 |
|
|
|
screen.window.fitIntoHeight = fitScreen ? window.innerHeight : 0 |
|
|
|
screen.window.fitIntoHeight = fitScreen ? window.innerHeight : 0 |
|
|
|
screen.window.padding = screenPadding |
|
|
|
screen.window.padding = screenPadding |
|
|
@ -108,6 +122,8 @@ module.exports = function (opts) { |
|
|
|
|
|
|
|
|
|
|
|
// add fullscreen mode & button
|
|
|
|
// add fullscreen mode & button
|
|
|
|
if (window.Element.prototype.requestFullscreen || window.Element.prototype.webkitRequestFullscreen) { |
|
|
|
if (window.Element.prototype.requestFullscreen || window.Element.prototype.webkitRequestFullscreen) { |
|
|
|
|
|
|
|
properFullscreen = true |
|
|
|
|
|
|
|
|
|
|
|
let checkForFullscreen = function () { |
|
|
|
let checkForFullscreen = function () { |
|
|
|
// document.fullscreenElement is not really supported yet, so here's a hack
|
|
|
|
// document.fullscreenElement is not really supported yet, so here's a hack
|
|
|
|
if (isFullscreen && (window.innerWidth !== window.screen.width || window.innerHeight !== window.screen.height)) { |
|
|
|
if (isFullscreen && (window.innerWidth !== window.screen.width || window.innerHeight !== window.screen.height)) { |
|
|
@ -116,28 +132,40 @@ module.exports = function (opts) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
setInterval(checkForFullscreen, 500) |
|
|
|
setInterval(checkForFullscreen, 500) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// (why are the buttons anchors?)
|
|
|
|
// (why are the buttons anchors?)
|
|
|
|
let button = mk('a') |
|
|
|
let button = mk('a') |
|
|
|
button.href = '#' |
|
|
|
button.id = 'fullscreen-button' |
|
|
|
button.addEventListener('click', e => { |
|
|
|
button.href = '#' |
|
|
|
e.preventDefault() |
|
|
|
button.addEventListener('click', e => { |
|
|
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
|
|
|
isFullscreen = true |
|
|
|
if (document.body.classList.contains('pseudo-fullscreen')) { |
|
|
|
|
|
|
|
document.body.classList.remove('pseudo-fullscreen') |
|
|
|
|
|
|
|
isFullscreen = false |
|
|
|
fitScreenIfNeeded() |
|
|
|
fitScreenIfNeeded() |
|
|
|
screen.updateSize() |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isFullscreen = true |
|
|
|
|
|
|
|
fitScreenIfNeeded() |
|
|
|
|
|
|
|
screen.updateSize() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (properFullscreen) { |
|
|
|
if (screen.canvas.requestFullscreen) screen.canvas.requestFullscreen() |
|
|
|
if (screen.canvas.requestFullscreen) screen.canvas.requestFullscreen() |
|
|
|
else screen.canvas.webkitRequestFullscreen() |
|
|
|
else screen.canvas.webkitRequestFullscreen() |
|
|
|
}) |
|
|
|
} else { |
|
|
|
let icon = mk('i') |
|
|
|
document.body.classList.add('pseudo-fullscreen') |
|
|
|
icon.classList.add('icn-resize-full') // TODO: less confusing icons
|
|
|
|
} |
|
|
|
button.appendChild(icon) |
|
|
|
}) |
|
|
|
let span = mk('span') |
|
|
|
fullscreenIcon = mk('i') |
|
|
|
span.textContent = 'Fullscreen' |
|
|
|
fullscreenIcon.className = 'icn-resize-full' |
|
|
|
button.appendChild(span) |
|
|
|
button.appendChild(fullscreenIcon) |
|
|
|
qs('#term-nav').insertBefore(button, qs('#term-nav').firstChild) |
|
|
|
let span = mk('span') |
|
|
|
} |
|
|
|
span.textContent = 'Fullscreen' |
|
|
|
|
|
|
|
button.appendChild(span) |
|
|
|
|
|
|
|
qs('#term-nav').insertBefore(button, qs('#term-nav').firstChild) |
|
|
|
|
|
|
|
|
|
|
|
// for debugging
|
|
|
|
// for debugging
|
|
|
|
window.termScreen = screen |
|
|
|
window.termScreen = screen |
|
|
|