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");
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, "zh,pt,da,tr,ru,de,ROOT,sv,ja,he,fi,nb,el,ar,pt-pt,cs,fr,es,ko,nl,zh-tw,pl,it,hu");
15 dojo.declare("dijit._editor.plugins.LinkDialog",
16 dijit._editor._Plugin,
19 // This plugin provides dialogs for inserting links and images into the editor
22 // The commands provided by this plugin are:
26 buttonClass: dijit.form.DropDownButton,
27 useDefaultCommand: false,
28 urlRegExp: "((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.:-]*)?)?",
31 "<label for='${id}_urlInput'>${url}</label>",
33 "<input dojoType='dijit.form.ValidationTextBox' regExp='${urlRegExp}' required='true' id='${id}_urlInput' name='urlInput'>",
35 "<label for='${id}_textInput'>${text}</label>",
37 "<input dojoType='dijit.form.ValidationTextBox' required='true' id='${id}_textInput' name='textInput'>",
38 "</td></tr><tr><td colspan='2'>",
39 "<button dojoType='dijit.form.Button' type='submit'>${set}</button>",
43 _initButton: function(){
45 this.tag = this.command == 'insertImage' ? 'img' : 'a';
46 var messages = dojo.i18n.getLocalization("dijit._editor", "LinkDialog", this.lang);
47 var dropDown = (this.dropDown = new dijit.TooltipDialog({
48 title: messages[this.command + "Title"],
49 execute: dojo.hitch(this, "setValue"),
51 _this._onOpenDialog();
52 dijit.TooltipDialog.prototype.onOpen.apply(this, arguments);
55 setTimeout(dojo.hitch(_this, "_onCloseDialog"),0);
57 onClose: dojo.hitch(this, "_onCloseDialog")
59 messages.urlRegExp = this.urlRegExp;
60 messages.id = dijit.getUniqueId(this.editor.id);
61 this._setContent(dropDown.title + "<div style='border-bottom: 1px black solid;padding-bottom:2pt;margin-bottom:4pt'></div>" + dojo.string.substitute(this.linkDialogTemplate, messages));
64 this.inherited(arguments);
67 _setContent: function(staticPanel){
68 this.dropDown.setContent(staticPanel);
71 setValue: function(args){
72 // summary: callback from the dialog when user hits "set" button
73 //TODO: prevent closing popup if the text is empty
74 this._onCloseDialog();
75 if(dojo.isIE){ //see #4151
76 var a = dojo.withGlobal(this.editor.window, "getAncestorElement", dijit._editor.selection, [this.tag]);
78 dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a]);
82 args.refAttr = this.tag == 'img' ? 'src' : 'href';
83 //TODO: textInput should be formatted by escapeXml
84 var template = "<${tag} ${refAttr}='${urlInput}' _djrealurl='${urlInput}'" +
85 (args.tag == 'img' ? " alt='${textInput}'>" : ">${textInput}") +
87 this.editor.execCommand('inserthtml', dojo.string.substitute(template, args));
90 _onCloseDialog: function(){
91 // FIXME: IE is really messed up here!!
93 if("_savedSelection" in this){
94 var b = this._savedSelection;
95 delete this._savedSelection;
97 this.editor._moveToBookmark(b);
104 _onOpenDialog: function(){
105 var a = dojo.withGlobal(this.editor.window, "getAncestorElement", dijit._editor.selection, [this.tag]);
108 url = a.getAttribute('_djrealurl');
109 text = this.tag == 'img' ? a.getAttribute('alt') : a.textContent || a.innerText;
110 dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a, true]);
112 text = dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText);
114 // FIXME: IE is *really* b0rken
116 this._savedSelection = this.editor._getBookmark();
118 this.dropDown.reset();
119 this.dropDown.setValues({urlInput: url || '', textInput: text || ''});
120 //dijit.focus(this.urlInput);
123 //TODO we don't show this state anymore
124 updateState: function(){
125 // summary: change shading on button if we are over a link (or not)
127 var _e = this.editor;
128 if(!_e || !_e.isLoaded){ return; }
130 // display button differently if there is an existing link associated with the current selection
131 var hasA = dojo.withGlobal(this.editor.window, "hasAncestorElement", dijit._editor.selection, [this.tag]);
132 this.button.setAttribute('checked', hasA);
139 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
140 if(o.plugin){ return; }
142 case "createLink": case "insertImage":
143 o.plugin = new dijit._editor.plugins.LinkDialog({command: o.args.name});