Skip to content

Commit

Permalink
Add fullscreen button
Browse files Browse the repository at this point in the history
  • Loading branch information
ferndot committed Aug 27, 2016
1 parent e75846a commit 4a2827f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
72 changes: 72 additions & 0 deletions laskyawm-fullscreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* This file is licensed under the Affero General Public License. */

/*global deviceType */
(function() {
// Don't show on mobile
if(deviceType === 'mobile') {
return;
}

// Create clock widget
var fsbutton = document.createElement('span');
fsbutton.id = 'barFullscreen';
fsbutton.textContent = "Fullscreen";

// Handle clicks
fsbutton.addEventListener("click",fs);

// Add to bar
window.bar.addItem(fsbutton);

// Fullscreen functions
var html = document.getElementsByTagName('html')[0];
function fs(enter) {
if (enter === true ||
enter != false &&
!html.classList.contains('fullscreen')) { // current working methods
// Make app fullscreen
if (html.requestFullscreen) {
html.requestFullscreen();
} else if (html.mozRequestFullScreen) {
html.mozRequestFullScreen();
} else if (html.webkitRequestFullscreen) {
html.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
// Exit fullscreen
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}

function onFullScreenChange() {
if (
document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement
) {
html.classList.add('fullscreen');
fsbutton.textContent = "Close fullscreen";
} else {
html.classList.remove('fullscreen');
fsbutton.textContent = "Fullscreen";
}
}

function onFullScreenError() {
alert('Could not enter into fullscreen.');
}

document.addEventListener('fullscreenchange', onFullScreenChange);
document.addEventListener('mozfullscreenchange', onFullScreenChange);
document.addEventListener('webkitfullscreenchange', onFullScreenChange);

document.addEventListener('fullscreenerror', onFullScreenError);
document.addEventListener('mozfullscreenerror', onFullScreenError);
document.addEventListener('webkitfullscreenerror', onFullScreenError);
})();
3 changes: 2 additions & 1 deletion laskyawm.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script src="laskyawm-bar.js"></script>
<script src="laskyawm-apps.js"></script>
<script src="laskyawm-power.js"></script>
<script src="laskyawm-fullscreen.js"></script>
<script src="laskyawm-clock.js"></script>
<script src="laskyawm-background.js"></script>
</body>
</body>

0 comments on commit 4a2827f

Please sign in to comment.