summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/index/index.js
blob: b370c9e9002c55a58cccff620d74a6b11a399a06 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var IndexView = View.extend({
  events: {},

  action: "/api/index",
  keywordAction: "/api/keyword/",

  initialize: function (opt) {
    // opt.parent = parent
    this.hootbox = new HootBox({ parent: this });
    this.threadbox = new ThreadBox({ parent: this });
    this.lastlog = new LastLog({ parent: this });
    this.countdown = new Countdown({ parent: this });
  },

  load: function (keyword) {
    $("body").addClass("index");
    if (keyword) {
      $(".subtitle").html(
        '<a href="/">&lt; Home</a> &middot; <a href="/keywords">Keywords</a>'
      );
      this.threadbox.options.latest = false;
      this.threadbox.options.welcome = false;
      $.get(this.keywordAction + keyword, this.populate.bind(this));
    } else {
      this.hootbox.options.required = true;
      this.threadbox.options.latest = true;
      this.threadbox.options.welcome = true;
      $.get(this.action, this.populate.bind(this));
    }
  },

  populate: function (data) {
    $("body").removeClass("loading");
    this.data = data;
    this.hootbox.load(data.hootbox);
    this.threadbox.load(data);
    this.lastlog.load(data.lastlog);
    if (data.mail.count) {
      $(".alert")
        .show()
        .html(
          "<a href='/mail'>" +
            "You have " +
            data.mail.count +
            " new message" +
            courtesy_s(data.mail.count) +
            "!</a>"
        );
      if (is_mobile) {
        $("#content").prepend($(".alert"));
      }
    }
    if (is_desktop) {
      $(".search_form input").focus();
    }
  },

  success: function () {
    window.location.href = "/index";
  },
});