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

Return useful methods for the selected area #7

Open
felquis opened this issue Jan 2, 2015 · 1 comment
Open

Return useful methods for the selected area #7

felquis opened this issue Jan 2, 2015 · 1 comment

Comments

@felquis
Copy link
Contributor

felquis commented Jan 2, 2015

What about provide an API wrapper for the selection object? For example, provide the size of the selected area, and other things that is possible to do using this API getSelection, Selection and Range

Also, this fokus plugin use this getSelection API, we can learn something from his code and learn more about this getSelection object, and turn selecting a lib to help people work with text selection in some way.

var selection = selecting('.selector-to-watch'); // otherwise watch in all document/window

// Fired when the user start selecting something
selection.on('selectionStart', function (text, selectionObject) {

});

// Fired when the selected text is changed
selection.on('selectionChange', function (newText, oldText, selectionObject) {

});

// Fired when the user remove the selection of text, return the selected text before the user remove the text selection
selection.on('selectionEnd', function (oldText, selectionObject) {

});

/*
  We can do something to the developer just play around with getSelection object if available
*/ 
selection.hasSelection(); // return true or false

selection.runif(function (api) {
  // `api` is the getSelection objet + some useful shortcut functions included by selecting
  // This function is only executed if there's some active text selection 
});

getSelection is supported by most of browsers, including smartTVs and consoles, just IE7,8, for these we can turn selection in a kind of basic polyfill to normalize something (but I don't think that is useful spend much time wondering about old browsers)

@EvandroLG
Copy link
Owner

I think that this idea is great.
And we can open a branch to work in these new implementations ;)

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

2 participants