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

📄 editor2.js

📁 对java中如何使用Ajax技术
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*	Copyright (c) 2004-2006, The Dojo Foundation	All Rights Reserved.	Licensed under the Academic Free License version 2.1 or above OR the	modified BSD license. For more information on Dojo licensing, see:		http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.widget.Editor2");dojo.require("dojo.io.*");dojo.require("dojo.widget.RichText");dojo.require("dojo.widget.Editor2Toolbar");dojo.widget.Editor2Manager = new dojo.widget.HandlerManager;dojo.lang.mixin(dojo.widget.Editor2Manager,{	// summary: Manager of current focused Editor2 Instance and available editor2 commands	_currentInstance: null,	// commandState: Object: state a command may be in	commandState: {Disabled: 0, Latched: 1, Enabled: 2},	getCurrentInstance: function(){		// summary: Return the current focused Editor2 instance		return this._currentInstance;	},	setCurrentInstance: function(/*Widget*/inst){		// summary: Set current focused Editor2 instance		this._currentInstance = inst;	},	getCommand: function(/*dojo.widget.Editor2*/editor,/*String*/name){		// summary: Return Editor2 command with the given name		// name: name of the command (case insensitive)		var oCommand;		name = name.toLowerCase();		for(var i=0;i<this._registeredHandlers.length;i++){			oCommand = this._registeredHandlers[i](editor, name);			if(oCommand){				return oCommand;			}		}		switch(name){			case 'htmltoggle':				//Editor2 natively provide the htmltoggle functionalitity				//and it is treated as a builtin command				oCommand = new dojo.widget.Editor2BrowserCommand(editor, name);				break;			case 'formatblock':				oCommand = new dojo.widget.Editor2FormatBlockCommand(editor, name);				break;			case 'anchor':				oCommand = new dojo.widget.Editor2Command(editor, name);				break;			//dialog command			case 'createlink':				oCommand = new dojo.widget.Editor2DialogCommand(editor, name,						{contentFile: "dojo.widget.Editor2Plugin.CreateLinkDialog",							contentClass: "Editor2CreateLinkDialog",							title: "Insert/Edit Link", width: "300px", height: "200px"});				break;			case 'insertimage':				oCommand = new dojo.widget.Editor2DialogCommand(editor, name,						{contentFile: "dojo.widget.Editor2Plugin.InsertImageDialog",							contentClass: "Editor2InsertImageDialog",							title: "Insert/Edit Image", width: "400px", height: "270px"});				break;			// By default we assume that it is a builtin simple command.			default:				var curtInst = this.getCurrentInstance();				if((curtInst && curtInst.queryCommandAvailable(name)) ||					(!curtInst && dojo.widget.Editor2.prototype.queryCommandAvailable(name))){					oCommand = new dojo.widget.Editor2BrowserCommand(editor, name);				}else{					dojo.debug("dojo.widget.Editor2Manager.getCommand: Unknown command "+name);					return;				}		}		return oCommand;	},	destroy: function(){		// summary: Cleaning up. This is called automatically on page unload.		this._currentInstance = null;		dojo.widget.HandlerManager.prototype.destroy.call(this);	}});dojo.addOnUnload(dojo.widget.Editor2Manager, "destroy");dojo.lang.declare("dojo.widget.Editor2Command",null,	function(editor,name){		// summary:		//		dojo.widget.Editor2Command is the base class for all commands in Editor2		this._editor = editor;		this._updateTime = 0;		this._name = name;	},{		_text: 'Unknown',		execute: function(para){			// summary: Execute the command. should be implemented in subclass			// description: this function should be re-implemented in subclass			dojo.unimplemented("dojo.widget.Editor2Command.execute");		},		getText: function(){			// summary: return the text name of this command			return this._text;		},		getState: function(){			// summary:			//		Return the state of the command. The default behavior is			//		to always return Enabled			return dojo.widget.Editor2Manager.commandState.Enabled;		},		destroy: function(){			// summary: Destructor		}	});dojo.widget.Editor2BrowserCommandNames={			'bold': 'Bold',			'copy': 'Copy',			'cut': 'Cut',			'Delete': 'Delete',			'indent': 'Indent',			'inserthorizontalrule': 'Horizental Rule',			'insertorderedlist': 'Numbered List',			'insertunorderedlist': 'Bullet List',			'italic': 'Italic',			'justifycenter': 'Align Center',			'justifyfull': 'Justify',			'justifyleft': 'Align Left',			'justifyright': 'Align Right',			'outdent': 'Outdent',			'paste': 'Paste',			'redo': 'Redo',			'removeformat': 'Remove Format',			'selectall': 'Select All',			'strikethrough': 'Strikethrough',			'subscript': 'Subscript',			'superscript': 'Superscript',			'underline': 'Underline',			'undo': 'Undo',			'unlink': 'Remove Link',			'createlink': 'Create Link',			'insertimage': 'Insert Image',			'htmltoggle': 'HTML Source',			'forecolor': 'Foreground Color',			'hilitecolor': 'Background Color',			'plainformatblock': 'Paragraph Style',			'formatblock': 'Paragraph Style',			'fontsize': 'Font Size',			'fontname': 'Font Name'//,//			'inserttable': 'Insert Table',//			'insertcell'://			'insertcol'://			'insertrow'://			'deletecells'://			'deletecols'://			'deleterows'://			'mergecells'://			'splitcell'://			'inserthtml'://			'blockdirltr'://			'blockdirrtl'://			'dirltr'://			'dirrtl'://			'inlinedirltr'://			'inlinedirrtl':}dojo.lang.declare("dojo.widget.Editor2BrowserCommand", dojo.widget.Editor2Command, 	function(editor,name){		// summary:		//		dojo.widget.Editor2BrowserCommand is the base class for all the browser built		//		in commands		var text = dojo.widget.Editor2BrowserCommandNames[name.toLowerCase()];		if(text){			this._text = text;		}	},{		execute: function(para){			this._editor.execCommand(this._name, para);		},		getState: function(){			if(this._editor._lastStateTimestamp > this._updateTime || this._state == undefined){				this._updateTime = this._editor._lastStateTimestamp;				try{					if(this._editor.queryCommandEnabled(this._name)){						if(this._editor.queryCommandState(this._name)){							this._state = dojo.widget.Editor2Manager.commandState.Latched;						}else{							this._state = dojo.widget.Editor2Manager.commandState.Enabled;						}					}else{						this._state = dojo.widget.Editor2Manager.commandState.Disabled;					}				}catch (e) {					//dojo.debug("exception when getting state for command "+this._name+": "+e);					this._state = dojo.widget.Editor2Manager.commandState.Enabled;				}			}			return this._state;		},		getValue: function(){			try{				return this._editor.queryCommandValue(this._name);			}catch(e){}		}	});dojo.lang.declare("dojo.widget.Editor2FormatBlockCommand", dojo.widget.Editor2BrowserCommand, {		/* In none-ActiveX mode under IE, <p> and no <p> text can not be distinguished		getCurrentValue: function(){			var curInst = dojo.widget.Editor2Manager.getCurrentInstance();			if(!curInst){ return ''; }			var h = dojo.render.html;			// safari f's us for selection primitives			if(h.safari){ return ''; }			var selectedNode = (h.ie) ? curInst.document.selection.createRange().parentElement() : curInst.window.getSelection().anchorNode;			// make sure we actuall have an element			while((selectedNode)&&(selectedNode.nodeType != 1)){				selectedNode = selectedNode.parentNode;			}			if(!selectedNode){ return ''; }			var formats = ["p", "pre", "h1", "h2", "h3", "h4", "h5", "h6", "address"];			// gotta run some specialized updates for the various			// formatting options			var type = formats[dojo.lang.find(formats, selectedNode.nodeName.toLowerCase())];			while((selectedNode!=curInst.editNode)&&(!type)){				selectedNode = selectedNode.parentNode;				if(!selectedNode){ break; }				type = formats[dojo.lang.find(formats, selectedNode.nodeName.toLowerCase())];			}			if(!type){				type = "";			}			return type;		}*/	});dojo.require("dojo.widget.FloatingPane");dojo.widget.defineWidget(	"dojo.widget.Editor2Dialog",	[dojo.widget.HtmlWidget, dojo.widget.FloatingPaneBase, dojo.widget.ModalDialogBase],	{		// summary:		//		Provides a Dialog which can be modal or normal for the Editor2.		templatePath: dojo.uri.dojoUri("src/widget/templates/Editor2/EditorDialog.html"),		// modal: Boolean: Whether this is a modal dialog. True by default.		modal: true,//		refreshOnShow: true, //for debug for now		// width: String: Width of the dialog. None by default.		width: "",		// height: String: Height of the dialog. None by default.		height: "",		// windowState: String: startup state of the dialog		windowState: "minimized",		displayCloseAction: true,		// contentFile: String		//	TODO		contentFile: "",				// contentClass: String		//	TODO		contentClass: "",		fillInTemplate: function(args, frag){			this.fillInFloatingPaneTemplate(args, frag);			dojo.widget.Editor2Dialog.superclass.fillInTemplate.call(this, args, frag);		},		postCreate: function(){			if(this.contentFile){				dojo.require(this.contentFile);			}			if(this.modal){				dojo.widget.ModalDialogBase.prototype.postCreate.call(this);			}else{				with(this.domNode.style) {					zIndex = 999;					display = "none";				}			}			dojo.widget.FloatingPaneBase.prototype.postCreate.apply(this, arguments);			dojo.widget.Editor2Dialog.superclass.postCreate.call(this);			if(this.width && this.height){				with(this.domNode.style){					width = this.width;					height = this.height;				}			}		},		createContent: function(){			if(!this.contentWidget && this.contentClass){				this.contentWidget = dojo.widget.createWidget(this.contentClass);				this.addChild(this.contentWidget);			}		},		show: function(){			if(!this.contentWidget){				//buggy IE: if the dialog is hidden, the button widgets				//in the dialog can not be shown, so show it temporary (as the				//dialog may decide not to show it in loadContent() later)				dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments);				this.createContent();				dojo.widget.Editor2Dialog.superclass.hide.call(this);			}			if(!this.contentWidget || !this.contentWidget.loadContent()){				return;			}			this.showFloatingPane();			dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments);			if(this.modal){				this.showModalDialog();			}			if(this.modal){				//place the background div under this modal pane				this.bg.style.zIndex = this.domNode.style.zIndex-1;			}		},		onShow: function(){			dojo.widget.Editor2Dialog.superclass.onShow.call(this);			this.onFloatingPaneShow();		},		closeWindow: function(){			this.hide();			dojo.widget.Editor2Dialog.superclass.closeWindow.apply(this, arguments);		},		hide: function(){			if(this.modal){				this.hideModalDialog();			}			dojo.widget.Editor2Dialog.superclass.hide.call(this);		},		//modified from ModalDialogBase.checkSize to call _sizeBackground conditionally		checkSize: function(){			if(this.isShowing()){				if(this.modal){					this._sizeBackground();				}				this.placeModalDialog();				this.onResized();			}		}	});dojo.widget.defineWidget(	"dojo.widget.Editor2DialogContent",	dojo.widget.HtmlWidget,{	// summary:	//		dojo.widget.Editor2DialogContent is the actual content of a Editor2Dialog.	//		This class should be subclassed to provide the content.	widgetsInTemplate: true,	loadContent:function(){		// summary: Load the content. Called by Editor2Dialog when first shown		return true;	},	cancel: function(){		// summary: Default handler when cancel button is clicked.		this.parent.hide();	}});dojo.lang.declare("dojo.widget.Editor2DialogCommand", dojo.widget.Editor2BrowserCommand,	function(editor, name, dialogParas){		// summary:		//		Provides an easy way to popup a dialog when		//		the command is executed.		this.dialogParas = dialogParas;	},{	execute: function(){		if(!this.dialog){			if(!this.dialogParas.contentFile || !this.dialogParas.contentClass){				alert("contentFile and contentClass should be set for dojo.widget.Editor2DialogCommand.dialogParas!");				return;			}			this.dialog = dojo.widget.createWidget("Editor2Dialog", this.dialogParas);

⌨️ 快捷键说明

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