mozdev.org

Mozile (xhtml editing in your browser)    

resources:
Overview

EditSource.js

Summary

This module allows editing of the HTML/XML source ofthe current element.

Version: 0.7.0

Author: Grant Gredvig


/* ***** BEGIN LICENSE BLOCK *****
 * Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
 * Full Terms at http://mozile.mozdev.org/license.html
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code was written by Grant Gredvig <Grant.Gredvig@Sun.COM>.
 *
 * The Initial Developer of the Original Code is Grant Gredvig.
 * Portions created by the Initial Developer are Copyright (C) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *	Grant Gredvig <Grant.Gredvig@Sun.COM>
 *	James A. Overton <james@overton.ca>
 *
 * ***** END LICENSE BLOCK ***** */
 
/**
 * @fileoverview This module allows editing of the HTML/XML source ofthe current element.
 * @link http://mozile.mozdev.org 
 * @author Grant Gredvig <Grant.Gredvig@Sun.COM>
 * @version 0.7.0
 */


/**
 * Gets Mozile's "Edit Source" interface.
 * @type MozileInterface
 */
MozileMediator.prototype.getEditSourceInterface = function() {
	if(!this._iface) {
		this._iface = new MozileInterface(
			this.getRoot()+"modules/EditSource/edit.xml",
			"MozileAboutInterface: width=450px");
		this._iface.init = function() { }
		this._iface.Apply = function() {
			this._editElement.innerHTML =
				document.getElementById("sourceEditor").value;
		}
	}
	return this._iface;
}

/**
 * Initializes this module. Creates the Edit Source command.
 * @type Void
 */
mozile.getModule("EditSource").init = function() {

	// Create the Edit Source command.
	var but = mozile.getCommandList().createCommand(
		"MozileCommand: id=Mozile-EditSource, label='Edit Source', image='"+
		mozile.getRoot()+"images/edit-source.png', "+
		"tooltip='Edit the source code of the current element', accelerator='Command-Alt-E'");
	
	// Put the innerHTML of the current element into the sourceEditor text box.
	but.execute = function(event) {
		var a = mozile.getEditSourceInterface();
		a.show();
		var selection = window.getSelection();
		var range = selection.getRangeAt(0);
		var container = range.commonAncestorContainer;
		if(container.nodeType==3) container = container.parentNode;

		a._editElement = container;
		document.getElementById("sourceEditor").value = container.innerHTML;
		return true;
	}
}




Documentation generated by JSDoc on Wed Nov 1 15:11:15 2006

The mozile project can be contacted through the mailing list or the member list.
Copyright © 2000-2019. All rights reserved. Terms of Use & Privacy Policy.