Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fullscreen button #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
})();
1 change: 1 addition & 0 deletions 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>