source: Dev/trunk/src/client/dijit/_editor/plugins/LinkDialog.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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