//>>built
define("dijit/_editor/range",["dojo/_base/array","dojo/_base/declare","dojo/_base/lang"],function(u,w,v){var k={getIndex:function(a,b){for(var c=[],d=[],e=a,g,f;a!=b;){var h=0;for(g=a.parentNode;f=g.childNodes[h++];)if(f===a){--h;break}c.unshift(h);d.unshift(h-g.childNodes.length);a=g}if(0<c.length&&3==e.nodeType){for(f=e.previousSibling;f&&3==f.nodeType;)c[c.length-1]--,f=f.previousSibling;for(f=e.nextSibling;f&&3==f.nodeType;)d[d.length-1]++,f=f.nextSibling}return{o:c,r:d}},getNode:function(a,b){if(!v.isArray(a)||
0==a.length)return b;var c=b;u.every(a,function(d){if(0<=d&&d<c.childNodes.length)c=c.childNodes[d];else return c=null,!1;return!0});return c},getCommonAncestor:function(a,b,c){c=c||a.ownerDocument.body;var d=function(f){for(var h=[];f;)if(h.unshift(f),f!==c)f=f.parentNode;else break;return h};a=d(a);b=d(b);d=Math.min(a.length,b.length);for(var e=a[0],g=1;g<d;g++)if(a[g]===b[g])e=a[g];else break;return e},getAncestor:function(a,b,c){for(c=c||a.ownerDocument.body;a&&a!==c;){var d=a.nodeName.toUpperCase();
if(b.test(d))return a;a=a.parentNode}return null},BlockTagNames:/^(?:P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI|DT|DE)$/,getBlockAncestor:function(a,b,c){c=c||a.ownerDocument.body;b=b||k.BlockTagNames;for(var d=null,e;a&&a!==c;){var g=a.nodeName.toUpperCase();!d&&b.test(g)&&(d=a);!e&&/^(?:BODY|TD|TH|CAPTION)$/.test(g)&&(e=a);a=a.parentNode}return{blockNode:d,blockContainer:e||a.ownerDocument.body}},atBeginningOfContainer:function(a,b,c){var d=!1,e=0==c;e||3!=b.nodeType||/^[\s\xA0]+$/.test(b.nodeValue.substr(0,
c))&&(e=!0);if(e)for(d=!0;b&&b!==a;){if(b.previousSibling){d=!1;break}b=b.parentNode}return d},atEndOfContainer:function(a,b,c){var d=!1,e=c==(b.length||b.childNodes.length);e||3!=b.nodeType||/^[\s\xA0]+$/.test(b.nodeValue.substr(c))&&(e=!0);if(e)for(d=!0;b&&b!==a;){if(b.nextSibling){d=!1;break}b=b.parentNode}return d},adjacentNoneTextNode:function(a,b){for(var c=a,d=0-a.length||0,e=b?"nextSibling":"previousSibling";c&&3==c.nodeType;)d+=c.length,c=c[e];return[c,d]},create:function(a){a=a||window;
return a.getSelection?a.document.createRange():new n},getSelection:function(a,b){if(a.getSelection)return a.getSelection();var c=new l.selection(a);b||c._getCurrentSelection();return c}};if(!window.getSelection)var l=k.ie={cachedSelection:{},selection:function(a){this._ranges=[];this.addRange=function(b,c){this._ranges.push(b);c||b._select();this.rangeCount=this._ranges.length};this.removeAllRanges=function(){this._ranges=[];this.rangeCount=0};this.getRangeAt=function(b){return this._ranges[b]};this._getCurrentSelection=
function(){this.removeAllRanges();var b=a.document.selection.createRange();b="CONTROL"==a.document.selection.type.toUpperCase()?new n(l.decomposeControlRange(b)):new n(l.decomposeTextRange(b));this.addRange(b,!0),this.isCollapsed=b.collapsed}},decomposeControlRange:function(a){var b=a.item(0),c=a.item(a.length-1);a=b.parentNode;var d=c.parentNode;b=k.getIndex(b,a).o[0];c=k.getIndex(c,d).o[0]+1;return[a,b,d,c]},getEndPoint:function(a,b){var c=a.duplicate();c.collapse(!b);var d="EndTo"+(b?"End":"Start"),
e=c.parentElement(),g;if(0<e.childNodes.length)u.every(e.childNodes,function(p,r){if(3!=p.nodeType)if(c.moveToElementText(p),0<c.compareEndPoints(d,a))if(g&&3==g.nodeType){f=g;var m=!0}else return f=e,h=r,!1;else{if(r==e.childNodes.length-1)return f=e,h=e.childNodes.length,!1}else r==e.childNodes.length-1&&(f=p,m=!0);if(m&&f){f=(m=k.adjacentNoneTextNode(f)[0])?m.nextSibling:e.firstChild;var q=k.adjacentNoneTextNode(f);m=q[0];q=q[1];m?(c.moveToElementText(m),c.collapse(!1)):c.moveToElementText(e);
c.setEndPoint(d,a);h=c.text.length-q;return!1}g=p;return!0});else{var f=e;var h=0}if(!b&&1==f.nodeType&&h==f.childNodes.length){var t=f.nextSibling;t&&3==t.nodeType&&(f=t,h=0)}return[f,h]},setEndPoint:function(a,b,c){a=a.duplicate();var d;if(3!=b.nodeType)if(0<c){if(d=b.childNodes[c-1])if(3==d.nodeType)b=d,c=d.length;else if(d.nextSibling&&3==d.nextSibling.nodeType)b=d.nextSibling,c=0;else{a.moveToElementText(d.nextSibling?d:b);var e=d.parentNode;d=e.insertBefore(d.ownerDocument.createTextNode(" "),
d.nextSibling);a.collapse(!1);e.removeChild(d)}}else a.moveToElementText(b),a.collapse(!0);3==b.nodeType&&(d=k.adjacentNoneTextNode(b),e=d[0],d=d[1],e?(a.moveToElementText(e),a.collapse(!1),"inherit"!=e.contentEditable&&d++):(a.moveToElementText(b.parentNode),a.collapse(!0),a.move("character",1),a.move("character",-1)),c+=d,0<c&&a.move("character",c));return a},decomposeTextRange:function(a){var b=l.getEndPoint(a),c=b[0],d=b[1],e=b[0];b=b[1];a.htmlText.length&&(a.htmlText==a.text?b=d+a.text.length:
(b=l.getEndPoint(a,!0),e=b[0],b=b[1]));return[c,d,e,b]},setRange:function(a,b,c,d,e,g){b=l.setEndPoint(a,b,c);a.setEndPoint("StartToStart",b);if(!g)var f=l.setEndPoint(a,d,e);a.setEndPoint("EndToEnd",f||b);return a}},n=k.W3CRange=w(null,{constructor:function(){0<arguments.length?(this.setStart(arguments[0][0],arguments[0][1]),this.setEnd(arguments[0][2],arguments[0][3])):(this.startContainer=this.commonAncestorContainer=null,this.startOffset=0,this.endContainer=null,this.endOffset=0,this.collapsed=
!0)},_updateInternal:function(){this.commonAncestorContainer=this.startContainer!==this.endContainer?k.getCommonAncestor(this.startContainer,this.endContainer):this.startContainer;this.collapsed=this.startContainer===this.endContainer&&this.startOffset==this.endOffset},setStart:function(a,b){b=parseInt(b);if(this.startContainer!==a||this.startOffset!=b)delete this._cachedBookmark,this.startContainer=a,this.startOffset=b,this.endContainer?this._updateInternal():this.setEnd(a,b)},setEnd:function(a,
b){b=parseInt(b);if(this.endContainer!==a||this.endOffset!=b)delete this._cachedBookmark,this.endContainer=a,this.endOffset=b,this.startContainer?this._updateInternal():this.setStart(a,b)},setStartAfter:function(a,b){this._setPoint("setStart",a,b,1)},setStartBefore:function(a,b){this._setPoint("setStart",a,b,0)},setEndAfter:function(a,b){this._setPoint("setEnd",a,b,1)},setEndBefore:function(a,b){this._setPoint("setEnd",a,b,0)},_setPoint:function(a,b,c,d){c=k.getIndex(b,b.parentNode).o;this[a](b.parentNode,
c.pop()+d)},_getIERange:function(){var a=(this._body||this.endContainer.ownerDocument.body).createTextRange();l.setRange(a,this.startContainer,this.startOffset,this.endContainer,this.endOffset,this.collapsed);return a},getBookmark:function(){this._getIERange();return this._cachedBookmark},_select:function(){this._getIERange().select()},deleteContents:function(){var a=this.startContainer,b=this._getIERange();3!==a.nodeType||this.startOffset||this.setStartBefore(a);b.pasteHTML("");this.endContainer=
this.startContainer;this.endOffset=this.startOffset;this.collapsed=!0},cloneRange:function(){var a=new n([this.startContainer,this.startOffset,this.endContainer,this.endOffset]);a._body=this._body;return a},detach:function(){this.startContainer=this.commonAncestorContainer=this._body=null;this.startOffset=0;this.endContainer=null;this.endOffset=0;this.collapsed=!0}});v.setObject("dijit.range",k);return k});