-/*jslint nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
+/*jslint regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
/*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, plugins, registerTouches, randomString */
kiwi.front = {
revision: 38,
new_width = new_width - parseInt($('#kiwi .userlist').css('margin-right'), 10);
// Make sure we don't remove the userlist alltogether
- console.log(new_width);
if (new_width < 20) {
$(this).data('draggable').offset.click.left = 10;
console.log('whoaa');
kiwi.front.doLayout();
try {
kiwi.front.run('/connect ' + netsel.val() + ' ' + netport.val() + ' ' + (netssl.attr('checked') ? 'true' : ''));
- } catch (e) {}
+ } catch (e) {
+ console.log(e);
+ }
$('#kiwi .connectwindow').slideUp('', kiwi.front.barsShow);
$('#windows').click(function () { $('#kiwi_msginput').focus(); });
case '/connect':
case '/server':
- if (parts[1] === undefined) {
- alert('Usage: /connect servername [[port] [ssl]]');
+ if (typeof parts[1] === 'undefined') {
+ alert('Usage: /connect servername [port] [ssl]');
break;
}
- if (parts[2] === undefined) {
+ if (typeof parts[2] === 'undefined') {
parts[2] = 6667;
}
- if ((parts[3] === undefined) || (parts[3] === 'false') || (parts[3] === 'no')) {
+ if ((typeof parts[3] === 'undefined') || !parts[3] || (parts[3] === 'false') || (parts[3] === 'no')) {
parts[3] = false;
} else {
parts[3] = true;
}
- kiwi.front.cur_channel.addMsg(null, ' ', '=== Connecting to ' + parts[1] + ' on port ' + parts[2] + ((parts[3]) ? ' using SSL' : '') + '...', 'status');
+ kiwi.front.cur_channel.addMsg(null, ' ', '=== Connecting to ' + parts[1] + ' on port ' + parts[2] + (parts[3] ? ' using SSL' : '') + '...', 'status');
kiwi.gateway.connect(parts[1], parts[2], parts[3]);
break;
default:
//kiwi.front.cur_channel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
- kiwi.gateway.raw(msg.substring(1));
+ kiwi.gateway.raw(msg.substring(1));
}
} else {
},
registerKeys: function () {
+ var tabcomplete = {active: false, data: [], prefix: ''};
$('#kiwi_msginput').bind('keydown', function (e) {
- var windows, meta, num, msg, data, candidates, word_pos, word, i;
+ var windows, meta, num, msg, data, candidates, word_pos, word, i, self;
windows = $('#windows');
//var meta = e.altKey;
meta = e.ctrlKey;
+ if (e.which !== 9) {
+ tabcomplete.active = false;
+ tabcomplete.data = [];
+ tabcomplete.prefix = '';
+ }
+
switch (true) {
case (e.which >= 48) && (e.which <= 57):
if (meta) {
break;
case e.which === 9: // tab
- // Get possible autocompletions
- data = [];
- kiwi.front.cur_channel.userlist.children().each(function () {
- var nick;
- nick = kiwi.front.nickStripPrefix($('a.nick', this).text());
- data.push(nick);
- });
+ tabcomplete.active = true;
+ if (_.isEqual(tabcomplete.data, [])) {
+ // Get possible autocompletions
+ data = [];
+ kiwi.front.cur_channel.userlist.children().each(function () {
+ var nick;
+ nick = kiwi.front.nickStripPrefix($('a.nick', this).text());
+ data.push(nick);
+ });
+ data = _.sortBy(data, function (nick) {
+ return nick;
+ });
+ tabcomplete.data = data;
+ }
- // Do the autocomplete
- if (this.value.length === this.selectionStart && this.value.length === this.selectionEnd) {
- candidates = [];
-
- word_pos = this.value.lastIndexOf(' ');
- word = "";
- if (word_pos === -1) {
- word = this.value;
- } else {
- word = this.value.substr(word_pos);
+ if (this.value[this.selectionStart - 1] === ' ') {
+ return false;
+ }
+ self = this;
+ (function () {
+ var tokens = self.value.substring(0, self.selectionStart).split(" "),
+ val,
+ p1,
+ newnick,
+ range;
+ nick = tokens[tokens.length - 1];
+ if (tabcomplete.prefix === '') {
+ tabcomplete.prefix = nick;
}
- word = word.trim();
- // filter data to find only strings that start with existing value
- for (i = 0; i < data.length; i++) {
- if (data[i].indexOf(word) === 0 && data[i].length > word.length) {
- candidates.push(data[i]);
- }
- }
+ tabcomplete.data = _.select(tabcomplete.data, function (n) {
+ return (n.toLowerCase().indexOf(tabcomplete.prefix.toLowerCase()) === 0);
+ });
- if (candidates.length > 0) {
- // some candidates for autocompletion are found
- this.value = this.value.substring(0, word_pos) + ' ' + candidates[0] + ': ';
- this.selectionStart = this.value.length;
+ if (tabcomplete.data.length > 0) {
+ p1 = self.selectionStart - (nick.length);
+ val = self.value.substr(0, p1);
+ newnick = tabcomplete.data.shift();
+ tabcomplete.data.push(newnick);
+ val += newnick;
+ val += self.value.substr(self.selectionStart);
+ self.value = val;
+ if (self.setSelectionRange) {
+ self.setSelectionRange(p1 + newnick.length, p1 + newnick.length);
+ } else if (self.createTextRange) { // not sure if this bit is actually needed....
+ range = self.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', p1 + newnick.length);
+ range.moveStart('character', p1 + newnick.length);
+ range.select();
+ }
}
- }
+ }());
return false;
}
});
this.name = rand_name;
this.title = name;
this.topic = ' ';
+ this.panel = $('#panel1');
- $('#kiwi .windows .scroller').append('<div id="' + tmp_divname + '" class="messages"></div>');
+ if (typeof $('.scroller', this.panel)[0] === 'undefined') {
+ this.panel.append('<div id="' + tmp_divname + '" class="messages"></div>');
+ } else {
+ $('.scroller', this.panel).append('<div id="' + tmp_divname + '" class="messages"></div>');
+ }
this.tab = $('<li id="' + tmp_tabname + '">' + this.title + '</li>');
this.tab.click(function () {
kiwi.front.utilityviews[rand_name.toLowerCase()].show();
});
$('#kiwi .utilityviewlist ul').append(this.tab);
+ kiwi.front.doLayoutSize();
this.div = $('#' + tmp_divname);
this.div.css('overflow', 'hidden');
Utilityview.prototype.div = null;
Utilityview.prototype.tab = null;
Utilityview.prototype.topic = ' ';
+Utilityview.prototype.panel = null;
Utilityview.prototype.show = function () {
- $('#kiwi .messages').removeClass("active");
+ $('.messages', this.panel).removeClass("active");
$('#kiwi .userlist ul').removeClass("active");
$('#kiwi .toolbars ul li').removeClass("active");
- $('#windows').css('overflow-y', 'hidden');
+ this.panel.css('overflow-y', 'hidden');
$('#windows').css('right', 0);
// Activate this tab!
this.div.addClass('active');
}
};
+Utilityview.prototype.setPanel = function (new_panel) {
+ this.div.detach();
+ this.panel = new_panel;
+ this.panel.append(this.div);
+ this.show();
+};
+
Utilityview.prototype.close = function () {
this.div.remove();
this.tab.remove();
*/
-var Tabview = function () {};
+var Tabview = function () {
+ this.panel = $('#panel1');
+};
Tabview.prototype.name = null;
Tabview.prototype.div = null;
Tabview.prototype.userlist = null;
Tabview.prototype.tab = null;
Tabview.prototype.topic = "";
Tabview.prototype.safe_to_close = false; // If we have been kicked/banned/etc from this channel, don't wait for a part message
+Tabview.prototype.panel = null;
Tabview.prototype.show = function () {
var w, u;
- $('#kiwi .messages').removeClass("active");
+ $('.messages', this.panel).removeClass("active");
$('#kiwi .userlist ul').removeClass("active");
$('#kiwi .toolbars ul li').removeClass("active");
w = $('#windows');
u = $('#kiwi .userlist');
- w.css('overflow-y', 'scroll');
+ this.panel.css('overflow-y', 'scroll');
// Set the window size accordingly
this.setUserlistWidth();
};
Tabview.prototype.scrollBottom = function () {
- var w = $('#windows');
- w[0].scrollTop = w[0].scrollHeight;
+ var panel = this.panel;
+ console.log(panel);
+ panel[0].scrollTop = panel[0].scrollHeight;
};
Tabview.prototype.changeNick = function (newNick, oldNick) {