aboutsummaryrefslogtreecommitdiff
path: root/static/pastebin.js
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2011-12-05 22:38:43 -0500
committerArmin Ronacher <armin.ronacher@active-4.com>2011-12-05 22:38:43 -0500
commit803d20968fea1e25a298aa3b4e670d5670995e0d (patch)
tree2f90c6b8403e85576d0109a672dccb46598ce115 /static/pastebin.js
downloadstackbin-803d20968fea1e25a298aa3b4e670d5670995e0d.tar.gz
stackbin-803d20968fea1e25a298aa3b4e670d5670995e0d.tar.bz2
stackbin-803d20968fea1e25a298aa3b4e670d5670995e0d.zip
Added as example app
Diffstat (limited to 'static/pastebin.js')
-rw-r--r--static/pastebin.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/static/pastebin.js b/static/pastebin.js
new file mode 100644
index 0000000..8507726
--- /dev/null
+++ b/static/pastebin.js
@@ -0,0 +1,61 @@
+(function() {
+ var global = this;
+
+ var jug = new Juggernaut();
+
+ var lib = global.pastebin = {
+ urlRoot : '/',
+ jug : jug,
+
+ autoHideFlashes : function() {
+ var flashes = $('p.flash:visible').hide();
+ if (flashes.length) {
+ flashes.slideDown('fast');
+ window.setTimeout(function() {
+ flashes.slideUp('slow');
+ }, 5000);
+ }
+ },
+
+ flash : function(message) {
+ $('<p class=flash></p>')
+ .append(message)
+ .hide()
+ .insertAfter('ul.nav')
+ .slideDown('fast');
+ },
+
+ onNewReply : function(reply, type) {
+ var pasteDescription = '';
+ if (type == 'user') {
+ pasteDescription = 'your paste <a href="' +
+ pastebin.urlRoot + reply.paste_id + '">#' + reply.paste_id + '</a>';
+ } else {
+ pasteDescription = 'this paste';
+ }
+ var msg = $('<span>New reply to ' + pasteDescription + ': <a href="' +
+ pastebin.urlRoot + reply.reply_id + '">#' + reply.reply_id + '</a></span>');
+ if (reply.author)
+ msg.append($('<span></span>').text(' ' + reply.author))
+ lib.flash(msg);
+ },
+
+ subscribePaste : function(pasteID) {
+ jug.subscribe('paste-replies:' + pasteID, function(data) {
+ lib.onNewReply(data, 'paste');
+ });
+ },
+
+ subscribeUser : function(userID) {
+ jug.subscribe('user-replies:' + userID, function(data) {
+ lib.onNewReply(data, 'user');
+ });
+ }
+ };
+
+
+ $(function() {
+ /* animate the server side flashes a bit */
+ lib.autoHideFlashes();
+ });
+})();
bgstack15