משתמש:אלישיב ליפא/HideTemplates.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
var savedTemplates = [];
var searchQuery = /{{פרשע/;
var replaceWith = "�";
/*********** functions ***********/
function HideTemplates(event)
{
	event.preventDefault();
	matchingBracket = function(text, pos)
	{
		pos += 2; //{{
		i = 0;
		flag = true;
		while(flag)
		{
			if (text[pos] == "{" && text[pos + 1] == "{") //Another template
			{
				i += 1;
				pos += 2;
			}
			else if (text[pos] == "}" && text[pos + 1] == "}")
				if (i === 0)
				{
					pos += 2;
					flag = false;
				}
				else
				{
					i -= 1;
					pos += 2;
				}
			else
				pos += 1;
		}
		return pos;
	};
	
	text = $("#wpTextbox1")[0].value;
	start = text.search(searchQuery);
	while (start != -1)
	{
		end = matchingBracket(text, start);
		template = text.substring(start,end);
		savedTemplates[savedTemplates.length] = template;
		text = text.replace(template, replaceWith);
		start = text.search(searchQuery);
	}
	
	$("#wpTextbox1")[0].value = text;
	
	$("#wpSave").attr("disabled",true);
	$("#wpDiff").attr("disabled",true);
	$("#wpPreview").attr("disabled",true);
	
	$("#HideBt").attr("disabled",true);
	$("#ShowBt").attr("disabled",false);
}

function ShowTemplates(event)
{
	event.preventDefault();
	text = $("#wpTextbox1")[0].value;
	start = text.search(replaceWith);
	while (start != -1)
	{
		template = savedTemplates.shift();
		text = text.replace(replaceWith, template);
		start = text.search(replaceWith);
	}
	
	$("#wpTextbox1")[0].value = text;

	$("#wpSave").attr("disabled",false);
	$("#wpDiff").attr("disabled",false);
	$("#wpPreview").attr("disabled",false);
	
	$("#HideBt").attr("disabled",false);
	$("#ShowBt").attr("disabled",true);
}

//add the button
$(function() 
{
	var HideButton = $("<Button />", 
	{
		id: "HideBt",
		text: "Hide",
		click: HideTemplates
	});
	var ShowButton = $("<Button />",
	{
		id: "ShowBt",
		text: "Show",
		click: ShowTemplates,
		disabled: true
	});
	$("#wikiEditor-section-main").append(HideButton).append(ShowButton);
});