| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/Deferred", |
| 6 |
"dojo/i18n", |
| 7 |
"dojo/dom-attr", |
| 8 |
"dojo/dom-class", |
| 9 |
"dojo/dom-geometry", |
| 10 |
"dojo/dom-style", |
| 11 |
"dojo/keys", |
| 12 |
"dojo/_base/lang", |
| 13 |
"dojo/sniff", |
| 14 |
"dojo/string", |
| 15 |
"dojo/topic", |
| 16 |
"./_Container", |
| 17 |
"./Toolbar", |
| 18 |
"./ToolbarSeparator", |
| 19 |
"./layout/_LayoutWidget", |
| 20 |
"./form/ToggleButton", |
| 21 |
"./_editor/_Plugin", |
| 22 |
"./_editor/plugins/EnterKeyHandling", |
| 23 |
"./_editor/html", |
| 24 |
"./_editor/range", |
| 25 |
"./_editor/RichText", |
| 26 |
"./main", |
| 27 |
"dojo/i18n!./_editor/nls/commands" |
| 28 |
], function(require, array, declare, Deferred, i18n, domAttr, domClass, domGeometry, domStyle, |
| 29 |
keys, lang, has, string, topic, |
| 30 |
_Container, Toolbar, ToolbarSeparator, _LayoutWidget, ToggleButton, |
| 31 |
_Plugin, EnterKeyHandling, html, rangeapi, RichText, dijit){ |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
var Editor = declare("dijit.Editor", RichText, { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
plugins: null, |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
extraPlugins: null, |
| 60 |
|
| 61 |
constructor: function(){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
if(!lang.isArray(this.plugins)){ |
| 70 |
this.plugins = ["undo", "redo", "|", "cut", "copy", "paste", "|", "bold", "italic", "underline", "strikethrough", "|", |
| 71 |
"insertOrderedList", "insertUnorderedList", "indent", "outdent", "|", "justifyLeft", "justifyRight", "justifyCenter", "justifyFull", |
| 72 |
EnterKeyHandling ]; |
| 73 |
} |
| 74 |
|
| 75 |
this._plugins = []; |
| 76 |
this._editInterval = this.editActionInterval * 1000; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
if(has("ie") || has("trident") || has("edge")){ |
| 89 |
this.events.push("onBeforeDeactivate"); |
| 90 |
this.events.push("onBeforeActivate"); |
| 91 |
} |
| 92 |
}, |
| 93 |
|
| 94 |
postMixInProperties: function(){ |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
this.setValueDeferred = new Deferred(); |
| 103 |
this.inherited(arguments); |
| 104 |
}, |
| 105 |
|
| 106 |
postCreate: function(){ |
| 107 |
this.inherited(arguments); |
| 108 |
|
| 109 |
|
| 110 |
this._steps = this._steps.slice(0); |
| 111 |
this._undoedSteps = this._undoedSteps.slice(0); |
| 112 |
|
| 113 |
if(lang.isArray(this.extraPlugins)){ |
| 114 |
this.plugins = this.plugins.concat(this.extraPlugins); |
| 115 |
} |
| 116 |
|
| 117 |
this.commands = i18n.getLocalization("dijit._editor", "commands", this.lang); |
| 118 |
|
| 119 |
if(has("webkit")){ |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
domStyle.set(this.domNode, "KhtmlUserSelect", "none"); |
| 124 |
} |
| 125 |
}, |
| 126 |
|
| 127 |
startup: function(){ |
| 128 |
|
| 129 |
this.inherited(arguments); |
| 130 |
|
| 131 |
if(!this.toolbar){ |
| 132 |
|
| 133 |
this.toolbar = new Toolbar({ |
| 134 |
ownerDocument: this.ownerDocument, |
| 135 |
dir: this.dir, |
| 136 |
lang: this.lang, |
| 137 |
"aria-label": this.id |
| 138 |
}); |
| 139 |
this.header.appendChild(this.toolbar.domNode); |
| 140 |
} |
| 141 |
|
| 142 |
array.forEach(this.plugins, this.addPlugin, this); |
| 143 |
|
| 144 |
|
| 145 |
this.setValueDeferred.resolve(true); |
| 146 |
|
| 147 |
domClass.add(this.iframe.parentNode, "dijitEditorIFrameContainer"); |
| 148 |
domClass.add(this.iframe, "dijitEditorIFrame"); |
| 149 |
domAttr.set(this.iframe, "allowTransparency", true); |
| 150 |
|
| 151 |
this.toolbar.startup(); |
| 152 |
this.onNormalizedDisplayChanged(); |
| 153 |
}, |
| 154 |
|
| 155 |
destroy: function(){ |
| 156 |
array.forEach(this._plugins, function(p){ |
| 157 |
if(p && p.destroy){ |
| 158 |
p.destroy(); |
| 159 |
} |
| 160 |
}); |
| 161 |
this._plugins = []; |
| 162 |
this.toolbar.destroyRecursive(); |
| 163 |
delete this.toolbar; |
| 164 |
this.inherited(arguments); |
| 165 |
}, |
| 166 |
addPlugin: function( plugin, index){ |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
var args = lang.isString(plugin) ? {name: plugin} : lang.isFunction(plugin) ? {ctor: plugin} : plugin; |
| 183 |
if(!args.setEditor){ |
| 184 |
var o = {"args": args, "plugin": null, "editor": this}; |
| 185 |
if(args.name){ |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
if(_Plugin.registry[args.name]){ |
| 191 |
o.plugin = _Plugin.registry[args.name](args); |
| 192 |
}else{ |
| 193 |
topic.publish(dijit._scopeName + ".Editor.getPlugin", o); |
| 194 |
} |
| 195 |
} |
| 196 |
if(!o.plugin){ |
| 197 |
try{ |
| 198 |
|
| 199 |
var pc = args.ctor || lang.getObject(args.name) || require(args.name); |
| 200 |
if(pc){ |
| 201 |
o.plugin = new pc(args); |
| 202 |
} |
| 203 |
}catch(e){ |
| 204 |
throw new Error(this.id + ": cannot find plugin [" + args.name + "]"); |
| 205 |
} |
| 206 |
} |
| 207 |
if(!o.plugin){ |
| 208 |
throw new Error(this.id + ": cannot find plugin [" + args.name + "]"); |
| 209 |
} |
| 210 |
plugin = o.plugin; |
| 211 |
} |
| 212 |
if(arguments.length > 1){ |
| 213 |
this._plugins[index] = plugin; |
| 214 |
}else{ |
| 215 |
this._plugins.push(plugin); |
| 216 |
} |
| 217 |
plugin.setEditor(this); |
| 218 |
if(lang.isFunction(plugin.setToolbar)){ |
| 219 |
plugin.setToolbar(this.toolbar); |
| 220 |
} |
| 221 |
}, |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
resize: function(size){ |
| 226 |
|
| 227 |
|
| 228 |
if(size){ |
| 229 |
|
| 230 |
|
| 231 |
_LayoutWidget.prototype.resize.apply(this, arguments); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
}, |
| 240 |
layout: function(){ |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
var areaHeight = (this._contentBox.h - |
| 251 |
(this.getHeaderHeight() + this.getFooterHeight() + |
| 252 |
domGeometry.getPadBorderExtents(this.iframe.parentNode).h + |
| 253 |
domGeometry.getMarginExtents(this.iframe.parentNode).h)); |
| 254 |
this.editingArea.style.height = areaHeight + "px"; |
| 255 |
if(this.iframe){ |
| 256 |
this.iframe.style.height = "100%"; |
| 257 |
} |
| 258 |
this._layoutMode = true; |
| 259 |
}, |
| 260 |
|
| 261 |
_onIEMouseDown: function( e){ |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
var outsideClientArea; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
var b = this.document.body; |
| 271 |
var clientWidth = b.clientWidth; |
| 272 |
var clientHeight = b.clientHeight; |
| 273 |
var clientLeft = b.clientLeft; |
| 274 |
var offsetWidth = b.offsetWidth; |
| 275 |
var offsetHeight = b.offsetHeight; |
| 276 |
var offsetLeft = b.offsetLeft; |
| 277 |
|
| 278 |
|
| 279 |
if(/^rtl$/i.test(b.dir || "")){ |
| 280 |
if(clientWidth < offsetWidth && e.x > clientWidth && e.x < offsetWidth){ |
| 281 |
|
| 282 |
outsideClientArea = true; |
| 283 |
} |
| 284 |
}else{ |
| 285 |
|
| 286 |
if(e.x < clientLeft && e.x > offsetLeft){ |
| 287 |
|
| 288 |
outsideClientArea = true; |
| 289 |
} |
| 290 |
} |
| 291 |
if(!outsideClientArea){ |
| 292 |
|
| 293 |
if(clientHeight < offsetHeight && e.y > clientHeight && e.y < offsetHeight){ |
| 294 |
|
| 295 |
outsideClientArea = true; |
| 296 |
} |
| 297 |
} |
| 298 |
if(!outsideClientArea){ |
| 299 |
delete this._cursorToStart; |
| 300 |
delete this._savedSelection; |
| 301 |
if(e.target.tagName == "BODY"){ |
| 302 |
this.defer("placeCursorAtEnd"); |
| 303 |
} |
| 304 |
this.inherited(arguments); |
| 305 |
} |
| 306 |
}, |
| 307 |
onBeforeActivate: function(){ |
| 308 |
this._restoreSelection(); |
| 309 |
}, |
| 310 |
onBeforeDeactivate: function(e){ |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
if(this.customUndo){ |
| 316 |
this.endEditing(true); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
if(e.target.tagName != "BODY"){ |
| 321 |
this._saveSelection(); |
| 322 |
} |
| 323 |
|
| 324 |
}, |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
customUndo: true, |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
editActionInterval: 3, |
| 344 |
|
| 345 |
beginEditing: function(cmd){ |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
if(!this._inEditing){ |
| 352 |
this._inEditing = true; |
| 353 |
this._beginEditing(cmd); |
| 354 |
} |
| 355 |
if(this.editActionInterval > 0){ |
| 356 |
if(this._editTimer){ |
| 357 |
this._editTimer.remove(); |
| 358 |
} |
| 359 |
this._editTimer = this.defer("endEditing", this._editInterval); |
| 360 |
} |
| 361 |
}, |
| 362 |
|
| 363 |
|
| 364 |
_steps: [], |
| 365 |
_undoedSteps: [], |
| 366 |
|
| 367 |
execCommand: function(cmd){ |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
if(this.customUndo && (cmd == 'undo' || cmd == 'redo')){ |
| 374 |
return this[cmd](); |
| 375 |
}else{ |
| 376 |
if(this.customUndo){ |
| 377 |
this.endEditing(); |
| 378 |
this._beginEditing(); |
| 379 |
} |
| 380 |
var r = this.inherited(arguments); |
| 381 |
if(this.customUndo){ |
| 382 |
this._endEditing(); |
| 383 |
} |
| 384 |
return r; |
| 385 |
} |
| 386 |
}, |
| 387 |
|
| 388 |
_pasteImpl: function(){ |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
return this._clipboardCommand("paste"); |
| 394 |
}, |
| 395 |
|
| 396 |
_cutImpl: function(){ |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
return this._clipboardCommand("cut"); |
| 402 |
}, |
| 403 |
|
| 404 |
_copyImpl: function(){ |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
return this._clipboardCommand("copy"); |
| 410 |
}, |
| 411 |
|
| 412 |
_clipboardCommand: function(cmd){ |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
var r; |
| 418 |
try{ |
| 419 |
|
| 420 |
r = this.document.execCommand(cmd, false, null); |
| 421 |
if(has("webkit") && !r){ |
| 422 |
throw {}; |
| 423 |
} |
| 424 |
}catch(e){ |
| 425 |
|
| 426 |
|
| 427 |
var sub = string.substitute, |
| 428 |
accel = {cut: 'X', copy: 'C', paste: 'V'}; |
| 429 |
alert(sub(this.commands.systemShortcut, |
| 430 |
[this.commands[cmd], sub(this.commands[has("mac") ? 'appleKey' : 'ctrlKey'], [accel[cmd]])])); |
| 431 |
r = false; |
| 432 |
} |
| 433 |
return r; |
| 434 |
}, |
| 435 |
|
| 436 |
queryCommandEnabled: function(cmd){ |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
if(this.customUndo && (cmd == 'undo' || cmd == 'redo')){ |
| 443 |
return cmd == 'undo' ? (this._steps.length > 1) : (this._undoedSteps.length > 0); |
| 444 |
}else{ |
| 445 |
return this.inherited(arguments); |
| 446 |
} |
| 447 |
}, |
| 448 |
_moveToBookmark: function(b){ |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
var bookmark = b.mark; |
| 454 |
var mark = b.mark; |
| 455 |
var col = b.isCollapsed; |
| 456 |
var r, sNode, eNode, sel; |
| 457 |
if(mark){ |
| 458 |
if(has("ie") < 9 || (has("ie") === 9 && has("quirks"))){ |
| 459 |
if(lang.isArray(mark)){ |
| 460 |
|
| 461 |
bookmark = []; |
| 462 |
array.forEach(mark, function(n){ |
| 463 |
bookmark.push(rangeapi.getNode(n, this.editNode)); |
| 464 |
}, this); |
| 465 |
this.selection.moveToBookmark({mark: bookmark, isCollapsed: col}); |
| 466 |
}else{ |
| 467 |
if(mark.startContainer && mark.endContainer){ |
| 468 |
|
| 469 |
|
| 470 |
sel = rangeapi.getSelection(this.window); |
| 471 |
if(sel && sel.removeAllRanges){ |
| 472 |
sel.removeAllRanges(); |
| 473 |
r = rangeapi.create(this.window); |
| 474 |
sNode = rangeapi.getNode(mark.startContainer, this.editNode); |
| 475 |
eNode = rangeapi.getNode(mark.endContainer, this.editNode); |
| 476 |
if(sNode && eNode){ |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
r.setStart(sNode, mark.startOffset); |
| 482 |
r.setEnd(eNode, mark.endOffset); |
| 483 |
sel.addRange(r); |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
}else{ |
| 489 |
sel = rangeapi.getSelection(this.window); |
| 490 |
if(sel && sel.removeAllRanges){ |
| 491 |
sel.removeAllRanges(); |
| 492 |
r = rangeapi.create(this.window); |
| 493 |
sNode = rangeapi.getNode(mark.startContainer, this.editNode); |
| 494 |
eNode = rangeapi.getNode(mark.endContainer, this.editNode); |
| 495 |
if(sNode && eNode){ |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
r.setStart(sNode, mark.startOffset); |
| 500 |
r.setEnd(eNode, mark.endOffset); |
| 501 |
sel.addRange(r); |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
}, |
| 507 |
_changeToStep: function(from, to){ |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
this.setValue(to.text); |
| 513 |
var b = to.bookmark; |
| 514 |
if(!b){ |
| 515 |
return; |
| 516 |
} |
| 517 |
this._moveToBookmark(b); |
| 518 |
}, |
| 519 |
undo: function(){ |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
var ret = false; |
| 525 |
if(!this._undoRedoActive){ |
| 526 |
this._undoRedoActive = true; |
| 527 |
this.endEditing(true); |
| 528 |
var s = this._steps.pop(); |
| 529 |
if(s && this._steps.length > 0){ |
| 530 |
this.focus(); |
| 531 |
this._changeToStep(s, this._steps[this._steps.length - 1]); |
| 532 |
this._undoedSteps.push(s); |
| 533 |
this.onDisplayChanged(); |
| 534 |
delete this._undoRedoActive; |
| 535 |
ret = true; |
| 536 |
} |
| 537 |
delete this._undoRedoActive; |
| 538 |
} |
| 539 |
return ret; |
| 540 |
}, |
| 541 |
redo: function(){ |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
var ret = false; |
| 547 |
if(!this._undoRedoActive){ |
| 548 |
this._undoRedoActive = true; |
| 549 |
this.endEditing(true); |
| 550 |
var s = this._undoedSteps.pop(); |
| 551 |
if(s && this._steps.length > 0){ |
| 552 |
this.focus(); |
| 553 |
this._changeToStep(this._steps[this._steps.length - 1], s); |
| 554 |
this._steps.push(s); |
| 555 |
this.onDisplayChanged(); |
| 556 |
ret = true; |
| 557 |
} |
| 558 |
delete this._undoRedoActive; |
| 559 |
} |
| 560 |
return ret; |
| 561 |
}, |
| 562 |
endEditing: function(ignore_caret){ |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
if(this._editTimer){ |
| 569 |
this._editTimer = this._editTimer.remove(); |
| 570 |
} |
| 571 |
if(this._inEditing){ |
| 572 |
this._endEditing(ignore_caret); |
| 573 |
this._inEditing = false; |
| 574 |
} |
| 575 |
}, |
| 576 |
|
| 577 |
_getBookmark: function(){ |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
var b = this.selection.getBookmark(); |
| 583 |
var tmp = []; |
| 584 |
if(b && b.mark){ |
| 585 |
var mark = b.mark; |
| 586 |
if(has("ie") < 9 || (has("ie") === 9 && has("quirks"))){ |
| 587 |
|
| 588 |
var sel = rangeapi.getSelection(this.window); |
| 589 |
if(!lang.isArray(mark)){ |
| 590 |
if(sel){ |
| 591 |
var range; |
| 592 |
if(sel.rangeCount){ |
| 593 |
range = sel.getRangeAt(0); |
| 594 |
} |
| 595 |
if(range){ |
| 596 |
b.mark = range.cloneRange(); |
| 597 |
}else{ |
| 598 |
b.mark = this.selection.getBookmark(); |
| 599 |
} |
| 600 |
} |
| 601 |
}else{ |
| 602 |
|
| 603 |
array.forEach(b.mark, function(n){ |
| 604 |
tmp.push(rangeapi.getIndex(n, this.editNode).o); |
| 605 |
}, this); |
| 606 |
b.mark = tmp; |
| 607 |
} |
| 608 |
} |
| 609 |
try{ |
| 610 |
if(b.mark && b.mark.startContainer){ |
| 611 |
tmp = rangeapi.getIndex(b.mark.startContainer, this.editNode).o; |
| 612 |
b.mark = {startContainer: tmp, |
| 613 |
startOffset: b.mark.startOffset, |
| 614 |
endContainer: b.mark.endContainer === b.mark.startContainer ? tmp : rangeapi.getIndex(b.mark.endContainer, this.editNode).o, |
| 615 |
endOffset: b.mark.endOffset}; |
| 616 |
} |
| 617 |
}catch(e){ |
| 618 |
b.mark = null; |
| 619 |
} |
| 620 |
} |
| 621 |
return b; |
| 622 |
}, |
| 623 |
_beginEditing: function(){ |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
if(this._steps.length === 0){ |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
this._steps.push({'text': html.getChildrenHtml(this.editNode), 'bookmark': this._getBookmark()}); |
| 635 |
} |
| 636 |
}, |
| 637 |
_endEditing: function(){ |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
var v = html.getChildrenHtml(this.editNode); |
| 646 |
|
| 647 |
this._undoedSteps = []; |
| 648 |
this._steps.push({text: v, bookmark: this._getBookmark()}); |
| 649 |
}, |
| 650 |
onKeyDown: function(e){ |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
if(!has("ie") && !this.iframe && e.keyCode == keys.TAB && !this.tabIndent){ |
| 659 |
this._saveSelection(); |
| 660 |
} |
| 661 |
if(!this.customUndo){ |
| 662 |
this.inherited(arguments); |
| 663 |
return; |
| 664 |
} |
| 665 |
var k = e.keyCode; |
| 666 |
if(e.ctrlKey && !e.shiftKey && !e.altKey){ |
| 667 |
if(k == 90 || k == 122){ |
| 668 |
e.stopPropagation(); |
| 669 |
e.preventDefault(); |
| 670 |
this.undo(); |
| 671 |
return; |
| 672 |
}else if(k == 89 || k == 121){ |
| 673 |
e.stopPropagation(); |
| 674 |
e.preventDefault(); |
| 675 |
this.redo(); |
| 676 |
return; |
| 677 |
} |
| 678 |
} |
| 679 |
this.inherited(arguments); |
| 680 |
|
| 681 |
switch(k){ |
| 682 |
case keys.ENTER: |
| 683 |
case keys.BACKSPACE: |
| 684 |
case keys.DELETE: |
| 685 |
this.beginEditing(); |
| 686 |
break; |
| 687 |
case 88: |
| 688 |
case 86: |
| 689 |
if(e.ctrlKey && !e.altKey && !e.metaKey){ |
| 690 |
this.endEditing(); |
| 691 |
if(e.keyCode == 88){ |
| 692 |
this.beginEditing('cut'); |
| 693 |
}else{ |
| 694 |
this.beginEditing('paste'); |
| 695 |
} |
| 696 |
|
| 697 |
this.defer("endEditing", 1); |
| 698 |
break; |
| 699 |
} |
| 700 |
|
| 701 |
default: |
| 702 |
if(!e.ctrlKey && !e.altKey && !e.metaKey && (e.keyCode < keys.F1 || e.keyCode > keys.F15)){ |
| 703 |
this.beginEditing(); |
| 704 |
break; |
| 705 |
} |
| 706 |
|
| 707 |
case keys.ALT: |
| 708 |
this.endEditing(); |
| 709 |
break; |
| 710 |
case keys.UP_ARROW: |
| 711 |
case keys.DOWN_ARROW: |
| 712 |
case keys.LEFT_ARROW: |
| 713 |
case keys.RIGHT_ARROW: |
| 714 |
case keys.HOME: |
| 715 |
case keys.END: |
| 716 |
case keys.PAGE_UP: |
| 717 |
case keys.PAGE_DOWN: |
| 718 |
this.endEditing(true); |
| 719 |
break; |
| 720 |
|
| 721 |
case keys.CTRL: |
| 722 |
case keys.SHIFT: |
| 723 |
case keys.TAB: |
| 724 |
break; |
| 725 |
} |
| 726 |
}, |
| 727 |
_onBlur: function(){ |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
this.inherited(arguments); |
| 735 |
this.endEditing(true); |
| 736 |
}, |
| 737 |
_saveSelection: function(){ |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
try{ |
| 743 |
this._savedSelection = this._getBookmark(); |
| 744 |
}catch(e){ |
| 745 |
} |
| 746 |
}, |
| 747 |
_restoreSelection: function(){ |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
if(this._savedSelection){ |
| 754 |
|
| 755 |
delete this._cursorToStart; |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
if(this.selection.isCollapsed()){ |
| 760 |
this._moveToBookmark(this._savedSelection); |
| 761 |
} |
| 762 |
delete this._savedSelection; |
| 763 |
} |
| 764 |
}, |
| 765 |
|
| 766 |
onClick: function(){ |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
this.endEditing(true); |
| 772 |
this.inherited(arguments); |
| 773 |
}, |
| 774 |
|
| 775 |
replaceValue: function( html){ |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
if(!this.customUndo){ |
| 781 |
this.inherited(arguments); |
| 782 |
}else{ |
| 783 |
if(this.isClosed){ |
| 784 |
this.setValue(html); |
| 785 |
}else{ |
| 786 |
this.beginEditing(); |
| 787 |
if(!html){ |
| 788 |
html = " "; |
| 789 |
} |
| 790 |
this.setValue(html); |
| 791 |
this.endEditing(); |
| 792 |
} |
| 793 |
} |
| 794 |
}, |
| 795 |
|
| 796 |
_setDisabledAttr: function( value){ |
| 797 |
this.setValueDeferred.then(lang.hitch(this, function(){ |
| 798 |
if((!this.disabled && value) || (!this._buttonEnabledPlugins && value)){ |
| 799 |
|
| 800 |
array.forEach(this._plugins, function(p){ |
| 801 |
p.set("disabled", true); |
| 802 |
}); |
| 803 |
}else if(this.disabled && !value){ |
| 804 |
|
| 805 |
array.forEach(this._plugins, function(p){ |
| 806 |
p.set("disabled", false); |
| 807 |
}); |
| 808 |
} |
| 809 |
})); |
| 810 |
this.inherited(arguments); |
| 811 |
}, |
| 812 |
|
| 813 |
_setStateClass: function(){ |
| 814 |
try{ |
| 815 |
this.inherited(arguments); |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
if(this.document && this.document.body){ |
| 821 |
domStyle.set(this.document.body, "color", domStyle.get(this.iframe, "color")); |
| 822 |
domStyle.set(this.document.body, "background-color", domStyle.get(this.iframe, "background-color")); |
| 823 |
} |
| 824 |
}catch(e){ |
| 825 |
} |
| 826 |
} |
| 827 |
}); |
| 828 |
|
| 829 |
|
| 830 |
function simplePluginFactory(args){ |
| 831 |
return new _Plugin({ command: args.name }); |
| 832 |
} |
| 833 |
|
| 834 |
function togglePluginFactory(args){ |
| 835 |
return new _Plugin({ buttonClass: ToggleButton, command: args.name }); |
| 836 |
} |
| 837 |
|
| 838 |
lang.mixin(_Plugin.registry, { |
| 839 |
"undo": simplePluginFactory, |
| 840 |
"redo": simplePluginFactory, |
| 841 |
"cut": simplePluginFactory, |
| 842 |
"copy": simplePluginFactory, |
| 843 |
"paste": simplePluginFactory, |
| 844 |
"insertOrderedList": simplePluginFactory, |
| 845 |
"insertUnorderedList": simplePluginFactory, |
| 846 |
"indent": simplePluginFactory, |
| 847 |
"outdent": simplePluginFactory, |
| 848 |
"justifyCenter": simplePluginFactory, |
| 849 |
"justifyFull": simplePluginFactory, |
| 850 |
"justifyLeft": simplePluginFactory, |
| 851 |
"justifyRight": simplePluginFactory, |
| 852 |
"delete": simplePluginFactory, |
| 853 |
"selectAll": simplePluginFactory, |
| 854 |
"removeFormat": simplePluginFactory, |
| 855 |
"unlink": simplePluginFactory, |
| 856 |
"insertHorizontalRule": simplePluginFactory, |
| 857 |
|
| 858 |
"bold": togglePluginFactory, |
| 859 |
"italic": togglePluginFactory, |
| 860 |
"underline": togglePluginFactory, |
| 861 |
"strikethrough": togglePluginFactory, |
| 862 |
"subscript": togglePluginFactory, |
| 863 |
"superscript": togglePluginFactory, |
| 864 |
|
| 865 |
"|": function(){ |
| 866 |
return new _Plugin({ |
| 867 |
setEditor: function(editor){ |
| 868 |
this.editor = editor; |
| 869 |
this.button = new ToolbarSeparator({ownerDocument: editor.ownerDocument}); |
| 870 |
} |
| 871 |
}); |
| 872 |
} |
| 873 |
}); |
| 874 |
|
| 875 |
return Editor; |
| 876 |
}); |