X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Ffront.js;h=6b48ecc0d33875c914312e9ff63b6031d17ed350;hb=ef885bffe8e010ba327a5884c6a8de7239c80340;hp=c11e51b75a5e966ca698f4e49b6d7f68ee6142cd;hpb=c89b9fdfa39466d416576727dbdaa305f07e856c;p=KiwiIRC.git diff --git a/js/front.js b/js/front.js index c11e51b..6b48ecc 100644 --- a/js/front.js +++ b/js/front.js @@ -69,7 +69,7 @@ var front = { front.registerKeys(); - $('#kiwi .cur_topic').resize(front.doLayoutSize); + $('#kiwi .toolbars').resize(front.doLayoutSize); $('#kiwi .formconnectwindow').submit(function () { var netsel = $('#kiwi .formconnectwindow .network'), @@ -94,7 +94,7 @@ var front = { alert(e); } - $('#kiwi .connectwindow').slideUp(); + $('#kiwi .connectwindow').slideUp('', front.barsShow); $('#windows').click(function () { $('#kiwi_msginput').focus(); }); return false; @@ -102,11 +102,19 @@ var front = { supportsOrientationChange = (typeof window.onorientationchange !== undefined); orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; - window.addEventListener(orientationEvent, front.doLayoutSize, false); + if (window.addEventListener) { + window.addEventListener(orientationEvent, front.doLayoutSize, false); + } else { + // < IE9 + window.attachEvent(orientationEvent, front.doLayoutSize, false); + } //$('#kiwi').bind("resize", front.doLayoutSize, false); front.doLayout(); + front.barsHide(); + front.tabviewAdd('server'); + front.tabviews.server.userlist_width = 0; // Disable the userlist // Any pre-defined nick? if (typeof window.init_data.nick === "string") { @@ -194,8 +202,9 @@ var front = { }, doLayoutSize: function () { - var kiwi, ct, ul, n_top, n_bottom; + var kiwi, toolbars, ul, n_top, n_bottom; kiwi = $('#kiwi'); + if (kiwi.width() < 330 && !kiwi.hasClass('small_kiwi')) { console.log("switching to small kiwi"); kiwi.removeClass('large_kiwi'); @@ -205,16 +214,10 @@ var front = { kiwi.addClass('large_kiwi'); } - ct = $('#kiwi .cur_topic'); + toolbars = $('#kiwi .cur_topic'); ul = $('#kiwi .userlist'); - n_top = parseInt(ct.offset().top, 10) + parseInt(ct.height(), 10); - n_top = n_top + parseInt(ct.css('border-top-width').replace('px', ''), 10); - n_top = n_top + parseInt(ct.css('border-bottom-width').replace('px', ''), 10); - n_top = n_top + parseInt(ct.css('padding-top').replace('px', ''), 10); - n_top = n_top + parseInt(ct.css('padding-bottom').replace('px', ''), 10); - n_top += 1; // Dunno why this is needed.. but it's always 1 px out :/ - + n_top = parseInt(toolbars.offset().top, 10) + parseInt(toolbars.outerHeight(true), 10); n_bottom = $(document).height() - parseInt($('#kiwi .control').offset().top, 10); $('#kiwi .windows').css({top: n_top + 'px', bottom: n_bottom + 'px'}); @@ -245,7 +248,16 @@ var front = { run: function (msg) { - var parts, dest, t, pos, textRange, d; + var parts, dest, t, pos, textRange, d, plugin_event; + + // Run through any plugins + plugin_event = {command: msg}; + plugin_event = plugs.run('command_run', plugin_event); + if (!plugin_event || typeof plugin_event.command === 'undefined') return; + + // Update msg if it's been changed by any plugins + msg = plugin_event.command.toString(); + console.log("running " + msg); if (msg.substring(0, 1) === '/') { parts = msg.split(' '); @@ -392,7 +404,7 @@ var front = { onMsg: function (e, data) { - var destination; + var destination, plugin_event; // Is this message from a user? if (data.channel === gateway.nick) { destination = data.nick.toLowerCase(); @@ -400,10 +412,14 @@ var front = { destination = data.channel.toLowerCase(); } - if (!front.tabviewExists(destination)) { - front.tabviewAdd(destination); + plugin_event = {nick: data.nick, msg:data.msg, destination: destination}; + plugin_event = plugs.run('msg_recieved', plugin_event); + if (!plugin_event) return; + + if (!front.tabviewExists(plugin_event.destination)) { + front.tabviewAdd(plugin_event.destination); } - front.tabviews[destination].addMsg(null, data.nick, data.msg); + front.tabviews[plugin_event.destination].addMsg(null, plugin_event.nick, plugin_event.msg); }, onDebug: function (e, data) { @@ -468,23 +484,32 @@ var front = { onConnect: function (e, data) { if (data.connected) { + if (gateway.nick !== data.nick) { + gateway.nick = data.nick; + front.doLayout(); + } + front.tabviews.server.addMsg(null, ' ', '=== Connected OK :)', 'status'); if (typeof init_data.channel === "string") { front.joinChannel(init_data.channel); } + plugs.run('connect', {success: true}); } else { front.tabviews.server.addMsg(null, ' ', '=== Failed to connect :(', 'status'); + plugs.run('connect', {success: false}); } }, onConnectFail: function (e, data) { var reason = (typeof data.reason === 'string') ? data.reason : ''; front.tabviews.server.addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error'); + plugs.run('connect', {success: false}); }, onDisconnect: function (e, data) { var tab; for (tab in front.tabviews) { front.tabviews[tab].addMsg(null, '', 'Disconnected from server!', 'error'); } + plugs.run('disconnect', {success: false}); }, onOptions: function (e, data) { if (typeof gateway.network_name === "string" && gateway.network_name !== "") { @@ -648,6 +673,10 @@ var front = { case 'no_such_nick': front.tabviews.server.addMsg(null, ' ', '=== ' + data.nick + ': ' + data.reason, 'status'); break; + case 'nickname_in_use': + front.tabviews.server.addMsg(null, ' ', '=== The nickname ' + data.nick + ' is already in use. Please select a new nickname', 'status'); + front.showChangeNick(); + break; default: // We don't know what data contains, so don't do anything with it. //front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status'); @@ -883,13 +912,15 @@ var front = { }, tabviewAdd: function (v_name) { - var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname; + var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, userlist_enabled = true; + if (v_name.charAt(0) === gateway.channel_prefix) { re = new RegExp(gateway.channel_prefix, "g"); htmlsafe_name = v_name.replace(re, 'pre'); htmlsafe_name = "chan_" + htmlsafe_name; } else { htmlsafe_name = 'query_' + v_name; + userlist_enabled = false; } tmp_divname = 'kiwi_window_' + htmlsafe_name; @@ -909,6 +940,7 @@ var front = { front.tabviews[v_name.toLowerCase()].div = $('#' + tmp_divname); front.tabviews[v_name.toLowerCase()].userlist = $('#' + tmp_userlistname); front.tabviews[v_name.toLowerCase()].tab = $('#' + tmp_tabname); + if (!userlist_enabled) front.tabviews[v_name.toLowerCase()].userlist_width = 0; front.tabviews[v_name.toLowerCase()].show(); if (typeof registerTouches === "function") { @@ -927,27 +959,27 @@ var front = { userClick: function (item) { + var li = $(item).parent(); + // Remove any existing userboxes $('#kiwi .userbox').remove(); - - var li = $(item).parent(); - /*var html = '
\ - \ - Message\ - Info\ -
'; - li.append(html);*/ - $('#tmpl_user_box').tmpl({nick: front.nickStripPrefix($(item).text())}).appendTo(li); - - $('#kiwi .userbox .userbox_query').click(function (ev) { - var nick = $('#kiwi .userbox_nick').val(); - front.run('/query ' + nick); - }); - - $('#kiwi .userbox .userbox_whois').click(function (ev) { - var nick = $('#kiwi .userbox_nick').val(); - front.run('/whois ' + nick); - }); + + if ($(li).data('userbox') === item) { + $(li).removeData('userbox'); + } else { + $('#tmpl_user_box').tmpl({nick: front.nickStripPrefix($(item).text())}).appendTo(li); + + $('#kiwi .userbox .userbox_query').click(function (ev) { + var nick = $('#kiwi .userbox_nick').val(); + front.run('/query ' + nick); + }); + + $('#kiwi .userbox .userbox_whois').click(function (ev) { + var nick = $('#kiwi .userbox_nick').val(); + front.run('/whois ' + nick); + }); + $(li).data('userbox', item); + } }, @@ -1081,6 +1113,18 @@ var front = { } i++; } + }, + + + + barsShow: function () { + $('#kiwi .toolbars').slideDown(); + $('#kiwi .control').slideDown(); + }, + + barsHide: function () { + $('#kiwi .toolbars').slideUp(); + $('#kiwi .control').slideUp(); } }; @@ -1114,7 +1158,7 @@ var Utilityview = function (name, src) { if (!front.tabviewExists(name)) { $('#kiwi .windows .scroller').append('
'); - $('#kiwi .windowlist ul').append('
  • ' + name + '
  • '); + $('#kiwi .utilityviewlist ul').append('
  • ' + name + '
  • '); } this.div = $('#' + tmp_divname); @@ -1137,10 +1181,10 @@ Utilityview.prototype.topic = ' '; Utilityview.prototype.show = function () { $('#kiwi .messages').removeClass("active"); $('#kiwi .userlist ul').removeClass("active"); - $('#kiwi .windowlist ul li').removeClass("active"); + $('#kiwi .toolbars ul li').removeClass("active"); $('#windows').css('overflow-y', 'hidden'); - + $('#windows').css('right', 0); // Activate this tab! this.div.addClass('active'); this.tab.addClass('active'); @@ -1185,7 +1229,7 @@ Utilityview.prototype.addPartImage = function () { }; Utilityview.prototype.clearPartImage = function () { - $('#kiwi .windowlist .tab_part').remove(); + $('#kiwi .toolbars .tab_part').remove(); }; @@ -1203,20 +1247,34 @@ var Tabview = function () {}; Tabview.prototype.name = null; Tabview.prototype.div = null; Tabview.prototype.userlist = null; +Tabview.prototype.userlist_width = 100; // 0 for disabled 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.show = function () { + var w, u; + $('#kiwi .messages').removeClass("active"); $('#kiwi .userlist ul').removeClass("active"); - $('#kiwi .windowlist ul li').removeClass("active"); + $('#kiwi .toolbars ul li').removeClass("active"); - $('#windows').css('overflow-y', 'scroll'); + w = $('#windows'); + u = $('#kiwi .userlist'); + + w.css('overflow-y', 'scroll'); + + // Set the window size accordingly + if (this.userlist_width > 0) { + u.width(this.userlist_width); + w.css('right', u.outerWidth(true)); + } else { + w.css('right', 0); + } // Activate this tab! this.div.addClass('active'); - this.userlist.addClass('active'); + if (this.userlist_width > 0) this.userlist.addClass('active'); this.tab.addClass('active'); // Add the part image to the tab @@ -1272,7 +1330,7 @@ Tabview.prototype.addPartImage = function () { }; Tabview.prototype.clearPartImage = function () { - $('#kiwi .windowlist .tab_part').remove(); + $('#kiwi .toolbars .tab_part').remove(); }; Tabview.prototype.addMsg = function (time, nick, msg, type, style) {