Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.Editor2Plugin.CreateLinkDialog");
14
dojo.widget.defineWidget("dojo.widget.Editor2CreateLinkDialog", dojo.widget.Editor2DialogContent, {templateString:"<table>\n<tr><td>URL</td><td> <input type=\"text\" dojoAttachPoint=\"link_href\" name=\"dojo_createLink_href\"/></td></tr>\n<tr><td>Target </td><td><select dojoAttachPoint=\"link_target\">\n\t<option value=\"\">Self</option>\n\t<option value=\"_blank\">New Window</option>\n\t<option value=\"_top\">Top Window</option>\n\t</select></td></tr>\n<tr><td>Class </td><td><input type=\"text\" dojoAttachPoint=\"link_class\" /></td></tr>\n<tr><td colspan=\"2\">\n\t<table><tr>\n\t<td><button dojoType='Button' dojoAttachEvent='onClick:ok'>OK</button></td>\n\t<td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td>\n\t</tr></table>\n\t</td></tr>\n</table>\n", editableAttributes:["href", "target", "class"], loadContent:function () {
15
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
16
	curInst.saveSelection();
17
	this.linkNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["a"]);
18
	var linkAttributes = {};
19
	this.extraAttribText = "";
20
	if (this.linkNode) {
21
		var attrs = this.linkNode.attributes;
22
		for (var i = 0; i < attrs.length; i++) {
23
			if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
24
				linkAttributes[attrs[i].name] = attrs[i].value;
25
			} else {
26
				if (attrs[i].specified == undefined || attrs[i].specified) {
27
					this.extraAttribText += attrs[i].name + "=\"" + attrs[i].value + "\" ";
28
				}
29
			}
30
		}
31
	} else {
32
		var html = dojo.withGlobal(curInst.window, "getSelectedText", dojo.html.selection);
33
		if (html == null || html.length == 0) {
34
			alert("Please select some text to create a link.");
35
			return false;
36
		}
37
	}
38
	for (var i = 0; i < this.editableAttributes.length; ++i) {
39
		name = this.editableAttributes[i];
40
		this["link_" + name].value = (linkAttributes[name] == undefined) ? "" : linkAttributes[name];
41
	}
42
	return true;
43
}, ok:function () {
44
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
45
	curInst.restoreSelection();
46
	if (!this.linkNode) {
47
		var html = dojo.withGlobal(curInst.window, "getSelectedHtml", dojo.html.selection);
48
	} else {
49
		var html = this.linkNode.innerHTML;
50
		dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.linkNode]);
51
	}
52
	var attstr = "";
53
	for (var i = 0; i < this.editableAttributes.length; ++i) {
54
		name = this.editableAttributes[i];
55
		var value = this["link_" + name].value;
56
		if (value.length > 0) {
57
			attstr += name + "=\"" + value + "\" ";
58
		}
59
	}
60
	curInst.execCommand("inserthtml", "<a " + attstr + this.extraAttribText + ">" + html + "</a>");
61
	this.cancel();
62
}});
63