// wikiautocompletion.js
// External Javascript to extend some HTML like wikiautocompletion.htm allowing for a dynamically created HTML div element "wikiautocompletion" (ie. dropdown + div contenteditable=true)
// November, 2020
// Called via ...
//
// ... or dropdown populated example as per ...
//
var divautoc='';
var divarr=[], divarrl=[], divarru=[];
var lastdivo=null;
var lastdivid='';
class Droptext {
constructor(wikiautocompletion) {
this.ele = document.createElement('div');
this.ele.id = ('' + wikiautocompletion).split(';')[0];
if (('' + wikiautocompletion).indexOf(';') != -1) {
this.ele.setAttribute('data-dropinnards', encodeURIComponent(('' + wikiautocompletion).split(';')[1].replace('') != -1) {
this.ele.innerHTML = ('' + wikiautocompletion).split(';')[1].split('')[0].replace(''; // + "";
} else {
this.ele.innerHTML = ('' + wikiautocompletion).split(';')[1].replace(''; // + "";
}
}
}
present() {
var teo=this.ele.outerHTML.replace('>')[1].trim() == '' && lastdivo.innerHTML.indexOf('ion id=') != -1) {
lastdivo.innerHTML=lastdivo.innerHTML.replace(/\ion id\=/g, 'ion data-id=');
lastdivo.setAttribute('data-dropinnards', encodeURIComponent(lastdivo.innerHTML));
atoih=ato.target.innerHTML;
}
} else if (atoih.trim() == '' && divarr.length > 0 && lastdivo.innerHTML.indexOf('ion id=') != -1) {
lastdivo.innerHTML=lastdivo.innerHTML.replace(/\ion id\=/g, 'ion data-id=');
lastdivo.setAttribute('data-dropinnards', encodeURIComponent(lastdivo.innerHTML));
atoih=ato.target.innerHTML;
}
if ((atoih + wasc) != '' && divarr.length > 0) { //document.getElementById('viapcontent').innerHTML != '') {
var found=false, foundlist='';
for (var ij=0; ij') != -1) {
if (!found && divarr[ij].toUpperCase().indexOf((atoih.split('')[1] + wasc).toUpperCase()) == 0) {
found=true;
foundlist=divarr[ij];
} else if (found && divarr[ij].toUpperCase().indexOf((atoih.split('')[1] + wasc).toUpperCase()) != 0) {
foundlist=foundlist;
} else if (found) {
foundlist+='`' + divarr[ij];
}
} else {
if (!found && divarr[ij].toUpperCase().indexOf((atoih + wasc).toUpperCase()) == 0) {
found=true;
foundlist='';
} else if (found && divarr[ij].toUpperCase().indexOf((atoih + wasc).toUpperCase()) != 0) {
foundlist=foundlist;
} else if (found && foundlist.indexOf('') == -1) {
foundlist+='`' + '';
}
}
}
if (atoih.indexOf('') != -1) {
//document.title=(' ' + wasc + ' Foundlist (via ' + atoih.split('')[1] + wasc + ')=' + foundlist);
document.getElementById('viapcontent').innerHTML=foundlist.replace(/\`/g,'
');
} else {
//document.title=(' ' + wasc + ' Foundlist (via ' + atoih + wasc + ')=' + foundlist);
document.getElementById('viapcontent').innerHTML=foundlist.replace(/\`/g,'
');
}
}
return atoih;
}
function atwo(wk, wkv) {
if (document.getElementById('lastopt')) {
document.getElementById('lastopt').innerHTML=wkv;
document.getElementById('lastopt').value=wkv;
document.getElementById(wk).innerHTML=document.getElementById(wk).innerHTML.replace(/\ id\=/g, ' data-id=');
document.getElementById('viapcontent').innerHTML='';
document.getElementById(wk).setAttribute('data-dropinnards', encodeURIComponent(document.getElementById(wk).innerHTML));
} else {
document.getElementById(wk).innerHTML=wkv;
//document.getElementById(wk).setAttribute('data-sofar',wkv);
//alert(("" + document.getElementById(wk).onblur).split('}')[0].split('{')[1].replace(/event\.target/g,"document.getElementById('" + wk + "')"));
eval(("" + document.getElementById(wk).onblur).split('}')[0].split('{')[1].replace(/event\.target/g,"document.getElementById('" + wk + "')"));
//eval(("" + document.getElementById(wk).onblur).split('}')[0].split('{')[1].replace(/event\.target/g,"document.getElementById('" + wk + "')"));
//document.getElementById(wk).click();
//document.getElementById('iootw').focus();
//document.getElementById(wk).setAttribute('data-dropinnards', encodeURIComponent(document.getElementById(wk).innerHTML));
document.getElementById('viapcontent').innerHTML='';
}
}
function autoc(ato) {
var wasc=String.fromCharCode(eval(eval('' + ato.keyCode)));
lastdivo=ato.target;
lastdivid='' + ato.target.id;
var atoih=ato.target.innerHTML;
if (atoih.indexOf('') != -1 && divarr.length > 0) {
if (atoih.split('')[1].trim() == '' && lastdivo.innerHTML.indexOf('ion id=') != -1) {
lastdivo.innerHTML=lastdivo.innerHTML.replace(/\ion id\=/g, 'ion data-id=');
//lastdivo.setAttribute('data-dropinnards', encodeURIComponent(lastdivo.innerHTML));
atoih=ato.target.innerHTML;
}
} else if (atoih.trim() == '' && divarr.length > 0 && lastdivo.innerHTML.indexOf('ion id=') != -1) {
lastdivo.innerHTML=lastdivo.innerHTML.replace(/\ion id\=/g, 'ion data-id=');
//lastdivo.setAttribute('data-dropinnards', encodeURIComponent(lastdivo.innerHTML));
atoih=ato.target.innerHTML;
}
if ((atoih + wasc) != '' && divarr.length > 0) { //document.getElementById('viapcontent').innerHTML != '') {
var found=false, foundlist='';
for (var ij=0; ij') != -1) {
if (!found && divarr[ij].toUpperCase().indexOf((atoih.split('')[1] + wasc).toUpperCase()) == 0) {
found=true;
foundlist=divarr[ij];
} else if (found && divarr[ij].toUpperCase().indexOf((atoih.split('')[1] + wasc).toUpperCase()) != 0) {
foundlist=foundlist;
} else if (found) {
foundlist+='`' + divarr[ij];
}
} else {
if (!found && divarr[ij].toUpperCase().indexOf((atoih + wasc).toUpperCase()) == 0) {
found=true;
//foundlist='';
foundlist='';
} else if (found && divarr[ij].toUpperCase().indexOf((atoih + wasc).toUpperCase()) != 0) {
foundlist=foundlist;
} else if (found && foundlist.indexOf('') == -1) {
foundlist+='`' + '';
}
}
}
if (atoih.indexOf('') != -1) {
//document.title+=(' ' + wasc + ' foundlist (via ' + atoih.split('')[1] + ')=' + foundlist);
document.getElementById('viapcontent').innerHTML=foundlist.replace(/\`/g,'
');
} else {
//document.title+=(' ' + wasc + ' foundlist (via ' + atoih + wasc + ')=' + foundlist);
document.getElementById('viapcontent').innerHTML=foundlist.replace(/\`/g,'
');
}
}
return atoih;
}
function askaboutsort(iw, iwc) {
var ioselo=null;
var sels=[], isels=0;
var curval='';
var ansis='';
var contarr=[], icont=0, incont='';
var ris='O';
sels=document.getElementsByTagName('select');
for (isels=0; isels');
contarr.sort();
ansis=prompt('Do you want to sort Ascending or Descending column or restore Original order ' + iwc + '? ... A or D or O', '');
} else {
ris='A';
ioselo.setAttribute('data-content', encodeURIComponent(ioselo.innerHTML));
contarr=decodeURIComponent(ioselo.getAttribute('data-content')).split('');
contarr.sort();
ansis=prompt('Do you want to sort Ascending or Descending column ' + iwc + '? ... A or D', '');
}
if (ansis == null) { ansis = ''; }
if ((ansis + ' ').toUpperCase().substring(0,1) == 'A') {
for (icont=0; icont';
}
ioselo.innerHTML=incont;
ioselo.value=curval;
} else if ((ansis + ' ').toUpperCase().substring(0,1) == 'D') {
for (icont=eval(-1 + contarr.length); icont>=0; icont--) {
incont+=contarr[icont] + '';
}
ioselo.innerHTML=incont;
ioselo.value=curval;
} else if ((ansis + ' ').toUpperCase().substring(0,1) == ris) {
ioselo.innerHTML=decodeURIComponent(ioselo.getAttribute('data-content'));
ioselo.value=curval;
}
}
}
function thprompts() {
var wasih='';
var ths=document.getElementsByTagName('th');
for (var iths=0; iths' + wasih + '';
}
}
}
function woit(sthis) {
if (sthis.value.indexOf(String.fromCharCode(104) + String.fromCharCode(116) + String.fromCharCode(116) + String.fromCharCode(112)) == 0) {
window.open(sthis.value,'_blank','top=100,left=100,width=600,height=600');
}
if (sthis.outerHTML.indexOf(' data-content=') != -1) {
if (decodeURIComponent(sthis.getAttribute('data-content')).replace(/\ value\=\"/g, ' value=').replace(/\ value\=\'/g, ' value=').indexOf(' value=' + sthis.value) == -1) {
sthis.setAttribute('data-content', sthis.getAttribute('data-content') + encodeURIComponent(''))
}
}
}
var ihs, selconts=[], selcont='', mywikiautocompletion=null, obody=null, ofound=false, jiip=0, iip=0, obs=[], ihsobs=[], iqw=0, ihsuff='', isokay=true, ioff=0, alle=[], ialle=0, sparebody=null;
ihs = "";
if (document.title != document.title.trim()) {
ihsobs = (" ").split('?ddlist=');
} else {
ihsobs = (document.head.innerHTML + document.body.innerHTML).replace(/\&ddlist\=/g,'?ddlist=').split('?ddlist=');
}
if (ihsobs.length > 2) {
ioff = -1;
ihs = decodeURIComponent((document.head.innerHTML + document.body.innerHTML).replace('&ddlist=','?ddlist=').split('?ddlist=')[1].split('&')[0].split('"')[0].split("'")[0]); // + ',';
if (document.URL.indexOf('ddlist=' + encodeURIComponent(ihs)) == -1 && (document.head.innerHTML + document.body.innerHTML).indexOf('?just=one') == -1) {
if (document.URL.indexOf('?') == -1) {
if (ihs.indexOf('/wiki/') == -1) { location.href = document.URL.split('#')[0] + '?ddlist=' + encodeURIComponent(ihs); }
ioff = -11;
} else {
if (ihs.indexOf('/wiki/') == -1) { location.href = document.URL.split('#')[0] + '&ddlist=' + encodeURIComponent(ihs); }
ioff = -11;
}
} else {
document.title+=' ';
}
} else if (ihsobs.length == 2) {
ioff = -1;
}
for (iqw=1; iqw<=eval(ioff + eval('' + ihsobs.length)); iqw++) {
ihs="";
isokay=true;
selconts = location.search.split('ddlist=')[1] ? (ihs + decodeURIComponent(location.search.split('ddlist=')[1].split('&')[0])).split(',') : (ihs + "").split(',');
if ((document.head.innerHTML + document.body.innerHTML).replace(/\&ddlist\=/g,'?ddlist=').indexOf('?ddlist=') != -1) {
ihs = decodeURIComponent((document.head.innerHTML + document.body.innerHTML).replace(/\&ddlist\=/g,'?ddlist=').split('?ddlist=')[iqw].split('&')[0].split('"')[0].split("'")[0]); // + ',';
if (ihs.trim() != '') { selconts = ihs.split(','); }
if (ihsobs.length > 2) {
isokay = false;
if (iqw > 1) {
selconts = ihs.split(',');
}
if (1 == 1 || document.URL.indexOf('ddlist=' + encodeURIComponent(ihsobs[1].split('&')[0].split('"')[0].split("'")[0])) != -1) {
isokay=true;
}
}
}
if (isokay) { console.log('yay ' + ioff + ' ' + ihsobs.length + ' ' + document.URL); } else { console.log('oops ' + ioff + ' ' + ihsobs.length + ' ' + document.URL + ' versus ' + 'ddlist=' + encodeURIComponent(ihsobs[1].split('&')[0].split('"')[0].split("'")[0])); }
if (isokay) {
thprompts();
if (selconts[0].indexOf('").replace(" name=selcombo>", " name=selcombo0>");
selcont = ("").replace(" name=selcombo>", " name=selcombo0>");
for (jiip=0; jiip' + selconts[jiip].split('|')[1].replace(/\_/g,' ').replace(/\'/g,'`') + '';
} else {
selcont += '';
}
} else {
selcont += '';
}
} else if (selconts[jiip].toLowerCase().indexOf('|') != -1) {
selcont += '';
} else {
selcont += '';
}
}
}
//selcont = selcont.replace('') != -1 && alle[ialle].outerHTML.indexOf('script') == -1) {
sparebody=alle[ialle];
}
}
if (sparebody) {
obody = sparebody;
} else if (document.getElementById('demo' + ihsuff)) {
obody = document.getElementById('demo' + ihsuff);
} else {
ofound = false;
obs = document.getElementsByTagName('div');
for (iip=0; iip';
obody = document.getElementById('demo' + ihsuff);
}
}
eval('obody.innerHTML += mywikiautocompletion' + ihsuff + '.show()');
//thprompts();
document.title+=' ';
}
ihsuff='' + eval(0 + iqw);
}
function lookviapcontent() {
if (document.getElementById('viapcontent').innerHTML == '') {
setTimeout(lookviapcontent, 1000);
} else {
divautoc=decodeURIComponent(document.getElementById('viapcontent').innerHTML);
//alert(divautoc);
divarr=divautoc.split('`');
divarr.sort();
divarru=divautoc.toUpperCase().split('`');
divarru.sort();
divarrl=divautoc.toLowerCase().split('`');
divarrl.sort();
//for (var iz=0; iz');
document.getElementById('viapcontent').style.position='fixed';
document.getElementById('viapcontent').style.left='50%';
document.getElementById('viapcontent').style.top='100px';
document.getElementById('viapcontent').style.display='block';
setTimeout(mthen,5000);
}
}
function mthen() {
document.getElementById('viapcontent').innerHTML='';
}
setTimeout(lookviapcontent, 1000);