User:Hippietrail/wiktionaryprefs.js

/*

// stylesheet just of personalized appearances css var wiktPersonalizedStyleSheet = null;

// fieldset of our preferences tab var wiktPrefsDiv = null; var wiktPrefsFieldset = null;

// cross-browser function to add a css rule to the end of a css style sheet function wiktAppendRule(selector, style) { // IE if (wiktPersonalizedStyleSheet.addRule) { wiktPersonalizedStyleSheet.addRule(selector, style);

// Firefox, Opera } else if (wiktPersonalizedStyleSheet.insertRule) { wiktPersonalizedStyleSheet.insertRule(selector + '{' + style + '}', wiktPersonalizedStyleSheet.cssRules.length); } }

// for now custom style prefs are stored as cookies rather than in the db function wiktGetStylesFromCookies {

// just a bit of a test if (getCookie('WiktionaryUseJSPreferences') == 'true') { wiktAppendRule('#p-cactions', 'background-color: #00ff00'); wiktAppendRule('#p-personal', 'background-color: #ff0000'); } }

// make a new css stylesheet just for wiktionary css prefs to interact with function wiktAddStyleSheet { // IE if (document.createStyleSheet) {   wiktPersonalizedStyleSheet = document.createStyleSheet;

// Firefox, Opera } else { var styleele = document.createElement('style'); styleele.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(styleele); wiktPersonalizedStyleSheet = styleele.styleSheet ? styleele.styleSheet : styleele.sheet; }

// get initial values from cookies wiktGetStylesFromCookies; }

// create the basic skeleton of our prefs tab function wiktCreatePrefsTabSkeleton { // find the preferences table of contents ul var pref_toc = document.getElementById('preftoc');

if (pref_toc) { var newli; var newa;

newli = document.createElement('li');

newa = document.createElement('a'); newa.href = '#prefsection-10'; newa.onmousedown = newa.onclick = uncoversection; newa.secid = 'prefsection-10';

newa.appendChild(document.createTextNode('Wiktionary')); newli.appendChild(newa);

// add our constructed li to the toc pref_toc.appendChild(newli); }

// find the preferences div. we add our tab inside it wiktPrefsDiv = document.getElementById('preferences');

if (wiktPrefsDiv) { var newlegend;

wiktPrefsFieldset = document.createElement('fieldset'); wiktPrefsFieldset.id = 'prefsection-10'; wiktPrefsFieldset.className = 'prefsection'; wiktPrefsFieldset.style.display = 'none';

newlegend = document.createElement('legend'); newlegend.className = 'mainLegend'; newlegend.appendChild(document.createTextNode('Wiktionary')); wiktPrefsFieldset.appendChild(newlegend); } }

// add controls to our prefs tab function wiktCreatePrefsTabGUI { var newfieldset; var newlegend; var newdiv; var newbutton;

newfieldset = document.createElement('fieldset');

newlegend = document.createElement('legend'); newlegend.appendChild(document.createTextNode('Appearance')); newfieldset.appendChild(newlegend);

newdiv = document.createElement('div');

newbutton = document.createElement('input'); newbutton.type = 'button'; newbutton.value = 'Magic!'; newbutton.onclick = wiktDoMagic; newdiv.appendChild(newbutton);

newfieldset.appendChild(newdiv);

wiktPrefsFieldset.appendChild(newfieldset); }

// magically add html from somewhere else to this page function wiktDoMagic { var previewdiv = document.getElementById('wiktPreviewDiv'); /* var hiddeniframe = document.getElementById('wiktHiddenIframe');

if (hiddeniframe && previewdiv) { //var iframeDocument = frames['wiktHiddenIframe'].document; //var root = iframeDocument.documentElement || iframeDocument.body; //previewdiv.innerHTML = root.innerHTML;

var iframedoc = hiddeniframe.contentWindow ? hiddeniframe.contentWindow.document : hiddeniframe.contentDocument; var root = iframedoc.documentElement || iframedoc.body; var HTML = root.innerHTML; previewdiv.innerHTML = HTML; } else debugPrint('no hiddeniframe or previewdiv\n'); // GUI //var url = '/w/index.php?title=User:Hippietrail/renderactiontest2&action=raw'; // article to use as preview var url = '/w/index.php?title=thimble&action=render';

if (window.XMLHttpRequest) { var request = new XMLHttpRequest; request.open('GET', url, false); request.send(null); } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); if (request) { request.open("GET", url, true); request.send; } }

// TODO this should be in the responsequery handler thingie... var webpage = request.responseText;

previewdiv.innerHTML = webpage; }

// add preview section to our prefs tab function wiktCreatePrefsTabPreview { var newiframe; var newfieldset; var newlegend; var previewdiv;

newiframe = document.createElement('iframe'); newiframe.src = '/w/index.php?title=User:Hippietrail/renderactiontest&action=render'; newiframe.name = 'wiktHiddenIframe'; newiframe.id = 'wiktHiddenIframe'; newiframe.onload = wiktDoMagic; newiframe.style.display = 'none';

// add it to the dom straight away! document.getElementsByTagName('body')[0].appendChild(newiframe);

newfieldset = document.createElement('fieldset');

newlegend = document.createElement('legend'); newlegend.appendChild(document.createTextNode('Preview')); newfieldset.appendChild(newlegend);

previewdiv = document.createElement('div'); previewdiv.id = 'wiktPreviewDiv'; newfieldset.appendChild(previewdiv);

wiktPrefsFieldset.appendChild(newfieldset); }

// create and add our new tab function wiktCreatePrefsTab { wiktCreatePrefsTabSkeleton; wiktCreatePrefsTabGUI; wiktCreatePrefsTabPreview; }

// insert our constructed prefs tab between the misc tab and the prefsubmit/prefcontrol div function wiktAddPrefsTab { var prefsubctrl_div = document.getElementById('prefsubmit'); if (!prefsubctrl_div) prefsubctrl_div = document.getElementById('prefcontrol');

if (prefsubctrl_div) { wiktPrefsDiv.insertBefore(wiktPrefsFieldset, prefsubctrl_div); } }

// generates CSS rules and provides a tab to manipulate them on the standard preferences tab function wiktionaryPrefs { // create our CSS stylesheet no matter which page we're on wiktAddStyleSheet;

// if we're on the Preferences page, add our Wiktionary-specific tab if (wgNamespaceNumber == -1 && document.getElementById('preftoc')) { wiktCreatePrefsTab; wiktAddPrefsTab; } }

/*