| 1 |
define([ |
| 2 |
"dojo", |
| 3 |
"dijit", |
| 4 |
"dojo/io/script", |
| 5 |
"dijit/popup", |
| 6 |
"dijit/_Widget", |
| 7 |
"dijit/_Templated", |
| 8 |
"dijit/_editor/_Plugin", |
| 9 |
"dijit/form/TextBox", |
| 10 |
"dijit/form/DropDownButton", |
| 11 |
"dijit/TooltipDialog", |
| 12 |
"dijit/form/MultiSelect", |
| 13 |
"dijit/Menu", |
| 14 |
"dojo/i18n!dojox/editor/plugins/nls/SpellCheck" |
| 15 |
], function(dojo, dijit, script, popup, _Widget, _Templated, _Plugin){ |
| 16 |
|
| 17 |
dojo.experimental("dojox.editor.plugins.SpellCheck"); |
| 18 |
|
| 19 |
var SpellCheckControl = dojo.declare("dojox.editor.plugins._spellCheckControl", [_Widget, _Templated], { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
widgetsInTemplate: true, |
| 24 |
|
| 25 |
templateString: |
| 26 |
"<table role='presentation' class='dijitEditorSpellCheckTable'>" + |
| 27 |
"<tr><td colspan='3' class='alignBottom'><label for='${textId}' id='${textId}_label'>${unfound}</label>" + |
| 28 |
"<div class='dijitEditorSpellCheckBusyIcon' id='${id}_progressIcon'></div></td></tr>" + |
| 29 |
"<tr>" + |
| 30 |
"<td class='dijitEditorSpellCheckBox'><input dojoType='dijit.form.TextBox' required='false' intermediateChanges='true' " + |
| 31 |
"class='dijitEditorSpellCheckBox' dojoAttachPoint='unfoundTextBox' id='${textId}'/></td>" + |
| 32 |
"<td><button dojoType='dijit.form.Button' class='blockButton' dojoAttachPoint='skipButton'>${skip}</button></td>" + |
| 33 |
"<td><button dojoType='dijit.form.Button' class='blockButton' dojoAttachPoint='skipAllButton'>${skipAll}</button></td>" + |
| 34 |
"</tr>" + |
| 35 |
"<tr>" + |
| 36 |
"<td class='alignBottom'><label for='${selectId}'>${suggestions}</td></label>" + |
| 37 |
"<td colspan='2'><button dojoType='dijit.form.Button' class='blockButton' dojoAttachPoint='toDicButton'>${toDic}</button></td>" + |
| 38 |
"</tr>" + |
| 39 |
"<tr>" + |
| 40 |
"<td>" + |
| 41 |
"<select dojoType='dijit.form.MultiSelect' id='${selectId}' " + |
| 42 |
"class='dijitEditorSpellCheckBox listHeight' dojoAttachPoint='suggestionSelect'></select>" + |
| 43 |
"</td>" + |
| 44 |
"<td colspan='2'>" + |
| 45 |
"<button dojoType='dijit.form.Button' class='blockButton' dojoAttachPoint='replaceButton'>${replace}</button>" + |
| 46 |
"<div class='topMargin'><button dojoType='dijit.form.Button' class='blockButton' " + |
| 47 |
"dojoAttachPoint='replaceAllButton'>${replaceAll}</button><div>" + |
| 48 |
"</td>" + |
| 49 |
"</tr>" + |
| 50 |
"<tr>" + |
| 51 |
"<td><div class='topMargin'><button dojoType='dijit.form.Button' dojoAttachPoint='cancelButton'>${cancel}</button></div></td>" + |
| 52 |
"<td></td>" + |
| 53 |
"<td></td>" + |
| 54 |
"</tr>" + |
| 55 |
"</table>", |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
constructor: function(){ |
| 61 |
|
| 62 |
this.ignoreChange = false; |
| 63 |
|
| 64 |
this.isChanged = false; |
| 65 |
|
| 66 |
this.isOpen = false; |
| 67 |
|
| 68 |
this.closable = true; |
| 69 |
}, |
| 70 |
|
| 71 |
postMixInProperties: function(){ |
| 72 |
this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_")); |
| 73 |
this.textId = this.id + "_textBox"; |
| 74 |
this.selectId = this.id + "_select"; |
| 75 |
}, |
| 76 |
|
| 77 |
postCreate: function(){ |
| 78 |
var select = this.suggestionSelect; |
| 79 |
|
| 80 |
|
| 81 |
dojo.removeAttr(select.domNode, "multiple"); |
| 82 |
select.addItems = function( items){ |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
var _this = this; |
| 90 |
var o = null; |
| 91 |
if(items && items.length > 0){ |
| 92 |
dojo.forEach(items, function(item, i){ |
| 93 |
o = dojo.create("option", {innerHTML: item, value: item}, _this.domNode); |
| 94 |
if(i == 0){ |
| 95 |
o.selected = true; |
| 96 |
} |
| 97 |
}); |
| 98 |
} |
| 99 |
}; |
| 100 |
select.removeItems = function(){ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
dojo.empty(this.domNode); |
| 106 |
}; |
| 107 |
|
| 108 |
select.deselectAll = function(){ |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
this.containerNode.selectedIndex = -1; |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
this.connect(this, "onKeyPress", "_cancel"); |
| 118 |
this.connect(this.unfoundTextBox, "onKeyPress", "_enter"); |
| 119 |
this.connect(this.unfoundTextBox, "onChange", "_unfoundTextBoxChange"); |
| 120 |
this.connect(this.suggestionSelect, "onKeyPress", "_enter"); |
| 121 |
this.connect(this.skipButton, "onClick", "onSkip"); |
| 122 |
this.connect(this.skipAllButton, "onClick", "onSkipAll"); |
| 123 |
this.connect(this.toDicButton, "onClick", "onAddToDic"); |
| 124 |
this.connect(this.replaceButton, "onClick", "onReplace"); |
| 125 |
this.connect(this.replaceAllButton, "onClick", "onReplaceAll"); |
| 126 |
this.connect(this.cancelButton, "onClick", "onCancel"); |
| 127 |
}, |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
onSkip: function(){ |
| 134 |
|
| 135 |
}, |
| 136 |
|
| 137 |
onSkipAll: function(){ |
| 138 |
|
| 139 |
}, |
| 140 |
|
| 141 |
onAddToDic: function(){ |
| 142 |
|
| 143 |
}, |
| 144 |
|
| 145 |
onReplace: function(){ |
| 146 |
|
| 147 |
}, |
| 148 |
|
| 149 |
onReplaceAll: function(){ |
| 150 |
|
| 151 |
}, |
| 152 |
|
| 153 |
onCancel: function(){ |
| 154 |
|
| 155 |
}, |
| 156 |
|
| 157 |
onEnter: function(){ |
| 158 |
|
| 159 |
}, |
| 160 |
|
| 161 |
focus: function(){ |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
this.unfoundTextBox.focus(); |
| 167 |
}, |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
_cancel: function( evt){ |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
if(evt.keyCode == dojo.keys.ESCAPE){ |
| 181 |
this.onCancel(); |
| 182 |
dojo.stopEvent(evt); |
| 183 |
} |
| 184 |
}, |
| 185 |
|
| 186 |
_enter: function( evt){ |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
if(evt.keyCode == dojo.keys.ENTER){ |
| 194 |
this.onEnter(); |
| 195 |
dojo.stopEvent(evt); |
| 196 |
} |
| 197 |
}, |
| 198 |
|
| 199 |
_unfoundTextBoxChange: function(){ |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
var id = this.textId + "_label"; |
| 205 |
if(!this.ignoreChange){ |
| 206 |
dojo.byId(id).innerHTML = this["replaceWith"]; |
| 207 |
this.isChanged = true; |
| 208 |
this.suggestionSelect.deselectAll(); |
| 209 |
}else{ |
| 210 |
dojo.byId(id).innerHTML = this["unfound"]; |
| 211 |
} |
| 212 |
}, |
| 213 |
|
| 214 |
_setUnfoundWordAttr: function( value){ |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
value = value || ""; |
| 222 |
this.unfoundTextBox.set("value", value); |
| 223 |
}, |
| 224 |
|
| 225 |
_getUnfoundWordAttr: function(){ |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
return this.unfoundTextBox.get("value"); |
| 231 |
}, |
| 232 |
|
| 233 |
_setSuggestionListAttr: function( values){ |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
var select = this.suggestionSelect; |
| 241 |
values = values || []; |
| 242 |
select.removeItems(); |
| 243 |
select.addItems(values); |
| 244 |
}, |
| 245 |
|
| 246 |
_getSelectedWordAttr: function(){ |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
var selected = this.suggestionSelect.getSelected(); |
| 254 |
if(selected && selected.length > 0){ |
| 255 |
return selected[0].value; |
| 256 |
}else{ |
| 257 |
return this.unfoundTextBox.get("value"); |
| 258 |
} |
| 259 |
}, |
| 260 |
|
| 261 |
_setDisabledAttr: function( disabled){ |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
this.skipButton.set("disabled", disabled); |
| 267 |
this.skipAllButton.set("disabled", disabled); |
| 268 |
this.toDicButton.set("disabled", disabled); |
| 269 |
this.replaceButton.set("disabled", disabled); |
| 270 |
this.replaceAllButton.set("disabled", disabled); |
| 271 |
}, |
| 272 |
|
| 273 |
_setInProgressAttr: function( show){ |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
var id = this.id + "_progressIcon"; |
| 279 |
dojo.toggleClass(id, "hidden", !show); |
| 280 |
} |
| 281 |
}); |
| 282 |
|
| 283 |
var SpellCheckScriptMultiPart = dojo.declare("dojox.editor.plugins._SpellCheckScriptMultiPart", null, { |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
ACTION_QUERY: "query", |
| 294 |
ACTION_UPDATE: "update", |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
callbackHandle: "callback", |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
maxBufferLength: 100, |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
delimiter: " ", |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
label: "response", |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
_timeout: 30000, |
| 328 |
SEC: 1000, |
| 329 |
|
| 330 |
constructor: function(){ |
| 331 |
|
| 332 |
this.serviceEndPoint = ""; |
| 333 |
|
| 334 |
this._queue = []; |
| 335 |
|
| 336 |
|
| 337 |
this.isWorking = false; |
| 338 |
|
| 339 |
this.exArgs = null; |
| 340 |
|
| 341 |
|
| 342 |
this._counter = 0; |
| 343 |
}, |
| 344 |
|
| 345 |
send: function( content, action){ |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
var _this = this, |
| 356 |
dt = this.delimiter, |
| 357 |
mbl = this.maxBufferLength, |
| 358 |
label = this.label, |
| 359 |
serviceEndPoint = this.serviceEndPoint, |
| 360 |
callbackParamName = this.callbackHandle, |
| 361 |
comms = this.exArgs, |
| 362 |
timeout = this._timeout, |
| 363 |
l = 0, r = 0; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
if(!this._result) { |
| 368 |
this._result = []; |
| 369 |
} |
| 370 |
|
| 371 |
action = action || this.ACTION_QUERY; |
| 372 |
|
| 373 |
var batchSend = function(){ |
| 374 |
var plan = []; |
| 375 |
var plannedSize = 0; |
| 376 |
if(content && content.length > 0){ |
| 377 |
_this.isWorking = true; |
| 378 |
var len = content.length; |
| 379 |
do{ |
| 380 |
l = r + 1; |
| 381 |
if((r += mbl) > len){ |
| 382 |
r = len; |
| 383 |
}else{ |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
while(dt && content.charAt(r) != dt && r <= len){ |
| 388 |
r++; |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
plan.push({l: l, r: r}); |
| 393 |
plannedSize++; |
| 394 |
}while(r < len); |
| 395 |
|
| 396 |
dojo.forEach(plan, function(item, index){ |
| 397 |
var jsonpArgs = { |
| 398 |
url: serviceEndPoint, |
| 399 |
action: action, |
| 400 |
timeout: timeout, |
| 401 |
callbackParamName: callbackParamName, |
| 402 |
handle: function(response, ioArgs){ |
| 403 |
if(++_this._counter <= this.size && !(response instanceof Error) && |
| 404 |
response[label] && dojo.isArray(response[label])){ |
| 405 |
|
| 406 |
var offset = this.offset; |
| 407 |
dojo.forEach(response[label], function(item){ |
| 408 |
item.offset += offset; |
| 409 |
}); |
| 410 |
|
| 411 |
_this._result[this.number]= response[label]; |
| 412 |
} |
| 413 |
if(_this._counter == this.size){ |
| 414 |
_this._finalizeCollection(this.action); |
| 415 |
_this.isWorking = false; |
| 416 |
if(_this._queue.length > 0){ |
| 417 |
|
| 418 |
(_this._queue.shift())(); |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
}; |
| 423 |
jsonpArgs.content = comms ? dojo.mixin(comms, {action: action, content: content.substring(item.l - 1, item.r)}): |
| 424 |
{action: action, content: content.substring(item.l - 1, item.r)}; |
| 425 |
jsonpArgs.size = plannedSize; |
| 426 |
jsonpArgs.number = index; |
| 427 |
jsonpArgs.offset = item.l - 1; |
| 428 |
dojo.io.script.get(jsonpArgs); |
| 429 |
}); |
| 430 |
} |
| 431 |
}; |
| 432 |
|
| 433 |
if(!_this.isWorking){ |
| 434 |
batchSend(); |
| 435 |
}else{ |
| 436 |
_this._queue.push(batchSend); |
| 437 |
} |
| 438 |
}, |
| 439 |
|
| 440 |
_finalizeCollection: function(action){ |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
var result = this._result, |
| 448 |
len = result.length; |
| 449 |
|
| 450 |
for(var i = 0; i < len; i++){ |
| 451 |
var temp = result.shift(); |
| 452 |
result = result.concat(temp); |
| 453 |
} |
| 454 |
if(action == this.ACTION_QUERY){ |
| 455 |
this.onLoad(result); |
| 456 |
} |
| 457 |
this._counter = 0; |
| 458 |
this._result = []; |
| 459 |
}, |
| 460 |
|
| 461 |
onLoad: function( data){ |
| 462 |
|
| 463 |
}, |
| 464 |
|
| 465 |
setWaitingTime: function( seconds){ |
| 466 |
this._timeout = seconds * this.SEC; |
| 467 |
} |
| 468 |
}); |
| 469 |
|
| 470 |
var SpellCheck = dojo.declare("dojox.editor.plugins.SpellCheck", [_Plugin], { |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
url: "", |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
bufferLength: 100, |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
interactive: false, |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
timeout: 30, |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
button: null, |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
_editor: null, |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
exArgs: null, |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
_cursorSpan: |
| 506 |
"<span class=\"cursorPlaceHolder\"></span>", |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
_cursorSelector: |
| 511 |
"cursorPlaceHolder", |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
_incorrectWordsSpan: |
| 516 |
"<span class='incorrectWordPlaceHolder'>${text}</span>", |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
_ignoredIncorrectStyle: |
| 521 |
{"cursor": "inherit", "borderBottom": "none", "backgroundColor": "transparent"}, |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
_normalIncorrectStyle: |
| 526 |
{"cursor": "pointer", "borderBottom": "1px dotted red", "backgroundColor": "yellow"}, |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
_highlightedIncorrectStyle: |
| 531 |
{"borderBottom": "1px dotted red", "backgroundColor": "#b3b3ff"}, |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
_selector: "incorrectWordPlaceHolder", |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
_maxItemNumber: 3, |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
constructor: function(){ |
| 546 |
|
| 547 |
|
| 548 |
this._spanList = []; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
this._cache = {}; |
| 555 |
|
| 556 |
this._enabled = true; |
| 557 |
|
| 558 |
this._iterator = 0; |
| 559 |
}, |
| 560 |
|
| 561 |
setEditor: function( editor){ |
| 562 |
this._editor = editor; |
| 563 |
this._initButton(); |
| 564 |
this._setNetwork(); |
| 565 |
this._connectUp(); |
| 566 |
}, |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
_initButton: function(){ |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
var _this = this, |
| 578 |
strings = (this._strings = dojo.i18n.getLocalization("dojox.editor.plugins", "SpellCheck")), |
| 579 |
dialogPane = (this._dialog = new dijit.TooltipDialog()); |
| 580 |
|
| 581 |
dialogPane.set("content", (this._dialogContent = new SpellCheckControl({ |
| 582 |
unfound: strings["unfound"], |
| 583 |
skip: strings["skip"], |
| 584 |
skipAll: strings["skipAll"], |
| 585 |
toDic: strings["toDic"], |
| 586 |
suggestions: strings["suggestions"], |
| 587 |
replaceWith: strings["replaceWith"], |
| 588 |
replace: strings["replace"], |
| 589 |
replaceAll: strings["replaceAll"], |
| 590 |
cancel: strings["cancel"] |
| 591 |
}))); |
| 592 |
|
| 593 |
this.button = new dijit.form.DropDownButton({ |
| 594 |
label: strings["widgetLabel"], |
| 595 |
showLabel: false, |
| 596 |
iconClass: "dijitEditorSpellCheckIcon", |
| 597 |
dropDown: dialogPane, |
| 598 |
id: dijit.getUniqueId(this.declaredClass.replace(/\./g,"_")) + "_dialogPane", |
| 599 |
closeDropDown: function(focus){ |
| 600 |
|
| 601 |
if(_this._dialogContent.closable){ |
| 602 |
_this._dialogContent.isOpen = false; |
| 603 |
if(dojo.isIE){ |
| 604 |
var pos = _this._iterator, |
| 605 |
list = _this._spanList; |
| 606 |
if(pos < list.length && pos >=0 ){ |
| 607 |
dojo.style(list[pos], _this._normalIncorrectStyle); |
| 608 |
} |
| 609 |
} |
| 610 |
if(this._opened){ |
| 611 |
popup.close(this.dropDown); |
| 612 |
if(focus){ this.focus(); } |
| 613 |
this._opened = false; |
| 614 |
this.state = ""; |
| 615 |
} |
| 616 |
} |
| 617 |
} |
| 618 |
}); |
| 619 |
_this._dialogContent.isOpen = false; |
| 620 |
|
| 621 |
dialogPane.domNode.setAttribute("aria-label", this._strings["widgetLabel"]); |
| 622 |
}, |
| 623 |
|
| 624 |
_setNetwork: function(){ |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
var comms = this.exArgs; |
| 630 |
|
| 631 |
if(!this._service){ |
| 632 |
var service = (this._service = new SpellCheckScriptMultiPart()); |
| 633 |
service.serviceEndPoint = this.url; |
| 634 |
service.maxBufferLength = this.bufferLength; |
| 635 |
service.setWaitingTime(this.timeout); |
| 636 |
|
| 637 |
if(comms){ |
| 638 |
delete comms.name; |
| 639 |
delete comms.url; |
| 640 |
delete comms.interactive; |
| 641 |
delete comms.timeout; |
| 642 |
service.exArgs = comms; |
| 643 |
} |
| 644 |
} |
| 645 |
}, |
| 646 |
|
| 647 |
_connectUp: function(){ |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
var editor = this._editor, |
| 653 |
cont = this._dialogContent; |
| 654 |
|
| 655 |
this.connect(this.button, "set", "_disabled"); |
| 656 |
this.connect(this._service, "onLoad", "_loadData"); |
| 657 |
this.connect(this._dialog, "onOpen", "_openDialog"); |
| 658 |
this.connect(editor, "onKeyPress", "_keyPress"); |
| 659 |
this.connect(editor, "onLoad", "_submitContent"); |
| 660 |
this.connect(cont, "onSkip", "_skip"); |
| 661 |
this.connect(cont, "onSkipAll", "_skipAll"); |
| 662 |
this.connect(cont, "onAddToDic", "_add"); |
| 663 |
this.connect(cont, "onReplace", "_replace"); |
| 664 |
this.connect(cont, "onReplaceAll", "_replaceAll"); |
| 665 |
this.connect(cont, "onCancel", "_cancel"); |
| 666 |
this.connect(cont, "onEnter", "_enter"); |
| 667 |
|
| 668 |
editor.contentPostFilters.push(this._spellCheckFilter); |
| 669 |
dojo.publish(dijit._scopeName + ".Editor.plugin.SpellCheck.getParser", [this]); |
| 670 |
if(!this.parser){ |
| 671 |
console.error("Can not get the word parser!"); |
| 672 |
} |
| 673 |
}, |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
_disabled: function(name, disabled){ |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
if(name == "disabled"){ |
| 690 |
if(disabled){ |
| 691 |
this._iterator = 0; |
| 692 |
this._spanList = []; |
| 693 |
}else if(this.interactive && !disabled && this._service){ |
| 694 |
this._submitContent(true); |
| 695 |
} |
| 696 |
this._enabled = !disabled; |
| 697 |
} |
| 698 |
}, |
| 699 |
|
| 700 |
_keyPress: function(evt){ |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
if(this.interactive){ |
| 706 |
var v = 118, V = 86, |
| 707 |
cc = evt.charCode; |
| 708 |
if(!evt.altKey && cc == dojo.keys.SPACE){ |
| 709 |
this._submitContent(); |
| 710 |
}else if((evt.ctrlKey && (cc == v || cc == V)) || (!evt.ctrlKey && evt.charCode)){ |
| 711 |
this._submitContent(true); |
| 712 |
} |
| 713 |
} |
| 714 |
}, |
| 715 |
|
| 716 |
_loadData: function( data){ |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
var cache = this._cache, |
| 724 |
html = this._editor.get("value"), |
| 725 |
cont = this._dialogContent; |
| 726 |
|
| 727 |
this._iterator = 0; |
| 728 |
|
| 729 |
|
| 730 |
dojo.forEach(data, function(d){ |
| 731 |
cache[d.text] = d.suggestion; |
| 732 |
cache[d.text].correct = false; |
| 733 |
}); |
| 734 |
|
| 735 |
if(this._enabled){ |
| 736 |
|
| 737 |
cont.closable = false; |
| 738 |
this._markIncorrectWords(html, cache); |
| 739 |
cont.closable = true; |
| 740 |
|
| 741 |
if(this._dialogContent.isOpen){ |
| 742 |
this._iterator = -1; |
| 743 |
this._skip(); |
| 744 |
} |
| 745 |
} |
| 746 |
}, |
| 747 |
|
| 748 |
_openDialog: function(){ |
| 749 |
|
| 750 |
|
| 751 |
var cont = this._dialogContent; |
| 752 |
|
| 753 |
|
| 754 |
cont.ignoreChange = true; |
| 755 |
cont.set("unfoundWord", ""); |
| 756 |
cont.set("suggestionList", null); |
| 757 |
cont.set("disabled", true); |
| 758 |
cont.set("inProgress", true); |
| 759 |
|
| 760 |
cont.isOpen = true; |
| 761 |
cont.closable = false; |
| 762 |
|
| 763 |
this._submitContent(); |
| 764 |
|
| 765 |
cont.closable = true; |
| 766 |
}, |
| 767 |
|
| 768 |
_skip: function( evt, noUpdate){ |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
var cont = this._dialogContent, |
| 778 |
list = this._spanList || [], |
| 779 |
len = list.length, |
| 780 |
iter = this._iterator; |
| 781 |
|
| 782 |
cont.closable = false; |
| 783 |
cont.isChanged = false; |
| 784 |
cont.ignoreChange = true; |
| 785 |
|
| 786 |
|
| 787 |
if(!noUpdate && iter >= 0 && iter < len){ |
| 788 |
this._skipWord(iter); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
while(++iter < len && list[iter].edited == true){ } |
| 793 |
if(iter < len){ |
| 794 |
this._iterator = iter; |
| 795 |
this._populateDialog(iter); |
| 796 |
this._selectWord(iter); |
| 797 |
}else{ |
| 798 |
|
| 799 |
this._iterator = -1; |
| 800 |
cont.set("unfoundWord", this._strings["msg"]); |
| 801 |
cont.set("suggestionList", null); |
| 802 |
cont.set("disabled", true); |
| 803 |
cont.set("inProgress", false); |
| 804 |
} |
| 805 |
|
| 806 |
setTimeout(function(){ |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
if(dojo.isWebKit) { cont.skipButton.focus(); } |
| 811 |
cont.focus(); |
| 812 |
cont.ignoreChange = false; |
| 813 |
cont.closable = true; |
| 814 |
}, 0); |
| 815 |
}, |
| 816 |
|
| 817 |
_skipAll: function(){ |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
this._dialogContent.closable = false; |
| 823 |
this._skipWordAll(this._iterator); |
| 824 |
this._skip(); |
| 825 |
}, |
| 826 |
|
| 827 |
_add: function(){ |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
var cont = this._dialogContent; |
| 833 |
|
| 834 |
cont.closable = false; |
| 835 |
cont.isOpen = true; |
| 836 |
this._addWord(this._iterator, cont.get("unfoundWord")); |
| 837 |
this._skip(); |
| 838 |
}, |
| 839 |
|
| 840 |
_replace: function(){ |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
var cont = this._dialogContent, |
| 847 |
iter = this._iterator, |
| 848 |
targetWord = cont.get("selectedWord"); |
| 849 |
|
| 850 |
cont.closable = false; |
| 851 |
this._replaceWord(iter, targetWord); |
| 852 |
this._skip(null, true); |
| 853 |
}, |
| 854 |
|
| 855 |
_replaceAll: function(){ |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
var cont = this._dialogContent, |
| 861 |
list = this._spanList, |
| 862 |
len = list.length, |
| 863 |
word = list[this._iterator].innerHTML.toLowerCase(), |
| 864 |
targetWord = cont.get("selectedWord"); |
| 865 |
|
| 866 |
cont.closable = false; |
| 867 |
for(var iter = 0; iter < len; iter++){ |
| 868 |
|
| 869 |
|
| 870 |
if(list[iter].innerHTML.toLowerCase() == word){ |
| 871 |
this._replaceWord(iter, targetWord); |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
this._skip(null, true); |
| 876 |
}, |
| 877 |
|
| 878 |
_cancel: function(){ |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
this._dialogContent.closable = true; |
| 884 |
this._editor.focus(); |
| 885 |
}, |
| 886 |
|
| 887 |
_enter: function(){ |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
if(this._dialogContent.isChanged){ |
| 893 |
this._replace(); |
| 894 |
}else{ |
| 895 |
this._skip(); |
| 896 |
} |
| 897 |
}, |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
_query: function( html){ |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
var service = this._service, |
| 912 |
cache = this._cache, |
| 913 |
words = this.parser.parseIntoWords(this._html2Text(html)) || []; |
| 914 |
var content = []; |
| 915 |
dojo.forEach(words, function(word){ |
| 916 |
word = word.toLowerCase(); |
| 917 |
if(!cache[word]){ |
| 918 |
|
| 919 |
cache[word] = []; |
| 920 |
cache[word].correct = true; |
| 921 |
content.push(word); |
| 922 |
} |
| 923 |
}); |
| 924 |
if(content.length > 0){ |
| 925 |
service.send(content.join(" ")); |
| 926 |
}else if(!service.isWorking){ |
| 927 |
this._loadData([]); |
| 928 |
} |
| 929 |
}, |
| 930 |
|
| 931 |
_html2Text: function(html){ |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
var text = [], |
| 942 |
isTag = false, |
| 943 |
len = html ? html.length : 0; |
| 944 |
|
| 945 |
for(var i = 0; i < len; i++){ |
| 946 |
if(html.charAt(i) == "<"){ isTag = true; } |
| 947 |
if(isTag == true){ |
| 948 |
text.push(" "); |
| 949 |
}else{ |
| 950 |
text.push(html.charAt(i)); |
| 951 |
} |
| 952 |
if(html.charAt(i) == ">"){ isTag = false; } |
| 953 |
|
| 954 |
} |
| 955 |
return text.join(""); |
| 956 |
}, |
| 957 |
|
| 958 |
_getBookmark: function( eValue){ |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
var ed = this._editor, |
| 967 |
cp = this._cursorSpan; |
| 968 |
ed.execCommand("inserthtml", cp); |
| 969 |
var nv = ed.get("value"), |
| 970 |
index = nv.indexOf(cp), |
| 971 |
i = -1; |
| 972 |
while(++i < index && eValue.charAt(i) == nv.charAt(i)){ } |
| 973 |
return i; |
| 974 |
}, |
| 975 |
|
| 976 |
_moveToBookmark: function(){ |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
var ed = this._editor, |
| 982 |
cps = dojo.query("." + this._cursorSelector, ed.document), |
| 983 |
cursorSpan = cps && cps[0]; |
| 984 |
|
| 985 |
if(cursorSpan){ |
| 986 |
ed._sCall("selectElement", [cursorSpan]); |
| 987 |
ed._sCall("collapse", [true]); |
| 988 |
var parent = cursorSpan.parentNode; |
| 989 |
if(parent){ parent.removeChild(cursorSpan); } |
| 990 |
} |
| 991 |
}, |
| 992 |
|
| 993 |
_submitContent: function( delay){ |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
if(delay){ |
| 1001 |
var _this = this, |
| 1002 |
interval = 3000; |
| 1003 |
if(this._delayHandler){ |
| 1004 |
clearTimeout(this._delayHandler); |
| 1005 |
this._delayHandler = null; |
| 1006 |
} |
| 1007 |
setTimeout(function(){ _this._query(_this._editor.get("value")); }, interval); |
| 1008 |
}else{ |
| 1009 |
this._query(this._editor.get("value")); |
| 1010 |
} |
| 1011 |
}, |
| 1012 |
|
| 1013 |
_populateDialog: function(index){ |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
var list = this._spanList, |
| 1021 |
cache = this._cache, |
| 1022 |
cont = this._dialogContent; |
| 1023 |
|
| 1024 |
cont.set("disabled", false); |
| 1025 |
if(index < list.length && list.length > 0){ |
| 1026 |
var word = list[index].innerHTML; |
| 1027 |
cont.set("unfoundWord", word); |
| 1028 |
cont.set("suggestionList", cache[word.toLowerCase()]); |
| 1029 |
cont.set("inProgress", false); |
| 1030 |
} |
| 1031 |
}, |
| 1032 |
|
| 1033 |
_markIncorrectWords: function( html, cache){ |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
var _this = this, |
| 1043 |
parser = this.parser, |
| 1044 |
editor = this._editor, |
| 1045 |
spanString = this._incorrectWordsSpan, |
| 1046 |
nstyle = this._normalIncorrectStyle, |
| 1047 |
selector = this._selector, |
| 1048 |
words = parser.parseIntoWords(this._html2Text(html).toLowerCase()), |
| 1049 |
indices = parser.getIndices(), |
| 1050 |
bookmark = this._cursorSpan, |
| 1051 |
bmpos = this._getBookmark(html), |
| 1052 |
spanOffset = "<span class='incorrectWordPlaceHolder'>".length, |
| 1053 |
bmMarked = false, |
| 1054 |
cArray = html.split(""), |
| 1055 |
spanList = null; |
| 1056 |
|
| 1057 |
|
| 1058 |
for(var i = words.length - 1; i >= 0; i--){ |
| 1059 |
var word = words[i]; |
| 1060 |
if(cache[word] && !cache[word].correct){ |
| 1061 |
var offset = indices[i], |
| 1062 |
len = words[i].length, |
| 1063 |
end = offset + len; |
| 1064 |
if(end <= bmpos && !bmMarked){ |
| 1065 |
cArray.splice(bmpos, 0, bookmark); |
| 1066 |
bmMarked = true; |
| 1067 |
} |
| 1068 |
cArray.splice(offset, len, dojo.string.substitute(spanString, {text: html.substring(offset, end)})); |
| 1069 |
if(offset < bmpos && bmpos < end && !bmMarked){ |
| 1070 |
var tmp = cArray[offset].split(""); |
| 1071 |
tmp.splice(spanOffset + bmpos - offset, 0, bookmark); |
| 1072 |
cArray[offset] = tmp.join(""); |
| 1073 |
bmMarked = true; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
} |
| 1077 |
if(!bmMarked){ |
| 1078 |
cArray.splice(bmpos, 0, bookmark); |
| 1079 |
bmMarked = true; |
| 1080 |
} |
| 1081 |
|
| 1082 |
editor.set("value", cArray.join("")); |
| 1083 |
editor._cursorToStart = false; |
| 1084 |
|
| 1085 |
this._moveToBookmark(); |
| 1086 |
|
| 1087 |
|
| 1088 |
spanList = this._spanList = dojo.query("." + this._selector, editor.document); |
| 1089 |
spanList.forEach(function(span, i){ span.id = selector + i; }); |
| 1090 |
|
| 1091 |
|
| 1092 |
if(!this.interactive){ delete nstyle.cursor; } |
| 1093 |
spanList.style(nstyle); |
| 1094 |
|
| 1095 |
if(this.interactive){ |
| 1096 |
|
| 1097 |
if(_this._contextMenu){ |
| 1098 |
_this._contextMenu.uninitialize(); |
| 1099 |
_this._contextMenu = null; |
| 1100 |
} |
| 1101 |
_this._contextMenu = new dijit.Menu({ |
| 1102 |
targetNodeIds: [editor.iframe], |
| 1103 |
|
| 1104 |
bindDomNode: function( node){ |
| 1105 |
|
| 1106 |
|
| 1107 |
node = dojo.byId(node); |
| 1108 |
|
| 1109 |
var cn; |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
var iframe, win; |
| 1114 |
if(node.tagName.toLowerCase() == "iframe"){ |
| 1115 |
iframe = node; |
| 1116 |
win = this._iframeContentWindow(iframe); |
| 1117 |
cn = dojo.body(editor.document) |
| 1118 |
}else{ |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
cn = (node == dojo.body() ? dojo.doc.documentElement : node); |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
var binding = { |
| 1128 |
node: node, |
| 1129 |
iframe: iframe |
| 1130 |
}; |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
dojo.attr(node, "_dijitMenu" + this.id, this._bindings.push(binding)); |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
var doConnects = dojo.hitch(this, function(cn){ |
| 1142 |
return [ |
| 1143 |
|
| 1144 |
|
| 1145 |
dojo.connect(cn, this.leftClickToOpen ? "onclick" : "oncontextmenu", this, function(evt){ |
| 1146 |
var target = evt.target, |
| 1147 |
strings = _this._strings; |
| 1148 |
|
| 1149 |
if(dojo.hasClass(target, selector) && !target.edited){ |
| 1150 |
dojo.stopEvent(evt); |
| 1151 |
|
| 1152 |
|
| 1153 |
var maxNumber = _this._maxItemNumber, |
| 1154 |
id = target.id, |
| 1155 |
index = id.substring(selector.length), |
| 1156 |
suggestions = cache[target.innerHTML.toLowerCase()], |
| 1157 |
slen = suggestions.length; |
| 1158 |
|
| 1159 |
|
| 1160 |
this.destroyDescendants(); |
| 1161 |
if(slen == 0){ |
| 1162 |
this.addChild(new dijit.MenuItem({ |
| 1163 |
label: strings["iMsg"], |
| 1164 |
disabled: true |
| 1165 |
})); |
| 1166 |
}else{ |
| 1167 |
for(var i = 0 ; i < maxNumber && i < slen; i++){ |
| 1168 |
this.addChild(new dijit.MenuItem({ |
| 1169 |
label: suggestions[i], |
| 1170 |
onClick: (function(){ |
| 1171 |
var idx = index, txt = suggestions[i]; |
| 1172 |
return function(){ |
| 1173 |
_this._replaceWord(idx, txt); |
| 1174 |
editor.focus(); |
| 1175 |
}; |
| 1176 |
})() |
| 1177 |
})); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
this.addChild(new dijit.MenuSeparator()); |
| 1183 |
this.addChild(new dijit.MenuItem({ |
| 1184 |
label: strings["iSkip"], |
| 1185 |
onClick: function(){ |
| 1186 |
_this._skipWord(index); |
| 1187 |
editor.focus(); |
| 1188 |
} |
| 1189 |
})); |
| 1190 |
this.addChild(new dijit.MenuItem({ |
| 1191 |
label: strings["iSkipAll"], |
| 1192 |
onClick: function(){ |
| 1193 |
_this._skipWordAll(index); |
| 1194 |
editor.focus(); |
| 1195 |
} |
| 1196 |
})); |
| 1197 |
this.addChild(new dijit.MenuSeparator()); |
| 1198 |
this.addChild(new dijit.MenuItem({ |
| 1199 |
label: strings["toDic"], |
| 1200 |
onClick: function(){ |
| 1201 |
_this._addWord(index); |
| 1202 |
editor.focus(); |
| 1203 |
} |
| 1204 |
})); |
| 1205 |
|
| 1206 |
this._scheduleOpen(target, iframe, {x: evt.pageX, y: evt.pageY}); |
| 1207 |
} |
| 1208 |
}), |
| 1209 |
dojo.connect(cn, "onkeydown", this, function(evt){ |
| 1210 |
if(evt.shiftKey && evt.keyCode == dojo.keys.F10){ |
| 1211 |
dojo.stopEvent(evt); |
| 1212 |
this._scheduleOpen(evt.target, iframe); |
| 1213 |
} |
| 1214 |
}) |
| 1215 |
]; |
| 1216 |
}); |
| 1217 |
binding.connects = cn ? doConnects(cn) : []; |
| 1218 |
|
| 1219 |
if(iframe){ |
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
binding.onloadHandler = dojo.hitch(this, function(){ |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
var win = this._iframeContentWindow(iframe), |
| 1230 |
cn = dojo.body(editor.document); |
| 1231 |
binding.connects = doConnects(cn); |
| 1232 |
}); |
| 1233 |
if(iframe.addEventListener){ |
| 1234 |
iframe.addEventListener("load", binding.onloadHandler, false); |
| 1235 |
}else{ |
| 1236 |
iframe.attachEvent("onload", binding.onloadHandler); |
| 1237 |
} |
| 1238 |
} |
| 1239 |
} |
| 1240 |
}); |
| 1241 |
} |
| 1242 |
}, |
| 1243 |
|
| 1244 |
_selectWord: function(index){ |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
var ed = this._editor, |
| 1252 |
list = this._spanList; |
| 1253 |
|
| 1254 |
if(index < list.length && list.length > 0){ |
| 1255 |
ed._sCall("selectElement", [list[index]]); |
| 1256 |
ed._sCall("collapse", [true]); |
| 1257 |
this._findText(list[index].innerHTML, false, false); |
| 1258 |
if(dojo.isIE){ |
| 1259 |
|
| 1260 |
|
| 1261 |
dojo.style(list[index], this._highlightedIncorrectStyle); |
| 1262 |
} |
| 1263 |
} |
| 1264 |
}, |
| 1265 |
|
| 1266 |
_replaceWord: function(index, text){ |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
var list = this._spanList; |
| 1276 |
|
| 1277 |
list[index].innerHTML = text; |
| 1278 |
dojo.style(list[index], this._ignoredIncorrectStyle); |
| 1279 |
list[index].edited = true; |
| 1280 |
}, |
| 1281 |
|
| 1282 |
_skipWord: function(index){ |
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
var list = this._spanList; |
| 1290 |
|
| 1291 |
dojo.style(list[index], this._ignoredIncorrectStyle); |
| 1292 |
this._cache[list[index].innerHTML.toLowerCase()].correct = true; |
| 1293 |
list[index].edited = true; |
| 1294 |
}, |
| 1295 |
|
| 1296 |
_skipWordAll: function(index, word){ |
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
var list = this._spanList, |
| 1308 |
len = list.length; |
| 1309 |
word = word || list[index].innerHTML.toLowerCase(); |
| 1310 |
|
| 1311 |
for(var i = 0; i < len; i++){ |
| 1312 |
if(!list[i].edited && list[i].innerHTML.toLowerCase() == word){ |
| 1313 |
this._skipWord(i); |
| 1314 |
} |
| 1315 |
} |
| 1316 |
}, |
| 1317 |
|
| 1318 |
_addWord: function(index, word){ |
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
var service = this._service; |
| 1329 |
service.send(word || this._spanList[index].innerHTML.toLowerCase(), service.ACTION_UPDATE); |
| 1330 |
this._skipWordAll(index, word); |
| 1331 |
}, |
| 1332 |
|
| 1333 |
_findText: function( txt, caseSensitive, backwards){ |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
var ed = this._editor, |
| 1347 |
win = ed.window, |
| 1348 |
found = false; |
| 1349 |
if(txt){ |
| 1350 |
if(win.find){ |
| 1351 |
found = win.find(txt, caseSensitive, backwards, false, false, false, false); |
| 1352 |
}else{ |
| 1353 |
var doc = ed.document; |
| 1354 |
if(doc.selection){ |
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
this._editor.focus(); |
| 1359 |
var txtRg = doc.body.createTextRange(); |
| 1360 |
var curPos = doc.selection?doc.selection.createRange():null; |
| 1361 |
if(curPos){ |
| 1362 |
if(backwards){ |
| 1363 |
txtRg.setEndPoint("EndToStart", curPos); |
| 1364 |
}else{ |
| 1365 |
txtRg.setEndPoint("StartToEnd", curPos); |
| 1366 |
} |
| 1367 |
} |
| 1368 |
var flags = caseSensitive?4:0; |
| 1369 |
if(backwards){ |
| 1370 |
flags = flags | 1; |
| 1371 |
} |
| 1372 |
|
| 1373 |
found = txtRg.findText(txt,txtRg.text.length,flags); |
| 1374 |
if(found){ |
| 1375 |
txtRg.select(); |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 1379 |
} |
| 1380 |
return found; |
| 1381 |
}, |
| 1382 |
|
| 1383 |
_spellCheckFilter: function( value){ |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
var regText = /<span class=["']incorrectWordPlaceHolder["'].*?>(.*?)<\/span>/g; |
| 1392 |
return value.replace(regText, "$1"); |
| 1393 |
} |
| 1394 |
}); |
| 1395 |
|
| 1396 |
|
| 1397 |
SpellCheck._SpellCheckControl = SpellCheckControl; |
| 1398 |
SpellCheck._SpellCheckScriptMultiPart = SpellCheckScriptMultiPart; |
| 1399 |
|
| 1400 |
|
| 1401 |
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ |
| 1402 |
if(o.plugin){ return; } |
| 1403 |
var name = o.args.name.toLowerCase(); |
| 1404 |
if(name === "spellcheck"){ |
| 1405 |
o.plugin = new SpellCheck({ |
| 1406 |
url: ("url" in o.args) ? o.args.url : "", |
| 1407 |
interactive: ("interactive" in o.args) ? o.args.interactive : false, |
| 1408 |
bufferLength: ("bufferLength" in o.args) ? o.args.bufferLength: 100, |
| 1409 |
timeout: ("timeout" in o.args) ? o.args.timeout : 30, |
| 1410 |
exArgs: o.args |
| 1411 |
}); |
| 1412 |
} |
| 1413 |
}); |
| 1414 |
|
| 1415 |
return SpellCheck; |
| 1416 |
|
| 1417 |
}); |