//>>built
define("dojox/editor/plugins/FindReplace","dojo dijit dojox dijit/_base/manager dijit/_base/popup dijit/_Widget dijit/_TemplatedMixin dijit/_KeyNavContainer dijit/_WidgetsInTemplateMixin dijit/TooltipDialog dijit/Toolbar dijit/form/CheckBox dijit/form/_TextBoxMixin dijit/form/TextBox dijit/_editor/_Plugin dijit/form/Button dijit/form/DropDownButton dijit/form/ToggleButton ./ToolbarLineBreak dojo/_base/connect dojo/_base/declare dojo/i18n dojo/string dojo/i18n!dojox/editor/plugins/nls/FindReplace".split(" "),
function(c,f,w,z,A,n,p,B,q,C,x,D,E,F,y){c.experimental("dojox.editor.plugins.FindReplace");var u=c.declare("dojox.editor.plugins._FindReplaceCloseBox",[n,p,q],{btnId:"",widget:null,widgetsInTemplate:!0,templateString:"\x3cspan style\x3d'float: right' class\x3d'dijitInline' tabindex\x3d'-1'\x3e\x3cbutton class\x3d'dijit dijitReset dijitInline' id\x3d'${btnId}' dojoAttachPoint\x3d'button' dojoType\x3d'dijit.form.Button' tabindex\x3d'-1' iconClass\x3d'dijitEditorIconsFindReplaceClose' showLabel\x3d'false'\x3eX\x3c/button\x3e\x3c/span\x3e",
postMixInProperties:function(){this.id=f.getUniqueId(this.declaredClass.replace(/\./g,"_"));this.btnId=this.id+"_close";this.inherited(arguments)},startup:function(){this.connect(this.button,"onClick","onClick")},onClick:function(){}}),r=c.declare("dojox.editor.plugins._FindReplaceTextBox",[n,p,q],{textId:"",label:"",toolTip:"",widget:null,widgetsInTemplate:!0,templateString:"\x3cspan style\x3d'white-space: nowrap' class\x3d'dijit dijitReset dijitInline dijitEditorFindReplaceTextBox' title\x3d'${tooltip}' tabindex\x3d'-1'\x3e\x3clabel class\x3d'dijitLeft dijitInline' for\x3d'${textId}' tabindex\x3d'-1'\x3e${label}\x3c/label\x3e\x3cinput dojoType\x3d'dijit.form.TextBox' intermediateChanges\x3d'true' class\x3d'focusTextBox' tabIndex\x3d'0' id\x3d'${textId}' dojoAttachPoint\x3d'textBox, focusNode' value\x3d'' dojoAttachEvent\x3d'onKeyPress: _onKeyPress'/\x3e\x3c/span\x3e",
postMixInProperties:function(){this.id=f.getUniqueId(this.declaredClass.replace(/\./g,"_"));this.textId=this.id+"_text";this.inherited(arguments)},postCreate:function(){this.textBox.set("value","");this.disabled=this.textBox.get("disabled");this.connect(this.textBox,"onChange","onChange");c.attr(this.textBox.textbox,"formnovalidate","true")},_setValueAttr:function(a){this.value=a;this.textBox.set("value",a)},focus:function(){this.textBox.focus()},_setDisabledAttr:function(a){this.disabled=a;this.textBox.set("disabled",
a)},onChange:function(a){this.value=a},_onKeyPress:function(a){var b=0,d=0;!a.target||a.ctrlKey||a.altKey||a.shiftKey||(a.keyCode==c.keys.LEFT_ARROW?(b=a.target.selectionStart,d=a.target.selectionEnd,b<d&&(f.selectInputText(a.target,b,b),c.stopEvent(a))):a.keyCode==c.keys.RIGHT_ARROW&&(b=a.target.selectionStart,d=a.target.selectionEnd,b<d&&(f.selectInputText(a.target,d,d),c.stopEvent(a))))}}),t=c.declare("dojox.editor.plugins._FindReplaceCheckBox",[n,p,q],{checkId:"",label:"",tooltip:"",widget:null,
widgetsInTemplate:!0,templateString:"\x3cspan style\x3d'white-space: nowrap' tabindex\x3d'-1' class\x3d'dijit dijitReset dijitInline dijitEditorFindReplaceCheckBox' title\x3d'${tooltip}' \x3e\x3cinput dojoType\x3d'dijit.form.CheckBox' tabIndex\x3d'0' id\x3d'${checkId}' dojoAttachPoint\x3d'checkBox, focusNode' value\x3d''/\x3e\x3clabel tabindex\x3d'-1' class\x3d'dijitLeft dijitInline' for\x3d'${checkId}'\x3e${label}\x3c/label\x3e\x3c/span\x3e",postMixInProperties:function(){this.id=f.getUniqueId(this.declaredClass.replace(/\./g,
"_"));this.checkId=this.id+"_check";this.inherited(arguments)},postCreate:function(){this.checkBox.set("checked",!1);this.disabled=this.checkBox.get("disabled");this.checkBox.isFocusable=function(){return!1}},_setValueAttr:function(a){this.checkBox.set("value",a)},_getValueAttr:function(){return this.checkBox.get("value")},focus:function(){this.checkBox.focus()},_setDisabledAttr:function(a){this.disabled=a;this.checkBox.set("disabled",a)}}),v=c.declare("dojox.editor.plugins._FindReplaceToolbar",x,
{postCreate:function(){this.connectKeyNavHandlers([],[]);this.connect(this.containerNode,"onclick","_onToolbarEvent");this.connect(this.containerNode,"onkeydown","_onToolbarEvent");c.addClass(this.domNode,"dijitToolbar")},addChild:function(a,b){f._KeyNavContainer.superclass.addChild.apply(this,arguments)},_onToolbarEvent:function(a){a.stopPropagation()}}),l=c.declare("dojox.editor.plugins.FindReplace",[y],{buttonClass:f.form.ToggleButton,iconClassPrefix:"dijitEditorIconsFindReplace",editor:null,button:null,
_frToolbar:null,_closeBox:null,_findField:null,_replaceField:null,_findButton:null,_replaceButton:null,_replaceAllButton:null,_caseSensitive:null,_backwards:null,_promDialog:null,_promDialogTimeout:null,_strings:null,_bookmark:null,_initButton:function(){this._strings=c.i18n.getLocalization("dojox.editor.plugins","FindReplace");this.button=new f.form.ToggleButton({label:this._strings.findReplace,showLabel:!1,iconClass:this.iconClassPrefix+" dijitEditorIconFindString",tabIndex:"-1",onChange:c.hitch(this,
"_toggleFindReplace")});c.isOpera&&this.button.set("disabled",!0);this.connect(this.button,"set",c.hitch(this,function(a,b){"disabled"===a&&this._toggleFindReplace(!b&&this._displayed,!0,!0)}))},setEditor:function(a){this.editor=a;this._initButton()},toggle:function(){this.button.set("checked",!this.button.get("checked"))},_toggleFindReplace:function(a,b,d){var e=c.marginBox(this.editor.domNode);a&&!c.isOpera?(c.style(this._frToolbar.domNode,"display","block"),this._populateFindField(),b||(this._displayed=
!0)):(c.style(this._frToolbar.domNode,"display","none"),b||(this._displayed=!1),d||this.editor.focus());this.editor.resize({h:e.h})},_populateFindField:function(){var a=this.editor._sCall("getSelectedText",[null]);this._findField&&this._findField.textBox&&(a&&this._findField.textBox.set("value",a),this._findField.textBox.focus(),f.selectInputText(this._findField.textBox.focusNode))},setToolbar:function(a){this.inherited(arguments);if(!c.isOpera){var b=this._frToolbar=new v;c.style(b.domNode,"display",
"none");c.place(b.domNode,a.domNode,"after");b.startup();this._closeBox=new u;b.addChild(this._closeBox);this._findField=new r({label:this._strings.findLabel,tooltip:this._strings.findTooltip});b.addChild(this._findField);this._replaceField=new r({label:this._strings.replaceLabel,tooltip:this._strings.replaceTooltip});b.addChild(this._replaceField);b.addChild(new w.editor.plugins.ToolbarLineBreak);this._findButton=new f.form.Button({label:this._strings.findButton,showLabel:!0,iconClass:this.iconClassPrefix+
" dijitEditorIconFind"});this._findButton.titleNode.title=this._strings.findButtonTooltip;b.addChild(this._findButton);this._replaceButton=new f.form.Button({label:this._strings.replaceButton,showLabel:!0,iconClass:this.iconClassPrefix+" dijitEditorIconReplace"});this._replaceButton.titleNode.title=this._strings.replaceButtonTooltip;b.addChild(this._replaceButton);this._replaceAllButton=new f.form.Button({label:this._strings.replaceAllButton,showLabel:!0,iconClass:this.iconClassPrefix+" dijitEditorIconReplaceAll"});
this._replaceAllButton.titleNode.title=this._strings.replaceAllButtonTooltip;b.addChild(this._replaceAllButton);this._caseSensitive=new t({label:this._strings.matchCase,tooltip:this._strings.matchCaseTooltip});b.addChild(this._caseSensitive);this._backwards=new t({label:this._strings.backwards,tooltip:this._strings.backwardsTooltip});b.addChild(this._backwards);this._findButton.set("disabled",!0);this._replaceButton.set("disabled",!0);this._replaceAllButton.set("disabled",!0);this.connect(this._findField,
"onChange","_checkButtons");this.connect(this._findField,"onKeyDown","_onFindKeyDown");this.connect(this._replaceField,"onKeyDown","_onReplaceKeyDown");this.connect(this._findButton,"onClick","_find");this.connect(this._replaceButton,"onClick","_replace");this.connect(this._replaceAllButton,"onClick","_replaceAll");this.connect(this._closeBox,"onClick","toggle");this._promDialog=new f.TooltipDialog;this._promDialog.startup();this._promDialog.set("content","")}},_checkButtons:function(){this._findField.get("value")?
(this._findButton.set("disabled",!1),this._replaceButton.set("disabled",!1),this._replaceAllButton.set("disabled",!1)):(this._findButton.set("disabled",!0),this._replaceButton.set("disabled",!0),this._replaceAllButton.set("disabled",!0))},_onFindKeyDown:function(a){a.keyCode==c.keys.ENTER&&(this._find(),c.stopEvent(a))},_onReplaceKeyDown:function(a){a.keyCode==c.keys.ENTER&&(this._replace()||this._replace(),c.stopEvent(a))},_find:function(a){var b=this._findField.get("value")||"";if(b){var d=this._caseSensitive.get("value"),
e=this._backwards.get("value");b=this._findText(b,d,e);!b&&a&&(this._promDialog.set("content",c.string.substitute(this._strings.eofDialogText,{0:this._strings.eofDialogTextFind})),f.popup.open({popup:this._promDialog,around:this._findButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;f.popup.close(this._promDialog)}),3E3),setTimeout(c.hitch(this,function(){this.editor.focus()}),0));return b}return!1},_replace:function(a){var b=
!1,d=this.editor;d.focus();var e=this._findField.get("value")||"",g=this._replaceField.get("value")||"";if(e){var h=this._caseSensitive.get("value"),k=this._backwards.get("value"),m=d._sCall("getSelectedText",[null]);c.isMoz&&(e=c.trim(e),m=c.trim(m));e=this._filterRegexp(e,!h);m&&e.test(m)&&(d.execCommand("inserthtml",g),b=!0,k&&(this._findText(g,h,k),d._sCall("collapse",[!0])));!this._find(!1)&&a&&(this._promDialog.set("content",c.string.substitute(this._strings.eofDialogText,{0:this._strings.eofDialogTextReplace})),
f.popup.open({popup:this._promDialog,around:this._replaceButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;f.popup.close(this._promDialog)}),3E3),setTimeout(c.hitch(this,function(){this.editor.focus()}),0));return b}return null},_replaceAll:function(a){var b=0;this._backwards.get("value")?this.editor.placeCursorAtEnd():this.editor.placeCursorAtStart();this._replace(!1)&&b++;var d=c.hitch(this,function(){this._replace(!1)?
(b++,setTimeout(d,10)):a&&(this._promDialog.set("content",c.string.substitute(this._strings.replaceDialogText,{0:""+b})),f.popup.open({popup:this._promDialog,around:this._replaceAllButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;f.popup.close(this._promDialog)}),3E3),setTimeout(c.hitch(this,function(){this._findField.focus();this._findField.textBox.focusNode.select()}),0))});d()},_findText:function(a,b,
d){var e=this.editor,g=e.window,h=!1;if(a)if(g.find)h=g.find(a,b,d,!1,!1,!1,!1);else{var k=e.document;if(k.selection||g.getSelection)if(this.editor.focus(),e=k.body.createTextRange(),h=e.duplicate(),g.getSelection().getRangeAt(0),(k=k.selection?k.selection.createRange():null)?d?e.setEndPoint("EndToStart",k):e.setEndPoint("StartToEnd",k):this._bookmark&&(g=g.getSelection().toString(),e.moveToBookmark(this._bookmark),e.text!=g?(e=h.duplicate(),this._bookmark=null):(d?h.setEndPoint("EndToStart",e):h.setEndPoint("StartToEnd",
e),e=h.duplicate())),b=b?4:0,d&&(b|=1),h=e.findText(a,e.text.length,b))e.select(),this._bookmark=e.getBookmark()}return h},_filterRegexp:function(a,b){for(var d="",e=null,g=0;g<a.length;g++)switch(e=a.charAt(g),e){case "\\":d+=e;g++;d+=a.charAt(g);break;case "$":case "^":case "/":case "+":case ".":case "|":case "(":case ")":case "{":case "}":case "[":case "]":d+="\\";default:d+=e}d="^"+d+"$";return b?new RegExp(d,"mi"):new RegExp(d,"m")},updateState:function(){this.button.set("disabled",this.get("disabled"))},
destroy:function(){this.inherited(arguments);this._promDialogTimeout&&(clearTimeout(this._promDialogTimeout),this._promDialogTimeout=null,f.popup.close(this._promDialog));this._frToolbar&&(this._frToolbar.destroyRecursive(),this._frToolbar=null);this._promDialog&&(this._promDialog.destroyRecursive(),this._promDialog=null)}});l._FindReplaceCloseBox=u;l._FindReplaceTextBox=r;l._FindReplaceCheckBox=t;l._FindReplaceToolbar=v;c.subscribe(f._scopeName+".Editor.getPlugin",null,function(a){a.plugin||"findreplace"!==
a.args.name.toLowerCase()||(a.plugin=new l({}))});return l});