Monday, November 08, 2010 at 12:03 AM.

system.verbs.builtins.html.editor.getEditingTool

on getEditingTool (pta=nil) {
	<<Changes
		<<8/5/03; 4:00:01 PM by JES
			<<Added support for Mozilla's rich text editor.
		<<8/31/01; 12:33:31 PM by JES
			<<Return the name of the editing tool to use: tagEditor, wysiwygEditor, or none.
			<<Factored from html.editor.get.
	
	if pta == nil {
		pta = html.getPageTableAddress ()};
	<<workspace.pt = pta^; edit (@workspace.pt) //debugging
	
	local (flWysEditor = false, flTagEditor = true, flMozilla = false);
	local (editingToolName = "tagEditor");
	if defined (pta^.editingToolName) {
		editingToolName = pta^.editingToolName;
		if string.lower (pta^.editingToolName) == "wysiwyg" {
			flWysEditor = true;
			flTagEditor = false}};
	
	local (flIeWin5OrGreater = false);
	local (flMozilla13OrGreater = false);
	bundle { //find reasons not to display an editor
		if string.lower (editingToolName) == "none" { //no editor
			return ("")};
		if defined (pta^.responderAttributes.flDiscussHtmlEditor) {
			if not (pta^.responderAttributes.flDiscussHtmlEditor) {
				return ("")}};
		if not defined (pta^.requestHeaders.["User-Agent"]) {
			return ("")};
		
		local (lowerUserAgent = string.lower (pta^.requestHeaders.["User-Agent"]));
		bundle { //Set flags for which supported browser the request came from
			flIeWin5OrGreater = lowerUserAgent contains "msie 5";
			flIeWin5OrGreater = flIeWin5OrGreater or (lowerUserAgent contains "msie 6");
			flIeWin5OrGreater = flIeWin5OrGreater and (lowerUserAgent contains "windows");
			
			flMozilla = (lowerUserAgent contains "mozilla") and (lowerUserAgent contains "gecko") and (lowerUserAgent contains " u;");
			if flMozilla {
				ix = string.patternMatch ("rv:", lowerUserAgent);
				if ix > 0 {
					ix = ix + 3;
					local (mozVers = string.mid (lowerUserAgent, ix, infinity));
					mozVers = string.popSuffix (mozVers, ")");
					flMozilla13OrGreater = not date.versionLessThan (mozVers, "1.3")}}};
		if not (flIeWin5OrGreater or flMozilla13OrGreater) {
			return ("")}};
	
	if flWysEditor {
		if flMozilla {
			editingToolName = "wysiwygEditorMozilla"}
		else { //must be IE Win
			editingToolName = "wysiwygEditor"}}
	else {
		if flTagEditor { //classic source-view editor, raw HTML
			if flIeWin5OrGreater {
				editingToolName = "tagEditor"}
			else {
				editingToolName = "none"}}
		else {
			editingToolName = "none"}};
	
	return (editingToolName)}
<<bundle //test code
	<<dialog.alert (getEditingTool (@workspace.pt))



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.