Permalink
Browse files

Added click listener to notification

  • Loading branch information...
1 parent f843488 commit 6ad7b629e94c28fc18bc2840db7012a420aa391e @samvtran committed Jan 11, 2013
Showing with 38 additions and 29 deletions.
  1. +19 −16 coffee/main.coffee
  2. +1 −1 manifest.json
  3. +18 −12 scripts/main.js
View
@@ -182,7 +182,7 @@ omgUtil.service 'Articles', ['$q', '$rootScope', 'LocalStorage', 'Notification',
addArticle.onsuccess = (event) ->
# TODO increment unread if matches categories list
LocalStorage.increment()
- localStorage['newArticles'] = parseInt(localStorage['newArticles']) + 1
+ localStorage['newArticles'] = ~~localStorage['newArticles'] + 1
$rootScope.$apply () ->
deferred.resolve()
addArticle.onerror = (event) ->
@@ -244,21 +244,18 @@ omgUtil.filter 'truncate', () -> (input, count) ->
if typeof input is "undefined" then return "";
if input.length <= count
return final
- truncated = input.substring(0, (count))
- # Is the current EOL whitespace?
- if truncated.substring(truncated.length - 1).match(/\s/)
- final = truncated
+ truncated = input.substring(0, count)
+
# Is the character after whitespace?
if input.substring(truncated.length, truncated.length + 1).match(/\s/)
final = truncated
-
- # Search backwards until we hit whitespace or the end of the string.
- for i in [1 .. (truncated.length - 1)]
- truncatedTest = truncated.substring(truncated.length - i, truncated.length - (i - 1));
- if truncatedTest.match(/\s/)
- final = truncated.substring(0, truncated.length - i)
- break;
- return final + "..."
+ else # Search backwards until we hit whitespace or the end of the string.
+ for i in [1 .. (truncated.length - 1)]
+ truncatedTest = truncated.substring(truncated.length - i, truncated.length - (i - 1))
+ if truncatedTest.match(/\s/)
+ final = truncated.substring(0, truncated.length - i)
+ break
+ final + "..."
omgUtil.filter 'uriEncode', () -> (input) ->
encodeURIComponent input
@@ -279,11 +276,11 @@ omgUtil.service 'Badge', [->
omgUtil.service 'LocalStorage', ['Badge', (Badge)->
increment = () ->
- localStorage['unread'] = parseInt(localStorage['unread']) + 1
+ localStorage['unread'] = ~~localStorage['unread'] + 1
Badge.notify()
decrement = () ->
if localStorage['unread'] is "0" then return
- localStorage['unread'] = parseInt(localStorage['unread']) - 1
+ localStorage['unread'] = ~~localStorage['unread'] - 1
Badge.notify()
reset = () ->
localStorage['unread'] = 0
@@ -307,17 +304,23 @@ omgUtil.service 'Notification', ['$filter', ($filter) ->
if cursor
singleNotify(cursor.value)
if localStorage['newArticles'] > 1
- multiNotify(localStorage['newArticles'])
+ multiNotify localStorage['newArticles']
singleNotify = (article) ->
if localStorage['notificationsEnabled'] is "false" then return
notification = webkitNotifications.createNotification('/images/icon48.png', "New article! #{article.title}", "#{$filter('truncate')(article.summary, 100)}")
+ notification.addEventListener 'click', () ->
+ notification.cancel()
+ window.open article.link
notification.show()
setTimeout () ->
notification.cancel()
, 7500
multiNotify = (number) ->
if localStorage['notificationsEnabled'] is "false" then return
notification = webkitNotifications.createNotification('/images/icon48.png', 'New articles!', "#{number} new articles on OMG! Ubuntu!")
+ notification.addEventListener 'click', () ->
+ notification.cancel()
+ window.open 'http://omgubuntu.co.uk'
notification.show()
setTimeout () ->
notification.cancel()
View
@@ -1,6 +1,6 @@
{
"name": "OMG! Ubuntu!",
- "version": "1.6",
+ "version": "1.7",
"manifest_version": 2,
"description": "The official OMG! Ubuntu! extension",
"icons": {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 6ad7b62

Please sign in to comment.