/* * $Id: documentselection.js 124 2006-11-27 19:21:36Z wingedfox $ * $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.001/documentselection.js $ * * Class implements cross-browser work with text selection * * @author Ilya Lebedev * @author $Author: wingedfox $ * @modified $Date: 2006-11-27 22:21:36 +0300 (Пнд, 27 Ноя 2006) $ * @version $Rev: 124 $ * @license LGPL */ DocumentSelection=new function(){var i=this;var I={'cursor':'__cursorPosition'};var l,o;this.setRange=function(O,Q,_,c){if(c){var C=i.getStart(O);_=C+_;Q=C+Q}if('function'==typeof O.setSelectionRange){try{O.setSelectionRange(Q,_)}catch(e){}}else{var v;try{v=O.createTextRange();}catch(e){try{v=document.body.createTextRange();v.moveToElementText(O);}catch(e){v=false}}if(!v)return false;v.collapse(true);v.moveStart("character",Q);v.moveEnd("character",_-Q);v.select();}i.setCursorPosition(O,Q);};this.setCursorPosition=function(O,Q){O[I['cursor']]=parseInt(Q);if(l)O.scrollTop=l;if(o)O.scrollLeft=o;l=null;o=null};this.getSelection=function(O){var Q=i.getCursorPosition(O),_=i.getEnd(O);if(_