Added /notice

This commit is contained in:
Mattias Erming 2014-05-03 19:21:11 +02:00
parent 750a0313ba
commit 13e4115f04
5 changed files with 45 additions and 33 deletions

View File

@ -13,6 +13,7 @@ These are the commands currently implemented:
- `/mode` - `/mode`
- `/msg` - `/msg`
- `/nick` - `/nick`
- `/notice`
- `/op` - `/op`
- `/part` - `/part`
- `/query` - `/query`

View File

@ -17,7 +17,6 @@
<aside id="sidebar"> <aside id="sidebar">
<div id="menu"> <div id="menu">
<h2>Shout Client</h2> <h2>Shout Client</h2>
<button data-target="#start">Start</button>
<button data-target="#settings">Settings</button> <button data-target="#settings">Settings</button>
</div> </div>
<div id="networks"></div> <div id="networks"></div>
@ -30,7 +29,6 @@
</aside> </aside>
<div id="main"> <div id="main">
<div id="windows"> <div id="windows">
<div id="start" class="window"></div>
<div id="settings" class="window"></div> <div id="settings" class="window"></div>
</div> </div>
<div id="chat"></div> <div id="chat"></div>

View File

@ -13,6 +13,7 @@ $(function() {
"/mode", "/mode",
"/msg", "/msg",
"/nick", "/nick",
"/notice",
"/op", "/op",
"/part", "/part",
"/query", "/query",

View File

@ -71,13 +71,13 @@
* Copyright (c) 2014 Mattias Erming <mattias@mattiaserming.com> * Copyright (c) 2014 Mattias Erming <mattias@mattiaserming.com>
* Licensed under the MIT License. * Licensed under the MIT License.
* *
* Version 1.1.0 * Version 1.2.0
*/ */
(function($) { (function($) {
$.fn.scrollGlue = function(options) { $.fn.scrollGlue = function(options) {
var settings = $.extend({ var settings = $.extend({
disableManualScroll: false, disableManualScroll: false,
overflow: "scroll", overflow: 'scroll',
scrollToBottom: true, scrollToBottom: true,
speed: 0 speed: 0
}, options); }, options);
@ -89,25 +89,40 @@
}); });
} }
self.css("overflow-y", settings.overflow); self.css('overflow-y', settings.overflow);
if (settings.scrollToBottom) { if (settings.scrollToBottom) {
self.scrollToBottom(); self.scrollToBottom();
} }
var timer;
var resizing = false;
$(window).on('resize', function() { $(window).on('resize', function() {
self.finish(); 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; var sticky = true;
self.on('scroll', function() { self.on('scroll', function() {
if (settings.disableManualScroll) { if (settings.disableManualScroll) {
self.scrollToBottom(); self.scrollToBottom();
} else { } else if (!resizing) {
sticky = self.isScrollAtBottom(); sticky = self.isScrollAtBottom();
} }
}); });
self.trigger('scroll'); self.trigger('scroll');
self.on('append', function() { self.on('prepend append', function() {
if (sticky) { if (sticky) {
self.scrollToBottom(settings.speed); self.scrollToBottom(settings.speed);
} }
@ -116,23 +131,20 @@
return this; return this;
}; };
var prepend = $.fn.prepend; // Normally, these functions won't trigger any events.
$.fn.prepend = function() { // Lets override them.
return prepend.apply(this, arguments).trigger('append'); var events = ['prepend', 'append'];
}; $.each(events, function(i, e) {
var fn = $.fn[e];
$.fn[e] = function() {
return fn.apply(this, arguments).trigger(e);
};
});
var append = $.fn.append; $.fn.isScrollAtBottom = function() {
$.fn.append = function() { if ((this.scrollTop() + this.outerHeight() + 1) >= this.prop('scrollHeight')) {
return append.apply(this, arguments).trigger('append'); return true;
};
var html = $.fn.html;
$.fn.html = function(string) {
var result = html.apply(this, arguments);
if (typeof string !== 'undefined') {
this.trigger('append');
} }
return result;
}; };
$.fn.scrollToBottom = function(speed) { $.fn.scrollToBottom = function(speed) {
@ -140,12 +152,6 @@
$(this).finish().animate({scrollTop: this.scrollHeight}, speed || 0); $(this).finish().animate({scrollTop: this.scrollHeight}, speed || 0);
}); });
}; };
$.fn.isScrollAtBottom = function() {
if ((this.scrollTop() + this.outerHeight() + 1) >= this.prop('scrollHeight')) {
return true;
}
};
})(jQuery); })(jQuery);
/*! /*!

View File

@ -152,6 +152,12 @@ function input(data) {
} }
break; break;
case "notice":
if (client && args[2]) {
client.notice(args[1], args.slice(2).join(" "));
}
break;
case "server": case "server":
case "connect": case "connect":
if (args[1]) { if (args[1]) {