forked from horejsek/groovesharkControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Improvement: notification.js rewrited to Class;
- Fix: notification stay doesn't works;
- Loading branch information
1 parent
3d0ae07
commit 58c91ad
Showing
6 changed files
with
75 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters