Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dijit._editor.plugins.LinkDialog"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dijit._editor.plugins.LinkDialog"] = true;
3
dojo.provide("dijit._editor.plugins.LinkDialog");
4
 
5
dojo.require("dijit._Widget");
6
dojo.require("dijit._Templated");
7
dojo.require("dijit._editor._Plugin");
8
dojo.require("dijit.Dialog");
9
dojo.require("dijit.form.Button");
10
dojo.require("dijit.form.ValidationTextBox");
11
dojo.require("dojo.i18n");
12
dojo.require("dojo.string");
13
dojo.requireLocalization("dijit._editor", "LinkDialog", null, "ko,zh,ja,zh-tw,ru,it,ROOT,hu,fr,pt,pl,es,de,cs");
14
 
15
dojo.declare("dijit._editor.plugins.DualStateDropDownButton",
16
	dijit.form.DropDownButton,
17
	{
18
		// summary: a DropDownButton but button can be displayed in two states (checked or unchecked)
19
		setChecked: dijit.form.ToggleButton.prototype.setChecked
20
	}
21
);
22
 
23
dojo.declare("dijit._editor.plugins.UrlTextBox",
24
	dijit.form.ValidationTextBox,
25
	{
26
		// summary: the URL input box we use in our dialog
27
 
28
		// regular expression for URLs, generated from dojo.regexp.url()
29
		regExp: "((https?|ftps?)\\://|)(([0-9a-zA-Z]([-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?\\.)+(arpa|aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|xxx|jobs|mobi|post|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|eu|es|et|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sk|sl|sm|sn|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])|(0[xX]0*[\\da-fA-F]?[\\da-fA-F]\\.){3}0[xX]0*[\\da-fA-F]?[\\da-fA-F]|(0+[0-3][0-7][0-7]\\.){3}0+[0-3][0-7][0-7]|(0|[1-9]\\d{0,8}|[1-3]\\d{9}|4[01]\\d{8}|42[0-8]\\d{7}|429[0-3]\\d{6}|4294[0-8]\\d{5}|42949[0-5]\\d{4}|429496[0-6]\\d{3}|4294967[01]\\d{2}|42949672[0-8]\\d|429496729[0-5])|0[xX]0*[\\da-fA-F]{1,8}|([\\da-fA-F]{1,4}\\:){7}[\\da-fA-F]{1,4}|([\\da-fA-F]{1,4}\\:){6}((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])))(\\:(0|[1-9]\\d*))?(/([^?#\\s/]+/)*)?([^?#\\s/]+(\\?[^?#\\s/]*)?(#[A-Za-z][\\w.:-]*)?)?",
30
 
31
		required: true,
32
 
33
		postMixInProperties: function(){
34
			this.inherited("postMixInProperties", arguments);
35
			this.invalidMessage = dojo.i18n.getLocalization("dijit._editor", "LinkDialog", this.lang).urlInvalidMessage;
36
		},
37
 
38
		getValue: function(){
39
			if(!/^(https?|ftps?)/.test(this.textbox.value)){
40
				this.textbox.value="http://"+this.textbox.value;
41
			}
42
			return this.textbox.value;
43
		}
44
	}
45
);
46
 
47
dojo.declare("dijit._editor.plugins.LinkDialog",
48
	dijit._editor._Plugin,
49
	{
50
		buttonClass: dijit._editor.plugins.DualStateDropDownButton,
51
		useDefaultCommand: false,
52
		command: "createLink",
53
		linkDialogTemplate: [
54
			"<label for='urlInput'>${url}&nbsp;</label>",
55
			"<input dojoType=dijit._editor.plugins.UrlTextBox name='urlInput'><br>",
56
			"<label for='textInput'>${text}&nbsp;</label>",
57
			"<input dojoType=dijit.form.TextBox name='textInput'>",
58
			"<br>",
59
			"<button dojoType=dijit.form.Button type='submit'>${set}</button>"
60
		].join(""),
61
 
62
		constructor: function(){
63
			var _this = this;
64
			var messages = dojo.i18n.getLocalization("dijit._editor", "LinkDialog", this.lang);
65
			this.dropDown = new dijit.TooltipDialog({
66
				title: messages.title,
67
				execute: dojo.hitch(this, "setValue"),
68
				onOpen: function(){
69
					_this._onOpenDialog();
70
					dijit.TooltipDialog.prototype.onOpen.apply(this, arguments);
71
				},
72
				onCancel: function(){
73
					setTimeout(dojo.hitch(_this, "_onCloseDialog"),0);
74
				},
75
				onClose: dojo.hitch(this, "_onCloseDialog")
76
			});
77
			this.dropDown.setContent(dojo.string.substitute(this.linkDialogTemplate, messages));
78
			this.dropDown.startup();
79
		},
80
 
81
		setValue: function(args){
82
			// summary: callback from the dialog when user hits "set" button
83
			//TODO: prevent closing popup if the text is empty
84
			this._onCloseDialog();
85
			if(dojo.isIE){ //see #4151
86
				var a = dojo.withGlobal(this.editor.window, "getAncestorElement",dijit._editor.selection, ['a']);
87
				if(a){
88
					dojo.withGlobal(this.editor.window, "selectElement",dijit._editor.selection, [a]);
89
				}
90
			}
91
			var attstr='href="'+args.urlInput+'" _djrealurl="'+args.urlInput+'"';
92
//			console.log(args,this.editor,'<a '+attstr+'>'+args.textInput+'</a>');
93
			this.editor.execCommand('inserthtml', '<a '+attstr+'>'+args.textInput+'</a>');
94
//			this.editor.execCommand(this.command, args.urlInput);
95
 		},
96
 
97
//		_savedSelection: null,
98
		_onCloseDialog: function(){
99
			// FIXME: IE is really messed up here!!
100
			if(dojo.isIE){
101
				if(this._savedSelection){
102
					var b=this._savedSelection;
103
					this._savedSelection=null;
104
					this.editor.focus();
105
					var range = this.editor.document.selection.createRange();
106
					range.moveToBookmark(b);
107
					range.select();
108
				}
109
			}else{this.editor.focus();
110
			}
111
		},
112
		_onOpenDialog: function(){
113
			var a = dojo.withGlobal(this.editor.window, "getAncestorElement",dijit._editor.selection, ['a']);
114
			var url='',text='';
115
			if(a){
116
				url=a.getAttribute('_djrealurl');
117
				text=a.textContent||a.innerText;
118
				dojo.withGlobal(this.editor.window, "selectElement",dijit._editor.selection, [a,true]);
119
			}else{
120
				text=dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText);
121
			}
122
			// FIXME: IE is *really* b0rken
123
			if(dojo.isIE){
124
				var range = this.editor.document.selection.createRange();
125
				this._savedSelection = range.getBookmark();
126
			}
127
			this.dropDown.setValues({'urlInput':url,'textInput':text});
128
			//dijit.focus(this.urlInput);
129
		},
130
 
131
		updateState: function(){
132
			// summary: change shading on button if we are over a link (or not)
133
 
134
			var _e = this.editor;
135
			if(!_e){ return; }
136
			if(!_e.isLoaded){ return; }
137
			if(this.button){
138
				try{
139
					// display button differently if there is an existing link associated with the current selection
140
					var hasA = dojo.withGlobal(this.editor.window, "hasAncestorElement",dijit._editor.selection, ['a']);
141
					this.button.setChecked(hasA);
142
				}catch(e){
143
					console.debug(e); //FIXME: probably shouldn't squelch an exception here
144
				}
145
			}
146
		}
147
	}
148
);
149
 
150
}