(function(){var e=function(e){var t=this;e.require().script("mvc/dom.range").done(function(){var n=function(){var t=function(e){return e.replace(/([a-z])([a-z]+)/gi,function(e,t,n){return t+n.toLowerCase()}).replace(/_/g,"")},n=function(e){return e.replace(/^([a-z]+)_TO_([a-z]+)/i,function(e,t,n){return n+"_TO_"+t})},r=function(e){return e?e.ownerDocument.defaultView||e.ownerDocument.parentWindow:window},i=function(t,n){var r=e.Range.current(t).clone(),i=e.Range(t).select(t);return r.overlaps(i)?(r.compare("START_TO_START",i)<1?(startPos=0,r.move("START_TO_START",i)):(fromElementToCurrent=i.clone(),fromElementToCurrent.move("END_TO_START",r),startPos=(fromElementToCurrent+"").length),r.compare("END_TO_END",i)<0?endPos=startPos+(r+"").length:endPos=(i+"").length,{start:startPos,end:endPos}):null},s=function(t){var n=r(t);if(t.selectionStart!==undefined)return document.activeElement&&document.activeElement!=t&&t.selectionStart==t.selectionEnd&&t.selectionStart==0?{start:t.value.length,end:t.value.length}:{start:t.selectionStart,end:t.selectionEnd};if(n.getSelection)return i(t,n);try{if(t.nodeName.toLowerCase()=="input"){var s=r(t).document.selection.createRange(),o=t.createTextRange();o.setEndPoint("EndToStart",s);var u=o.text.length;return{start:u,end:u+s.text.length}}var a=i(t,n);if(!a)return a;var f=e.Range.current().clone(),l=f.clone().collapse().range,c=f.clone().collapse(!1).range;return l.moveStart("character",-1),c.moveStart("character",-1),a.startPos!=0&&l.text==""&&(a.startPos+=2),a.endPos!=0&&c.text==""&&(a.endPos+=2),a}catch(h){return{start:t.value.length,end:t.value.length}}},o=function(e,t,n){var i=r(e);if(e.setSelectionRange)n===undefined?(e.focus(),e.setSelectionRange(t,t)):(e.select(),e.selectionStart=t,e.selectionEnd=n);else if(e.createTextRange){var s=e.createTextRange();s.moveStart("character",t),n=n||t,s.moveEnd("character",n-e.value.length),s.select()}else if(i.getSelection){var o=i.document,u=i.getSelection(),f=o.createRange(),l=[t,n!==undefined?n:t];a([e],l),f.setStart(l[0].el,l[0].count),f.setEnd(l[1].el,l[1].count),u.removeAllRanges(),u.addRange(f)}else if(i.document.body.createTextRange){var f=document.body.createTextRange();f.moveToElementText(e),f.collapse(),f.moveStart("character",t),f.moveEnd("character",n!==undefined?n:t),f.select()}},u=function(e,t,n,r){typeof n[0]=="number"&&n[0]<t&&(n[0]={el:r,count:n[0]-e}),typeof n[1]=="number"&&n[1]<=t&&(n[1]={el:r,count:n[1]-e})},a=function(e,t,n){var r,i;n=n||0;for(var s=0;e[s];s++)r=e[s],r.nodeType===3||r.nodeType===4?(i=n,n+=r.nodeValue.length,u(i,n,t,r)):r.nodeType!==8&&(n=a(r.childNodes,t,n));return n};e.fn.selection=function(e,t){return e!==undefined?this.each(function(){o(this,e,t)}):s(this[0])},e.fn.selection.getCharElement=a};n(),t.resolveWith(n)})};dispatch("mvc/dom.selection").containing(e).to("Foundry/2.1 Modules")})();