User:Connel MacKenzie/keypad.js

/* todo: -find better "icon" -refactor/cleanup

var html;

// Returns a new XMLHttpRequest object, except in IE, where it returns the // equivalent. function newXMLHttpRequest { var reqObj = false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { reqObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { reqObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { reqObj = false; }  } @else reqObj = false; @end @*/ if (!reqObj) { try { reqObj = new XMLHttpRequest; } catch (e) { reqObj = false; } } return reqObj; }

function keyPadSelection( keyBoardNumber ) { var q='"'; var sq="'";  var txt = html.split(']*class=["'][^"']*\bcharinsert\b[^"']*["'][^>]*>/g, ' ');  kybs = txt.split(' ');  var onthisline=0;  for (i=1; i' ) && ( chars[j] != "'" ) && ( chars[j] != '"' ) ) { onthisline++; cell = document.createElement('td'); cell.bgcolor = 'gray'; cell.align = 'center'; link = document.createElement('a'); link.href = '#' + chars[j]; link.innerHTML = ''+chars[j]+''; cell.appendChild(link); row.appendChild(cell); needBr=true; if (onthisline > 7) { tbl.appendChild(row); row = document.createElement('tr'); onthisline=0; }     } else { if ( chars[j].search(/special/g) != -1 ) { tbl.appendChild(row); row = document.createElement('tr'); onthisline=0; }     }    }  }  tbl.appendChild(row); kW.insertBefore(tbl, kW.firstChild); return true; }

function keyPad { var q='"';   var sq="'";    var selected = parseInt( getCookie('edittoolscharsubset') );    if ( isNaN(selected) ) selected = 1;    if (selected < 1) selected = 1; //skip zero, as that is the "templates" thing.    var sF = document.getElementById("searchform");        var searchBox = document.getElementById('searchInput');        var kW = document.createElement('div');        var tbl = document.createElement('table');        tbl.bgcolor = 'black';        tbl.id = 'searchKeyboard';        var row = document.createElement('tr');        var cell = document.createElement('td');        var link = document.createElement('a');        var func;        link.appendChild(document.createTextNode('testing'));        cell.appendChild(link);        cell.bgcolor = 'gray';        cell.align = 'center';

var req = newXMLHttpRequest; req.open('GET', '//en.wiktionary.org/w/index.php?title=MediaWiki:Edittools&action=raw', true) ; req.send(null); req.onreadystatechange = function { if (req.readyState==4) { html = req.responseText; //TODO: get all of them, extract name, add combobox, all loop thing that makes them visible=flase/visible=true. var menus = html.split('editpage-specialchars')[1].split(' -1) lin = lin.split('"')[1]; if (lin.indexOf('edittools-') == 0) lin = lin.split('edittools-')[1]; if (lin == '') { lin = 'Unnamed ' + j; }; menu.options[menu.options.length] = new Option(lin); }    menu.options[selected-1].selected = true; menu.onchange = function { keyPadSelection(this.selectedIndex); }; var txt = html.split('' ) && ( chars[j] != "'" ) && ( chars[j] != '"' ) ) {           onthisline++;            cell = document.createElement('td');            cell.bgcolor = 'gray';            cell.align = 'center';            link = document.createElement('a');            link.href = '#' + chars[j];            link.innerHTML = ''+chars[j]+'';            cell.appendChild(link);            row.appendChild(cell);            needBr=true;            if (onthisline > 7) {              tbl.appendChild(row);              row = document.createElement('tr');              onthisline=0;             }            } else {            if ( chars[j].search(/special/g) != -1 ) {                tbl.appendChild(row); row = document.createElement('tr'); onthisline=0; }           }          }       }     tbl.appendChild(row); kW.appendChild(tbl); searchBox.appendChild(kW); kW.appendChild(menu); }  }

return; }

function addKeyPadTimer { setTimeout( 'keyPad', 200 ); //wait 1/5th of one second. }

function addKeyPadIcon { var searchform = document.getElementById("searchform"); if (!searchform) return; //not possible var keyPadButton = document.createElement('input'); keyPadButton.type = 'image'; keyPadButton.src = '//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Keyboard-gray-old.jpg/60px-Keyboard-gray-old.jpg'; keyPadButton.value = 'Keyboard'; keyPadButton.title = 'Open keyboard window for entering special characters'; keyPadButton.onclick = function { keyPadButton.src = ''; keyPadButton.value = ''; keyPad; return false; }; searchform.appendChild( keyPadButton ); }

$( addKeyPadTimer );