/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:24
*/
KISSY.add("input-selection",function(h,d){function p(a){var b=i;b||(b=d.create(q));"textarea"==a.type?d.css(b,"width",d.css(a,"width")):d.css(b,"width",9999);h.each(r,function(c){d.css(b,c,d.css(a,c))});if(!i){var c=a.ownerDocument.body;c.insertBefore(b,c.firstChild)}return i=b}var j=d._propHooks,l=!0;try{l="number"==typeof h.Env.host.document.createElement("input").selectionEnd}catch(s){}if(!l){j.selectionStart={set:function(a,b){var c=a.ownerDocument.selection.createRange();if(k(a).inRange(c)){var f=
g(a,1)[1],e=m(a,b,f);c.collapse(!1);c.moveStart("character",-e);b>f&&c.collapse(!0);c.select()}},get:function(a){return g(a)[0]}};j.selectionEnd={set:function(a,b){var c=a.ownerDocument.selection.createRange();if(k(a).inRange(c)){var f=g(a)[0],e=m(a,f,b);c.collapse(!0);c.moveEnd("character",e);f>b&&c.collapse(!1);c.select()}},get:function(a){return g(a,1)[1]}};var g=function(a,b){var c=0,f=0,e=a.ownerDocument.selection.createRange(),d=k(a);d.inRange(e)&&(d.setEndPoint("EndToStart",e),c=n(a,d).length,
b&&(f=c+n(a,e).length));return[c,f]},k=function(a){if("textarea"==a.type){var b=a.document.body.createTextRange();b.moveToElementText(a);return b}return a.createTextRange()},m=function(a,b,c){var d=Math.min(b,c),e=Math.max(b,c);return d==e?0:"textarea"==a.type?(a=a.value.substring(d,e).replace(/\r\n/g,"\n").length,b>c&&(a=-a),a):c-b},n=function(a,b){if("textarea"==a.type){var c=b.text,d=b.duplicate();if(0==d.compareEndPoints("StartToEnd",d))return c;d.moveEnd("character",-1);d.text==c&&(c+="\r\n");
return c}return b.text}}var q="<div style='z-index:-9999;overflow:hidden;position: fixed;left:-9999px;top:-9999px;opacity:0;white-space:pre-wrap;word-wrap:break-word;'></div>",i,r="paddingLeft,paddingTop,paddingBottom,paddingRight,marginLeft,marginTop,marginBottom,marginRight,borderLeftStyle,borderTopStyle,borderBottomStyle,borderRightStyle,borderLeftWidth,borderTopWidth,borderBottomWidth,borderRightWidth,line-height,outline,height,fontFamily,fontSize,fontWeight,fontVariant,fontStyle".split(","),
o=!0;h.ready(function(){var a=document,b=d.create("<input>");d.css(b,{width:1,position:"absolute",left:-9999,top:-9999});b.value="123456789";a.body.appendChild(b);b.focus();o=!!(0<b.scrollLeft);d.remove(b)});j.KsCursorOffset={get:function(a){var b=a.ownerDocument,c=a.scrollTop,f=a.scrollLeft;if(b.selection)return b=b.selection.createRange(),{left:b.boundingLeft+f+d.scrollLeft(),top:b.boundingTop+c+b.boundingHeight+d.scrollTop()};var e=d.offset(a);if(!o&&"textarea"!=a.type)return e.top+=a.offsetHeight,
e;var g=p(a),b=a.selectionStart;g.innerHTML=h.escapeHTML(a.value.substring(0,b-1))+"<span>x</span>";d.offset(g,e);e=g.lastChild;a=d.offset(e);a.top+=d.height(e);0<b&&(a.left+=d.width(e));a.top-=c;a.left-=f;return a}}},{requires:["dom"]});
