]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/_editor/plugins/LinkDialog.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dijit / _editor / plugins / LinkDialog.js.uncompressed.js
1 define("dijit/_editor/plugins/LinkDialog", [
2 "require",
3 "dojo/_base/declare", // declare
4 "dojo/dom-attr", // domAttr.get
5 "dojo/keys", // keys.ENTER
6 "dojo/_base/lang", // lang.delegate lang.hitch lang.trim
7 "dojo/sniff", // has("ie")
8 "dojo/_base/query", // query
9 "dojo/string", // string.substitute
10 "../../_Widget",
11 "../_Plugin",
12 "../../form/DropDownButton",
13 "../range"
14 ], function(require, declare, domAttr, keys, lang, has, query, string,
15 _Widget, _Plugin, DropDownButton, rangeapi){
16
17
18 // module:
19 // dijit/_editor/plugins/LinkDialog
20 // summary:
21 // Editor plugins: LinkDialog (for inserting links) and ImgLinkDialog (for inserting images)
22
23
24 var LinkDialog = declare("dijit._editor.plugins.LinkDialog", _Plugin, {
25 // summary:
26 // This plugin provides the basis for an 'anchor' (link) dialog and an extension of it
27 // provides the image link dialog.
28 // description:
29 // The command provided by this plugin is:
30 //
31 // - createLink
32
33 // Override _Plugin.buttonClass. This plugin is controlled by a DropDownButton
34 // (which triggers a TooltipDialog).
35 buttonClass: DropDownButton,
36
37 // Override _Plugin.useDefaultCommand... processing is handled by this plugin, not by dijit/Editor.
38 useDefaultCommand: false,
39
40 // urlRegExp: [protected] String
41 // Used for validating input as correct URL. While file:// urls are not terribly
42 // useful, they are technically valid.
43 urlRegExp: "((https?|ftps?|file)\\://|\./|\.\./|/|)(/[a-zA-Z]{1,1}:/|)(((?:(?:[\\da-zA-Z](?:[-\\da-zA-Z]{0,61}[\\da-zA-Z])?)\\.)*(?:[a-zA-Z](?:[-\\da-zA-Z]{0,80}[\\da-zA-Z])?)\\.?)|(((\\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])))(\\:\\d+)?(/(?:[^?#\\s/]+/)*(?:[^?#\\s/]{0,}(?:\\?[^?#\\s/]*)?(?:#.*)?)?)?",
44
45 // emailRegExp: [protected] String
46 // Used for validating input as correct email address. Taken from dojox.validate
47 emailRegExp: "<?(mailto\\:)([!#-'*+\\-\\/-9=?A-Z^-~]+[.])*[!#-'*+\\-\\/-9=?A-Z^-~]+" /*username*/ + "@" +
48 "((?:(?:[\\da-zA-Z](?:[-\\da-zA-Z]{0,61}[\\da-zA-Z])?)\\.)+(?:[a-zA-Z](?:[-\\da-zA-Z]{0,6}[\\da-zA-Z])?)\\.?)|localhost|^[^-][a-zA-Z0-9_-]*>?", // host.
49
50 // htmlTemplate: [protected] String
51 // String used for templating the HTML to insert at the desired point.
52 htmlTemplate: "<a href=\"${urlInput}\" _djrealurl=\"${urlInput}\"" +
53 " target=\"${targetSelect}\"" +
54 ">${textInput}</a>",
55
56 // tag: [protected] String
57 // Tag used for the link type.
58 tag: "a",
59
60 // _hostRxp [private] RegExp
61 // Regular expression used to validate url fragments (ip address, hostname, etc)
62 _hostRxp: /^((([^\[:]+):)?([^@]+)@)?(\[([^\]]+)\]|([^\[:]*))(:([0-9]+))?$/,
63
64 // _userAtRxp [private] RegExp
65 // Regular expression used to validate e-mail address fragment.
66 _userAtRxp: /^([!#-'*+\-\/-9=?A-Z^-~]+[.])*[!#-'*+\-\/-9=?A-Z^-~]+@/i,
67
68 // linkDialogTemplate: [protected] String
69 // Template for contents of TooltipDialog to pick URL
70 linkDialogTemplate: [
71 "<table role='presentation'><tr><td>",
72 "<label for='${id}_urlInput'>${url}</label>",
73 "</td><td>",
74 "<input data-dojo-type='dijit.form.ValidationTextBox' required='true' " +
75 "id='${id}_urlInput' name='urlInput' data-dojo-props='intermediateChanges:true'/>",
76 "</td></tr><tr><td>",
77 "<label for='${id}_textInput'>${text}</label>",
78 "</td><td>",
79 "<input data-dojo-type='dijit.form.ValidationTextBox' required='true' id='${id}_textInput' " +
80 "name='textInput' data-dojo-props='intermediateChanges:true'/>",
81 "</td></tr><tr><td>",
82 "<label for='${id}_targetSelect'>${target}</label>",
83 "</td><td>",
84 "<select id='${id}_targetSelect' name='targetSelect' data-dojo-type='dijit.form.Select'>",
85 "<option selected='selected' value='_self'>${currentWindow}</option>",
86 "<option value='_blank'>${newWindow}</option>",
87 "<option value='_top'>${topWindow}</option>",
88 "<option value='_parent'>${parentWindow}</option>",
89 "</select>",
90 "</td></tr><tr><td colspan='2'>",
91 "<button data-dojo-type='dijit.form.Button' type='submit' id='${id}_setButton'>${set}</button>",
92 "<button data-dojo-type='dijit.form.Button' type='button' id='${id}_cancelButton'>${buttonCancel}</button>",
93 "</td></tr></table>"
94 ].join(""),
95
96 _initButton: function(){
97 this.inherited(arguments);
98
99 // Setup to lazy create TooltipDialog first time the button is clicked
100 this.button.loadDropDown = lang.hitch(this, "_loadDropDown");
101
102 this._connectTagEvents();
103 },
104 _loadDropDown: function(callback){
105 // Called the first time the button is pressed. Initialize TooltipDialog.
106 require([
107 "dojo/i18n", // i18n.getLocalization
108 "../../TooltipDialog",
109 "../../registry", // registry.byId, registry.getUniqueId
110 "../../form/Button", // used by template
111 "../../form/Select", // used by template
112 "../../form/ValidationTextBox", // used by template
113 "dojo/i18n!../../nls/common",
114 "dojo/i18n!../nls/LinkDialog"
115 ], lang.hitch(this, function(i18n, TooltipDialog, registry){
116 var _this = this;
117 this.tag = this.command == 'insertImage' ? 'img' : 'a';
118 var messages = lang.delegate(i18n.getLocalization("dijit", "common", this.lang),
119 i18n.getLocalization("dijit._editor", "LinkDialog", this.lang));
120 var dropDown = (this.dropDown = this.button.dropDown = new TooltipDialog({
121 title: messages[this.command + "Title"],
122 ownerDocument: this.editor.ownerDocument,
123 dir: this.editor.dir,
124 execute: lang.hitch(this, "setValue"),
125 onOpen: function(){
126 _this._onOpenDialog();
127 TooltipDialog.prototype.onOpen.apply(this, arguments);
128 },
129 onCancel: function(){
130 setTimeout(lang.hitch(_this, "_onCloseDialog"),0);
131 }
132 }));
133 messages.urlRegExp = this.urlRegExp;
134 messages.id = registry.getUniqueId(this.editor.id);
135 this._uniqueId = messages.id;
136 this._setContent(dropDown.title +
137 "<div style='border-bottom: 1px black solid;padding-bottom:2pt;margin-bottom:4pt'></div>" +
138 string.substitute(this.linkDialogTemplate, messages));
139 dropDown.startup();
140 this._urlInput = registry.byId(this._uniqueId + "_urlInput");
141 this._textInput = registry.byId(this._uniqueId + "_textInput");
142 this._setButton = registry.byId(this._uniqueId + "_setButton");
143 this.connect(registry.byId(this._uniqueId + "_cancelButton"), "onClick", function(){
144 this.dropDown.onCancel();
145 });
146 if(this._urlInput){
147 this.connect(this._urlInput, "onChange", "_checkAndFixInput");
148 }
149 if(this._textInput){
150 this.connect(this._textInput, "onChange", "_checkAndFixInput");
151 }
152
153 // Build up the dual check for http/https/file:, and mailto formats.
154 this._urlRegExp = new RegExp("^" + this.urlRegExp + "$", "i");
155 this._emailRegExp = new RegExp("^" + this.emailRegExp + "$", "i");
156 this._urlInput.isValid = lang.hitch(this, function(){
157 // Function over-ride of isValid to test if the input matches a url or a mailto style link.
158 var value = this._urlInput.get("value");
159 return this._urlRegExp.test(value) || this._emailRegExp.test(value);
160 });
161
162 // Listen for enter and execute if valid.
163 this.connect(dropDown.domNode, "onkeypress", function(e){
164 if(e && e.charOrCode == keys.ENTER &&
165 !e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey){
166 if(!this._setButton.get("disabled")){
167 dropDown.onExecute();
168 dropDown.execute(dropDown.get('value'));
169 }
170 }
171 });
172
173 callback();
174 }));
175 },
176
177 _checkAndFixInput: function(){
178 // summary:
179 // A function to listen for onChange events and test the input contents
180 // for valid information, such as valid urls with http/https/ftp and if
181 // not present, try and guess if the input url is relative or not, and if
182 // not, append http:// to it. Also validates other fields as determined by
183 // the internal _isValid function.
184 var self = this;
185 var url = this._urlInput.get("value");
186 var fixupUrl = function(url){
187 var appendHttp = false;
188 var appendMailto = false;
189 if(url && url.length > 1){
190 url = lang.trim(url);
191 if(url.indexOf("mailto:") !== 0){
192 if(url.indexOf("/") > 0){
193 if(url.indexOf("://") === -1){
194 // Check that it doesn't start with /, ./, or ../, which would
195 // imply 'target server relativeness'
196 if(url.charAt(0) !== '/' && url.indexOf("./") && url.indexOf("../") !== 0){
197 if(self._hostRxp.test(url)){
198 appendHttp = true;
199 }
200 }
201 }
202 }else if(self._userAtRxp.test(url)){
203 // If it looks like a foo@, append a mailto.
204 appendMailto = true;
205 }
206 }
207 }
208 if(appendHttp){
209 self._urlInput.set("value", "http://" + url);
210 }
211 if(appendMailto){
212 self._urlInput.set("value", "mailto:" + url);
213 }
214 self._setButton.set("disabled", !self._isValid());
215 };
216 if(this._delayedCheck){
217 clearTimeout(this._delayedCheck);
218 this._delayedCheck = null;
219 }
220 this._delayedCheck = setTimeout(function(){
221 fixupUrl(url);
222 }, 250);
223 },
224
225 _connectTagEvents: function(){
226 // summary:
227 // Over-ridable function that connects tag specific events.
228 this.editor.onLoadDeferred.then(lang.hitch(this, function(){
229 this.connect(this.editor.editNode, "ondblclick", this._onDblClick);
230 }));
231 },
232
233 _isValid: function(){
234 // summary:
235 // Internal function to allow validating of the inputs
236 // for a link to determine if set should be disabled or not
237 // tags:
238 // protected
239 return this._urlInput.isValid() && this._textInput.isValid();
240 },
241
242 _setContent: function(staticPanel){
243 // summary:
244 // Helper for _initButton above. Not sure why it's a separate method.
245 this.dropDown.set({
246 parserScope: "dojo", // make parser search for dojoType/data-dojo-type even if page is multi-version
247 content: staticPanel
248 });
249 },
250
251 _checkValues: function(args){
252 // summary:
253 // Function to check the values in args and 'fix' them up as needed.
254 // args: Object
255 // Content being set.
256 // tags:
257 // protected
258 if(args && args.urlInput){
259 args.urlInput = args.urlInput.replace(/"/g, "&quot;");
260 }
261 return args;
262 },
263
264 setValue: function(args){
265 // summary:
266 // Callback from the dialog when user presses "set" button.
267 // tags:
268 // private
269
270 // TODO: prevent closing popup if the text is empty
271 this._onCloseDialog();
272 if(has("ie") < 9){ //see #4151
273 var sel = rangeapi.getSelection(this.editor.window);
274 var range = sel.getRangeAt(0);
275 var a = range.endContainer;
276 if(a.nodeType === 3){
277 // Text node, may be the link contents, so check parent.
278 // This plugin doesn't really support nested HTML elements
279 // in the link, it assumes all link content is text.
280 a = a.parentNode;
281 }
282 if(a && (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){
283 // Still nothing, one last thing to try on IE, as it might be 'img'
284 // and thus considered a control.
285 a = this.editor._sCall("getSelectedElement", [this.tag]);
286 }
287 if(a && (a.nodeName && a.nodeName.toLowerCase() === this.tag)){
288 // Okay, we do have a match. IE, for some reason, sometimes pastes before
289 // instead of removing the targeted paste-over element, so we unlink the
290 // old one first. If we do not the <a> tag remains, but it has no content,
291 // so isn't readily visible (but is wrong for the action).
292 if(this.editor.queryCommandEnabled("unlink")){
293 // Select all the link children, then unlink. The following insert will
294 // then replace the selected text.
295 this.editor._sCall("selectElementChildren", [a]);
296 this.editor.execCommand("unlink");
297 }
298 }
299 }
300 // make sure values are properly escaped, etc.
301 args = this._checkValues(args);
302 this.editor.execCommand('inserthtml',
303 string.substitute(this.htmlTemplate, args));
304
305 // IE sometimes leaves a blank link, so we need to fix it up.
306 // Go ahead and do this for everyone just to avoid blank links
307 // in the page.
308 query("a", this.editor.document).forEach(function(a){
309 if(!a.innerHTML && !domAttr.has(a, "name")){
310 // Remove empty anchors that do not have "name" set.
311 // Empty ones with a name set could be a hidden hash
312 // anchor.
313 a.parentNode.removeChild(a);
314 }
315 }, this);
316 },
317
318 _onCloseDialog: function(){
319 // summary:
320 // Handler for close event on the dialog
321 this.editor.focus();
322 },
323
324 _getCurrentValues: function(a){
325 // summary:
326 // Over-ride for getting the values to set in the dropdown.
327 // a:
328 // The anchor/link to process for data for the dropdown.
329 // tags:
330 // protected
331 var url, text, target;
332 if(a && a.tagName.toLowerCase() === this.tag){
333 url = a.getAttribute('_djrealurl') || a.getAttribute('href');
334 target = a.getAttribute('target') || "_self";
335 text = a.textContent || a.innerText;
336 this.editor._sCall("selectElement", [a, true]);
337 }else{
338 text = this.editor._sCall("getSelectedText");
339 }
340 return {urlInput: url || '', textInput: text || '', targetSelect: target || ''}; //Object;
341 },
342
343 _onOpenDialog: function(){
344 // summary:
345 // Handler for when the dialog is opened.
346 // If the caret is currently in a URL then populate the URL's info into the dialog.
347 var a,b,fc;
348 if(has("ie")){
349 // IE, even IE10, is difficult to select the element in, using the range unified
350 // API seems to work reasonably well.
351 var sel = rangeapi.getSelection(this.editor.window);
352 if(sel.rangeCount){
353 var range = sel.getRangeAt(0);
354 a = range.endContainer;
355 if(a.nodeType === 3){
356 // Text node, may be the link contents, so check parent.
357 // This plugin doesn't really support nested HTML elements
358 // in the link, it assumes all link content is text.
359 a = a.parentNode;
360 }
361 if(a && (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){
362 // Still nothing, one last thing to try on IE, as it might be 'img'
363 // and thus considered a control.
364 a = this.editor._sCall("getSelectedElement", [this.tag]);
365 }
366 if(!a || (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){
367 // Try another lookup, IE's selection is just terrible.
368 b = this.editor._sCall("getAncestorElement", [this.tag]);
369 if(b && (b.nodeName && b.nodeName.toLowerCase() == this.tag)){
370 // Looks like we found an A tag, use it and make sure just it is
371 // selected.
372 a = b;
373 this.editor._sCall("selectElement", [a]);
374 }else if (range.startContainer === range.endContainer){
375 // STILL nothing. Trying one more thing. Lets look at the first child.
376 // It might be an anchor tag in a div by itself or the like. If it is,
377 // we'll use it otherwise we give up. The selection is not easily
378 // determinable to be on an existing anchor tag.
379 fc = range.startContainer.firstChild;
380 if(fc && (fc.nodeName && fc.nodeName.toLowerCase() == this.tag)){
381 a = fc;
382 this.editor._sCall("selectElement", [a]);
383 }
384 }
385 }
386 }
387 }else{
388 a = this.editor._sCall("getAncestorElement", [this.tag]);
389 }
390 this.dropDown.reset();
391 this._setButton.set("disabled", true);
392 this.dropDown.set("value", this._getCurrentValues(a));
393 },
394
395 _onDblClick: function(e){
396 // summary:
397 // Function to define a behavior on double clicks on the element
398 // type this dialog edits to select it and pop up the editor
399 // dialog.
400 // e: Object
401 // The double-click event.
402 // tags:
403 // protected.
404 if(e && e.target){
405 var t = e.target;
406 var tg = t.tagName ? t.tagName.toLowerCase() : "";
407 if(tg === this.tag && domAttr.get(t,"href")){
408 var editor = this.editor;
409
410 this.editor._sCall("selectElement", [t]);
411 editor.onDisplayChanged();
412
413 // Call onNormalizedDisplayChange() now, rather than on timer.
414 // On IE, when focus goes to the first <input> in the TooltipDialog, the editor loses it's selection.
415 // Later if onNormalizedDisplayChange() gets called via the timer it will disable the LinkDialog button
416 // (actually, all the toolbar buttons), at which point clicking the <input> will close the dialog,
417 // since (for unknown reasons) focus.js ignores disabled controls.
418 if(editor._updateTimer){
419 editor._updateTimer.remove();
420 delete editor._updateTimer;
421 }
422 editor.onNormalizedDisplayChanged();
423
424 var button = this.button;
425 setTimeout(function(){
426 // Focus shift outside the event handler.
427 // IE doesn't like focus changes in event handles.
428 button.set("disabled", false);
429 button.loadAndOpenDropDown().then(function(){
430 if(button.dropDown.focus){
431 button.dropDown.focus();
432 }
433 });
434 }, 10);
435 }
436 }
437 }
438 });
439
440 var ImgLinkDialog = declare("dijit._editor.plugins.ImgLinkDialog", [LinkDialog], {
441 // summary:
442 // This plugin extends LinkDialog and adds in a plugin for handling image links.
443 // provides the image link dialog.
444 // description:
445 // The command provided by this plugin is:
446 //
447 // - insertImage
448
449 // linkDialogTemplate: [protected] String
450 // Over-ride for template since img dialog doesn't need target that anchor tags may.
451 linkDialogTemplate: [
452 "<table role='presentation'><tr><td>",
453 "<label for='${id}_urlInput'>${url}</label>",
454 "</td><td>",
455 "<input dojoType='dijit.form.ValidationTextBox' regExp='${urlRegExp}' " +
456 "required='true' id='${id}_urlInput' name='urlInput' data-dojo-props='intermediateChanges:true'/>",
457 "</td></tr><tr><td>",
458 "<label for='${id}_textInput'>${text}</label>",
459 "</td><td>",
460 "<input data-dojo-type='dijit.form.ValidationTextBox' required='false' id='${id}_textInput' " +
461 "name='textInput' data-dojo-props='intermediateChanges:true'/>",
462 "</td></tr><tr><td>",
463 "</td><td>",
464 "</td></tr><tr><td colspan='2'>",
465 "<button data-dojo-type='dijit.form.Button' type='submit' id='${id}_setButton'>${set}</button>",
466 "<button data-dojo-type='dijit.form.Button' type='button' id='${id}_cancelButton'>${buttonCancel}</button>",
467 "</td></tr></table>"
468 ].join(""),
469
470 // htmlTemplate: [protected] String
471 // String used for templating the `<img>` HTML to insert at the desired point.
472 htmlTemplate: "<img src=\"${urlInput}\" _djrealurl=\"${urlInput}\" alt=\"${textInput}\" />",
473
474 // tag: [protected] String
475 // Tag used for the link type (img).
476 tag: "img",
477
478 _getCurrentValues: function(img){
479 // summary:
480 // Over-ride for getting the values to set in the dropdown.
481 // a:
482 // The anchor/link to process for data for the dropdown.
483 // tags:
484 // protected
485 var url, text;
486 if(img && img.tagName.toLowerCase() === this.tag){
487 url = img.getAttribute('_djrealurl') || img.getAttribute('src');
488 text = img.getAttribute('alt');
489 this.editor._sCall("selectElement", [img, true]);
490 }else{
491 text = this.editor._sCall("getSelectedText", []);
492 }
493 return {urlInput: url || '', textInput: text || ''}; //Object
494 },
495
496 _isValid: function(){
497 // summary:
498 // Over-ride for images. You can have alt text of blank, it is valid.
499 // tags:
500 // protected
501 return this._urlInput.isValid();
502 },
503
504 _connectTagEvents: function(){
505 // summary:
506 // Over-ridable function that connects tag specific events.
507 this.inherited(arguments);
508 this.editor.onLoadDeferred.then(lang.hitch(this, function(){
509 // Use onmousedown instead of onclick. Seems that IE eats the first onclick
510 // to wrap it in a selector box, then the second one acts as onclick. See #10420
511 this.connect(this.editor.editNode, "onmousedown", this._selectTag);
512 }));
513 },
514
515 _selectTag: function(e){
516 // summary:
517 // A simple event handler that lets me select an image if it is clicked on.
518 // makes it easier to select images in a standard way across browsers. Otherwise
519 // selecting an image for edit becomes difficult.
520 // e: Event
521 // The mousedown event.
522 // tags:
523 // private
524 if(e && e.target){
525 var t = e.target;
526 var tg = t.tagName? t.tagName.toLowerCase() : "";
527 if(tg === this.tag){
528 this.editor._sCall("selectElement", [t]);
529 }
530 }
531 },
532
533 _checkValues: function(args){
534 // summary:
535 // Function to check the values in args and 'fix' them up as needed
536 // (special characters in the url or alt text)
537 // args: Object
538 // Content being set.
539 // tags:
540 // protected
541 if(args && args.urlInput){
542 args.urlInput = args.urlInput.replace(/"/g, "&quot;");
543 }
544 if(args && args.textInput){
545 args.textInput = args.textInput.replace(/"/g, "&quot;");
546 }
547 return args;
548 },
549
550 _onDblClick: function(e){
551 // summary:
552 // Function to define a behavior on double clicks on the element
553 // type this dialog edits to select it and pop up the editor
554 // dialog.
555 // e: Object
556 // The double-click event.
557 // tags:
558 // protected.
559 if(e && e.target){
560 var t = e.target;
561 var tg = t.tagName ? t.tagName.toLowerCase() : "";
562 if(tg === this.tag && domAttr.get(t,"src")){
563 var editor = this.editor;
564
565 this.editor._sCall("selectElement", [t]);
566 editor.onDisplayChanged();
567
568 // Call onNormalizedDisplayChange() now, rather than on timer.
569 // On IE, when focus goes to the first <input> in the TooltipDialog, the editor loses it's selection.
570 // Later if onNormalizedDisplayChange() gets called via the timer it will disable the LinkDialog button
571 // (actually, all the toolbar buttons), at which point clicking the <input> will close the dialog,
572 // since (for unknown reasons) focus.js ignores disabled controls.
573 if(editor._updateTimer){
574 editor._updateTimer.remove();
575 delete editor._updateTimer;
576 }
577 editor.onNormalizedDisplayChanged();
578
579 var button = this.button;
580 setTimeout(function(){
581 // Focus shift outside the event handler.
582 // IE doesn't like focus changes in event handles.
583 button.set("disabled", false);
584 button.loadAndOpenDropDown().then(function(){
585 if(button.dropDown.focus){
586 button.dropDown.focus();
587 }
588 });
589 }, 10);
590 }
591 }
592 }
593 });
594
595 // Register these plugins
596 _Plugin.registry["createLink"] = function(){
597 return new LinkDialog({command: "createLink"});
598 };
599 _Plugin.registry["insertImage"] = function(){
600 return new ImgLinkDialog({command: "insertImage"});
601 };
602
603
604 // Export both LinkDialog and ImgLinkDialog
605 // TODO for 2.0: either return both classes in a hash, or split this file into two separate files.
606 // Then the documentation for the module can be applied to the hash, and will show up in the API doc.
607 LinkDialog.ImgLinkDialog = ImgLinkDialog;
608 return LinkDialog;
609 });