User:Emanuele/smfcurve.js: Difference between revisions From Online Manual

Jump to: navigation, search
mNo edit summary
No edit summary
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
window.onload = add_code_select;
var failsafe = 0;
function create_translation_dropdown ()
{
var translation_bar = document.getElementById('translation_bar');
if (typeof translation_bar == 'undefined' && failsafe < 5)
{
setTimeout("create_translation_dropdown();", 250);
failsafe++;
return;
}


function add_code_select(){
var avail_languages = translation_bar.getElementsByTagName('a');
var cont = document.getElementById('content');
if (typeof avail_languages == 'undefined' && failsafe < 10)
var codes = getElementsByClass('code', cont, 'div');
{
setTimeout("create_translation_dropdown();", 250);
failsafe++;
return;
}


if(codes != null){
// Get the <td> where the list is
for (var a in codes) {
var tds = translation_bar.getElementsByTagName('td');
var aSpan = document.createElement('span');
for (var i = 0; i < tds.length; i++)
var aLink = document.createElement('a');
if (tds[i].className == 'mw-pt-languages-list')
var aText = document.createTextNode("Code: [");
var list_position = tds[i];


aLink.onclick = 'return smfWikiSelectText(this,true);';
var tSelect = document.createElement('select');
aLink.innerHTML = 'Select';
tSelect.onchange = function() {
aLink.id = 'link_code_'+a;
window.location = this.options[this.selectedIndex].value;
aSpan.appendChild(aText);
};
aSpan.appendChild(aLink);
var aText = document.createTextNode("]");
aSpan.appendChild(aText);


codes[a].insertBefore(aSpan, codes[a].firstChild);
var tSelectLang = document.createElement('option');
codes[a].id = 'code_'+a;
tSelectLang.value = window.location.href;
}
tSelectLang.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
}
tSelectLang.appendChild(document.createTextNode('Select your language'));
}
tSelect.appendChild(tSelectLang);


function getElementsByClass(searchClass,node,tag) {
var tEnglish = document.createElement('option');
  var classElements = new Array();
tEnglish.value = getEnglishPage(window.location.href);
  if ( node == null )
tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
    node = document;
tEnglish.appendChild(document.createTextNode('English'));
  if ( tag == null )
tSelect.appendChild(tEnglish);
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}


// Get the text in a code tag.
var langs = avail_languages.length;
function smfWikiSelectText(oElement, bActOnElement)
for (var i = 0; i < langs; i++)
{
{
oCurElement = oElement.id.substr(5);
var tOption = document.createElement('option');
// The place we're looking for is one div up, and next door - if it's auto detect.
tOption.value = avail_languages[0].href;
if (typeof(bActOnElement) == 'boolean' && bActOnElement)
var tImg = avail_languages[0].getElementsByTagName('img')[0];
var oCodeArea = document.getElementById(oCurElement);
if (tImg == undefined)
else
continue;
var oCodeArea = oCurElement.parentNode.nextSibling;
tOption.style = 'background: url(' + tImg.src + ') rgba(0,0,0,0);';
 
avail_languages[0].removeChild(tImg);
var els = oCodeArea.getElementsByTagName('pre');
if (avail_languages[0].innerHTML.replace(/^\s\s*/, '').replace(/\s\s*$/, '') != '')
oCodeArea = els[0];
alert(oCodeArea);
if (typeof(oCodeArea) != 'object' || oCodeArea == null)
return false;
 
// Start off with my favourite, internet explorer.
if ('createTextRange' in document.body)
{
{
var oCurRange = document.body.createTextRange();
tOption.appendChild(document.createTextNode(avail_languages[0].innerHTML));
oCurRange.moveToElementText(oCodeArea);
tSelect.appendChild(tOption);
oCurRange.select();
}
}
// Firefox at el.
avail_languages[0].parentNode.removeChild(avail_languages[0]);
else if (window.getSelection)
}
{
list_position.innerHTML = '';
var oCurSelection = window.getSelection();
list_position.appendChild(tSelect);
// Safari is special!
}
if (oCurSelection.setBaseAndExtent)
setTimeout("create_translation_dropdown();", 250);
{
var oLastChild = oCodeArea.lastChild;
oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
}
else
{
var curRange = document.createRange();
curRange.selectNodeContents(oCodeArea);


oCurSelection.removeAllRanges();
function getEnglishPage(aUrl)
oCurSelection.addRange(curRange);
{
}
return aUrl.replace(aUrl.substr(aUrl.lastIndexOf('/')), '');
}
 
return false;
}
}

Latest revision as of 08:54, 24 April 2013

var failsafe = 0;
function create_translation_dropdown ()
{
var translation_bar = document.getElementById('translation_bar');
if (typeof translation_bar == 'undefined' && failsafe < 5)
{
	setTimeout("create_translation_dropdown();", 250);
	failsafe++;
	return;
}

var avail_languages = translation_bar.getElementsByTagName('a');
if (typeof avail_languages == 'undefined' && failsafe < 10)
{
	setTimeout("create_translation_dropdown();", 250);
	failsafe++;
	return;
}

// Get the <td> where the list is
var tds = translation_bar.getElementsByTagName('td');
for (var i = 0; i < tds.length; i++)
	if (tds[i].className == 'mw-pt-languages-list')
		var list_position = tds[i];

var tSelect = document.createElement('select');
tSelect.onchange = function() {
	window.location = this.options[this.selectedIndex].value;
};

var tSelectLang = document.createElement('option');
tSelectLang.value = window.location.href;
tSelectLang.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
tSelectLang.appendChild(document.createTextNode('Select your language'));
tSelect.appendChild(tSelectLang);

var tEnglish = document.createElement('option');
tEnglish.value = getEnglishPage(window.location.href);
tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
tEnglish.appendChild(document.createTextNode('English'));
tSelect.appendChild(tEnglish);

var langs = avail_languages.length;
for (var i = 0; i < langs; i++)
{
	var tOption = document.createElement('option');
	tOption.value = avail_languages[0].href;
	var tImg = avail_languages[0].getElementsByTagName('img')[0];
	if (tImg == undefined)
		continue;
	tOption.style = 'background: url(' + tImg.src + ') rgba(0,0,0,0);';
	avail_languages[0].removeChild(tImg);
	if (avail_languages[0].innerHTML.replace(/^\s\s*/, '').replace(/\s\s*$/, '') != '')
	{
		tOption.appendChild(document.createTextNode(avail_languages[0].innerHTML));
		tSelect.appendChild(tOption);
	}
	avail_languages[0].parentNode.removeChild(avail_languages[0]);
}
list_position.innerHTML = '';
list_position.appendChild(tSelect);
}
setTimeout("create_translation_dropdown();", 250);

function getEnglishPage(aUrl)
{
	return aUrl.replace(aUrl.substr(aUrl.lastIndexOf('/')), '');
}


Advertisement: