From 5afe5f667eb7120ec0790f82809d585cb36c9707 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 12 Apr 2011 17:15:02 -0700 Subject: [PATCH] Move js out of notifications index, fix reference to notifications badge --- app/views/notifications/index.html.haml | 32 ++----------------------- config/assets.yml | 2 ++ public/javascripts/notifications.js | 28 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 public/javascripts/notifications.js diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 4cc038c02..bc4de8fae 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,33 +1,5 @@ -:javascript - $('.stream_element').live('mousedown', function(evt){ - var note = $(this).closest('.stream_element'), - note_id = note.attr('data-guid'), - nBadge = $("#notification_badge_number"); - - if(note.hasClass('unread') ){ - note.removeClass('unread'); - $.ajax({ - url: 'notifications/' + note_id, - type: 'PUT' - }); - } - if(nBadge.html() != null) { - nBadge.html().replace(/\d+/, function(num){ - num = parseInt(num); - nBadge.html(parseInt(num)-1); - if(num == 1) { - nBadge.addClass("hidden"); - } - }); - - } - }); - - $('a.more').live('click', function(){ - $(this).hide(); - $(this).next('span').removeClass('hidden'); - }); - +- content_for :head do + = include_javascripts :notifications .span-1 = image_tag 'icons/mail_big.png', :height => 30, :width => 30, :style=>"margin-top:3px;" .span-10 diff --git a/config/assets.yml b/config/assets.yml index ad1df666f..34d5db119 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -66,6 +66,8 @@ javascripts: - public/javascripts/inbox.js profile: - public/javascripts/vendor/jquery.autoSuggest.custom.js + notifications: + - public/javascripts/notifications.js stylesheets: default: diff --git a/public/javascripts/notifications.js b/public/javascripts/notifications.js new file mode 100644 index 000000000..12aa5263b --- /dev/null +++ b/public/javascripts/notifications.js @@ -0,0 +1,28 @@ +$('.stream_element').live('mousedown', function(evt){ + var note = $(this).closest('.stream_element'), + note_id = note.attr('data-guid'), + nBadge = $("#notification_badge .badge_count") + + if(note.hasClass('unread') ){ + note.removeClass('unread'); + $.ajax({ + url: 'notifications/' + note_id, + type: 'PUT' + }); + } + if(nBadge.html() != null) { + nBadge.html().replace(/\d+/, function(num){ + num = parseInt(num); + nBadge.html(parseInt(num)-1); + if(num == 1) { + nBadge.addClass("hidden"); + } + }); + + } +}); + +$('a.more').live('click', function(){ + $(this).hide(); + $(this).next('span').removeClass('hidden'); +});