text:
User:Sitaron/edittools.js

/* Basic flow

* Get existing `select` element, remove all children → All of its `option` children have numeric IDs corresponding to the position of the `p` element containing the special chars to insert. Since we're going to change that, it's safer to have the IDs correspond directly to the IDs of those `p` elements, and for that, it's easier to just create these afresh rather than try to rejigger the existing ones. * Get content of user's `edittools` page → This is retrieved as a text string, not as a DOM object. The content is wrapped in ` ` by the MW parser, so       we need to regex the string to remove this extraneous unwanted. * Prepend this user content to the existing ` ` content. * Create new `select` element, populate with `option` children for all of the `p` elements in ` `

/** * startAjaxGet starts an XmlHttpRequest call on mediawiki. * should be in a library somewhere function startAjaxGet(url,onsuccess,argument){ // See https://en.wikipedia.org/wiki/XMLHttpRequest var req = new XMLHttpRequest; if(!req) return false; // Set up `onreadystatechange` event listener req.onreadystatechange=function{ if( req.readyState == 4 ) // DONE state if( req.status == 200 ) // HTML request return code: 200 = normal success if(typeof(onsuccess)=='function')onsuccess(req.responseText,argument); // responseText: this returns text, NOT a DOM object. };   req.open("GET",url); req.send(); //the  is required for firefox 3b2 return true; } var wet = {}; //Wiktionary Edit Tools global object /** * wet_init starts the process of sorting the edittools, should be called every * page load. function wet_init{ //Check we are in edit mode wet.div=document.getElementById('editpage-specialchars'); if(!wet.div)return false;

// Get existing `select` element, remove all children wet.sel = document.getElementById('charSubsetControl'); wet.sel.innerHTML = "";

// TODO: what are these? Document! wet.ps={};wet.os={};wet.fp=0;

//Get any user edittools section startAjaxGet(       mw.config.get( 'wgScript' ) +'?title=User:'+encodeURIComponent(mw.config.get( 'wgUserName' ))+'/edittools&action=render',        wet_user_ajax    ); //Parse the stuff we already have for(var i=0;i<wet.div.childNodes.length;i++){ var p = wet.div.childNodes[i]; if(p.nodeName.toUpperCase=='P'){ if(p.getAttribute('id')){ wet_add_option(p); }       }    }    //Insert select. wet.div.insertBefore(wet.sel,wet.div.childNodes[0]); wet.sel.setAttribute('id','edittools-select'); try{ wet.sel.addEventListener('change',function{wet_select_set},false); }catch(e){ wet.sel.attachEvent('onchange',function{wet_select_set}); }   wet_select_first; } function wet_user_ajax(resText){ if(resText.indexOf('class="noarticletext"')>-1) return wet_select_first;

// Throwaway div to put the `resText` somewhere so we can use the DOM on it   var div=document.createElement('div'); div.innerHTML=resText;

/* Loop through all the `p` elements in `div` and add to `wet.div`, and to the `select` options. Note that there's `div`, containing then ` ` added by the parser, and the div wrapper from my edittools page to emulate MediaWiki:Edittools. So we dig down to get at the `p` elements. */   div = div.childNodes[0]; for(var i=0;i]*>/g,''); var cn = wet.ps[which].className; cn=cn.replace(/( +)?delayload( +)?/g,''); wet.ps[which].className=cn; }catch(e){ alert("Mediawiki:Edittools/"+which+" contains illegal elements ( s only!)"); } } function wet_add_option(p,before){ var nme=p.getAttribute('id'); p.style.cssText='display:none';

var opt=document.createElement('option'); opt.setAttribute('value',nme); opt.appendChild(document.createTextNode(decodeURIComponent(nme                       .replace(/^edittools-/, '')                        .replace(/\.([0-9A-F][0-9A-F])/g, '%$1')                        .replace(/_/g, '%20')                        )));

if(before){ wet.sel.insertBefore(opt,wet.sel.childNodes[wet.fp]); wet.fp+=1; }else{ wet.sel.appendChild(opt); }   wet.ps[nme]=p; } function wet_select_set(index){ if(typeof(index)=='undefined'&&wet.sel.selectedIndex>-1){ index=wet.sel.selectedIndex; }   if(index>-1&&wet.sel.options[index]){ if(wet.currentIndex>-1&&wet.sel.options[wet.currentIndex]){ wet.ps[ wet.sel.options[wet.currentIndex].getAttribute('value') ].style.cssText='display: none'; }       wet.currentIndex=index; wet.sel.options[index].selected=true; jQuery.cookie('edittoolscharsubset',wet.currentIndex); var which=wet.sel.options[wet.currentIndex].getAttribute('value'); wet.ps[which].style.cssText='display:inline'; if(wet.ps[which].className.indexOf('delayload')>=0){ startAjaxGet(               mw.config.get( 'wgScript' ) +'?title=Mediawiki:Edittools/'+which.replace(/.([0-9A-F]{2})/g,"%$1")+'&action=render',                wet_getset_ajax,which           	); }   } } wet.done=0; function wet_select_first{ wet.done+=1; if(wet.done<2)return false; var index=parseInt(jQuery.cookie('edittoolscharsubset')); if(isNaN(index))index=0; wet_select_set(index); } jQuery(wet_init);

title: User:Sitaron/edittools.js


text:
𐔳𐔰𐔼

Adjective

 * 1) green
 * 2) wet

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: 𐔳𐔰𐔼


text: Category:Mongolian verb inflection-table templates


text: neuronais

title: neuronais


text:
Module:User:QFQ/ordered-table

-- see also: local ordered_table = {}

local _v = {} -- key: k, value: v local _k = {} -- key: i, value: k local _i = {} -- key: k, value: i

function ordered_table.insert(t, k, v)	if v == nil then ordered_table.remove(t, k)	else if t[_v][k] == nil then t[_k][#t[_k] + 1] = k			t[_i][k] = #t[_k] end t[_v][k] = v 	end end

function ordered_table.findk(t, k)	return t[_i][k] end

local function find(t, v)	for i, val in ipairs(t) do		if v == val then return i		end end end

-- O(n) function ordered_table.remove(t, k)	local tv = t[_v] local ti = t[_i] local v = tv[k] local i = ti[k] if i then local tk = t[_k] table.remove(tk, i)		for j = i, #tk do			ti[tk[j]] = j		end ti[k] = nil tv[k] = nil end return v end

function ordered_table.pairs(t) local i = 0 return function i = i + 1 local k = t[_k][i] if k ~= nil then return k, t[_v][k] end end end

function ordered_table.index(t, ik) return type(ik) == 'number' and t[_k][ik] or t[_v][ik] end

ordered_table.__newindex = ordered_table.insert ordered_table.__len = function(t) return #t[_k] end ordered_table.__pairs = ordered_table.pairs ordered_table.__index = ordered_table.index

function ordered_table:new(init) init = init or {} local key_table = {} local value_table = {} local index_table = {} local t = { [_k]=key_table, [_v]=value_table, [_i]=index_table } local n = #init if n % 2 ~= 0 then error("key: " .. tostring(init[#init]).. " is missing value", 2) end for i = 1, n/2 do		local k = init[i * 2 - 1] local v = init[i * 2] if value_table[k] ~= nil then error("duplicated key: " .. tostring(k), 2) end key_table[#key_table + 1] = k		index_table[k] = #key_table value_table[k] = v	end return setmetatable(t, self) end

return setmetatable(ordered_table, { __call=ordered_table.new })

title: Module:User:QFQ/ordered-table