$(function () {
kiwi.app = new kiwi.model.Application({container: $('#kiwi')});
+ kiwi.app.start();
});
</script>
</body>
\r
kiwi.model.PanelList = Backbone.Collection.extend({\r
model: kiwi.model.Panel,\r
+\r
+ // Holds the active panel\r
+ active: null,\r
+\r
comparator: function (chan) {\r
return chan.get("name");\r
},\r
kiwi.gateway.on('change:name', this.view.render, this.view);\r
this.add(this.server);\r
\r
- // Set the default view to the server tab\r
- kiwi.current_panel = this.server;\r
+ this.bind('active', function (active_panel) {\r
+ this.active = active_panel;\r
+ }, this);\r
\r
},\r
getByName: function (name) {\r
\r
this.destroy();\r
\r
- if (this.cid === kiwi.current_panel.cid) {\r
+ // If closing the active panel, switch to the server panel\r
+ if (this.cid === kiwi.app.panels.active.cid) {\r
kiwi.app.panels.server.view.show();\r
}\r
},\r
this.initialize = function () {\r
// Update `that` with this new Model object\r
that = this;\r
+ };\r
\r
+ this.start = function () {\r
// Set the gateway up\r
kiwi.gateway = new kiwi.model.Gateway();\r
this.bindGatewayCommands(kiwi.gateway);\r
c.set('topic', event.topic);\r
\r
// If this is the active channel, update the topic bar too\r
- if (c.get('name') === kiwi.current_panel.get('name')) {\r
+ if (c.get('name') === kiwi.app.panels.active.get('name')) {\r
that.topicbar.setCurrentTopic(event.topic);\r
}\r
});\r
};\r
\r
this.actionCommand = function (ev) {\r
- if (kiwi.current_panel === kiwi.app.panels.server) {\r
+ if (kiwi.app.panels.active === kiwi.app.panels.server) {\r
return;\r
}\r
\r
- var panel = kiwi.current_panel;\r
+ var panel = kiwi.app.panels.active;\r
panel.addMsg('', '* ' + kiwi.gateway.get('nick') + ' ' + ev.params.join(' '), 'action');\r
kiwi.gateway.action(panel.get('name'), ev.params.join(' '));\r
};\r
\r
this.partCommand = function (ev) {\r
if (ev.params.length === 0) {\r
- kiwi.gateway.part(kiwi.current_panel.get('name'));\r
+ kiwi.gateway.part(kiwi.app.panels.active.get('name'));\r
} else {\r
_.each(ev.params, function (channel) {\r
kiwi.gateway.part(channel);\r
});\r
}\r
// TODO: More responsive = close tab now, more accurate = leave until part event\r
- //kiwi.app.panels.remove(kiwi.current_panel);\r
+ //kiwi.app.panels.remove(kiwi.app.panels.active);\r
};\r
\r
this.topicCommand = function (ev) {\r
channel_name = ev.params[0];\r
ev.params.shift();\r
} else {\r
- channel_name = kiwi.current_panel.get('name');\r
+ channel_name = kiwi.app.panels.active.get('name');\r
}\r
\r
kiwi.gateway.topic(channel_name, ev.params.join(' '));\r
this.$container.parent().css('right', '0');\r
}\r
\r
- // TODO: Why is kiwi.app not defined when this is fist called :/\r
- if (kiwi.app) {\r
- kiwi.app.topicbar.setCurrentTopic(this.model.get("topic") || "");\r
- }\r
+ kiwi.app.topicbar.setCurrentTopic(this.model.get("topic") || "");\r
\r
this.scrollToBottom();\r
\r
- kiwi.current_panel = this.model;\r
-\r
this.trigger('active', this.model);\r
+ kiwi.app.panels.trigger('active', this.model);\r
},\r
\r
\r
this.model.addMsg('', '=== Topic for ' + this.model.get('name') + ' is: ' + topic, 'topic');\r
\r
// If this is the active channel then update the topic bar\r
- if (kiwi.current_panel === this) {\r
+ if (kiwi.app.panels.active === this) {\r
kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));\r
}\r
}\r
\r
if (ev.keyCode !== 13) return;\r
\r
- if (kiwi.current_panel.isChannel && kiwi.current_panel.isChannel()) {\r
- kiwi.gateway.topic(kiwi.current_panel.get('name'), inp_val);\r
+ if (kiwi.app.panels.active.isChannel()) {\r
+ kiwi.gateway.topic(kiwi.app.panels.active.get('name'), inp_val);\r
}\r
},\r
\r
} else {\r
// Default command\r
command = 'msg';\r
- params.unshift(kiwi.current_panel.get('name'));\r
+ params.unshift(kiwi.app.panels.active.get('name'));\r
}\r
\r
// Trigger the command events\r