10 Commits

3 changed files with 65 additions and 63 deletions

View File

@@ -3,3 +3,4 @@
46fe533682419c8a519836ac95b5575053aa0fa8 release-1.0.2
a2c92b262f339f82eb01c8d92dda252a27432255 release-1.1.0
d14041daa7bbbd37ea2ff47aa978b9595af67ca3 release-1.1.1
7278eb0d067d8ed2a653de6a1feeeb7f76fb9891 release-1.1.2

View File

@@ -13,6 +13,13 @@ Tags: nmdc
=CHANGELOG=
2017-02-11 1.1.3
- Feature: Display user IP address on hover, if available
- Enhancement: Allow clicking on popup notifications
- Enhancement: Only show 'popups enabled' notification when enabling for the first time, not persistent page load
- Update libnmdc to 0.13
- Fix a cosmetic issue with not displaying non-zero user share sizes
2017-02-06 1.1.2
- Autodetect 'extern', no need to include it in config files
- Enhancement: Remove redundant request, for a faster page load

View File

@@ -7,23 +7,22 @@ var SENTINEL_PASSWORD = "************";
var CHAT_SCROLLBACK_LIMIT = 50; // Once over 2x $limit, the first $limit will be trimmed off the list
var EXTERN_ROOT = window.location.protocol + "//" + window.location.host + "/";
var $ = (document.querySelectorAll ?
function(s) {
var r = document.querySelectorAll(s);
return (s[0] === '#' && r.length === 1) ? r[0] : r;
} :
function(s) {
// i'm not writing a selector engine...
if (! s.length) return [];
if (s[0] === '#') {
return document.getElementById(s.slice(1));
} else if (s[0] === '.') {
return document.getElementsByClassName(s.slice(1));
} else {
return document.getElementsByTagName(s);
}
var $ = function(s) {
// There used to be a querySelectorAll implementation, but, better that we don't have
// potentially-incompatible implementations if this one does actually work.
// i'm not writing a selector engine...
if (! s.length) {
return [];
}
);
if (s[0] === '#') {
return document.getElementById(s.slice(1)); // single element
} else if (s[0] === '.') {
return document.getElementsByClassName(s.slice(1)); // multiple elements
} else {
return document.getElementsByTagName(s); // multiple elements
}
};
var nmdc_escape = function(str) {
return (
@@ -47,8 +46,8 @@ var fmtBytes = function(b) {
var k = 1024;
var sizes = [' B', ' KiB', ' MiB', ' GiB', ' TiB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(3)) + sizes[i];
var i = Math.floor(Math.log(b) / Math.log(k));
return parseFloat((b / Math.pow(k, i)).toFixed(3)) + sizes[i];
};
@@ -96,7 +95,7 @@ var b64 = function(str) {
})).replace(/=/g, '');
}
// https://gist.github.com/eligrey/1276030
// @ref https://gist.github.com/eligrey/1276030
var appendInnerHTML = function($el, html) {
var child = document.createElement("span");
child.innerHTML = html;
@@ -107,7 +106,7 @@ var appendInnerHTML = function($el, html) {
}
};
// http://stackoverflow.com/a/5598797
// @ref http://stackoverflow.com/a/5598797
function getOffsetLeft( elem ) {
var offsetLeft = 0;
do {
@@ -147,17 +146,23 @@ var date_format = function(d, format) {
/* */
var notify = function(title, body) {
var notify = function(title, body, tab) {
if (!("Notification" in window)) {
return; // not supported by browser
}
switch (window.Notification.permission) {
case "granted": {
new Notification(title, {
var n = new Notification(title, {
body: body,
icon: EXTERN_ROOT + "/favicon.ico"
});
n.onclick = function() {
parent.focus(); // recent chrome
window.focus(); // older browsers
tab_set(tab);
this.close();
};
} break;
case "denied": return;
@@ -243,8 +248,7 @@ var userMenu = function(u, ev) {
usermenu.show();
//
ev.preventDefault();
return false;
return noprop(ev);
};
var userlist = {
@@ -336,6 +340,9 @@ var userlist = {
if (props.ClientTag.length > 0) {
prop_str.push(props.ClientTag + " " + props.ClientVersion);
}
if (props.IPAddress.length > 0) {
prop_str.push(props.IPAddress);
}
prop_str.push("Sharing " + fmtBytes(props.ShareSize));
for (var i = 0; i < $el.length; ++i) {
@@ -365,7 +372,7 @@ var submit = function() {
}
if (hub_pass === SENTINEL_PASSWORD) {
// Probably not a real password. Attempt to load a better one from the saved state
var cache = persistence_get("login");
var cache = persistence_get("login", "");
if (cache.indexOf(":") != -1) {
hub_pass = cache.substr(cache.indexOf(":") + 1);
}
@@ -525,6 +532,20 @@ var tab_free = function(id) {
}
};
var noprop = function(ev) {
if (ev.preventDefault) {
ev.preventDefault();
}
if (ev.stopPropagation) {
ev.stopPropagation();
} else {
ev.cancelBubble = true; // oldIE
}
return false;
}
var tab_addHandlers = function() {
var tabitems = $(".tabitem");
for (var i = 0; i < tabitems.length; i++) {
@@ -533,13 +554,7 @@ var tab_addHandlers = function() {
tabitems[i].onclick = function(ev) {
tab_set( this.getAttribute('data-tab') );
// 360nobubble
if (ev.stopPropagation) {
ev.stopPropagation();
} else {
ev.cancelBubble = true; // oldIE
}
return false;
return noprop(ev);
};
}
@@ -550,13 +565,7 @@ var tab_addHandlers = function() {
tabclosers[i].onclick = function(ev) {
tab_free( this.getAttribute('data-tab') );
// 360nobubble
if (ev.stopPropagation) {
ev.stopPropagation();
} else {
ev.cancelBubble = true; // oldIE
}
return false;
return noprop(ev);
};
}
};
@@ -848,7 +857,7 @@ var desktop_notifications_toggle = function(ev) {
persistence_set("notifications", desktop_notifications_enabled);
if (desktop_notifications_enabled) {
desktop_notifications_onEnable();
notify(hub_hubname, "Desktop popups enabled", "tab-main");
}
persistence_set("popups", desktop_notifications_enabled);
@@ -856,10 +865,6 @@ var desktop_notifications_toggle = function(ev) {
$el.innerHTML = desktop_notifications_fmtstr();
};
var desktop_notifications_onEnable = function() {
notify(hub_hubname, "Desktop popups enabled");
}
var scrollback_move = function(delta) {
if (chat_scrollback.length === 0) {
return; // no effect
@@ -949,26 +954,21 @@ window.onload = function() {
$("#form-none").onsubmit = function(ev) {
submit();
// don't submit form
ev.preventDefault();
return false;
return noprop(ev); // don't submit form
};
$("#chatbox").onkeydown = function(ev) {
if (ev.keyCode === 9 /* Tab */) {
tabcompletion_start( ev.shiftKey ? -1 : 1 );
ev.preventDefault();
return false;
return noprop(ev);
} else if (ev.keyCode == 38 /* ArrowUp */ && ev.ctrlKey) {
scrollback_move(-1);
ev.preventDefault();
return false;
return noprop(ev);
} else if (ev.keyCode == 40 /* ArrowDown */ && ev.ctrlKey) {
scrollback_move(1);
ev.preventDefault();
return false;
return noprop(ev);
} else {
tabcompletion_inactive();
@@ -987,9 +987,7 @@ window.onload = function() {
$("#menubutton").onclick = function(ev) {
menu.toggle();
ev.preventDefault();
ev.stopPropagation();
return false;
return noprop(ev);
};
window.onclick = function() {
@@ -1009,13 +1007,9 @@ window.onload = function() {
timestamp_format_index = persistence_get("timestamps", 0);
should_warn_on_close = persistence_get("warnonclose");
should_warn_on_close = persistence_get("warnonclose", false);
desktop_notifications_enabled = persistence_get("popups");
if (desktop_notifications_enabled) {
// prompt for permissions
desktop_notifications_onEnable();
}
desktop_notifications_enabled = persistence_get("popups", false);
menu.reset();
@@ -1090,7 +1084,7 @@ window.onload = function() {
tab_mark_unread( pm_tabs[data.user] );
if (desktop_notifications_enabled) {
notify("Message from " + data.user, data.message);
notify("Message from " + data.user, data.message, pm_tabs[data.user]);
}
}
});