| 1 |
define([ |
| 2 |
"dojo", |
| 3 |
"dijit", |
| 4 |
"dojox", |
| 5 |
"dijit/_base/manager", |
| 6 |
"dijit/_base/popup", |
| 7 |
"dijit/_Widget", |
| 8 |
"dijit/_TemplatedMixin", |
| 9 |
"dijit/_KeyNavContainer", |
| 10 |
"dijit/_WidgetsInTemplateMixin", |
| 11 |
"dijit/TooltipDialog", |
| 12 |
"dijit/Toolbar", |
| 13 |
"dijit/form/CheckBox", |
| 14 |
"dijit/form/_TextBoxMixin", |
| 15 |
"dijit/form/TextBox", |
| 16 |
"dijit/_editor/_Plugin", |
| 17 |
"dijit/form/Button", |
| 18 |
"dijit/form/DropDownButton", |
| 19 |
"dijit/form/ToggleButton", |
| 20 |
"./ToolbarLineBreak", |
| 21 |
"dojo/_base/connect", |
| 22 |
"dojo/_base/declare", |
| 23 |
"dojo/i18n", |
| 24 |
"dojo/string", |
| 25 |
"dojo/i18n!dojox/editor/plugins/nls/FindReplace" |
| 26 |
], function(dojo, dijit, dojox, manager, popup, |
| 27 |
_Widget, _TemplatedMixin, _KeyNavContainer, _WidgetsInTemplateMixin, TooltipDialog, |
| 28 |
Toolbar, CheckBox, _TextBoxMixin, TextBox, _Plugin) { |
| 29 |
|
| 30 |
dojo.experimental("dojox.editor.plugins.FindReplace"); |
| 31 |
|
| 32 |
var FindReplaceCloseBox = dojo.declare("dojox.editor.plugins._FindReplaceCloseBox", |
| 33 |
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
btnId: "", |
| 39 |
widget: null, |
| 40 |
widgetsInTemplate: true, |
| 41 |
|
| 42 |
templateString: |
| 43 |
"<span style='float: right' class='dijitInline' tabindex='-1'>" + |
| 44 |
"<button class='dijit dijitReset dijitInline' " + |
| 45 |
"id='${btnId}' dojoAttachPoint='button' dojoType='dijit.form.Button' tabindex='-1' iconClass='dijitEditorIconsFindReplaceClose' showLabel='false'>X</button>" + |
| 46 |
"</span>", |
| 47 |
|
| 48 |
postMixInProperties: function(){ |
| 49 |
|
| 50 |
this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_")); |
| 51 |
this.btnId = this.id + "_close"; |
| 52 |
this.inherited(arguments); |
| 53 |
}, |
| 54 |
startup: function(){ |
| 55 |
this.connect(this.button, "onClick", "onClick"); |
| 56 |
}, |
| 57 |
onClick: function(){ |
| 58 |
} |
| 59 |
}); |
| 60 |
|
| 61 |
|
| 62 |
var FindReplaceTextBox = dojo.declare("dojox.editor.plugins._FindReplaceTextBox", |
| 63 |
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],{ |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
textId: "", |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
label: "", |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
toolTip: "", |
| 80 |
widget: null, |
| 81 |
widgetsInTemplate: true, |
| 82 |
|
| 83 |
templateString: |
| 84 |
"<span style='white-space: nowrap' class='dijit dijitReset dijitInline dijitEditorFindReplaceTextBox' " + |
| 85 |
"title='${tooltip}' tabindex='-1'>" + |
| 86 |
"<label class='dijitLeft dijitInline' for='${textId}' tabindex='-1'>${label}</label>" + |
| 87 |
"<input dojoType='dijit.form.TextBox' intermediateChanges='true' class='focusTextBox' " + |
| 88 |
"tabIndex='0' id='${textId}' dojoAttachPoint='textBox, focusNode' value='' dojoAttachEvent='onKeyPress: _onKeyPress'/>" + |
| 89 |
"</span>", |
| 90 |
|
| 91 |
postMixInProperties: function(){ |
| 92 |
|
| 93 |
this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_")); |
| 94 |
this.textId = this.id + "_text"; |
| 95 |
|
| 96 |
this.inherited(arguments); |
| 97 |
}, |
| 98 |
|
| 99 |
postCreate: function(){ |
| 100 |
this.textBox.set("value", ""); |
| 101 |
this.disabled = this.textBox.get("disabled"); |
| 102 |
this.connect(this.textBox, "onChange", "onChange"); |
| 103 |
dojo.attr(this.textBox.textbox, "formnovalidate", "true"); |
| 104 |
}, |
| 105 |
|
| 106 |
_setValueAttr: function( value){ |
| 107 |
|
| 108 |
this.value = value; |
| 109 |
this.textBox.set("value", value); |
| 110 |
}, |
| 111 |
|
| 112 |
focus: function(){ |
| 113 |
this.textBox.focus(); |
| 114 |
}, |
| 115 |
|
| 116 |
_setDisabledAttr: function( value){ |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
this.disabled = value; |
| 125 |
this.textBox.set("disabled", value); |
| 126 |
}, |
| 127 |
|
| 128 |
onChange: function( val){ |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
this.value= val; |
| 134 |
}, |
| 135 |
|
| 136 |
_onKeyPress: function( evt){ |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
var start = 0; |
| 144 |
var end = 0; |
| 145 |
|
| 146 |
|
| 147 |
if(evt.target && !evt.ctrlKey && !evt.altKey && !evt.shiftKey){ |
| 148 |
if(evt.keyCode == dojo.keys.LEFT_ARROW){ |
| 149 |
start = evt.target.selectionStart; |
| 150 |
end = evt.target.selectionEnd; |
| 151 |
if(start < end){ |
| 152 |
dijit.selectInputText(evt.target, start, start); |
| 153 |
dojo.stopEvent(evt); |
| 154 |
} |
| 155 |
}else if(evt.keyCode == dojo.keys.RIGHT_ARROW){ |
| 156 |
start = evt.target.selectionStart; |
| 157 |
end = evt.target.selectionEnd; |
| 158 |
if(start < end){ |
| 159 |
dijit.selectInputText(evt.target, end, end); |
| 160 |
dojo.stopEvent(evt); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
}); |
| 166 |
|
| 167 |
|
| 168 |
var FindReplaceCheckBox = dojo.declare("dojox.editor.plugins._FindReplaceCheckBox", |
| 169 |
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin],{ |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
checkId: "", |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
label: "", |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
tooltip: "", |
| 186 |
|
| 187 |
widget: null, |
| 188 |
widgetsInTemplate: true, |
| 189 |
|
| 190 |
templateString: |
| 191 |
"<span style='white-space: nowrap' tabindex='-1' " + |
| 192 |
"class='dijit dijitReset dijitInline dijitEditorFindReplaceCheckBox' title='${tooltip}' >" + |
| 193 |
"<input dojoType='dijit.form.CheckBox' " + |
| 194 |
"tabIndex='0' id='${checkId}' dojoAttachPoint='checkBox, focusNode' value=''/>" + |
| 195 |
"<label tabindex='-1' class='dijitLeft dijitInline' for='${checkId}'>${label}</label>" + |
| 196 |
"</span>", |
| 197 |
|
| 198 |
postMixInProperties: function(){ |
| 199 |
|
| 200 |
this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_")); |
| 201 |
this.checkId = this.id + "_check"; |
| 202 |
this.inherited(arguments); |
| 203 |
}, |
| 204 |
|
| 205 |
postCreate: function(){ |
| 206 |
this.checkBox.set("checked", false); |
| 207 |
this.disabled = this.checkBox.get("disabled"); |
| 208 |
this.checkBox.isFocusable = function(){ return false; }; |
| 209 |
}, |
| 210 |
|
| 211 |
_setValueAttr: function( value){ |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
this.checkBox.set('value', value); |
| 217 |
}, |
| 218 |
|
| 219 |
_getValueAttr: function(){ |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
return this.checkBox.get('value'); |
| 225 |
}, |
| 226 |
|
| 227 |
focus: function(){ |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
this.checkBox.focus(); |
| 233 |
}, |
| 234 |
|
| 235 |
_setDisabledAttr: function( value){ |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
this.disabled = value; |
| 244 |
this.checkBox.set("disabled", value); |
| 245 |
} |
| 246 |
}); |
| 247 |
|
| 248 |
|
| 249 |
var FindReplaceToolbar = dojo.declare("dojox.editor.plugins._FindReplaceToolbar", Toolbar, { |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
postCreate: function(){ |
| 256 |
this.connectKeyNavHandlers([], []); |
| 257 |
this.connect(this.containerNode, "onclick", "_onToolbarEvent"); |
| 258 |
this.connect(this.containerNode, "onkeydown", "_onToolbarEvent"); |
| 259 |
dojo.addClass(this.domNode, "dijitToolbar"); |
| 260 |
}, |
| 261 |
|
| 262 |
addChild: function( widget, insertIndex){ |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
dijit._KeyNavContainer.superclass.addChild.apply(this, arguments); |
| 268 |
}, |
| 269 |
|
| 270 |
_onToolbarEvent: function( evt){ |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
evt.stopPropagation(); |
| 277 |
} |
| 278 |
}); |
| 279 |
|
| 280 |
var FindReplace = dojo.declare("dojox.editor.plugins.FindReplace",[_Plugin],{ |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
buttonClass: dijit.form.ToggleButton, |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
iconClassPrefix: "dijitEditorIconsFindReplace", |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
editor: null, |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
button: null, |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
_frToolbar: null, |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
_closeBox: null, |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
_findField: null, |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
_replaceField: null, |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
_findButton: null, |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
_replaceButton: null, |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
_replaceAllButton: null, |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
_caseSensitive: null, |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
_backwards: null, |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
_promDialog: null, |
| 342 |
_promDialogTimeout: null, |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
_strings: null, |
| 347 |
|
| 348 |
_bookmark: null, |
| 349 |
|
| 350 |
_initButton: function(){ |
| 351 |
|
| 352 |
|
| 353 |
this._strings = dojo.i18n.getLocalization("dojox.editor.plugins", "FindReplace"); |
| 354 |
this.button = new dijit.form.ToggleButton({ |
| 355 |
label: this._strings["findReplace"], |
| 356 |
showLabel: false, |
| 357 |
iconClass: this.iconClassPrefix + " dijitEditorIconFindString", |
| 358 |
tabIndex: "-1", |
| 359 |
onChange: dojo.hitch(this, "_toggleFindReplace") |
| 360 |
}); |
| 361 |
if(dojo.isOpera){ |
| 362 |
|
| 363 |
this.button.set("disabled", true); |
| 364 |
} |
| 365 |
|
| 366 |
this.connect(this.button, "set", dojo.hitch(this, function(attr, val){ |
| 367 |
if(attr === "disabled"){ |
| 368 |
this._toggleFindReplace((!val && this._displayed), true, true); |
| 369 |
} |
| 370 |
})); |
| 371 |
}, |
| 372 |
|
| 373 |
setEditor: function(editor){ |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
this.editor = editor; |
| 378 |
this._initButton(); |
| 379 |
}, |
| 380 |
|
| 381 |
toggle: function(){ |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
this.button.set("checked", !this.button.get("checked")); |
| 387 |
}, |
| 388 |
|
| 389 |
_toggleFindReplace: function( show, ignoreState, buttonDisabled){ |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
var size = dojo.marginBox(this.editor.domNode); |
| 401 |
if(show && !dojo.isOpera){ |
| 402 |
dojo.style(this._frToolbar.domNode, "display", "block"); |
| 403 |
|
| 404 |
this._populateFindField(); |
| 405 |
if(!ignoreState){ |
| 406 |
this._displayed = true; |
| 407 |
} |
| 408 |
}else{ |
| 409 |
dojo.style(this._frToolbar.domNode, "display", "none"); |
| 410 |
if(!ignoreState){ |
| 411 |
this._displayed = false; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
if(!buttonDisabled){ |
| 420 |
this.editor.focus(); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
this.editor.resize({h: size.h}); |
| 426 |
}, |
| 427 |
|
| 428 |
_populateFindField: function(){ |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
var ed = this.editor; |
| 436 |
var win = ed.window; |
| 437 |
var selectedTxt = ed._sCall("getSelectedText", [null]); |
| 438 |
if(this._findField && this._findField.textBox){ |
| 439 |
if(selectedTxt){ |
| 440 |
this._findField.textBox.set("value", selectedTxt); |
| 441 |
} |
| 442 |
this._findField.textBox.focus(); |
| 443 |
dijit.selectInputText(this._findField.textBox.focusNode); |
| 444 |
} |
| 445 |
}, |
| 446 |
|
| 447 |
setToolbar: function( toolbar){ |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
this.inherited(arguments); |
| 455 |
if(!dojo.isOpera){ |
| 456 |
var _tb = (this._frToolbar = new FindReplaceToolbar()); |
| 457 |
dojo.style(_tb.domNode, "display", "none"); |
| 458 |
dojo.place(_tb.domNode, toolbar.domNode, "after"); |
| 459 |
_tb.startup(); |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
this._closeBox = new FindReplaceCloseBox(); |
| 465 |
_tb.addChild(this._closeBox); |
| 466 |
|
| 467 |
|
| 468 |
this._findField = new FindReplaceTextBox( |
| 469 |
{label: this._strings["findLabel"], tooltip: this._strings["findTooltip"]}); |
| 470 |
_tb.addChild(this._findField); |
| 471 |
|
| 472 |
this._replaceField = new FindReplaceTextBox( |
| 473 |
{label: this._strings["replaceLabel"], tooltip: this._strings["replaceTooltip"]}); |
| 474 |
_tb.addChild(this._replaceField); |
| 475 |
|
| 476 |
|
| 477 |
_tb.addChild(new dojox.editor.plugins.ToolbarLineBreak()); |
| 478 |
|
| 479 |
this._findButton = new dijit.form.Button({label: this._strings["findButton"], showLabel: true, |
| 480 |
iconClass: this.iconClassPrefix + " dijitEditorIconFind"}); |
| 481 |
this._findButton.titleNode.title = this._strings["findButtonTooltip"]; |
| 482 |
_tb.addChild(this._findButton); |
| 483 |
|
| 484 |
this._replaceButton = new dijit.form.Button({label: this._strings["replaceButton"], showLabel: true, |
| 485 |
iconClass: this.iconClassPrefix + " dijitEditorIconReplace"}); |
| 486 |
this._replaceButton.titleNode.title = this._strings["replaceButtonTooltip"]; |
| 487 |
_tb.addChild(this._replaceButton); |
| 488 |
|
| 489 |
this._replaceAllButton = new dijit.form.Button({label: this._strings["replaceAllButton"], showLabel: true, |
| 490 |
iconClass: this.iconClassPrefix + " dijitEditorIconReplaceAll"}); |
| 491 |
this._replaceAllButton.titleNode.title = this._strings["replaceAllButtonTooltip"]; |
| 492 |
_tb.addChild(this._replaceAllButton); |
| 493 |
|
| 494 |
|
| 495 |
this._caseSensitive = new FindReplaceCheckBox( |
| 496 |
{label: this._strings["matchCase"], tooltip: this._strings["matchCaseTooltip"]}); |
| 497 |
_tb.addChild(this._caseSensitive); |
| 498 |
|
| 499 |
this._backwards = new FindReplaceCheckBox( |
| 500 |
{label: this._strings["backwards"], tooltip: this._strings["backwardsTooltip"]}); |
| 501 |
_tb.addChild(this._backwards); |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
this._findButton.set("disabled", true); |
| 506 |
this._replaceButton.set("disabled", true); |
| 507 |
this._replaceAllButton.set("disabled", true); |
| 508 |
|
| 509 |
|
| 510 |
this.connect(this._findField, "onChange", "_checkButtons"); |
| 511 |
this.connect(this._findField, "onKeyDown", "_onFindKeyDown"); |
| 512 |
this.connect(this._replaceField, "onKeyDown", "_onReplaceKeyDown"); |
| 513 |
|
| 514 |
|
| 515 |
this.connect(this._findButton, "onClick", "_find"); |
| 516 |
this.connect(this._replaceButton, "onClick", "_replace"); |
| 517 |
this.connect(this._replaceAllButton, "onClick", "_replaceAll"); |
| 518 |
|
| 519 |
|
| 520 |
this.connect(this._closeBox, "onClick", "toggle"); |
| 521 |
|
| 522 |
|
| 523 |
this._promDialog = new dijit.TooltipDialog(); |
| 524 |
this._promDialog.startup(); |
| 525 |
this._promDialog.set("content", ""); |
| 526 |
} |
| 527 |
}, |
| 528 |
|
| 529 |
_checkButtons: function(){ |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
var fText = this._findField.get("value"); |
| 534 |
|
| 535 |
if(fText){ |
| 536 |
|
| 537 |
this._findButton.set("disabled", false); |
| 538 |
this._replaceButton.set("disabled", false); |
| 539 |
this._replaceAllButton.set("disabled", false); |
| 540 |
}else{ |
| 541 |
this._findButton.set("disabled", true); |
| 542 |
this._replaceButton.set("disabled", true); |
| 543 |
this._replaceAllButton.set("disabled", true); |
| 544 |
} |
| 545 |
}, |
| 546 |
|
| 547 |
_onFindKeyDown: function(evt){ |
| 548 |
if(evt.keyCode == dojo.keys.ENTER){ |
| 549 |
|
| 550 |
this._find(); |
| 551 |
dojo.stopEvent(evt); |
| 552 |
} |
| 553 |
}, |
| 554 |
|
| 555 |
_onReplaceKeyDown: function(evt){ |
| 556 |
if(evt.keyCode == dojo.keys.ENTER){ |
| 557 |
|
| 558 |
if(!this._replace()) this._replace(); |
| 559 |
dojo.stopEvent(evt); |
| 560 |
} |
| 561 |
}, |
| 562 |
|
| 563 |
_find: function( showMessage){ |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
var txt = this._findField.get("value") || ""; |
| 574 |
if(txt){ |
| 575 |
var caseSensitive = this._caseSensitive.get("value"); |
| 576 |
var backwards = this._backwards.get("value"); |
| 577 |
var isFound = this._findText(txt, caseSensitive, backwards); |
| 578 |
if(!isFound && showMessage){ |
| 579 |
this._promDialog.set("content", dojo.string.substitute( |
| 580 |
this._strings["eofDialogText"], {"0": this._strings["eofDialogTextFind"]})); |
| 581 |
dijit.popup.open({popup: this._promDialog, around: this._findButton.domNode}); |
| 582 |
this._promDialogTimeout = setTimeout(dojo.hitch(this, function(){ |
| 583 |
clearTimeout(this._promDialogTimeout); |
| 584 |
this._promDialogTimeout = null; |
| 585 |
dijit.popup.close(this._promDialog); |
| 586 |
}), 3000); |
| 587 |
setTimeout(dojo.hitch(this, function(){ |
| 588 |
this.editor.focus(); |
| 589 |
}), 0); |
| 590 |
} |
| 591 |
return isFound; |
| 592 |
} |
| 593 |
|
| 594 |
return false; |
| 595 |
}, |
| 596 |
|
| 597 |
_replace: function( showMessage){ |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
var isReplaced = false; |
| 608 |
var ed = this.editor; |
| 609 |
ed.focus(); |
| 610 |
var txt = this._findField.get("value") || ""; |
| 611 |
var repTxt = this._replaceField.get("value") || ""; |
| 612 |
|
| 613 |
if(txt){ |
| 614 |
var caseSensitive = this._caseSensitive.get("value"); |
| 615 |
|
| 616 |
var backwards = this._backwards.get("value"); |
| 617 |
|
| 618 |
|
| 619 |
var selected = ed._sCall("getSelectedText", [null]); |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
if(dojo.isMoz){ |
| 624 |
txt = dojo.trim(txt); |
| 625 |
selected = dojo.trim(selected); |
| 626 |
} |
| 627 |
|
| 628 |
var regExp = this._filterRegexp(txt, !caseSensitive); |
| 629 |
if(selected && regExp.test(selected)){ |
| 630 |
ed.execCommand("inserthtml", repTxt); |
| 631 |
isReplaced = true; |
| 632 |
|
| 633 |
if(backwards){ |
| 634 |
|
| 635 |
|
| 636 |
this._findText(repTxt, caseSensitive, backwards); |
| 637 |
ed._sCall("collapse", [true]); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
if(!this._find(false) && showMessage){ |
| 642 |
this._promDialog.set("content", dojo.string.substitute( |
| 643 |
this._strings["eofDialogText"], {"0": this._strings["eofDialogTextReplace"]})); |
| 644 |
dijit.popup.open({popup: this._promDialog, around: this._replaceButton.domNode}); |
| 645 |
this._promDialogTimeout = setTimeout(dojo.hitch(this, function(){ |
| 646 |
clearTimeout(this._promDialogTimeout); |
| 647 |
this._promDialogTimeout = null; |
| 648 |
dijit.popup.close(this._promDialog); |
| 649 |
}), 3000); |
| 650 |
setTimeout(dojo.hitch(this, function(){ |
| 651 |
this.editor.focus(); |
| 652 |
}), 0); |
| 653 |
} |
| 654 |
return isReplaced; |
| 655 |
} |
| 656 |
return null; |
| 657 |
}, |
| 658 |
|
| 659 |
_replaceAll: function( showMessage){ |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
var replaced = 0; |
| 668 |
var backwards = this._backwards.get("value"); |
| 669 |
|
| 670 |
if(backwards){ |
| 671 |
this.editor.placeCursorAtEnd(); |
| 672 |
}else{ |
| 673 |
this.editor.placeCursorAtStart(); |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
if(this._replace(false)) { replaced++; } |
| 680 |
|
| 681 |
var loopBody = dojo.hitch(this, function(){ |
| 682 |
if(this._replace(false)){ |
| 683 |
replaced++; |
| 684 |
setTimeout(loopBody, 10); |
| 685 |
}else{ |
| 686 |
if(showMessage){ |
| 687 |
this._promDialog.set("content", dojo.string.substitute( |
| 688 |
this._strings["replaceDialogText"], {"0": "" + replaced})); |
| 689 |
dijit.popup.open({ |
| 690 |
popup: this._promDialog, |
| 691 |
around: this._replaceAllButton.domNode |
| 692 |
}); |
| 693 |
this._promDialogTimeout = setTimeout(dojo.hitch(this, function(){ |
| 694 |
clearTimeout(this._promDialogTimeout); |
| 695 |
this._promDialogTimeout = null; |
| 696 |
dijit.popup.close(this._promDialog); |
| 697 |
}), 3000); |
| 698 |
setTimeout(dojo.hitch(this, function(){ |
| 699 |
this._findField.focus(); |
| 700 |
this._findField.textBox.focusNode.select(); |
| 701 |
}), 0); |
| 702 |
} |
| 703 |
} |
| 704 |
}); |
| 705 |
loopBody(); |
| 706 |
}, |
| 707 |
|
| 708 |
_findText: function( txt, caseSensitive, backwards){ |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
var ed = this.editor; |
| 722 |
var win = ed.window; |
| 723 |
var found = false; |
| 724 |
if(txt){ |
| 725 |
if(win.find){ |
| 726 |
found = win.find(txt, caseSensitive, backwards, false, false, false, false); |
| 727 |
}else{ |
| 728 |
var doc = ed.document; |
| 729 |
if(doc.selection || win.getSelection){ |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
this.editor.focus(); |
| 734 |
var txtRg = doc.body.createTextRange(); |
| 735 |
var txtRg2 = txtRg.duplicate(); |
| 736 |
var sel1 = win.getSelection(); |
| 737 |
var sRange = sel1.getRangeAt(0); |
| 738 |
var curPos = doc.selection?doc.selection.createRange():null; |
| 739 |
if(curPos){ |
| 740 |
if(backwards){ |
| 741 |
txtRg.setEndPoint("EndToStart", curPos); |
| 742 |
}else{ |
| 743 |
txtRg.setEndPoint("StartToEnd", curPos); |
| 744 |
} |
| 745 |
}else if(this._bookmark){ |
| 746 |
var currentText = win.getSelection().toString(); |
| 747 |
txtRg.moveToBookmark(this._bookmark); |
| 748 |
|
| 749 |
if ( txtRg.text != currentText ) { |
| 750 |
txtRg = txtRg2.duplicate(); |
| 751 |
this._bookmark = null; |
| 752 |
}else if(backwards){ |
| 753 |
txtRg2.setEndPoint("EndToStart", txtRg); |
| 754 |
txtRg = txtRg2.duplicate(); |
| 755 |
}else{ |
| 756 |
txtRg2.setEndPoint("StartToEnd", txtRg); |
| 757 |
txtRg = txtRg2.duplicate(); |
| 758 |
} |
| 759 |
} |
| 760 |
var flags = caseSensitive?4:0; |
| 761 |
if(backwards){ |
| 762 |
flags = flags | 1; |
| 763 |
} |
| 764 |
|
| 765 |
found = txtRg.findText(txt,txtRg.text.length,flags); |
| 766 |
if(found){ |
| 767 |
txtRg.select(); |
| 768 |
this._bookmark = txtRg.getBookmark(); |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
return found; |
| 774 |
}, |
| 775 |
|
| 776 |
_filterRegexp: function( pattern, ignoreCase){ |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
var rxp = ""; |
| 804 |
var c = null; |
| 805 |
for(var i = 0; i < pattern.length; i++){ |
| 806 |
c = pattern.charAt(i); |
| 807 |
switch(c){ |
| 808 |
case '\\': |
| 809 |
rxp += c; |
| 810 |
i++; |
| 811 |
rxp += pattern.charAt(i); |
| 812 |
break; |
| 813 |
case '$': |
| 814 |
case '^': |
| 815 |
case '/': |
| 816 |
case '+': |
| 817 |
case '.': |
| 818 |
case '|': |
| 819 |
case '(': |
| 820 |
case ')': |
| 821 |
case '{': |
| 822 |
case '}': |
| 823 |
case '[': |
| 824 |
case ']': |
| 825 |
rxp += "\\"; |
| 826 |
default: |
| 827 |
rxp += c; |
| 828 |
} |
| 829 |
} |
| 830 |
rxp = "^" + rxp + "$"; |
| 831 |
if(ignoreCase){ |
| 832 |
return new RegExp(rxp,"mi"); |
| 833 |
}else{ |
| 834 |
return new RegExp(rxp,"m"); |
| 835 |
} |
| 836 |
|
| 837 |
}, |
| 838 |
|
| 839 |
updateState: function(){ |
| 840 |
|
| 841 |
|
| 842 |
this.button.set("disabled", this.get("disabled")); |
| 843 |
}, |
| 844 |
|
| 845 |
destroy: function(){ |
| 846 |
|
| 847 |
|
| 848 |
this.inherited(arguments); |
| 849 |
if(this._promDialogTimeout){ |
| 850 |
clearTimeout(this._promDialogTimeout); |
| 851 |
this._promDialogTimeout = null; |
| 852 |
dijit.popup.close(this._promDialog); |
| 853 |
} |
| 854 |
if(this._frToolbar){ |
| 855 |
this._frToolbar.destroyRecursive(); |
| 856 |
this._frToolbar = null; |
| 857 |
} |
| 858 |
if(this._promDialog){ |
| 859 |
this._promDialog.destroyRecursive(); |
| 860 |
this._promDialog = null; |
| 861 |
} |
| 862 |
} |
| 863 |
}); |
| 864 |
|
| 865 |
|
| 866 |
FindReplace._FindReplaceCloseBox = FindReplaceCloseBox; |
| 867 |
FindReplace._FindReplaceTextBox = FindReplaceTextBox; |
| 868 |
FindReplace._FindReplaceCheckBox = FindReplaceCheckBox; |
| 869 |
FindReplace._FindReplaceToolbar = FindReplaceToolbar; |
| 870 |
|
| 871 |
|
| 872 |
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ |
| 873 |
if(o.plugin){ return; } |
| 874 |
var name = o.args.name.toLowerCase(); |
| 875 |
if(name === "findreplace"){ |
| 876 |
o.plugin = new FindReplace({}); |
| 877 |
} |
| 878 |
}); |
| 879 |
|
| 880 |
return FindReplace; |
| 881 |
|
| 882 |
}); |