aboutsummaryrefslogtreecommitdiff
path: root/static/pastebin.js
blob: 441259529d1b5a87acae75d2b6a3f1b13bf0f5aa (plain)
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
(function() {
  var global = this;

  var lib = global.pastebin = {
    urlRoot : '/',

    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);
    }

  };


  $(function() {
    /* animate the server side flashes a bit */
    lib.autoHideFlashes();
  });
})();
bgstack15