serialize-selection
Serialize and restore DOM Selections via text offset from a reference Node.
Installation
npm install serialize-selection
Usage
save
ss.save([referenceNode])
Arguments
[referenceNode]
- (optional) a DOMElement
used as the reference for serialization. Default:document.body
.
Returns
save
returns an object with the following properties:
start
- the start offset of the selection from the reference nodeend
- the end offset of the selection from the reference nodecontent
- the string content of the saved selectionrestore
- shortcut method to restore the selection
restore
ss.restore(state, [referenceNode])
Arguments
state
- a selection state object (any object withstart
andend
properties).[referenceNode]
- (optional) a DOMElement
used as the reference for serialization. Default:document.body
.
Returns
restore
returns a Selection object
var ss = var referenceEl = document var state = ss// state object with start/end/content properties var sel = state // equivalent to ss.restore(state, referenceEl)// selection is restored
License
Copyright 2015 Cameron Lakenen