Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f2871b917 | |||
| 855206feed | |||
| efa195df5b | |||
| 89c8cb0dc8 | |||
| c2de4c8d45 | |||
| 738e9aed41 | |||
| bdb7b4835d | |||
| 447e8c2591 | |||
| 37014f7f52 | |||
| b8791f6aa2 | |||
| 377131e43d | |||
| 20fa044906 | |||
| 0cb14fb964 | |||
| a60d821e39 | |||
| 15d9ee0023 | |||
| ed0195c4b8 | |||
| a71eb45dd5 | |||
| 086ecfb0a9 | |||
| dff36f6bff | |||
| 7a9b271b90 | |||
| 1c7842c182 | |||
| 9e33e50986 | |||
| 7f618db70a | |||
| 7894355647 | |||
| af324441b7 | |||
| d862a3f703 | |||
| 59c118dc34 | |||
| 42a8298362 | |||
| c4e37bf47d | |||
| 95d56dbca2 | |||
| 761d0bfad5 | |||
| 1d3f16e6c6 | |||
| e5ceadb03a | |||
| 6999069fd7 | |||
| 5da61d5922 | |||
| d33ba5c085 | |||
| a28e5ce9b0 | |||
| 3448cb7eeb | |||
| ba941adfdd | |||
| 48d96f9efe | |||
| 1a1f361e60 | |||
| 3f1f575652 | |||
| e2af839101 |
6
.hgtags
6
.hgtags
@@ -1,3 +1,9 @@
|
||||
769fad81e3f8db8f7e5f5c164656a382a169d735 release-1.0.0
|
||||
9ed95938d809a8226aca529e34b655e6d8c8c379 release-1.0.1
|
||||
46fe533682419c8a519836ac95b5575053aa0fa8 release-1.0.2
|
||||
a2c92b262f339f82eb01c8d92dda252a27432255 release-1.1.0
|
||||
d14041daa7bbbd37ea2ff47aa978b9595af67ca3 release-1.1.1
|
||||
7278eb0d067d8ed2a653de6a1feeeb7f76fb9891 release-1.1.2
|
||||
6cbd9d59630372c0dff430e3dc6c1fbd7dcee734 release-1.1.3
|
||||
76c178b8f27ec894e79b8f73649fcb3e45a73729 release-1.1.4
|
||||
0eeab5594ba4d683e6a268ef971675c73b226bd0 release-1.2.0
|
||||
|
||||
@@ -2,13 +2,13 @@ package main
|
||||
|
||||
type Config struct {
|
||||
App struct {
|
||||
MotdHTML string `json:"motd"`
|
||||
MotdHTML string `json:"motd"`
|
||||
ContentedServer string `json:"contented_server"`
|
||||
}
|
||||
|
||||
Web struct {
|
||||
Port int `json:"port"`
|
||||
BindTo string `json:"bind_to"`
|
||||
Extern string `json:"extern"`
|
||||
Title string `json:"title"`
|
||||
CustomFavicon bool `json:"custom_favicon"`
|
||||
|
||||
|
||||
@@ -8,10 +8,39 @@ Tags: nmdc
|
||||
|
||||
=UPGRADING FROM DCWEBUI2=
|
||||
|
||||
- The configuration file format is identical, but please now ensure it's valid json instead of just a .js file. This means no assignment, use double-quoted strings, and no comments.
|
||||
- The configuration file content is identical between nmdc-webfrontend 1.0.0 and dcwebui2 1.3.0, but please now ensure it's valid JSON instead of arbitrary javascript. This means no assignment, use double-quoted strings, and no comments.
|
||||
- Future changes to the configuration file since nmdc-webfrontend 1.0.0 are backward compatible (see the changelog for more details).
|
||||
|
||||
=CHANGELOG=
|
||||
|
||||
2017-10-16 1.2.1
|
||||
- Enhancement: Increase scrollback buffer size
|
||||
- Fix an issue with missing `contented` upload link once logged in
|
||||
- Fix a cosmetic issue with `(0)` appearing in page title
|
||||
|
||||
2017-10-15 1.2.0
|
||||
- Feature: Add `contented` integration (set `app.contented_server` in config file)
|
||||
- Fix a cosmetic issue with the menu icon on devices without unicode font coverage
|
||||
|
||||
2017-02-11 1.1.4
|
||||
- Update libnmdc to 0.14
|
||||
|
||||
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
|
||||
- Display server version number in log file and in response headers
|
||||
- Fix a cosmetic issue with spacing around user count in page title
|
||||
|
||||
2017-02-06 1.1.1
|
||||
- Fix an issue with malformed content in minified build
|
||||
|
||||
2017-02-06 1.1.0
|
||||
- Feature: Remember last username/password for login; remember last "show joins/parts" status
|
||||
- Feature: Display user details on hover (description, email, client tag, share size)
|
||||
|
||||
12
build.sh
Normal file → Executable file
12
build.sh
Normal file → Executable file
@@ -86,11 +86,13 @@ single_build() {
|
||||
|
||||
# Build.
|
||||
# GOARCH/GOOS supplied in function env
|
||||
local gofwdpath=$(echo -n $GOPATH | sed 's/[\\/]$//')
|
||||
|
||||
go build \
|
||||
-a \
|
||||
-ldflags '-s -w' \
|
||||
-gcflags "-trimpath=${GOPATH}" \
|
||||
-asmflags "-trimpath=${GOPATH}" \
|
||||
-ldflags "-s -w -X main.VERSION=nmdc-webfrontend/${version}" \
|
||||
-gcflags "-trimpath ${gofwdpath}" \
|
||||
-asmflags "-trimpath ${gofwdpath}" \
|
||||
-o "$(pathfix "${tmpdir}/${local_bin_name}")"
|
||||
|
||||
# Archive.
|
||||
@@ -160,11 +162,9 @@ main() {
|
||||
fi
|
||||
php clientpack.php
|
||||
go-bindata -nomemcopy -prefix clientpack clientpack
|
||||
|
||||
GOARCH=amd64 GOOS=windows single_build "$version"
|
||||
|
||||
GOARCH=386 GOOS=windows single_build "$version"
|
||||
GOARCH=amd64 GOOS=linux single_build "$version"
|
||||
GOARCH=386 GOOS=linux single_build "$version"
|
||||
|
||||
# Also make source tarball
|
||||
|
||||
|
||||
@@ -71,10 +71,15 @@ html,body {
|
||||
color:black;
|
||||
font-weight:bold;
|
||||
|
||||
line-height:18px;
|
||||
line-height:0;
|
||||
height:18px;
|
||||
width:18px;
|
||||
text-align:center;
|
||||
}
|
||||
.menubutton svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
.menubutton:hover {
|
||||
background:white;
|
||||
}
|
||||
@@ -397,4 +402,4 @@ html,body {
|
||||
.position-panel {
|
||||
display:block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,25 +4,25 @@
|
||||
"use strict";
|
||||
|
||||
var SENTINEL_PASSWORD = "************";
|
||||
var CHAT_SCROLLBACK_LIMIT = 50; // Once over 2x $limit, the first $limit will be trimmed off the list
|
||||
var CHAT_SCROLLBACK_LIMIT = 200; // 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 el = 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 (
|
||||
@@ -46,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];
|
||||
};
|
||||
|
||||
|
||||
@@ -95,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;
|
||||
@@ -106,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 {
|
||||
@@ -146,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: DCWEBUI_CONF.extern + "/favicon.ico"
|
||||
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;
|
||||
@@ -173,7 +179,7 @@ var notify = function(title, body) {
|
||||
/* Tab writers */
|
||||
|
||||
var write = function(tab) {
|
||||
var $tab = $('#inner-'+tab);
|
||||
var $tab = el('#inner-'+tab);
|
||||
return {
|
||||
'cls': function() {
|
||||
$tab.innerHTML = '';
|
||||
@@ -242,15 +248,14 @@ var userMenu = function(u, ev) {
|
||||
usermenu.show();
|
||||
|
||||
//
|
||||
ev.preventDefault();
|
||||
return false;
|
||||
return noprop(ev);
|
||||
};
|
||||
|
||||
var userlist = {
|
||||
'add': function(u) {
|
||||
if (this.has(u)) return;
|
||||
|
||||
var userlists = $(".userlist");
|
||||
var userlists = el(".userlist");
|
||||
for (var l = 0, e = userlists.length; l !== e; ++l) {
|
||||
var userlist = userlists[l];
|
||||
|
||||
@@ -279,7 +284,7 @@ var userlist = {
|
||||
return this;
|
||||
},
|
||||
'del': function(u) {
|
||||
var userlists = $(".userlist");
|
||||
var userlists = el(".userlist");
|
||||
for (var l = 0, e = userlists.length; l !== e; ++l) {
|
||||
if (! userlists[l].children) continue;
|
||||
var userlist = userlists[l];
|
||||
@@ -296,7 +301,7 @@ var userlist = {
|
||||
return this;
|
||||
},
|
||||
'clear': function() {
|
||||
var userlists = $(".userlist");
|
||||
var userlists = el(".userlist");
|
||||
for (var i in userlists) {
|
||||
if (! userlists[i].children) continue;
|
||||
var userlist = userlists[i];
|
||||
@@ -309,7 +314,7 @@ var userlist = {
|
||||
return this;
|
||||
},
|
||||
'names': function() {
|
||||
var userlist = $(".userlist")[0].children;
|
||||
var userlist = el(".userlist")[0].children;
|
||||
var ret = [];
|
||||
for (var i = 0, e = userlist.length; i < e; ++i) {
|
||||
ret.push( textContent(userlist[i]) );
|
||||
@@ -317,14 +322,14 @@ var userlist = {
|
||||
return ret;
|
||||
},
|
||||
'has': function(u) {
|
||||
return $(".user-" + b64(u)).length !== 0; /* there are two - large and non-large */
|
||||
return el(".user-" + b64(u)).length !== 0; /* there are two - large and non-large */
|
||||
},
|
||||
'count': function() {
|
||||
return $(".userlist")[0].children.length;
|
||||
return el(".userlist")[0].children.length;
|
||||
},
|
||||
'setInfo': function(nick, props) {
|
||||
var baseClass = "user-" + b64(nick);
|
||||
var $el = $("." + baseClass);
|
||||
var $el = el("." + baseClass);
|
||||
var prop_str = [];
|
||||
if (props.Description.length > 0) {
|
||||
prop_str.push(props.Description);
|
||||
@@ -335,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) {
|
||||
@@ -350,7 +358,7 @@ var userlist = {
|
||||
};
|
||||
|
||||
var submit = function() {
|
||||
var str = $("#chatbox").value;
|
||||
var str = el("#chatbox").value;
|
||||
if (! str.length) return;
|
||||
|
||||
if (hub_state === STATE_READY_FOR_LOGIN) {
|
||||
@@ -364,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);
|
||||
}
|
||||
@@ -393,7 +401,7 @@ var submit = function() {
|
||||
write("tab-main").system("Invalid internal state.");
|
||||
}
|
||||
|
||||
$("#chatbox").value = '';
|
||||
el("#chatbox").value = '';
|
||||
};
|
||||
|
||||
/* page visibility */
|
||||
@@ -440,13 +448,13 @@ var pagevis_setup = function(fnActive, fnInactive) {
|
||||
*/
|
||||
var tab_set = function(tab) {
|
||||
|
||||
var tabs = $(".tabpane");
|
||||
var tabs = el(".tabpane");
|
||||
for (var i in tabs) {
|
||||
try {
|
||||
tabs[i].style.display = (tabs[i].id === tab ? 'block' : 'none');
|
||||
} catch (e) {};
|
||||
}
|
||||
var tabitems = $(".tabitem");
|
||||
var tabitems = el(".tabitem");
|
||||
for (var i in tabitems) {
|
||||
try {
|
||||
// Update UNREAD/SELECTED flags for the target
|
||||
@@ -474,13 +482,13 @@ var tab_set = function(tab) {
|
||||
updateTitle();
|
||||
|
||||
write(tab).scroll();
|
||||
$("#chatbox").focus();
|
||||
el("#chatbox").focus();
|
||||
last_tab = tab;
|
||||
|
||||
};
|
||||
|
||||
var tab_new = function(id, name) {
|
||||
appendInnerHTML($("#bar"),
|
||||
appendInnerHTML(el("#bar"),
|
||||
' <div class="tabitem" data-tab="tab-ext-'+id+'" id="tabitem-tab-ext-'+id+'">'+
|
||||
'<span class="tab-label">'+
|
||||
hesc(name)+
|
||||
@@ -488,7 +496,7 @@ var tab_new = function(id, name) {
|
||||
'<a class="tab-closer" data-tab="tab-ext-'+id+'">×</a>'+
|
||||
'</div> '
|
||||
);
|
||||
appendInnerHTML($("#extratabs"),
|
||||
appendInnerHTML(el("#extratabs"),
|
||||
' <div class="tabpane content placement-mid" id="tab-ext-'+id+'" style="display:none;">'+
|
||||
'<div class="content-inner" id="inner-tab-ext-'+id+'"></div>'+
|
||||
'</div>'
|
||||
@@ -501,10 +509,10 @@ var tab_free = function(id) {
|
||||
if (id === "tab-main") return;
|
||||
|
||||
// remove tab item and body
|
||||
var el = $("#tabitem-"+id);
|
||||
var el = el("#tabitem-"+id);
|
||||
el.parentNode.removeChild(el);
|
||||
|
||||
var el = $("#"+id);
|
||||
var el = el("#"+id);
|
||||
el.parentNode.removeChild(el);
|
||||
|
||||
// clear from PM tabs
|
||||
@@ -524,38 +532,40 @@ 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");
|
||||
var tabitems = el(".tabitem");
|
||||
for (var i = 0; i < tabitems.length; i++) {
|
||||
if (! tabitems[i]) continue;
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
var tabclosers = $(".tab-closer");
|
||||
var tabclosers = el(".tab-closer");
|
||||
for (var i = 0; i < tabclosers.length; i++) {
|
||||
if (! tabclosers[i]) continue;
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -588,7 +598,7 @@ var tabcomplete_state = '';
|
||||
|
||||
var tabcompletion_start = function(direction) {
|
||||
|
||||
var cursor = $("#chatbox").value.replace(/^.*\s([^\s]+)$/, '$1');
|
||||
var cursor = el("#chatbox").value.replace(/^.*\s([^\s]+)$/, '$1');
|
||||
|
||||
if (tabcomplete_state === '') {
|
||||
// new tab completion
|
||||
@@ -624,10 +634,10 @@ var tabcompletion_start = function(direction) {
|
||||
|
||||
// Replace in textbox
|
||||
|
||||
var chatprefix = $("#chatbox").value.substr(0, $("#chatbox").value.length - cursor.length);
|
||||
var chatprefix = el("#chatbox").value.substr(0, el("#chatbox").value.length - cursor.length);
|
||||
|
||||
$("#chatbox").value = chatprefix + targetName;
|
||||
$("#chatbox").focus();
|
||||
el("#chatbox").value = chatprefix + targetName;
|
||||
el("#chatbox").focus();
|
||||
};
|
||||
|
||||
var tabcompletion_inactive = function() {
|
||||
@@ -676,10 +686,17 @@ MenuList.prototype.toggle = function() {
|
||||
|
||||
/* */
|
||||
|
||||
var menu = new MenuList($("#menubutton"));
|
||||
var menu = new MenuList(el("#menubutton"));
|
||||
|
||||
menu.reset = function() {
|
||||
this.clear();
|
||||
|
||||
if (contented_url.length > 0) {
|
||||
menu.add("Upload", function() {
|
||||
contented_load();
|
||||
});
|
||||
}
|
||||
|
||||
this.add(joinparts_getstr(), toggle_joinparts);
|
||||
this.add(desktop_notifications_fmtstr(), desktop_notifications_toggle);
|
||||
this.add(warnonclose_fmtstr(), warnonclose_toggle);
|
||||
@@ -772,20 +789,24 @@ var toggle_joinparts = function(ev) {
|
||||
|
||||
var updateTitle = function() {
|
||||
var prefix = "";
|
||||
var unrTabs = $(".unread");
|
||||
var unrTabs = el(".unread");
|
||||
if (unrTabs.length === 1 && unrTabs[0].getAttribute('data-tab') == "tab-main") {
|
||||
prefix = "[" + mainchat_unread_count + " NEW] "
|
||||
} else if (unrTabs.length > 0) {
|
||||
prefix = "[NEW PM] "
|
||||
}
|
||||
|
||||
document.title = prefix + hub_hubname + "("+userlist.count()+") "
|
||||
var suffix = "";
|
||||
if (userlist.count() > 0) {
|
||||
suffix = " ("+userlist.count()+")";
|
||||
}
|
||||
document.title = prefix + hub_hubname + suffix;
|
||||
};
|
||||
|
||||
var sock = {};
|
||||
var hub_state = 0; // [disconnected, sent-nick, connected]
|
||||
var hub_last_nick = '';
|
||||
var hub_hubname = DCWEBUI_CONF.title;
|
||||
var hub_hubname = "Loading...";
|
||||
|
||||
var pm_tabs = {}; // nick => tabid
|
||||
var next_tabid = 1;
|
||||
@@ -847,7 +868,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);
|
||||
@@ -855,10 +876,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
|
||||
@@ -877,7 +894,7 @@ var scrollback_move = function(delta) {
|
||||
}
|
||||
}
|
||||
|
||||
$("#chatbox").value = chat_scrollback[chat_scrollback_index];
|
||||
el("#chatbox").value = chat_scrollback[chat_scrollback_index];
|
||||
};
|
||||
|
||||
/* */
|
||||
@@ -902,24 +919,25 @@ var transition = function(new_state) {
|
||||
switch(new_state) {
|
||||
case STATE_DISCONNECTED: {
|
||||
userlist.clear();
|
||||
$("#chatbox").disabled = true;
|
||||
$("#chatbox").value = ''; // clear
|
||||
el("#chatbox").disabled = true;
|
||||
el("#chatbox").value = ''; // clear
|
||||
} break;
|
||||
|
||||
case STATE_READY_FOR_LOGIN: {
|
||||
userlist.clear();
|
||||
$("#chatbox").spellcheck = false;
|
||||
$("#chatbox").disabled = false;
|
||||
$("#chatbox").value = ''; // clear
|
||||
el("#chatbox").spellcheck = false;
|
||||
el("#chatbox").disabled = false;
|
||||
el("#chatbox").value = ''; // clear
|
||||
} break;
|
||||
|
||||
case STATE_CONNECTING: {
|
||||
$("#chatbox").disabled = true;
|
||||
el("#chatbox").disabled = true;
|
||||
} break;
|
||||
|
||||
case STATE_ACTIVE: {
|
||||
$("#chatbox").disabled = false;
|
||||
$("#chatbox").spellcheck = true;
|
||||
case STATE_ACTIVE: {
|
||||
write("tab-main").system("Now talking on "+hub_hubname);
|
||||
el("#chatbox").disabled = false;
|
||||
el("#chatbox").spellcheck = true;
|
||||
} break;
|
||||
}
|
||||
};
|
||||
@@ -929,44 +947,76 @@ var tab_is_visible = function(tabref) {
|
||||
}
|
||||
|
||||
var tab_mark_unread = function(tabref) {
|
||||
if ($("#tabitem-"+tabref).className.indexOf('unread') === -1) {
|
||||
$("#tabitem-"+tabref).className += " unread";
|
||||
if (el("#tabitem-"+tabref).className.indexOf('unread') === -1) {
|
||||
el("#tabitem-"+tabref).className += " unread";
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var contented_url = "";
|
||||
var contented_loaded_sdk = false;
|
||||
var contented_load = function() {
|
||||
if (contented_url.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var onceSDKLoaded = function() {
|
||||
contented.init("#inner-tab-main", function(items) {
|
||||
var val = el("#chatbox").value;
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
if (val.length > 0) {
|
||||
val += " ";
|
||||
}
|
||||
val += contented.getPreviewURL(items[i]);
|
||||
}
|
||||
el("#chatbox").value = val;
|
||||
});
|
||||
};
|
||||
|
||||
if (contented_loaded_sdk) {
|
||||
onceSDKLoaded();
|
||||
} else {
|
||||
var scriptElement = document.createElement('script');
|
||||
scriptElement.onload = function() {
|
||||
contented_loaded_sdk = true;
|
||||
onceSDKLoaded();
|
||||
};
|
||||
scriptElement.src = contented_url + "sdk.js";
|
||||
document.body.appendChild(scriptElement);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
window.onload = function() {
|
||||
write("tab-main").system("Communicating with server...");
|
||||
|
||||
show_joins = persistence_get("show_joins", false);
|
||||
|
||||
document.title = DCWEBUI_CONF.title;
|
||||
document.title = hub_hubname; // "Loading...";
|
||||
|
||||
// HTML event handlers
|
||||
|
||||
$("#form-none").onsubmit = function(ev) {
|
||||
el("#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) {
|
||||
el("#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();
|
||||
@@ -983,11 +1033,9 @@ window.onload = function() {
|
||||
usermenu.hide();
|
||||
};
|
||||
|
||||
$("#menubutton").onclick = function(ev) {
|
||||
el("#menubutton").onclick = function(ev) {
|
||||
menu.toggle();
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
return false;
|
||||
return noprop(ev);
|
||||
};
|
||||
|
||||
window.onclick = function() {
|
||||
@@ -1007,13 +1055,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();
|
||||
|
||||
@@ -1039,7 +1083,7 @@ window.onload = function() {
|
||||
|
||||
// Socket event handlers
|
||||
|
||||
sock = io.connect(DCWEBUI_CONF.extern);
|
||||
sock = io.connect(EXTERN_ROOT);
|
||||
sock.on('cls', function() {
|
||||
transition(STATE_READY_FOR_LOGIN);
|
||||
|
||||
@@ -1047,7 +1091,7 @@ window.onload = function() {
|
||||
if (pre_login.indexOf(":") !== -1) {
|
||||
pre_login = pre_login.substr(0, pre_login.indexOf(":")) + ":" + SENTINEL_PASSWORD;
|
||||
}
|
||||
$("#chatbox").value = pre_login;
|
||||
el("#chatbox").value = pre_login;
|
||||
|
||||
if (have_cleared_once) {
|
||||
// re-log-in automatically
|
||||
@@ -1062,7 +1106,6 @@ window.onload = function() {
|
||||
}
|
||||
});
|
||||
sock.on('hubname', function(s) {
|
||||
write("tab-main").system("Now talking on "+s);
|
||||
hub_hubname = s;
|
||||
updateTitle();
|
||||
});
|
||||
@@ -1089,7 +1132,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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1142,6 +1185,10 @@ window.onload = function() {
|
||||
sock.on('usercommand', function(data) {
|
||||
process_usercommand(data);
|
||||
});
|
||||
sock.on('contented', function(url) {
|
||||
contented_url = url;
|
||||
menu.reset(); // sent before login
|
||||
});
|
||||
};
|
||||
|
||||
//IIFEMODE:})();
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
<link rel="stylesheet" href="/dcwebui.css">
|
||||
<link rel="stylesheet" href="/dcwebui.css">
|
||||
<title>Loading...</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="tabbar placement-top" id="bar">
|
||||
<div class="menubutton" id="menubutton">☰</div>
|
||||
<div class="menubutton" id="menubutton">
|
||||
<svg viewBox="0 0 24 24">
|
||||
<path fill="#000000" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="tabitem selected" data-tab="tab-main" id="tabitem-tab-main">
|
||||
<span class="tab-label">
|
||||
Main
|
||||
@@ -53,7 +57,6 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/socket.io-1.7.2.js"></script>
|
||||
<script type="text/javascript" src="/conf"></script>
|
||||
<script type="text/javascript" src="/dcwebui.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
23
clientpack.php
Normal file → Executable file
23
clientpack.php
Normal file → Executable file
@@ -3,7 +3,7 @@
|
||||
|
||||
# Dependencies:
|
||||
# - PHP
|
||||
# - Uglifyjs (`npm install -g uglifyjs`)
|
||||
# - Uglifyjs (`npm install -g uglify-js`)
|
||||
# - Lessc (`npm install -g less`)
|
||||
# - Lessc minifier (`npm install -g less-plugin-clean-css`)
|
||||
# - HTML minifier (`npm install -g html-minifier`)
|
||||
@@ -30,21 +30,18 @@ if (is_dir('clientpack')) {
|
||||
|
||||
// Embed css into HTML file
|
||||
|
||||
$css_file = file_get_contents('clientpack/dcwebui.min.css');
|
||||
|
||||
$html_content = file_get_contents('clientpack/index.htm');
|
||||
$html_content = preg_replace('~<link[^>]+dcwebui.css[^>]*>~', '<style type="text/css">'.$css_file.'</style>', $html_content);
|
||||
|
||||
$html_content = preg_replace_callback('~<link[^>]+dcwebui.css[^>]*>~', function() { return '<style type="text/css">'.file_get_contents('clientpack/dcwebui.min.css').'</style>'; }, $html_content);
|
||||
|
||||
// Embed JS into HTML file
|
||||
|
||||
$js_file = file_get_contents('clientpack/dcwebui.min.js');
|
||||
$html_content = preg_replace('~<script[^>]+dcwebui.js[^>]*>~', '<script type="text/javascript">'.$js_file.'</script>', $html_content);
|
||||
$html_content = preg_replace_callback('~<script[^>]+dcwebui.js[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/dcwebui.min.js').'</script>'; }, $html_content);
|
||||
|
||||
// Embed socketio into HTML file
|
||||
|
||||
$SIO_NAME = 'socket.io-1.7.2.js';
|
||||
$sio_file = file_get_contents('clientpack/'.$SIO_NAME);
|
||||
$html_content = preg_replace('~<script[^>]+'.$SIO_NAME.'[^>]*>~', '<script type="text/javascript">'.$sio_file.'</script>', $html_content);
|
||||
define('SIO_NAME', 'socket.io-1.7.2.js');
|
||||
$html_content = preg_replace_callback('~<script[^>]+'.SIO_NAME.'[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/'.SIO_NAME).'</script>'; }, $html_content);
|
||||
|
||||
// Minify the combined file
|
||||
|
||||
@@ -54,6 +51,10 @@ file_put_contents('clientpack/index.htm', $html_content);
|
||||
|
||||
// Clean up files
|
||||
|
||||
`rm clientpack/{index.htm,dcwebui{.min,}.js,dcwebui{.min,}.css}`;
|
||||
unlink('clientpack/'.$SIO_NAME);
|
||||
unlink('clientpack/index.htm');
|
||||
unlink('clientpack/dcwebui.js');
|
||||
unlink('clientpack/dcwebui.min.js');
|
||||
unlink('clientpack/dcwebui.css');
|
||||
unlink('clientpack/dcwebui.min.css');
|
||||
unlink('clientpack/'.SIO_NAME);
|
||||
rename('clientpack/index.min.htm', 'clientpack/index.htm');
|
||||
|
||||
55
main.go
55
main.go
@@ -12,6 +12,8 @@ import (
|
||||
"github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
var VERSION string = `nmdc-webfrontend/devel-unreleased`
|
||||
|
||||
type App struct {
|
||||
cfg *Config
|
||||
}
|
||||
@@ -164,9 +166,14 @@ func (this *App) SocketIOServer(so socketio.Socket) {
|
||||
log.Printf("[%s] Client connected", so.Id())
|
||||
|
||||
so.Emit("cls")
|
||||
so.Emit("hubname", this.cfg.Web.Title)
|
||||
so.Emit("raw", this.cfg.App.MotdHTML+"<br>")
|
||||
so.Emit("sys", "Enter a name to connect as (or name:pass for a registered nick)")
|
||||
|
||||
if len(this.cfg.App.ContentedServer) > 0 {
|
||||
so.Emit("contented", this.cfg.App.ContentedServer)
|
||||
}
|
||||
|
||||
doneChan := make(chan struct{}, 0)
|
||||
|
||||
so.On("hello", func(data map[string]string) {
|
||||
@@ -185,24 +192,6 @@ func (this *App) customFaviconHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "favicon.ico")
|
||||
}
|
||||
|
||||
func (this *App) ConfigRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
confStruct := struct {
|
||||
Extern string `json:"extern"`
|
||||
Title string `json:"title"`
|
||||
}{
|
||||
Extern: this.cfg.Web.Extern,
|
||||
Title: this.cfg.Web.Title,
|
||||
}
|
||||
confBytes, _ := json.Marshal(confStruct)
|
||||
|
||||
//
|
||||
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
w.WriteHeader(200)
|
||||
fmt.Fprintf(w, "var DCWEBUI_CONF = %s;\n", string(confBytes))
|
||||
}
|
||||
|
||||
func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fileName := r.URL.Path[1:]
|
||||
if fileName == "" {
|
||||
@@ -241,6 +230,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (this *App) RunServer() {
|
||||
|
||||
// Inner mux {{
|
||||
innerMux := http.NewServeMux()
|
||||
|
||||
// Socket.io handler
|
||||
server, err := socketio.NewServer(nil)
|
||||
if err != nil {
|
||||
@@ -250,30 +242,39 @@ func (this *App) RunServer() {
|
||||
server.On("error", func(so socketio.Socket, err error) {
|
||||
log.Println("error:", err)
|
||||
})
|
||||
http.Handle("/socket.io/", server)
|
||||
|
||||
// Configuration handler
|
||||
http.HandleFunc("/conf", this.ConfigRequestHandler)
|
||||
innerMux.Handle("/socket.io/", server)
|
||||
|
||||
// Custom favicon handler
|
||||
if this.cfg.Web.CustomFavicon {
|
||||
http.HandleFunc("/favicon.ico", this.customFaviconHandler)
|
||||
innerMux.HandleFunc("/favicon.ico", this.customFaviconHandler)
|
||||
}
|
||||
|
||||
// Other files: asset handler
|
||||
// Asset handler
|
||||
if this.cfg.Web.ExternalWebroot {
|
||||
http.Handle("/", http.FileServer(http.Dir("client")))
|
||||
innerMux.Handle("/", http.FileServer(http.Dir("client")))
|
||||
} else {
|
||||
http.HandleFunc("/", this.StaticRequestHandler)
|
||||
innerMux.HandleFunc("/", this.StaticRequestHandler)
|
||||
}
|
||||
// }}
|
||||
|
||||
// Wrapper mux {{
|
||||
outerMux := http.NewServeMux()
|
||||
outerMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Server", VERSION)
|
||||
innerMux.ServeHTTP(w, r)
|
||||
})
|
||||
// }}
|
||||
|
||||
// Listen and serve
|
||||
bindAddr := fmt.Sprintf("%s:%d", this.cfg.Web.BindTo, this.cfg.Web.Port)
|
||||
log.Printf("Serving at %s...", bindAddr)
|
||||
log.Fatal(http.ListenAndServe(bindAddr, nil))
|
||||
log.Fatal(http.ListenAndServe(bindAddr, outerMux))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
log.Println(VERSION)
|
||||
|
||||
a, err := NewApp("nmdc-webfrontend.conf")
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
{
|
||||
|
||||
"app": {
|
||||
"motd" : "Welcome!<br>"
|
||||
"motd": "Welcome!<br>"
|
||||
},
|
||||
|
||||
"web": {
|
||||
"port" : 8082,
|
||||
"port": 8082,
|
||||
"bind_to": "127.0.0.1",
|
||||
"extern" : "http://127.0.0.1:8082",
|
||||
"title" : "DCWebUI",
|
||||
"title": "NMDC Web Frontend",
|
||||
"custom_favicon": false
|
||||
},
|
||||
|
||||
"hub": {
|
||||
"address": "127.0.0.1",
|
||||
"port" : 411,
|
||||
"tag" : "nmdc-webfrontend"
|
||||
"port": 411,
|
||||
"tag": "nmdc-webfrontend"
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user