Tabview completely removed
[KiwiIRC.git] / client / js / view.js
1 /*jslint white:true, regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
2 /*global kiwi */
3
4 kiwi.view = {};
5
6 kiwi.view.MemberList = Backbone.View.extend({
7 tagName: "ul",
8 events: {
9 "click .nick": "nickClick"
10 },
11 initialize: function (options) {
12 $(this.el).attr("id", 'kiwi_userlist_' + options.name);
13 this.model.get("members").bind('change', this.render, this);
14 },
15 render: function () {
16 var $this = $(this.el);
17 $this.empty();
18 this.model.get("members").forEach(function (member) {
19 $this.append('<li><a class="nick"><span class="prefix">' + user.prefix + user.nick + '</a></li>');
20 });
21 },
22 nickClick: function (x) {
23 console.log(x);
24 }
25 });
26
27 kiwi.view.Channel = Backbone.View.extend({
28 tagName: "div",
29 className: "messages",
30 events: {
31 "click .chan": "chanClick"
32 },
33 initialize: function (options) {
34 this.htmlsafe_name = 'chan_' + randomString(15);
35 $(this.el).attr("id", 'kiwi_window_' + this.htmlsafe_name).css('display', 'none');
36 this.el = $(this.el).appendTo('#panel1 .scroller')[0];
37 this.model.bind('msg', this.newMsg, this);
38 this.msg_count = 0;
39 this.model.set({"view": this}, {"silent": true});
40 },
41 render: function () {
42 var $this = $(this.el);
43 $this.empty();
44 this.model.get("backscroll").forEach(this.newMsg);
45 },
46 newMsg: function (msg) {
47 var re, line_msg, $this = $(this.el);
48 // Make the channels clickable
49 re = new RegExp('\\B(' + kiwi.gateway.channel_prefix + '[^ ,.\\007]+)', 'g');
50 msg.msg = msg.msg.replace(re, function (match) {
51 return '<a class="chan">' + match + '</a>';
52 });
53
54 msg.msg = kiwi.front.formatIRCMsg(msg.msg);
55
56 // Build up and add the line
57 line_msg = $('<div class="msg ' + msg.type + '"><div class="time">' + msg.time + '</div><div class="nick">' + msg.nick + '</div><div class="text" style="' + msg.style + '">' + msg.msg + ' </div></div>');
58 $this.append(line_msg);
59 this.msg_count++;
60 if (this.msg_count > 250) {
61 $('.msg:first', this.div).remove();
62 this.msg_count--;
63 }
64 },
65 chanClick: function (x) {
66 console.log(x);
67 },
68 show: function () {
69 $('#panel1 .scroller').children().css('display','none');
70 $(this.el).css('display', 'block');
71 }
72 });
73
74 kiwi.view.Tabs = Backbone.View.extend({
75 events: {
76 "click li": "tabClick"
77 },
78 initialize: function () {
79 this.model.bind("add", this.addTab, this);
80 this.model.bind("remove", this.removeTab, this);
81 this.model.bind("reset", this.render, this);
82 },
83 render: function () {
84 $this = $(this.el);
85 $this.empty();
86 this.model.forEach(function (tab) {
87 var tabname = $(tab.get("view").el).attr("id");
88 $('<li id="tab_' + tabname + '"><span>' + tab.get("name") + '</span></li>').data('chan', tab).appendTo($this)
89 });
90 },
91 addTab: function (tab) {
92 var tabname = $(tab.get("view").el).attr("id"),
93 $this = $(this.el);
94 $('<li id="tab_' + tabname + '"><span>' + tab.get("name") + '</span></li>').data('chan', tab).appendTo($this)
95 },
96 removeTab: function (tab) {
97 $('#tab_' + $(tab.get("view").el).attr("id")).remove();
98 },
99 tabClick: function (e) {
100 $(e.currentTarget).data('chan').view.show();
101 }
102 });
103
104
105
106
107
108
109
110
111
112
113