Участник:D.bratchuk/wiki-rules-select.js

Материал из Википедии — свободной энциклопедии
// На основании скрипта Участник:DerLetzteRegenbogen/warnings.js 

function rulebuttons() {
	if (mwCustomEditButtons && document.getElementById('toolbar') ) {
		button = document.createElement('a');
		button.href = "javascript:quickRuleMain()";
		button.title = "Добавить ссылку на правило";
		buttonimage = document.createElement('img');
		buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/a/a4/Button-rules-rus.png";
		buttonimage.alt = "Добавить ссылку на правило";
		button.appendChild(buttonimage);
		var toolbar = document.getElementById('toolbar');
		if (navigator.userAgent.indexOf('MSIE') == -1) {
			if (toolbar.style != null) {
				toolbar.style.height = 'auto';
			}
			else {
				toolbar.setAttribute('style', 'margin-bottom: 6px; height: auto;');
			}
			toolbar.appendChild(button);
			rulemain = document.createElement('div');
			rulemain.style.display = 'none';
			rulemain.style.margin = '0.2em 0';
			rulemain.setAttribute('Id', 'ruleselect');

			var btn;
			for (var i = 0; i < ruleButtons.length; i++)
			 if (btn=buttonsData[ruleButtons[i]])
				rulemain.appendChild( addOption("addRule('"+btn[1]+"')", ruleButtons[i]) );		

			rulemain.appendChild( addOption("hideInitial()", "x") );
			toolbar.appendChild(rulemain);
		}
		else {
			toolbar.appendChild(button);
			selection = '<div id="citeselect" style="display:none">';
			var btn;
			for (var i = 0; i < ruleButtons.length; i++)
			 if (btn=buttonsData[ruleButtons[i]])
				selection+="<input type='button' value='"+ruleButtons[i]+"' onclick='addRule("+btn[1]+")' />";
			selection+='<input type="button" value="x" onclick="hideInitial()" /></div>';
			document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
			}
	}
}
 
function quickRuleMain() {
	document.getElementById('ruleselect').style.display = '';
}
 
function hideInitial() {
	document.getElementById('ruleselect').style.display = 'none';
}

function addRule($rule) {
	insertTags( "[[ВП:"+$rule+"|", "]]", "" );
}
 
$(rulebuttons);