/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.editor.plugins.AutoUrlLink"],["require","dojo.string"],["require","dijit._editor._Plugin"],["require","dijit.form.Button"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.editor.plugins.AutoUrlLink"]){_4._hasResource["dojox.editor.plugins.AutoUrlLink"]=true;_4.provide("dojox.editor.plugins.AutoUrlLink");_4.require("dojo.string");_4.require("dijit._editor._Plugin");_4.require("dijit.form.Button");_4.declare("dojox.editor.plugins.AutoUrlLink",[_5._editor._Plugin],{_template:"<a _djrealurl='${url}' href='${url}'>${url}</a>",setEditor:function(_7){this.editor=_7;if(!_4.isIE){_4.some(_7._plugins,function(_8){if(_8.isInstanceOf(_5._editor.plugins.EnterKeyHandling)){this.blockNodeForEnter=_8.blockNodeForEnter;return true;}return false;},this);this.connect(_7,"onKeyPress","_keyPress");this.connect(_7,"onClick","_recognize");this.connect(_7,"onBlur","_recognize");}},_keyPress:function(_9){var ks=_4.keys,v=118,V=86,kc=_9.keyCode,cc=_9.charCode;if(cc==ks.SPACE||(_9.ctrlKey&&(cc==v||cc==V))){setTimeout(_4.hitch(this,"_recognize"),0);}else{if(kc==ks.ENTER){setTimeout(_4.hitch(this,function(){this._recognize({enter:true});}),0);}else{this._saved=this.editor.window.getSelection().anchorNode;}}},_recognize:function(_a){var _b=this._template,_c=_a?_a.enter:false,ed=this.editor,_d=ed.window.getSelection();if(_d){var _e=_c?this._findLastEditingNode(_d.anchorNode):(this._saved||_d.anchorNode),bm=this._saved=_d.anchorNode,_f=_d.anchorOffset;if(_e.nodeType==3&&!this._inLink(_e)){var _10=false,_11=this._findUrls(_e,bm,_f),_12=ed.document.createRange(),_13,_14=0,_15=(bm==_e);_13=_11.shift();while(_13){_12.setStart(_e,_13.start);_12.setEnd(_e,_13.end);_d.removeAllRanges();_d.addRange(_12);ed.execCommand("insertHTML",_4.string.substitute(_b,{url:_12.toString()}));_14+=_13.end;_13=_11.shift();_10=true;}if(_15&&(_f=_f-_14)<=0){return;}if(!_10){return;}try{_12.setStart(bm,0);_12.setEnd(bm,_f);_d.removeAllRanges();_d.addRange(_12);_4.withGlobal(ed.window,"collapse",_5._editor.selection,[]);}catch(e){}}}},_inLink:function(_16){var _17=this.editor.editNode,_18=false,_19;_16=_16.parentNode;while(_16&&_16!==_17){_19=_16.tagName?_16.tagName.toLowerCase():"";if(_19=="a"){_18=true;break;}_16=_16.parentNode;}return _18;},_findLastEditingNode:function(_1a){var _1b=_5.range.BlockTagNames,_1c=this.editor.editNode,_1d;if(!_1a){return _1a;}if(this.blockNodeForEnter=="BR"&&(!(_1d=_5.range.getBlockAncestor(_1a,null,_1c).blockNode)||_1d.tagName.toUpperCase()!="LI")){while((_1a=_1a.previousSibling)&&_1a.nodeType!=3){}}else{if((_1d||(_1d=_5.range.getBlockAncestor(_1a,null,_1c).blockNode))&&_1d.tagName.toUpperCase()=="LI"){_1a=_1d;}else{_1a=_5.range.getBlockAncestor(_1a,null,_1c).blockNode;}while((_1a=_1a.previousSibling)&&!(_1a.tagName&&_1a.tagName.match(_1b))){}if(_1a){_1a=_1a.lastChild;while(_1a){if(_1a.nodeType==3&&_4.trim(_1a.nodeValue)!=""){break;}else{if(_1a.nodeType==1){_1a=_1a.lastChild;}else{_1a=_1a.previousSibling;}}}}}return _1a;},_findUrls:function(_1e,bm,_1f){var _20=/(http|https|ftp):\/\/[^\s]+/ig,_21=[],_22=0,_23=_1e.nodeValue,_24,ch;if(_1e===bm&&_1f<_23.length){_23=_23.substr(0,_1f);}while((_24=_20.exec(_23))!=null){if(_24.index==0||(ch=_23.charAt(_24.index-1))==" "||ch==" "){_21.push({start:_24.index-_22,end:_24.index+_24[0].length-_22});_22=_24.index+_24[0].length;}}return _21;}});_4.subscribe(_5._scopeName+".Editor.getPlugin",null,function(o){if(o.plugin){return;}var _25=o.args.name.toLowerCase();if(_25==="autourllink"){o.plugin=new _6.editor.plugins.AutoUrlLink();}});}}};});