| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/dom-attr", |
| 6 |
"dojo/keys", |
| 7 |
"dojo/_base/lang", |
| 8 |
"dojo/on", |
| 9 |
"dojo/sniff", |
| 10 |
"dojo/query", |
| 11 |
"dojo/string", |
| 12 |
"../_Plugin", |
| 13 |
"../../form/DropDownButton", |
| 14 |
"../range" |
| 15 |
], function(require, array, declare, domAttr, keys, lang, on, has, query, string, |
| 16 |
_Plugin, DropDownButton, rangeapi){ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
var LinkDialog = declare("dijit._editor.plugins.LinkDialog", _Plugin, { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
allowUnsafeHtml: false, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
linkFilter: [ |
| 42 |
[/</g, "<"] |
| 43 |
], |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
buttonClass: DropDownButton, |
| 48 |
|
| 49 |
|
| 50 |
useDefaultCommand: false, |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
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/]*)?(?:#.*)?)?)?", |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
emailRegExp: "<?(mailto\\:)([!#-'*+\\-\\/-9=?A-Z^-~]+[.])*[!#-'*+\\-\\/-9=?A-Z^-~]+" + "@" + |
| 60 |
"((?:(?:[\\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_-]*>?", |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
htmlTemplate: "<a href=\"${urlInput}\" _djrealurl=\"${urlInput}\"" + |
| 65 |
" target=\"${targetSelect}\"" + |
| 66 |
">${textInput}</a>", |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
tag: "a", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
_hostRxp: /^((([^\[:]+):)?([^@]+)@)?(\[([^\]]+)\]|([^\[:]*))(:([0-9]+))?$/, |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
_userAtRxp: /^([!#-'*+\-\/-9=?A-Z^-~]+[.])*[!#-'*+\-\/-9=?A-Z^-~]+@/i, |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
linkDialogTemplate: [ |
| 83 |
"<table role='presentation'><tr><td>", |
| 84 |
"<label for='${id}_urlInput'>${url}</label>", |
| 85 |
"</td><td>", |
| 86 |
"<input data-dojo-type='dijit.form.ValidationTextBox' required='true' " + |
| 87 |
"id='${id}_urlInput' name='urlInput' data-dojo-props='intermediateChanges:true'/>", |
| 88 |
"</td></tr><tr><td>", |
| 89 |
"<label for='${id}_textInput'>${text}</label>", |
| 90 |
"</td><td>", |
| 91 |
"<input data-dojo-type='dijit.form.ValidationTextBox' required='true' id='${id}_textInput' " + |
| 92 |
"name='textInput' data-dojo-props='intermediateChanges:true'/>", |
| 93 |
"</td></tr><tr><td>", |
| 94 |
"<label for='${id}_targetSelect'>${target}</label>", |
| 95 |
"</td><td>", |
| 96 |
"<select id='${id}_targetSelect' name='targetSelect' data-dojo-type='dijit.form.Select'>", |
| 97 |
"<option selected='selected' value='_self'>${currentWindow}</option>", |
| 98 |
"<option value='_blank'>${newWindow}</option>", |
| 99 |
"<option value='_top'>${topWindow}</option>", |
| 100 |
"<option value='_parent'>${parentWindow}</option>", |
| 101 |
"</select>", |
| 102 |
"</td></tr><tr><td colspan='2'>", |
| 103 |
"<button data-dojo-type='dijit.form.Button' type='submit' id='${id}_setButton'>${set}</button>", |
| 104 |
"<button data-dojo-type='dijit.form.Button' type='button' id='${id}_cancelButton'>${buttonCancel}</button>", |
| 105 |
"</td></tr></table>" |
| 106 |
].join(""), |
| 107 |
|
| 108 |
_initButton: function(){ |
| 109 |
this.inherited(arguments); |
| 110 |
|
| 111 |
|
| 112 |
this.button.loadDropDown = lang.hitch(this, "_loadDropDown"); |
| 113 |
|
| 114 |
this._connectTagEvents(); |
| 115 |
}, |
| 116 |
_loadDropDown: function(callback){ |
| 117 |
|
| 118 |
require([ |
| 119 |
"dojo/i18n", |
| 120 |
"../../TooltipDialog", |
| 121 |
"../../registry", |
| 122 |
"../../form/Button", |
| 123 |
"../../form/Select", |
| 124 |
"../../form/ValidationTextBox", |
| 125 |
"dojo/i18n!../../nls/common", |
| 126 |
"dojo/i18n!../nls/LinkDialog" |
| 127 |
], lang.hitch(this, function(i18n, TooltipDialog, registry){ |
| 128 |
var _this = this; |
| 129 |
this.tag = this.command == 'insertImage' ? 'img' : 'a'; |
| 130 |
var messages = lang.delegate(i18n.getLocalization("dijit", "common", this.lang), |
| 131 |
i18n.getLocalization("dijit._editor", "LinkDialog", this.lang)); |
| 132 |
var dropDown = (this.dropDown = this.button.dropDown = new TooltipDialog({ |
| 133 |
title: messages[this.command + "Title"], |
| 134 |
ownerDocument: this.editor.ownerDocument, |
| 135 |
dir: this.editor.dir, |
| 136 |
execute: lang.hitch(this, "setValue"), |
| 137 |
onOpen: function(){ |
| 138 |
_this._onOpenDialog(); |
| 139 |
TooltipDialog.prototype.onOpen.apply(this, arguments); |
| 140 |
}, |
| 141 |
onCancel: function(){ |
| 142 |
setTimeout(lang.hitch(_this, "_onCloseDialog"), 0); |
| 143 |
} |
| 144 |
})); |
| 145 |
messages.urlRegExp = this.urlRegExp; |
| 146 |
messages.id = registry.getUniqueId(this.editor.id); |
| 147 |
this._uniqueId = messages.id; |
| 148 |
this._setContent(dropDown.title + |
| 149 |
"<div style='border-bottom: 1px black solid;padding-bottom:2pt;margin-bottom:4pt'></div>" + |
| 150 |
string.substitute(this.linkDialogTemplate, messages)); |
| 151 |
dropDown.startup(); |
| 152 |
this._urlInput = registry.byId(this._uniqueId + "_urlInput"); |
| 153 |
this._textInput = registry.byId(this._uniqueId + "_textInput"); |
| 154 |
this._setButton = registry.byId(this._uniqueId + "_setButton"); |
| 155 |
this.own(registry.byId(this._uniqueId + "_cancelButton").on("click", lang.hitch(this.dropDown, "onCancel"))); |
| 156 |
if(this._urlInput){ |
| 157 |
this.own(this._urlInput.on("change", lang.hitch(this, "_checkAndFixInput"))); |
| 158 |
} |
| 159 |
if(this._textInput){ |
| 160 |
this.own(this._textInput.on("change", lang.hitch(this, "_checkAndFixInput"))); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
this._urlRegExp = new RegExp("^" + this.urlRegExp + "$", "i"); |
| 165 |
this._emailRegExp = new RegExp("^" + this.emailRegExp + "$", "i"); |
| 166 |
this._urlInput.isValid = lang.hitch(this, function(){ |
| 167 |
|
| 168 |
var value = this._urlInput.get("value"); |
| 169 |
return this._urlRegExp.test(value) || this._emailRegExp.test(value); |
| 170 |
}); |
| 171 |
|
| 172 |
|
| 173 |
this.own(on(dropDown.domNode, "keydown", lang.hitch(this, lang.hitch(this, function(e){ |
| 174 |
if(e && e.keyCode == keys.ENTER && !e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey){ |
| 175 |
if(!this._setButton.get("disabled")){ |
| 176 |
dropDown.onExecute(); |
| 177 |
dropDown.execute(dropDown.get('value')); |
| 178 |
} |
| 179 |
} |
| 180 |
})))); |
| 181 |
|
| 182 |
callback(); |
| 183 |
})); |
| 184 |
}, |
| 185 |
|
| 186 |
_checkAndFixInput: function(){ |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
var self = this; |
| 194 |
var url = this._urlInput.get("value"); |
| 195 |
var fixupUrl = function(url){ |
| 196 |
var appendHttp = false; |
| 197 |
var appendMailto = false; |
| 198 |
if(url && url.length > 1){ |
| 199 |
url = lang.trim(url); |
| 200 |
if(url.indexOf("mailto:") !== 0){ |
| 201 |
if(url.indexOf("/") > 0){ |
| 202 |
if(url.indexOf("://") === -1){ |
| 203 |
|
| 204 |
|
| 205 |
if(url.charAt(0) !== '/' && url.indexOf("./") && url.indexOf("../") !== 0){ |
| 206 |
if(self._hostRxp.test(url)){ |
| 207 |
appendHttp = true; |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
}else if(self._userAtRxp.test(url)){ |
| 212 |
|
| 213 |
appendMailto = true; |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
if(appendHttp){ |
| 218 |
self._urlInput.set("value", "http://" + url); |
| 219 |
} |
| 220 |
if(appendMailto){ |
| 221 |
self._urlInput.set("value", "mailto:" + url); |
| 222 |
} |
| 223 |
self._setButton.set("disabled", !self._isValid()); |
| 224 |
}; |
| 225 |
if(this._delayedCheck){ |
| 226 |
clearTimeout(this._delayedCheck); |
| 227 |
this._delayedCheck = null; |
| 228 |
} |
| 229 |
this._delayedCheck = setTimeout(function(){ |
| 230 |
fixupUrl(url); |
| 231 |
}, 250); |
| 232 |
}, |
| 233 |
|
| 234 |
_connectTagEvents: function(){ |
| 235 |
|
| 236 |
|
| 237 |
this.editor.onLoadDeferred.then(lang.hitch(this, function(){ |
| 238 |
this.own(on(this.editor.editNode, "mouseup", lang.hitch(this, "_onMouseUp"))); |
| 239 |
this.own(on(this.editor.editNode, "dblclick", lang.hitch(this, "_onDblClick"))); |
| 240 |
})); |
| 241 |
}, |
| 242 |
|
| 243 |
_isValid: function(){ |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
return this._urlInput.isValid() && this._textInput.isValid(); |
| 250 |
}, |
| 251 |
|
| 252 |
_setContent: function(staticPanel){ |
| 253 |
|
| 254 |
|
| 255 |
this.dropDown.set({ |
| 256 |
parserScope: "dojo", |
| 257 |
content: staticPanel |
| 258 |
}); |
| 259 |
}, |
| 260 |
|
| 261 |
_checkValues: function(args){ |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
if(args && args.urlInput){ |
| 269 |
args.urlInput = args.urlInput.replace(/"/g, """); |
| 270 |
} |
| 271 |
if(!this.allowUnsafeHtml && args && args.textInput){ |
| 272 |
if(typeof this.linkFilter === 'function'){ |
| 273 |
args.textInput = this.linkFilter(args.textInput); |
| 274 |
} |
| 275 |
else{ |
| 276 |
array.forEach(this.linkFilter, function (currentFilter) { |
| 277 |
args.textInput = args.textInput.replace(currentFilter[0], currentFilter[1]); |
| 278 |
}); |
| 279 |
} |
| 280 |
} |
| 281 |
return args; |
| 282 |
}, |
| 283 |
|
| 284 |
_createlinkEnabledImpl: function() { |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
return true; |
| 292 |
}, |
| 293 |
|
| 294 |
setValue: function(args){ |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
this._onCloseDialog(); |
| 302 |
if(has("ie") < 9){ |
| 303 |
var sel = rangeapi.getSelection(this.editor.window); |
| 304 |
var range = sel.getRangeAt(0); |
| 305 |
var a = range.endContainer; |
| 306 |
if(a.nodeType === 3){ |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
a = a.parentNode; |
| 311 |
} |
| 312 |
if(a && (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){ |
| 313 |
|
| 314 |
|
| 315 |
a = this.editor.selection.getSelectedElement(this.tag); |
| 316 |
} |
| 317 |
if(a && (a.nodeName && a.nodeName.toLowerCase() === this.tag)){ |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
if(this.editor.queryCommandEnabled("unlink")){ |
| 323 |
|
| 324 |
|
| 325 |
this.editor.selection.selectElementChildren(a); |
| 326 |
this.editor.execCommand("unlink"); |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
args = this._checkValues(args); |
| 332 |
this.editor.execCommand('inserthtml', |
| 333 |
string.substitute(this.htmlTemplate, args)); |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
query("a", this.editor.document).forEach(function(a){ |
| 339 |
if(!a.innerHTML && !domAttr.has(a, "name")){ |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
a.parentNode.removeChild(a); |
| 344 |
} |
| 345 |
}, this); |
| 346 |
}, |
| 347 |
|
| 348 |
_onCloseDialog: function(){ |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
if(this.editor.focused){ |
| 353 |
|
| 354 |
this.editor.focus(); |
| 355 |
} |
| 356 |
}, |
| 357 |
|
| 358 |
_getCurrentValues: function(a){ |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
var url, text, target; |
| 366 |
if(a && a.tagName.toLowerCase() === this.tag){ |
| 367 |
url = a.getAttribute('_djrealurl') || a.getAttribute('href'); |
| 368 |
target = a.getAttribute('target') || "_self"; |
| 369 |
text = a.textContent || a.innerText; |
| 370 |
this.editor.selection.selectElement(a, true); |
| 371 |
}else{ |
| 372 |
text = this.editor.selection.getSelectedText(); |
| 373 |
} |
| 374 |
return {urlInput: url || '', textInput: text || '', targetSelect: target || ''}; |
| 375 |
}, |
| 376 |
|
| 377 |
_onOpenDialog: function(){ |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
var a, b, fc; |
| 382 |
if(has("ie")){ |
| 383 |
|
| 384 |
|
| 385 |
var sel = rangeapi.getSelection(this.editor.window); |
| 386 |
if(sel.rangeCount){ |
| 387 |
var range = sel.getRangeAt(0); |
| 388 |
a = range.endContainer; |
| 389 |
if(a.nodeType === 3){ |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
a = a.parentNode; |
| 394 |
} |
| 395 |
if(a && (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){ |
| 396 |
|
| 397 |
|
| 398 |
a = this.editor.selection.getSelectedElement(this.tag); |
| 399 |
} |
| 400 |
if(!a || (a.nodeName && a.nodeName.toLowerCase() !== this.tag)){ |
| 401 |
|
| 402 |
b = this.editor.selection.getAncestorElement(this.tag); |
| 403 |
if(b && (b.nodeName && b.nodeName.toLowerCase() == this.tag)){ |
| 404 |
|
| 405 |
|
| 406 |
a = b; |
| 407 |
this.editor.selection.selectElement(a); |
| 408 |
}else if(range.startContainer === range.endContainer){ |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
fc = range.startContainer.firstChild; |
| 414 |
if(fc && (fc.nodeName && fc.nodeName.toLowerCase() == this.tag)){ |
| 415 |
a = fc; |
| 416 |
this.editor.selection.selectElement(a); |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
}else{ |
| 422 |
a = this.editor.selection.getAncestorElement(this.tag); |
| 423 |
} |
| 424 |
this.dropDown.reset(); |
| 425 |
this._setButton.set("disabled", true); |
| 426 |
this.dropDown.set("value", this._getCurrentValues(a)); |
| 427 |
}, |
| 428 |
|
| 429 |
_onDblClick: function(e){ |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
if(e && e.target){ |
| 439 |
var t = e.target; |
| 440 |
var tg = t.tagName ? t.tagName.toLowerCase() : ""; |
| 441 |
if(tg === this.tag && domAttr.get(t, "href")){ |
| 442 |
var editor = this.editor; |
| 443 |
|
| 444 |
this.editor.selection.selectElement(t); |
| 445 |
editor.onDisplayChanged(); |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
if(editor._updateTimer){ |
| 453 |
editor._updateTimer.remove(); |
| 454 |
delete editor._updateTimer; |
| 455 |
} |
| 456 |
editor.onNormalizedDisplayChanged(); |
| 457 |
|
| 458 |
var button = this.button; |
| 459 |
setTimeout(function(){ |
| 460 |
|
| 461 |
|
| 462 |
button.set("disabled", false); |
| 463 |
button.loadAndOpenDropDown().then(function(){ |
| 464 |
if(button.dropDown.focus){ |
| 465 |
button.dropDown.focus(); |
| 466 |
} |
| 467 |
}); |
| 468 |
}, 10); |
| 469 |
} |
| 470 |
} |
| 471 |
}, |
| 472 |
|
| 473 |
_onMouseUp: function(){ |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
if(has('ff')){ |
| 481 |
var a = this.editor.selection.getAncestorElement(this.tag); |
| 482 |
if(a){ |
| 483 |
var selection = rangeapi.getSelection(this.editor.window); |
| 484 |
var range = selection.getRangeAt(0); |
| 485 |
if(range.collapsed && a.childNodes.length){ |
| 486 |
var test = range.cloneRange(); |
| 487 |
test.selectNodeContents(a.childNodes[a.childNodes.length - 1]); |
| 488 |
test.setStart(a.childNodes[0], 0); |
| 489 |
if(range.compareBoundaryPoints(test.START_TO_START, test) !== 1){ |
| 490 |
|
| 491 |
range.setStartBefore(a); |
| 492 |
}else if(range.compareBoundaryPoints(test.END_TO_START, test) !== -1){ |
| 493 |
|
| 494 |
range.setStartAfter(a); |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
}); |
| 501 |
|
| 502 |
var ImgLinkDialog = declare("dijit._editor.plugins.ImgLinkDialog", [LinkDialog], { |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
linkDialogTemplate: [ |
| 514 |
"<table role='presentation'><tr><td>", |
| 515 |
"<label for='${id}_urlInput'>${url}</label>", |
| 516 |
"</td><td>", |
| 517 |
"<input dojoType='dijit.form.ValidationTextBox' regExp='${urlRegExp}' " + |
| 518 |
"required='true' id='${id}_urlInput' name='urlInput' data-dojo-props='intermediateChanges:true'/>", |
| 519 |
"</td></tr><tr><td>", |
| 520 |
"<label for='${id}_textInput'>${text}</label>", |
| 521 |
"</td><td>", |
| 522 |
"<input data-dojo-type='dijit.form.ValidationTextBox' required='false' id='${id}_textInput' " + |
| 523 |
"name='textInput' data-dojo-props='intermediateChanges:true'/>", |
| 524 |
"</td></tr><tr><td>", |
| 525 |
"</td><td>", |
| 526 |
"</td></tr><tr><td colspan='2'>", |
| 527 |
"<button data-dojo-type='dijit.form.Button' type='submit' id='${id}_setButton'>${set}</button>", |
| 528 |
"<button data-dojo-type='dijit.form.Button' type='button' id='${id}_cancelButton'>${buttonCancel}</button>", |
| 529 |
"</td></tr></table>" |
| 530 |
].join(""), |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
htmlTemplate: "<img src=\"${urlInput}\" _djrealurl=\"${urlInput}\" alt=\"${textInput}\" />", |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
tag: "img", |
| 539 |
|
| 540 |
_getCurrentValues: function(img){ |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
var url, text; |
| 548 |
if(img && img.tagName.toLowerCase() === this.tag){ |
| 549 |
url = img.getAttribute('_djrealurl') || img.getAttribute('src'); |
| 550 |
text = img.getAttribute('alt'); |
| 551 |
this.editor.selection.selectElement(img, true); |
| 552 |
}else{ |
| 553 |
text = this.editor.selection.getSelectedText(); |
| 554 |
} |
| 555 |
return {urlInput: url || '', textInput: text || ''}; |
| 556 |
}, |
| 557 |
|
| 558 |
_isValid: function(){ |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
return this._urlInput.isValid(); |
| 564 |
}, |
| 565 |
|
| 566 |
_connectTagEvents: function(){ |
| 567 |
|
| 568 |
|
| 569 |
this.inherited(arguments); |
| 570 |
this.editor.onLoadDeferred.then(lang.hitch(this, function(){ |
| 571 |
|
| 572 |
|
| 573 |
this.own(on(this.editor.editNode, "mousedown", lang.hitch(this, "_selectTag"))); |
| 574 |
})); |
| 575 |
}, |
| 576 |
|
| 577 |
_selectTag: function(e){ |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
if(e && e.target){ |
| 587 |
var t = e.target; |
| 588 |
var tg = t.tagName ? t.tagName.toLowerCase() : ""; |
| 589 |
if(tg === this.tag){ |
| 590 |
this.editor.selection.selectElement(t); |
| 591 |
} |
| 592 |
} |
| 593 |
}, |
| 594 |
|
| 595 |
_checkValues: function(args){ |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
if(args && args.urlInput){ |
| 604 |
args.urlInput = args.urlInput.replace(/"/g, """); |
| 605 |
} |
| 606 |
if(args && args.textInput){ |
| 607 |
args.textInput = args.textInput.replace(/"/g, """); |
| 608 |
} |
| 609 |
return args; |
| 610 |
}, |
| 611 |
|
| 612 |
_onDblClick: function(e){ |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
if(e && e.target){ |
| 622 |
var t = e.target; |
| 623 |
var tg = t.tagName ? t.tagName.toLowerCase() : ""; |
| 624 |
if(tg === this.tag && domAttr.get(t, "src")){ |
| 625 |
var editor = this.editor; |
| 626 |
|
| 627 |
this.editor.selection.selectElement(t); |
| 628 |
editor.onDisplayChanged(); |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
if(editor._updateTimer){ |
| 636 |
editor._updateTimer.remove(); |
| 637 |
delete editor._updateTimer; |
| 638 |
} |
| 639 |
editor.onNormalizedDisplayChanged(); |
| 640 |
|
| 641 |
var button = this.button; |
| 642 |
setTimeout(function(){ |
| 643 |
|
| 644 |
|
| 645 |
button.set("disabled", false); |
| 646 |
button.loadAndOpenDropDown().then(function(){ |
| 647 |
if(button.dropDown.focus){ |
| 648 |
button.dropDown.focus(); |
| 649 |
} |
| 650 |
}); |
| 651 |
}, 10); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
}); |
| 656 |
|
| 657 |
|
| 658 |
_Plugin.registry["createLink"] = function(args){ |
| 659 |
var pluginOptions = { |
| 660 |
command: "createLink", |
| 661 |
allowUnsafeHtml: ("allowUnsafeHtml" in args) ? args.allowUnsafeHtml : false |
| 662 |
}; |
| 663 |
if("linkFilter" in args){ |
| 664 |
pluginOptions.linkFilter = args.linkFilter; |
| 665 |
} |
| 666 |
return new LinkDialog(pluginOptions); |
| 667 |
}; |
| 668 |
_Plugin.registry["insertImage"] = function(){ |
| 669 |
return new ImgLinkDialog({command: "insertImage"}); |
| 670 |
}; |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
LinkDialog.ImgLinkDialog = ImgLinkDialog; |
| 677 |
return LinkDialog; |
| 678 |
}); |