Skip to content

Commit

Permalink
Create better status bar API + Structure, add time to status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ferndot authored and twiss committed Aug 10, 2015
1 parent 62f6c5b commit cec9cb4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 10 deletions.
11 changes: 10 additions & 1 deletion laskyawm-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
position: absolute;
width: 100%;
height: 25px;
color: white;
}
.barButton {
color: white;
Expand All @@ -17,9 +18,17 @@
text-align: center;
display: inline-block;
}
#togglePowerMenu {
#barIcons {
float: right;
}
#barIcons > * {
padding: 3px 0;
font-size: 15px;
float: right;
}
#togglePowerMenu {
padding: 4px 10px 5px;
margin: 0;
}
.barMenu {
display: none;
Expand Down
35 changes: 32 additions & 3 deletions laskyawm-bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
/* This file is licensed under the Affero General Public License. */

var bar = document.createElement('div');
bar.id = 'bar';
document.body.appendChild(bar);
/*global $ */

(function() {
// Add namespace
var bar = window.bar = {};

// Add bar
var barElement = document.createElement('div');
barElement.id = 'bar';
document.body.appendChild(barElement);

// Add icon panel
var barIcons = window.barIcons = document.createElement('div');
barIcons.id = 'barIcons';
barElement.appendChild(barIcons);

bar.addItem = function(node) {
$(barIcons).append(node);
bar.updateWidth();
};

bar.removeItem = function(node) {
barIcons.removeChild(node);
bar.updateWidth();
};

bar.updateWidth = function() {
window.barIconsWidth = barIcons.offsetWidth;
};

bar.updateWidth();
})(window);
33 changes: 33 additions & 0 deletions laskyawm-clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* This file is licensed under the Affero General Public License. */

/*global deviceType */

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

// Create clock widget
var clock = document.createElement('span');
clock.id = 'barClock';
updateTime();

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

// Prevent freeze
var updateTimeout;

function updateTime() {
// Clear timeout
clearTimeout(updateTimeout);

// Get time
var currentTime = new Date();
clock.textContent = currentTime.toLocaleTimeString(navigator.language, {hour: 'numeric', minute: 'numeric'});

// Keep up-to-date
updateTimeout = setTimeout(updateTime, 60000 - (currentTime.getSeconds() * 1000) - currentTime.getMilliseconds());
}
})();
7 changes: 5 additions & 2 deletions laskyawm-power.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* This file is licensed under the Affero General Public License. */

/*global $, prepareUrl */
/*global $, prepareUrl, bar */

var powerMenu;

Expand All @@ -11,11 +11,14 @@ togglePowerMenu.type = 'image';
togglePowerMenu.alt = 'Log Out…';
prepareUrl('/Core/power.png', {rootParent: '/'}, function(url) {
togglePowerMenu.src = url;
togglePowerMenu.addEventListener('load', function() {
bar.updateWidth();
});
});
togglePowerMenu.addEventListener('click', function() {
$(powerMenu).toggle();
});
document.body.appendChild(togglePowerMenu);
bar.addItem(togglePowerMenu);

powerMenu = document.createElement('div');
powerMenu.id = 'powerMenu';
Expand Down
1 change: 1 addition & 0 deletions laskyawm.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<script src="laskyawm-bar.js"></script>
<script src="laskyawm-apps.js"></script>
<script src="laskyawm-power.js"></script>
<script src="laskyawm-clock.js"></script>
</body>
8 changes: 4 additions & 4 deletions laskyawm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* This file is licensed under the Affero General Public License. */

/*global _, $, File, apps, powerMenu, getFile: true, prepareUrl: true, listenForFileChanges: true, showProgress: true, setProgress: true, hideProgress: true, openFile: true, openWindow: true, extension: true */
/*global _, $, File, barIconsWidth, apps, powerMenu, getFile: true, prepareUrl: true, listenForFileChanges: true, showProgress: true, setProgress: true, hideProgress: true, openFile: true, openWindow: true, extension: true */

var deviceType = window.matchMedia('only screen and (max-device-width: 640px)').matches ? 'mobile' : 'desktop';

Expand Down Expand Up @@ -687,8 +687,8 @@ function positionMinimized() {
if(left < minMinimizedLeft) {
minimizedLeft = minMinimizedLeft;
moved = true;
} else if(left > window.innerWidth - 350) {
minimizedLeft = window.innerWidth - 350;
} else if(left > window.innerWidth - barIconsWidth - 260) {
minimizedLeft = window.innerWidth - barIconsWidth - 260;
moved = true;
pushLeft = true;
} else {
Expand All @@ -703,7 +703,7 @@ function positionMinimized() {
}
if(moved) {
if(!win.realLeft) win.realLeft = win.style.left;
win.style.cssText += '; left: ' + (pushLeft ? window.innerWidth - 350 : minimizedLeft) + 'px !important;';
win.style.cssText += '; left: ' + (pushLeft ? window.innerWidth - barIconsWidth - 260 : minimizedLeft) + 'px !important;';
}
full[minimizedLeft] = win;
}
Expand Down

0 comments on commit cec9cb4

Please sign in to comment.