main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
780 bytes
|
Rev | Line | |
---|
[d565449] | 1 |
|
---|
| 2 | module.exports = function () {
|
---|
| 3 | var selection = document.getSelection();
|
---|
| 4 | if (!selection.rangeCount) {
|
---|
| 5 | return function () {};
|
---|
| 6 | }
|
---|
| 7 | var active = document.activeElement;
|
---|
| 8 |
|
---|
| 9 | var ranges = [];
|
---|
| 10 | for (var i = 0; i < selection.rangeCount; i++) {
|
---|
| 11 | ranges.push(selection.getRangeAt(i));
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | switch (active.tagName.toUpperCase()) { // .toUpperCase handles XHTML
|
---|
| 15 | case 'INPUT':
|
---|
| 16 | case 'TEXTAREA':
|
---|
| 17 | active.blur();
|
---|
| 18 | break;
|
---|
| 19 |
|
---|
| 20 | default:
|
---|
| 21 | active = null;
|
---|
| 22 | break;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | selection.removeAllRanges();
|
---|
| 26 | return function () {
|
---|
| 27 | selection.type === 'Caret' &&
|
---|
| 28 | selection.removeAllRanges();
|
---|
| 29 |
|
---|
| 30 | if (!selection.rangeCount) {
|
---|
| 31 | ranges.forEach(function(range) {
|
---|
| 32 | selection.addRange(range);
|
---|
| 33 | });
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | active &&
|
---|
| 37 | active.focus();
|
---|
| 38 | };
|
---|
| 39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.