⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radeditordiagnostics.js

📁 Telerik是很大的第三方软件制造商
💻 JS
字号:
RadEditorDiagnostics.prototype = new RadEditorModuleBase();
RadEditorDiagnostics.prototype.base = RadEditorModuleBase.prototype.constructor;

function RadEditorDiagnostics(moduleArgs)
{		
	moduleArgs.ModuleElement = moduleArgs.Document.createElement("div");		
	this.base(moduleArgs);		
	this.DebugConsole = null;		
};

RadEditorDiagnostics.prototype.OnCreate = function() 
{
	var oDebugDivId = "Debug" + this.Editor.Id;	
	this.DebugConsole = new RadEditorDebugConsole(oDebugDivId);			
	var oTable = this.CreateModule(oDebugDivId);		
	this.ModuleElement.appendChild(oTable);					
	this.EnableDebug(true);
};

RadEditorDiagnostics.prototype.EnableDebug = function (bEnable)
{			
	if (this.DebugConsole)
	{
		//Attach to Editor event handlers
		var oModule = this;
		var oDebug = this.DebugConsole;
		var oEditor = this.Editor;
				
		var oFire = oEditor.Fire;	
		//Replace editor Fire method
		oEditor.Fire = function(commandName, oTool)
		{		
			if (oDebug.EnableFire) oDebug.Info("Fire " + commandName);
			oFire.call(oEditor, commandName, oTool);
		}
						
		//Sel changed
		var selCounter = 0;
		oEditor.AttachEventHandler("RADEVENT_SEL_CHANGED"
			, function()
			{ 										
				if (oDebug.EnableSelChanged)
				{					
					var sel = oEditor.GetSelectionHtml();
					var selHtml = oModule.ConvertText2Html(sel);					
					var text = "<a href='#' onclick='getElementById(\"HtmlDiv" + selCounter + "\").style.display = \"block\";return false;'>Show Selection HTML</a>";					
					text += "<div style='margin-left:20px;border:0px;border-left:1px solid green;display:none;' id='HtmlDiv" + selCounter + "'>" + selHtml + "</div>";										
					if (sel) sel = text;					
					oDebug.WriteLn("SEL CHANGED " + sel);					
					selCounter++;
				}
			}
		);				
		
		//Key event handlers		
		var HandleKey = function anon(oName, e, oDebug)
		{
			var key = e.keyCode;
			var keyStr = String.fromCharCode(key);
			if (keyStr) keyStr = "(" + keyStr + ")";
			else keyStr = "(keyCode:" + key + ")";
			oDebug.WriteLn(oName + keyStr);
		}
					
		oEditor.AttachEventHandler("onkeydown"
			, function(e)
			{				
				if (oDebug.EnableKeys)
				{
					HandleKey("key down", e, oDebug);
				}
			}
		);

		oEditor.AttachEventHandler("onkeyup"
			, function(e)
			{
				if (oDebug.EnableKeys)
				{
					HandleKey("key up", e, oDebug);
				}
			}
		);

		oEditor.AttachEventHandler("onpaste"
			, function(e)
			{
				if (oDebug.EnablePaste) oDebug.WriteLn("onpaste (" + oEditor.GetClipboardAsHtml() + ")");
			}
		);
				
		//this.DebugConsole.Info("Diagnostics started");
	}
};

RadEditorDiagnostics.prototype.ConvertText2Html = function(text)
{	
	text = text.replace(/</g, "&lt;");
	text = text.replace(/>/g, "&gt;");
	text = text.replace(/\n/g, "<br>");
	return text;
};

RadEditorDiagnostics.prototype.CreateModule = function(oDebugDivId)
{
	var oTable = document.createElement("table");
	oTable.width = "100%";	
	oTable.height = "300px";	
	oTable.style.fontFamily = "Verdana";
	oTable.style.fontSize = "8pt";
		
	var oRow = oTable.insertRow(-1);
	var oCell = oRow.insertCell(-1);
		
	var oDebug = this.DebugConsole;
	var labels = ["Fire ","Sel Changed ","Key up/down ","Paste "];
	var functions = ["Fire","SelChanged ","Keys","Paste"];
	
	var initCheckBox = function(oCheck, enableStr)
	{
		oCheck.onclick = function(){oDebug.Enable("Enable" + enableStr, this.checked); };
	};
	
	for (var i = 0; i < labels.length; i++)
	{
		var oInput = document.createElement("input");
		oInput.type = "checkbox";		
		oInput.defaultChecked = true;			
		oCell.appendChild(oInput);	
		initCheckBox(oInput, functions[i]);
		
		var oSpan = document.createElement("span");
		oSpan.innerHTML = labels[i];
		oCell.appendChild(oSpan);
	}
	
	//Create diagnostics area
	oRow = oTable.insertRow(-1);
	oCell = oRow.insertCell(-1);
	oCell.valign = "top";
	oCell.height = "100%";		
	oCell.innerHTML = '<div id="' + oDebugDivId + '" style="border:1px solid #bb0000;background-color:#dddddd;width:98%;height:280px;overflow:auto;padding:2px;"></div>';
			
	//Create the clear console button
	oRow = oTable.insertRow(-1);
	oCell = oRow.insertCell(-1);
	oCell.height = "1";
	oCell.innerHTML = '<input type=button class="RadEXhtmlButton" value="Clear Console">';	
	oCell.firstChild.onclick = function () {
		oDebug.Clear();
	}
	
	return oTable;
};

function RadEditorDebugConsole(oDebugDivId)
{
	this.EnableFire = true;
	this.EnableSelChanged = true;
	this.EnablePaste = true;				
	this.EnableKeys = true;
	this.DebugDivId = oDebugDivId;

	this.Enable = function(what, toEnable)
	{										
		this[what] = toEnable;	
	};
					
	this.Clear = function()
	{
		document.getElementById(this.DebugDivId).innerHTML = "";
	};
	
	this.WriteLn = function(sText, color)
	{
		if (!color) color = "#999999";		
		var oDiv = document.getElementById(this.DebugDivId);																				
		
		var oFont = document.createElement("FONT");
		oFont.innerHTML = sText + "<BR>";
		oFont.color = color;						
		
		if (oDiv.firstChild)
		{
			oDiv.insertBefore(oFont, oDiv.firstChild);
		} 
		else oDiv.appendChild(oFont);								
		oDiv.scrollTop = 0;
	};
																																			
	this.Info = function(sText)
	{									
		this.WriteLn("<br>" + "[" + new Date().toLocaleTimeString() + "]&nbsp;" + sText, "#008100");
	};						
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -