From 13e4115f04784253e8900ac85de5a263c2ca99c2 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 3 May 2014 19:21:11 +0200 Subject: [PATCH] Added /notice --- README.md | 1 + client/index.html | 2 -- client/js/chat.js | 1 + client/js/jquery.plugins.js | 68 ++++++++++++++++++++----------------- lib/server.js | 6 ++++ 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 66f082f..3c971da 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ These are the commands currently implemented: - `/mode` - `/msg` - `/nick` +- `/notice` - `/op` - `/part` - `/query` diff --git a/client/index.html b/client/index.html index 122c650..41af48d 100644 --- a/client/index.html +++ b/client/index.html @@ -17,7 +17,6 @@
-
diff --git a/client/js/chat.js b/client/js/chat.js index de163b9..6d56cf3 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -13,6 +13,7 @@ $(function() { "/mode", "/msg", "/nick", + "/notice", "/op", "/part", "/query", diff --git a/client/js/jquery.plugins.js b/client/js/jquery.plugins.js index 87ec3ae..529eb4a 100644 --- a/client/js/jquery.plugins.js +++ b/client/js/jquery.plugins.js @@ -71,17 +71,17 @@ * Copyright (c) 2014 Mattias Erming * Licensed under the MIT License. * - * Version 1.1.0 + * Version 1.2.0 */ (function($) { $.fn.scrollGlue = function(options) { var settings = $.extend({ disableManualScroll: false, - overflow: "scroll", + overflow: 'scroll', scrollToBottom: true, speed: 0 }, options); - + var self = this; if (self.size() > 1) { return self.each(function() { @@ -89,50 +89,62 @@ }); } - self.css("overflow-y", settings.overflow); + self.css('overflow-y', settings.overflow); if (settings.scrollToBottom) { self.scrollToBottom(); } - + + var timer; + var resizing = false; $(window).on('resize', function() { self.finish(); + + // This will prevent the scroll event from triggering + // while resizing the browser. + resizing = true; + + clearTimeout(timer); + timer = setTimeout(function() { + resizing = false; + }, 100); + + if (sticky) { + self.scrollToBottom(); + } }); - + var sticky = true; self.on('scroll', function() { if (settings.disableManualScroll) { self.scrollToBottom(); - } else { + } else if (!resizing) { sticky = self.isScrollAtBottom(); } }); self.trigger('scroll'); - self.on('append', function() { + self.on('prepend append', function() { if (sticky) { self.scrollToBottom(settings.speed); } }); - + return this; }; - - var prepend = $.fn.prepend; - $.fn.prepend = function() { - return prepend.apply(this, arguments).trigger('append'); - }; - var append = $.fn.append; - $.fn.append = function() { - return append.apply(this, arguments).trigger('append'); - }; - - var html = $.fn.html; - $.fn.html = function(string) { - var result = html.apply(this, arguments); - if (typeof string !== 'undefined') { - this.trigger('append'); + // Normally, these functions won't trigger any events. + // Lets override them. + var events = ['prepend', 'append']; + $.each(events, function(i, e) { + var fn = $.fn[e]; + $.fn[e] = function() { + return fn.apply(this, arguments).trigger(e); + }; + }); + + $.fn.isScrollAtBottom = function() { + if ((this.scrollTop() + this.outerHeight() + 1) >= this.prop('scrollHeight')) { + return true; } - return result; }; $.fn.scrollToBottom = function(speed) { @@ -140,12 +152,6 @@ $(this).finish().animate({scrollTop: this.scrollHeight}, speed || 0); }); }; - - $.fn.isScrollAtBottom = function() { - if ((this.scrollTop() + this.outerHeight() + 1) >= this.prop('scrollHeight')) { - return true; - } - }; })(jQuery); /*! diff --git a/lib/server.js b/lib/server.js index 724bcf1..27ee5ef 100644 --- a/lib/server.js +++ b/lib/server.js @@ -152,6 +152,12 @@ function input(data) { } break; + case "notice": + if (client && args[2]) { + client.notice(args[1], args.slice(2).join(" ")); + } + break; + case "server": case "connect": if (args[1]) {