diff options
author | Git <git@what.cd> | 2013-08-28 23:08:41 +0000 |
---|---|---|
committer | Git <git@what.cd> | 2013-08-28 23:08:41 +0000 |
commit | 3e3fdfb804b3faea02df1c0a40ed2cba3b5f3663 (patch) | |
tree | 0dfbaae1ba2bc758afcdf45dacb3471552f9849c /static/functions/user_notifications.js | |
parent | db7ddd03782cae2be19499450d3948c5950e43fa (diff) | |
download | Gazelle-3e3fdfb804b3faea02df1c0a40ed2cba3b5f3663.zip Gazelle-3e3fdfb804b3faea02df1c0a40ed2cba3b5f3663.tar.gz Gazelle-3e3fdfb804b3faea02df1c0a40ed2cba3b5f3663.tar.bz2 |
Empty commit
Diffstat (limited to 'static/functions/user_notifications.js')
-rw-r--r-- | static/functions/user_notifications.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/static/functions/user_notifications.js b/static/functions/user_notifications.js new file mode 100644 index 0000000..3639799 --- /dev/null +++ b/static/functions/user_notifications.js @@ -0,0 +1,124 @@ +// This a global variable because other scripts need to use it +var notifications; + +$(document).ready(function() { + var url = new URL(); + + $.ajax({ + type: "GET", + url: "ajax.php?action=get_user_notifications" + (url.query.clearcache ? "&clearcache=" + url.query.clearcache : ""), + dataType: "json", + data: { + "skip" : getSkippedPage(url) + } + }).done(function(results) { + notifications = results; + if (results['status'] == 'success') { + results = results['response']; + if (results) { + $.each(results, function(type, notification) { + if (type != "Rippy") { + createNoty(type, notification['contents']['id'], notification['contents']['message'], notification['contents']['url'], notification['contents']['importance']); + if (type == "Subscriptions") { + $("#userinfo_minor").addClass("highlite"); + $("#nav_subscriptions").addClass("new-subscriptions"); + } + } + else { + $.getScript("static/functions/rippy.js"); + } + }); + } + } + }); +}); + +function getSkippedPage(url) { + var skip = ""; + switch(url.path) { + case "inbox": + if (url.query.length == 0) { + skip = "Inbox"; + } + break; + case "userhistory": + if (url.query['action'] == "subscriptions") { + skip = "Subscriptions"; + } + if (url.query['action'] == "quote_notifications") { + skip = "Quotes"; + } + if (url.query['action'] == "subscribed_collages") { + skip = "Collages"; + } + break; + case "user": + if (url.query['action'] == "notify") { + skip = "Torrents"; + } + break; + case "blog": + if (url.query.length == 0) { + skip = "Blog"; + } + break; + case "index": + if (url.query.length == 0) { + skip = "News"; + } + break; + case "staffpm": + if (url.query.length == 0) { + skip = "StaffPM"; + } + break; + default: + break; + } + return skip; +} + +function createNoty(type, id, message, url, importance) { + var hidden = !url ? "hidden" : ""; + noty({ + text: message, + type: importance, + layout: 'bottomRight', + closeWith: ['click'], + animation: { + open: {height: 'toggle'}, + close: {height: 'toggle'}, + easing: 'swing', + speed: 250 + }, + buttonElement : 'a', + buttons: [ + { + addClass: 'brackets noty_button_view ' + hidden, text: 'View', href: url + }, + { + addClass: 'brackets noty_button_clear', text: 'Clear', onClick: function($noty) { + $noty.close(); + clear(type, id); + } + }, + { + addClass: 'brackets noty_button_close ', text: 'Dismiss', onClick: function($noty) { + $noty.close(); + } + }, + ] + }); +} + +function clear(type, id) { + $.ajax({ + type : "POST", + url: "ajax.php?action=clear_user_notification", + dataType: "json", + data : { + "type" : type, + "id" : id + } + }); +} |