Skip to content

Commit

Permalink
- Improvement: notification.js rewrited to Class;
Browse files Browse the repository at this point in the history
- Fix: notification stay doesn't works;
  • Loading branch information
rentalhost committed Oct 1, 2011
1 parent 3d0ae07 commit 58c91ad
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 77 deletions.
13 changes: 2 additions & 11 deletions javascript/groovesharkControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,9 @@ function _showNotification (stay, view) {

if ((!isNotificationOpen() && !isGroovesharkFocused) || stay) {
var notification = webkitNotifications.createHTMLNotification('../views/'+view+'.html');
notification.show();
}

if (stay) {
chrome.extension.getViews({type: 'popup'}).forEach(function(win) {
win.hidePin();
});
setTimeout(function () {
chrome.extension.getViews({type: 'notification'}).forEach(function (win) {
win.turnOffCloseOfWindow();
});
}, 100);
localStorage['_notificationStay'] = stay === true;
notification.show();
}
}

Expand Down
113 changes: 59 additions & 54 deletions javascript/notification.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@

var shouldClose = true;
var Notification = new function(){
this.timer = false;

function closeNotification () {
setTimeout(function () {
if (shouldClose) window.close();
}, howLongDisplayNotification());
}
// Init notification system
this.init = function(){
// Countdown ONLY if not need "stay"
if (localStorage.getItem('_notificationStay') !== 'true') {
this.countDown();
}
else {
localStorage['_notificationStay'] = false;
this.cancelClose();
}

function countDown () {
var step = 50;
var totalTime = 0;
getData();
setUpProgressbar();

function _countDown () {
if (shouldClose) {
totalTime += step;
var percent = totalTime / (howLongDisplayNotification() / 100);
$('#countDown').css('width', (100-percent) + '%');
setTimeout(_countDown, step);
}
}
_countDown();
}
$('#liteLine').SetScroller({
velocity: 50,
direction: 'horizontal',
startfrom: 'right',
loop: 'infinite',
movetype: 'linear',
onmouseover: 'pause',
onmouseout: 'play',
onstartup: 'play',
cursor: 'pointer'
});

function init () {
closeNotification();
countDown();
getData();
setUpProgressbar();
setUpNotification();
$('#switchToLiteNotification').click(function () {
showLiteNotification(true);
setTimeout(window.close, 200);
});

// Start the controller
controlInit();
$('#switchToFullNotification').click(function () {
showNotification(true);
setTimeout(window.close, 200);
});

// Close window if tab is closed
onTabCloseAccept();
}
// Start the controller
controlInit();

function turnOffCloseOfWindow () {
shouldClose = false;
$('#countDown').css('display', 'none');
}
// Close window if tab is closed
onTabCloseAccept();
}

// Starts the countdown
this.countDown = function(){
console.trace();
var startTime = (new Date()).getTime();
this.timer = setInterval(function(){
var percent = Math.min(100, 100 / howLongDisplayNotification() * ( (new Date()).getTime() - startTime ));
$('#countDown').width((100 - percent) + '%');

function setUpNotification () {
$('#liteLine').SetScroller({
velocity: 50,
direction: 'horizontal',
startfrom: 'right',
loop: 'infinite',
movetype: 'linear',
onmouseover: 'pause',
onmouseout: 'play',
onstartup: 'play',
cursor: 'pointer'
});
// Close if get 100%
if (percent === 100) {
window.close();
}
}, 50);
}

$('#switchToLiteNotification').click(function () {
showLiteNotification(true);
setTimeout(window.close, 200);
});
// Cancel the close
this.cancelClose = function(){
if (this.timer !== false) {
clearInterval(this.timer);
}

$('#switchToFullNotification').click(function () {
showNotification(true);
setTimeout(window.close, 200);
});
$('#countDown').hide();
}
}
20 changes: 11 additions & 9 deletions javascript/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ var Popup = new function(){
// Close window if tab is closed
onTabCloseAccept();

if (isNotificationOpen()) hidePin();
else showPin();
}
}
// Show/hide notification pin
this.togglePin(!isNotificationOpen());

function showPin () {
$('#pin').show();
}
// On click in pin, hide it
$('#pin').click(function(){
window.close();
});
}

function hidePin () {
$('#pin').hide();
// Show/hide notification pin
this.togglePin = function(mode) {
$('#pin').toggle(mode);
}
}
2 changes: 1 addition & 1 deletion views/liteNotification.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="text/javascript" src="../javascript/groovesharkControl.js"></script>
<script type="text/javascript" src="../javascript/notification.js"></script>
</head>
<body onload="init();" onmouseover="turnOffCloseOfWindow();">
<body onload="Notification.init();" onmouseover="Notification.cancelClose();">
<div class="nowPlaying">
<div id="liteLine">
<div class="scrollingtext">
Expand Down
2 changes: 1 addition & 1 deletion views/notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="text/javascript" src="../javascript/groovesharkControl.js"></script>
<script type="text/javascript" src="../javascript/notification.js"></script>
</head>
<body onload="init();" onmouseover="turnOffCloseOfWindow();">
<body onload="Notification.init();" onmouseover="Notification.cancelClose();">
<div class="nowPlaying">
<img class="image" />
<div class="song"></div>
Expand Down
2 changes: 1 addition & 1 deletion views/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</head>
<body onload="Popup.init();">
<div id="player" class="player">
<button id="pin" class="unpin" onclick="showNotification(stay=true);" i18n-title="playerPin"></button>
<button id="pin" class="unpin" onclick="showNotification(true);" i18n-title="playerPin"></button>
<button id="shuffle" class="false" onclick="userAction('toggleShuffle');" i18n-title="songShuffle"></button>
<button id="loop" class="none" onclick="userAction('toggleLoop');" title="Loop songs" i18n-title="songLoop"></button>
<button id="crossfade" class="false" onclick="userAction('toggleCrossfade');" i18n-title="songCrossfade"></button>
Expand Down

0 comments on commit 58c91ad

Please sign in to comment.