1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| function get_data() { $.ajax({ url: '/ajax/notify-pull', data: '', success: function(data) {
var j= $.parseJSON(data); var temp = $.parseJSON(localStorage.getItem('notify')); if (j.count != 0) { if(temp == null) temp = {}; for (var n in j.notifies) { temp[j.notifies[n]['id']] = j.notifies[n]; } localStorage.setItem('notify', JSON.stringify(temp)); } $(".scroll-content>ul").html(""); var n = temp; var num = 0; for(var a in n) { if (n[a]!=null) { moment.locale('zh-Cn'); var day = moment.unix(n[a]['created_at']).fromNow(); $(".scroll-content>ul").append( "<li>"+ "<a id='"+ n[a]['id']+"' href='"+ n[a]['content']['url']+ "'>"+ "<i style='margin-right: 10px;' class=\"btn btn-xs btn-primary fa fa-user\"></i>"+ n[a]['content']['message']+"<span>"+day+"</span>"+ "</a>"+ "</li>" ); num ++; } }
if(num==0){ $(".badge.badge-important").html("0"); $(".dropdown-header").html("您现在没有通知!"); }else{ $(".badge.badge-important").html(num); $(".dropdown-header").html("您有"+num+"条通知,请注意查收!"); }
$(document).on("click", '.scroll-content ul li a', function(){
delete n[parseInt($(this).attr('id'))];
localStorage.setItem('notify', JSON.stringify(n));
$(".badge.badge-important").html(num-1); $(".dropdown-header").html("您有"+(num-1)+"条通知,请注意查收!");
return true; }); } }); }
|