123456789101112131415161718192021222324252627282930313233343536373839 |
- module.exports = function () {
- var selection = document.getSelection();
- if (!selection.rangeCount) {
- return function () {};
- }
- var active = document.activeElement;
- var ranges = [];
- for (var i = 0; i < selection.rangeCount; i++) {
- ranges.push(selection.getRangeAt(i));
- }
- switch (active.tagName.toUpperCase()) { // .toUpperCase handles XHTML
- case 'INPUT':
- case 'TEXTAREA':
- active.blur();
- break;
- default:
- active = null;
- break;
- }
- selection.removeAllRanges();
- return function () {
- selection.type === 'Caret' &&
- selection.removeAllRanges();
- if (!selection.rangeCount) {
- ranges.forEach(function(range) {
- selection.addRange(range);
- });
- }
- active &&
- active.focus();
- };
- };
|