code: function( containerNode )
      {
          if( window.getSelection )
          {
              var sel = window.getSelection();
              if( sel.rangeCount > 0 )
                  return sel.getRangeAt(0);
          }
          else if( document.selection )
          {
              var sel = document.selection;
              return sel.createRange();
          }
          return null;
      }
docs: save/restore selection http://stackoverflow.com/questions/13949059/persisting-the-changes-of-range-objects-after-selection-in-html/13950376#13950376