js: rename $ -> el for jQuery compat

This commit is contained in:
mappu 2017-10-15 20:56:23 +13:00
parent 377131e43d
commit b8791f6aa2

View File

@ -7,7 +7,7 @@ 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 = 50; // Once over 2x $limit, the first $limit will be trimmed off the list
var EXTERN_ROOT = window.location.protocol + "//" + window.location.host + "/"; var EXTERN_ROOT = window.location.protocol + "//" + window.location.host + "/";
var $ = function(s) { var el = function(s) {
// There used to be a querySelectorAll implementation, but, better that we don't have // There used to be a querySelectorAll implementation, but, better that we don't have
// potentially-incompatible implementations if this one does actually work. // potentially-incompatible implementations if this one does actually work.
// i'm not writing a selector engine... // i'm not writing a selector engine...
@ -179,7 +179,7 @@ var notify = function(title, body, tab) {
/* Tab writers */ /* Tab writers */
var write = function(tab) { var write = function(tab) {
var $tab = $('#inner-'+tab); var $tab = el('#inner-'+tab);
return { return {
'cls': function() { 'cls': function() {
$tab.innerHTML = ''; $tab.innerHTML = '';
@ -255,7 +255,7 @@ var userlist = {
'add': function(u) { 'add': function(u) {
if (this.has(u)) return; if (this.has(u)) return;
var userlists = $(".userlist"); var userlists = el(".userlist");
for (var l = 0, e = userlists.length; l !== e; ++l) { for (var l = 0, e = userlists.length; l !== e; ++l) {
var userlist = userlists[l]; var userlist = userlists[l];
@ -284,7 +284,7 @@ var userlist = {
return this; return this;
}, },
'del': function(u) { 'del': function(u) {
var userlists = $(".userlist"); var userlists = el(".userlist");
for (var l = 0, e = userlists.length; l !== e; ++l) { for (var l = 0, e = userlists.length; l !== e; ++l) {
if (! userlists[l].children) continue; if (! userlists[l].children) continue;
var userlist = userlists[l]; var userlist = userlists[l];
@ -301,7 +301,7 @@ var userlist = {
return this; return this;
}, },
'clear': function() { 'clear': function() {
var userlists = $(".userlist"); var userlists = el(".userlist");
for (var i in userlists) { for (var i in userlists) {
if (! userlists[i].children) continue; if (! userlists[i].children) continue;
var userlist = userlists[i]; var userlist = userlists[i];
@ -314,7 +314,7 @@ var userlist = {
return this; return this;
}, },
'names': function() { 'names': function() {
var userlist = $(".userlist")[0].children; var userlist = el(".userlist")[0].children;
var ret = []; var ret = [];
for (var i = 0, e = userlist.length; i < e; ++i) { for (var i = 0, e = userlist.length; i < e; ++i) {
ret.push( textContent(userlist[i]) ); ret.push( textContent(userlist[i]) );
@ -322,14 +322,14 @@ var userlist = {
return ret; return ret;
}, },
'has': function(u) { '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() { 'count': function() {
return $(".userlist")[0].children.length; return el(".userlist")[0].children.length;
}, },
'setInfo': function(nick, props) { 'setInfo': function(nick, props) {
var baseClass = "user-" + b64(nick); var baseClass = "user-" + b64(nick);
var $el = $("." + baseClass); var $el = el("." + baseClass);
var prop_str = []; var prop_str = [];
if (props.Description.length > 0) { if (props.Description.length > 0) {
prop_str.push(props.Description); prop_str.push(props.Description);
@ -358,7 +358,7 @@ var userlist = {
}; };
var submit = function() { var submit = function() {
var str = $("#chatbox").value; var str = el("#chatbox").value;
if (! str.length) return; if (! str.length) return;
if (hub_state === STATE_READY_FOR_LOGIN) { if (hub_state === STATE_READY_FOR_LOGIN) {
@ -401,7 +401,7 @@ var submit = function() {
write("tab-main").system("Invalid internal state."); write("tab-main").system("Invalid internal state.");
} }
$("#chatbox").value = ''; el("#chatbox").value = '';
}; };
/* page visibility */ /* page visibility */
@ -448,13 +448,13 @@ var pagevis_setup = function(fnActive, fnInactive) {
*/ */
var tab_set = function(tab) { var tab_set = function(tab) {
var tabs = $(".tabpane"); var tabs = el(".tabpane");
for (var i in tabs) { for (var i in tabs) {
try { try {
tabs[i].style.display = (tabs[i].id === tab ? 'block' : 'none'); tabs[i].style.display = (tabs[i].id === tab ? 'block' : 'none');
} catch (e) {}; } catch (e) {};
} }
var tabitems = $(".tabitem"); var tabitems = el(".tabitem");
for (var i in tabitems) { for (var i in tabitems) {
try { try {
// Update UNREAD/SELECTED flags for the target // Update UNREAD/SELECTED flags for the target
@ -482,13 +482,13 @@ var tab_set = function(tab) {
updateTitle(); updateTitle();
write(tab).scroll(); write(tab).scroll();
$("#chatbox").focus(); el("#chatbox").focus();
last_tab = tab; last_tab = tab;
}; };
var tab_new = function(id, name) { var tab_new = function(id, name) {
appendInnerHTML($("#bar"), appendInnerHTML(el("#bar"),
' <div class="tabitem" data-tab="tab-ext-'+id+'" id="tabitem-tab-ext-'+id+'">'+ ' <div class="tabitem" data-tab="tab-ext-'+id+'" id="tabitem-tab-ext-'+id+'">'+
'<span class="tab-label">'+ '<span class="tab-label">'+
hesc(name)+ hesc(name)+
@ -496,7 +496,7 @@ var tab_new = function(id, name) {
'<a class="tab-closer" data-tab="tab-ext-'+id+'">&times;</a>'+ '<a class="tab-closer" data-tab="tab-ext-'+id+'">&times;</a>'+
'</div> ' '</div> '
); );
appendInnerHTML($("#extratabs"), appendInnerHTML(el("#extratabs"),
' <div class="tabpane content placement-mid" id="tab-ext-'+id+'" style="display:none;">'+ ' <div class="tabpane content placement-mid" id="tab-ext-'+id+'" style="display:none;">'+
'<div class="content-inner" id="inner-tab-ext-'+id+'"></div>'+ '<div class="content-inner" id="inner-tab-ext-'+id+'"></div>'+
'</div>' '</div>'
@ -509,10 +509,10 @@ var tab_free = function(id) {
if (id === "tab-main") return; if (id === "tab-main") return;
// remove tab item and body // remove tab item and body
var el = $("#tabitem-"+id); var el = el("#tabitem-"+id);
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
var el = $("#"+id); var el = el("#"+id);
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
// clear from PM tabs // clear from PM tabs
@ -547,7 +547,7 @@ var noprop = function(ev) {
} }
var tab_addHandlers = function() { var tab_addHandlers = function() {
var tabitems = $(".tabitem"); var tabitems = el(".tabitem");
for (var i = 0; i < tabitems.length; i++) { for (var i = 0; i < tabitems.length; i++) {
if (! tabitems[i]) continue; if (! tabitems[i]) continue;
@ -558,7 +558,7 @@ var tab_addHandlers = function() {
}; };
} }
var tabclosers = $(".tab-closer"); var tabclosers = el(".tab-closer");
for (var i = 0; i < tabclosers.length; i++) { for (var i = 0; i < tabclosers.length; i++) {
if (! tabclosers[i]) continue; if (! tabclosers[i]) continue;
@ -598,7 +598,7 @@ var tabcomplete_state = '';
var tabcompletion_start = function(direction) { 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 === '') { if (tabcomplete_state === '') {
// new tab completion // new tab completion
@ -634,10 +634,10 @@ var tabcompletion_start = function(direction) {
// Replace in textbox // 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; el("#chatbox").value = chatprefix + targetName;
$("#chatbox").focus(); el("#chatbox").focus();
}; };
var tabcompletion_inactive = function() { var tabcompletion_inactive = function() {
@ -686,7 +686,7 @@ MenuList.prototype.toggle = function() {
/* */ /* */
var menu = new MenuList($("#menubutton")); var menu = new MenuList(el("#menubutton"));
menu.reset = function() { menu.reset = function() {
this.clear(); this.clear();
@ -782,7 +782,7 @@ var toggle_joinparts = function(ev) {
var updateTitle = function() { var updateTitle = function() {
var prefix = ""; var prefix = "";
var unrTabs = $(".unread"); var unrTabs = el(".unread");
if (unrTabs.length === 1 && unrTabs[0].getAttribute('data-tab') == "tab-main") { if (unrTabs.length === 1 && unrTabs[0].getAttribute('data-tab') == "tab-main") {
prefix = "[" + mainchat_unread_count + " NEW] " prefix = "[" + mainchat_unread_count + " NEW] "
} else if (unrTabs.length > 0) { } else if (unrTabs.length > 0) {
@ -883,7 +883,7 @@ var scrollback_move = function(delta) {
} }
} }
$("#chatbox").value = chat_scrollback[chat_scrollback_index]; el("#chatbox").value = chat_scrollback[chat_scrollback_index];
}; };
/* */ /* */
@ -908,25 +908,25 @@ var transition = function(new_state) {
switch(new_state) { switch(new_state) {
case STATE_DISCONNECTED: { case STATE_DISCONNECTED: {
userlist.clear(); userlist.clear();
$("#chatbox").disabled = true; el("#chatbox").disabled = true;
$("#chatbox").value = ''; // clear el("#chatbox").value = ''; // clear
} break; } break;
case STATE_READY_FOR_LOGIN: { case STATE_READY_FOR_LOGIN: {
userlist.clear(); userlist.clear();
$("#chatbox").spellcheck = false; el("#chatbox").spellcheck = false;
$("#chatbox").disabled = false; el("#chatbox").disabled = false;
$("#chatbox").value = ''; // clear el("#chatbox").value = ''; // clear
} break; } break;
case STATE_CONNECTING: { case STATE_CONNECTING: {
$("#chatbox").disabled = true; el("#chatbox").disabled = true;
} break; } break;
case STATE_ACTIVE: { case STATE_ACTIVE: {
write("tab-main").system("Now talking on "+hub_hubname); write("tab-main").system("Now talking on "+hub_hubname);
$("#chatbox").disabled = false; el("#chatbox").disabled = false;
$("#chatbox").spellcheck = true; el("#chatbox").spellcheck = true;
} break; } break;
} }
}; };
@ -936,8 +936,8 @@ var tab_is_visible = function(tabref) {
} }
var tab_mark_unread = function(tabref) { var tab_mark_unread = function(tabref) {
if ($("#tabitem-"+tabref).className.indexOf('unread') === -1) { if (el("#tabitem-"+tabref).className.indexOf('unread') === -1) {
$("#tabitem-"+tabref).className += " unread"; el("#tabitem-"+tabref).className += " unread";
updateTitle(); updateTitle();
} }
} }
@ -951,13 +951,13 @@ window.onload = function() {
// HTML event handlers // HTML event handlers
$("#form-none").onsubmit = function(ev) { el("#form-none").onsubmit = function(ev) {
submit(); submit();
return noprop(ev); // don't submit form return noprop(ev); // don't submit form
}; };
$("#chatbox").onkeydown = function(ev) { el("#chatbox").onkeydown = function(ev) {
if (ev.keyCode === 9 /* Tab */) { if (ev.keyCode === 9 /* Tab */) {
tabcompletion_start( ev.shiftKey ? -1 : 1 ); tabcompletion_start( ev.shiftKey ? -1 : 1 );
return noprop(ev); return noprop(ev);
@ -985,7 +985,7 @@ window.onload = function() {
usermenu.hide(); usermenu.hide();
}; };
$("#menubutton").onclick = function(ev) { el("#menubutton").onclick = function(ev) {
menu.toggle(); menu.toggle();
return noprop(ev); return noprop(ev);
}; };
@ -1043,7 +1043,7 @@ window.onload = function() {
if (pre_login.indexOf(":") !== -1) { if (pre_login.indexOf(":") !== -1) {
pre_login = pre_login.substr(0, pre_login.indexOf(":")) + ":" + SENTINEL_PASSWORD; pre_login = pre_login.substr(0, pre_login.indexOf(":")) + ":" + SENTINEL_PASSWORD;
} }
$("#chatbox").value = pre_login; el("#chatbox").value = pre_login;
if (have_cleared_once) { if (have_cleared_once) {
// re-log-in automatically // re-log-in automatically
@ -1137,6 +1137,12 @@ window.onload = function() {
sock.on('usercommand', function(data) { sock.on('usercommand', function(data) {
process_usercommand(data); process_usercommand(data);
}); });
sock.on('contented', function(url) {
contented_url = url;
menu.add("Upload", function() {
contented_load();
});
});
}; };
//IIFEMODE:})(); //IIFEMODE:})();