//>>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,d,v,y,z,h,k,A,l,B,w,C,D,E,x){c.experimental("dojox.editor.plugins.FindReplace");var p=c.declare("dojox.editor.plugins._FindReplaceCloseBox",[h,k,l],{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=d.getUniqueId(this.declaredClass.replace(/\./g,"_"));this.btnId=this.id+"_close";this.inherited(arguments)},startup:function(){this.connect(this.button,"onClick","onClick")},onClick:function(){}}),m=c.declare("dojox.editor.plugins._FindReplaceTextBox",[h,k,l],{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=d.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,f=0;!a.target||a.ctrlKey||a.altKey||a.shiftKey||(a.keyCode==c.keys.LEFT_ARROW?(b=a.target.selectionStart,f=a.target.selectionEnd,b<f&&(d.selectInputText(a.target,b,b),c.stopEvent(a))):a.keyCode==c.keys.RIGHT_ARROW&&(b=a.target.selectionStart,f=a.target.selectionEnd,b<f&&(d.selectInputText(a.target,f,f),c.stopEvent(a))))}}),n=c.declare("dojox.editor.plugins._FindReplaceCheckBox",[h,k,l],{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=d.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)}}),q=c.declare("dojox.editor.plugins._FindReplaceToolbar",w,
{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){d._KeyNavContainer.superclass.addChild.apply(this,arguments)},_onToolbarEvent:function(a){a.stopPropagation()}}),g=c.declare("dojox.editor.plugins.FindReplace",[x],{buttonClass:d.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 d.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,f){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),f||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(),d.selectInputText(this._findField.textBox.focusNode))},setToolbar:function(a){this.inherited(arguments);if(!c.isOpera){var b=this._frToolbar=new q;c.style(b.domNode,"display",
"none");c.place(b.domNode,a.domNode,"after");b.startup();this._closeBox=new p;b.addChild(this._closeBox);this._findField=new m({label:this._strings.findLabel,tooltip:this._strings.findTooltip});b.addChild(this._findField);this._replaceField=new m({label:this._strings.replaceLabel,tooltip:this._strings.replaceTooltip});b.addChild(this._replaceField);b.addChild(new v.editor.plugins.ToolbarLineBreak);this._findButton=new d.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 d.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 d.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 n({label:this._strings.matchCase,tooltip:this._strings.matchCaseTooltip});b.addChild(this._caseSensitive);this._backwards=new n({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 d.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 f=this._caseSensitive.get("value"),
e=this._backwards.get("value"),b=this._findText(b,f,e);!b&&a&&(this._promDialog.set("content",c.string.substitute(this._strings.eofDialogText,{0:this._strings.eofDialogTextFind})),d.popup.open({popup:this._promDialog,around:this._findButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;d.popup.close(this._promDialog)}),3E3),setTimeout(c.hitch(this,function(){this.editor.focus()}),0));return b}return!1},_replace:function(a){var b=
!1,f=this.editor;f.focus();var e=this._findField.get("value")||"",r=this._replaceField.get("value")||"";if(e){var t=this._caseSensitive.get("value"),u=this._backwards.get("value"),g=f._sCall("getSelectedText",[null]);c.isMoz&&(e=c.trim(e),g=c.trim(g));e=this._filterRegexp(e,!t);g&&e.test(g)&&(f.execCommand("inserthtml",r),b=!0,u&&(this._findText(r,t,u),f._sCall("collapse",[!0])));!this._find(!1)&&a&&(this._promDialog.set("content",c.string.substitute(this._strings.eofDialogText,{0:this._strings.eofDialogTextReplace})),
d.popup.open({popup:this._promDialog,around:this._replaceButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;d.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 f=c.hitch(this,function(){this._replace(!1)?
(b++,setTimeout(f,10)):a&&(this._promDialog.set("content",c.string.substitute(this._strings.replaceDialogText,{0:""+b})),d.popup.open({popup:this._promDialog,around:this._replaceAllButton.domNode}),this._promDialogTimeout=setTimeout(c.hitch(this,function(){clearTimeout(this._promDialogTimeout);this._promDialogTimeout=null;d.popup.close(this._promDialog)}),3E3),setTimeout(c.hitch(this,function(){this._findField.focus();this._findField.textBox.focusNode.select()}),0))});f()},_findText:function(a,b,
c){var e=this.editor,f=e.window,d=!1;if(a)if(f.find)d=f.find(a,b,c,!1,!1,!1,!1);else{var g=e.document;if(g.selection||f.getSelection)if(this.editor.focus(),e=g.body.createTextRange(),d=e.duplicate(),f.getSelection().getRangeAt(0),(g=g.selection?g.selection.createRange():null)?c?e.setEndPoint("EndToStart",g):e.setEndPoint("StartToEnd",g):this._bookmark&&(f=f.getSelection().toString(),e.moveToBookmark(this._bookmark),e.text!=f?(e=d.duplicate(),this._bookmark=null):(c?d.setEndPoint("EndToStart",e):d.setEndPoint("StartToEnd",
e),e=d.duplicate())),b=b?4:0,c&&(b|=1),d=e.findText(a,e.text.length,b))e.select(),this._bookmark=e.getBookmark()}return d},_filterRegexp:function(a,c){for(var b="",e=null,d=0;d<a.length;d++)switch(e=a.charAt(d),e){case "\\":b+=e;d++;b+=a.charAt(d);break;case "$":case "^":case "/":case "+":case ".":case "|":case "(":case ")":case "{":case "}":case "[":case "]":b+="\\";default:b+=e}b="^"+b+"$";return c?new RegExp(b,"mi"):new RegExp(b,"m")},updateState:function(){this.button.set("disabled",this.get("disabled"))},
destroy:function(){this.inherited(arguments);this._promDialogTimeout&&(clearTimeout(this._promDialogTimeout),this._promDialogTimeout=null,d.popup.close(this._promDialog));this._frToolbar&&(this._frToolbar.destroyRecursive(),this._frToolbar=null);this._promDialog&&(this._promDialog.destroyRecursive(),this._promDialog=null)}});g._FindReplaceCloseBox=p;g._FindReplaceTextBox=m;g._FindReplaceCheckBox=n;g._FindReplaceToolbar=q;c.subscribe(d._scopeName+".Editor.getPlugin",null,function(a){a.plugin||"findreplace"!==
a.args.name.toLowerCase()||(a.plugin=new g({}))});return g});