Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storing selection objects #279

Closed
nschloe opened this issue Feb 23, 2015 · 7 comments
Closed

storing selection objects #279

nschloe opened this issue Feb 23, 2015 · 7 comments

Comments

@nschloe
Copy link

nschloe commented Feb 23, 2015

I would like to store a selection objects as retrieved from rangy.getSelection() for later highlighting. Shallow copying

var mySelection = rangy.getSelection();

won't do to the trick, and also lodash's clone

var mySelection = _.clone(rangy.getSelection());

doesn't seem to work. Any hints?

@nschloe
Copy link
Author

nschloe commented Feb 23, 2015

Probably, the serializer module is what I want. The rangy.serializeSelection(textSelection) returns an empty string, however. Any idea what might be going wrong?

@nschloe
Copy link
Author

nschloe commented Feb 23, 2015

Debugging this right now. It turns out that

textSelection.getAllRanges()

is empty. Investigating why that might be...

@parisni
Copy link

parisni commented Feb 24, 2015

Hi !

I wan't exactly the same feature. I guess serializer module (you can test it https://rangy.googlecode.com/svn/trunk/demos/serializer.html) is not a good idea because it depends on the browser the client uses.
I am interrested in a solution to store those objects too !

@parisni
Copy link

parisni commented Feb 24, 2015

Well I have found a workaround, but maybe it won't satisfied you.
I serialize the entire DOM (with jquery) and send it to the server. Then, for each modification by users, save a new version of the document

  1. first page without highlight
  2. user1 adds highlight -> send to serveur (version2 with highlight )
  3. user2 connect, looks version2 ; he adds his own highlight -> send to server version3
    4... etc

My case the document is an SVG, this idea works for html too.

Here is the code

<div id="myTextUserCanHighlight">
Hey you can highlight me
</div>
<script type="text/javascript">
function svg(e) {
var svg = $("#myTextUserCanHighlight");
var s = new XMLSerializer();
var svgContent = s.serializeToString(svg[0]);//to send to the server with POST http Request
console.log(svgContent);
}
</script>
<a href='#export' onclick="svg(this)">export</a>

You store this dynamic div in database, and dynamix load it in your page. It will get the highlight of users (if they do not connect the same time on your website)

@timdown
Copy link
Owner

timdown commented Mar 22, 2015

I've added saveRanges() and restoreRanges(saved) to selection. The object returned by saveRanges() just contains an array of copies of the selection's ranges and a selection direction.

@timdown timdown closed this as completed Mar 22, 2015
@andrenarchy
Copy link

While trying to work around bug #282, I realized that the introduced methods saveRanges() and restoreRanges() do not work if the DOM has been modified between saveRanges() and restoreRanges(). This should probably be mentioned in the documentation.

@timdown
Copy link
Owner

timdown commented Mar 27, 2015

@andrenarchy Good point. I've updated the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants