Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
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:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.Editor2Plugin.CreateLinkDialog");
13
dojo.provide("dojo.widget.Editor2Plugin.CreateLinkDialog");
12
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 () {
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 () {
13
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
15
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
14
	curInst.saveSelection();
16
	curInst.saveSelection();
15
	this.linkNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["a"]);
17
	this.linkNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["a"]);
16
	var linkAttributes = {};
18
	var linkAttributes = {};
17
	this.extraAttribText = "";
19
	this.extraAttribText = "";
18
	if (this.linkNode) {
20
	if (this.linkNode) {
19
		var attrs = this.linkNode.attributes;
21
		var attrs = this.linkNode.attributes;
20
		for (var i = 0; i < attrs.length; i++) {
22
		for (var i = 0; i < attrs.length; i++) {
21
			if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
23
			if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
22
				linkAttributes[attrs[i].name] = attrs[i].value;
24
				linkAttributes[attrs[i].name] = attrs[i].value;
23
			} else {
25
			} else {
24
				if (attrs[i].specified == undefined || attrs[i].specified) {
26
				if (attrs[i].specified == undefined || attrs[i].specified) {
25
					this.extraAttribText += attrs[i].name + "=\"" + attrs[i].value + "\" ";
27
					this.extraAttribText += attrs[i].name + "=\"" + attrs[i].value + "\" ";
26
				}
28
				}
27
			}
29
			}
28
		}
30
		}
29
	} else {
31
	} else {
30
		var html = dojo.withGlobal(curInst.window, "getSelectedText", dojo.html.selection);
32
		var html = dojo.withGlobal(curInst.window, "getSelectedText", dojo.html.selection);
31
		if (html == null || html.length == 0) {
33
		if (html == null || html.length == 0) {
32
			alert("Please select some text to create a link.");
34
			alert("Please select some text to create a link.");
33
			return false;
35
			return false;
34
		}
36
		}
35
	}
37
	}
36
	for (var i = 0; i < this.editableAttributes.length; ++i) {
38
	for (var i = 0; i < this.editableAttributes.length; ++i) {
37
		name = this.editableAttributes[i];
39
		name = this.editableAttributes[i];
38
		this["link_" + name].value = (linkAttributes[name] == undefined) ? "" : linkAttributes[name];
40
		this["link_" + name].value = (linkAttributes[name] == undefined) ? "" : linkAttributes[name];
39
	}
41
	}
40
	return true;
42
	return true;
41
}, ok:function () {
43
}, ok:function () {
42
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
44
	var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
43
	curInst.restoreSelection();
45
	curInst.restoreSelection();
44
	if (!this.linkNode) {
46
	if (!this.linkNode) {
45
		var html = dojo.withGlobal(curInst.window, "getSelectedHtml", dojo.html.selection);
47
		var html = dojo.withGlobal(curInst.window, "getSelectedHtml", dojo.html.selection);
46
	} else {
48
	} else {
47
		var html = this.linkNode.innerHTML;
49
		var html = this.linkNode.innerHTML;
48
		dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.linkNode]);
50
		dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.linkNode]);
49
	}
51
	}
50
	var attstr = "";
52
	var attstr = "";
51
	for (var i = 0; i < this.editableAttributes.length; ++i) {
53
	for (var i = 0; i < this.editableAttributes.length; ++i) {
52
		name = this.editableAttributes[i];
54
		name = this.editableAttributes[i];
53
		var value = this["link_" + name].value;
55
		var value = this["link_" + name].value;
54
		if (value.length > 0) {
56
		if (value.length > 0) {
55
			attstr += name + "=\"" + value + "\" ";
57
			attstr += name + "=\"" + value + "\" ";
56
		}
58
		}
57
	}
59
	}
58
	curInst.execCommand("inserthtml", "<a " + attstr + this.extraAttribText + ">" + html + "</a>");
60
	curInst.execCommand("inserthtml", "<a " + attstr + this.extraAttribText + ">" + html + "</a>");
59
	this.cancel();
61
	this.cancel();
60
}});
62
}});
61
 
63