mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 11:13:06 +00:00
1571 lines
No EOL
173 KiB
JavaScript
1571 lines
No EOL
173 KiB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.horsey=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
var sell = require('sell');
|
|
var crossvent = require('crossvent');
|
|
var bullseye = require('bullseye');
|
|
var fuzzysearch = require('fuzzysearch');
|
|
var KEY_BACKSPACE = 8;
|
|
var KEY_ENTER = 13;
|
|
var KEY_ESC = 27;
|
|
var KEY_UP = 38;
|
|
var KEY_DOWN = 40;
|
|
var KEY_TAB = 9;
|
|
var cache = [];
|
|
var doc = document;
|
|
var docElement = doc.documentElement;
|
|
|
|
function find (el) {
|
|
var entry;
|
|
var i;
|
|
for (i = 0; i < cache.length; i++) {
|
|
entry = cache[i];
|
|
if (entry.el === el) {
|
|
return entry.api;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function horsey (el, options) {
|
|
var cached = find(el);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
|
|
var o = options || {};
|
|
var parent = o.appendTo || doc.body;
|
|
var render = o.render || defaultRenderer;
|
|
var getText = o.getText || defaultGetText;
|
|
var getValue = o.getValue || defaultGetValue;
|
|
var form = o.form;
|
|
var limit = typeof o.limit === 'number' ? o.limit : Infinity;
|
|
var suggestions = o.suggestions;
|
|
var userFilter = o.filter || defaultFilter;
|
|
var userSet = o.set || defaultSetter;
|
|
var ul = tag('ul', 'sey-list');
|
|
var selection = null;
|
|
var eye;
|
|
var deferredFiltering = defer(filtering);
|
|
var attachment = el;
|
|
var textInput;
|
|
var anyInput;
|
|
var ranchorleft;
|
|
var ranchorright;
|
|
var suggestionsLoad = { counter: 0, value: null };
|
|
|
|
if (o.autoHideOnBlur === void 0) { o.autoHideOnBlur = true; }
|
|
if (o.autoHideOnClick === void 0) { o.autoHideOnClick = true; }
|
|
if (o.autoShowOnUpDown === void 0) { o.autoShowOnUpDown = el.tagName === 'INPUT'; }
|
|
if (o.anchor) {
|
|
ranchorleft = new RegExp('^' + o.anchor);
|
|
ranchorright = new RegExp(o.anchor + '$');
|
|
}
|
|
|
|
var api = {
|
|
add: add,
|
|
anchor: o.anchor,
|
|
clear: clear,
|
|
show: show,
|
|
hide: hide,
|
|
toggle: toggle,
|
|
destroy: destroy,
|
|
refreshPosition: refreshPosition,
|
|
appendText: appendText,
|
|
appendHTML: appendHTML,
|
|
filterAnchoredText: filterAnchoredText,
|
|
filterAnchoredHTML: filterAnchoredHTML,
|
|
defaultAppendText: appendText,
|
|
defaultFilter: defaultFilter,
|
|
defaultGetText: defaultGetText,
|
|
defaultGetValue: defaultGetValue,
|
|
defaultRenderer: defaultRenderer,
|
|
defaultSetter: defaultSetter,
|
|
retarget: retarget,
|
|
attachment: attachment,
|
|
list: ul,
|
|
suggestions: []
|
|
};
|
|
var entry = { el: el, api: api };
|
|
|
|
retarget(el);
|
|
cache.push(entry);
|
|
parent.appendChild(ul);
|
|
el.setAttribute('autocomplete', 'off');
|
|
|
|
if (Array.isArray(suggestions)) {
|
|
loaded(suggestions, false);
|
|
}
|
|
|
|
return api;
|
|
|
|
function retarget (el) {
|
|
inputEvents(true);
|
|
attachment = api.attachment = el;
|
|
textInput = attachment.tagName === 'INPUT' || attachment.tagName === 'TEXTAREA';
|
|
anyInput = textInput || isEditable(attachment);
|
|
inputEvents();
|
|
}
|
|
|
|
function refreshPosition () {
|
|
if (eye) { eye.refresh(); }
|
|
}
|
|
|
|
function loading (forceShow) {
|
|
if (typeof suggestions === 'function') {
|
|
crossvent.remove(attachment, 'focus', loading);
|
|
var value = textInput ? el.value : el.innerHTML;
|
|
if (value !== suggestionsLoad.value) {
|
|
suggestionsLoad.counter++;
|
|
suggestionsLoad.value = value;
|
|
|
|
var counter = suggestionsLoad.counter;
|
|
suggestions(value, function(s) {
|
|
if (suggestionsLoad.counter === counter) {
|
|
loaded(s, forceShow);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
function loaded (suggestions, forceShow) {
|
|
clear();
|
|
suggestions.forEach(add);
|
|
api.suggestions = suggestions;
|
|
if (forceShow) {
|
|
show();
|
|
}
|
|
filtering();
|
|
}
|
|
|
|
function clear () {
|
|
unselect();
|
|
while (ul.lastChild) {
|
|
ul.removeChild(ul.lastChild);
|
|
}
|
|
}
|
|
|
|
function add (suggestion) {
|
|
var li = tag('li', 'sey-item');
|
|
render(li, suggestion);
|
|
crossvent.add(li, 'click', clickedSuggestion);
|
|
crossvent.add(li, 'horsey-filter', filterItem);
|
|
crossvent.add(li, 'horsey-hide', hideItem);
|
|
ul.appendChild(li);
|
|
api.suggestions.push(suggestion);
|
|
return li;
|
|
|
|
function clickedSuggestion () {
|
|
var value = getValue(suggestion);
|
|
set(value);
|
|
hide();
|
|
attachment.focus();
|
|
crossvent.fabricate(attachment, 'horsey-selected', value);
|
|
}
|
|
|
|
function filterItem () {
|
|
var value = textInput ? el.value : el.innerHTML;
|
|
if (filter(value, suggestion)) {
|
|
li.className = li.className.replace(/ sey-hide/g, '');
|
|
} else {
|
|
crossvent.fabricate(li, 'horsey-hide');
|
|
}
|
|
}
|
|
|
|
function hideItem () {
|
|
if (!hidden(li)) {
|
|
li.className += ' sey-hide';
|
|
if (selection === li) {
|
|
unselect();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function set (value) {
|
|
if (o.anchor) {
|
|
return (isText() ? api.appendText : api.appendHTML)(value);
|
|
}
|
|
userSet(value);
|
|
}
|
|
|
|
function filter (value, suggestion) {
|
|
if (o.anchor) {
|
|
var il = (isText() ? api.filterAnchoredText : api.filterAnchoredHTML)(value, suggestion);
|
|
return il ? userFilter(il.input, il.suggestion) : false;
|
|
}
|
|
return userFilter(value, suggestion);
|
|
}
|
|
|
|
function isText () { return isInput(attachment); }
|
|
function visible () { return ul.className.indexOf('sey-show') !== -1; }
|
|
function hidden (li) { return li.className.indexOf('sey-hide') !== -1; }
|
|
|
|
function show () {
|
|
if (!visible()) {
|
|
ul.className += ' sey-show';
|
|
eye.refresh();
|
|
crossvent.fabricate(attachment, 'horsey-show');
|
|
}
|
|
}
|
|
|
|
function toggler (e) {
|
|
var left = e.which === 1 && !e.metaKey && !e.ctrlKey;
|
|
if (left === false) {
|
|
return; // we only care about honest to god left-clicks
|
|
}
|
|
toggle();
|
|
}
|
|
|
|
function toggle () {
|
|
if (!visible()) {
|
|
show();
|
|
} else {
|
|
hide();
|
|
}
|
|
}
|
|
|
|
function select (suggestion) {
|
|
unselect();
|
|
if (suggestion) {
|
|
selection = suggestion;
|
|
selection.className += ' sey-selected';
|
|
}
|
|
}
|
|
|
|
function unselect () {
|
|
if (selection) {
|
|
selection.className = selection.className.replace(/ sey-selected/g, '');
|
|
selection = null;
|
|
}
|
|
}
|
|
|
|
function move (up, moves) {
|
|
var total = ul.children.length;
|
|
if (total < moves) {
|
|
unselect();
|
|
return;
|
|
}
|
|
if (total === 0) {
|
|
return;
|
|
}
|
|
var first = up ? 'lastChild' : 'firstChild';
|
|
var next = up ? 'previousSibling' : 'nextSibling';
|
|
var suggestion = selection && selection[next] || ul[first];
|
|
|
|
select(suggestion);
|
|
|
|
if (hidden(suggestion)) {
|
|
move(up, moves ? moves + 1 : 1);
|
|
}
|
|
}
|
|
|
|
function hide () {
|
|
eye.sleep();
|
|
ul.className = ul.className.replace(/ sey-show/g, '');
|
|
unselect();
|
|
crossvent.fabricate(attachment, 'horsey-hide');
|
|
}
|
|
|
|
function keydown (e) {
|
|
var shown = visible();
|
|
var which = e.which || e.keyCode;
|
|
if (which === KEY_DOWN) {
|
|
if (anyInput && o.autoShowOnUpDown) {
|
|
show();
|
|
}
|
|
if (shown) {
|
|
move();
|
|
stop(e);
|
|
}
|
|
} else if (which === KEY_UP) {
|
|
if (anyInput && o.autoShowOnUpDown) {
|
|
show();
|
|
}
|
|
if (shown) {
|
|
move(true);
|
|
stop(e);
|
|
}
|
|
} else if (which === KEY_BACKSPACE) {
|
|
if (anyInput && o.autoShowOnUpDown) {
|
|
show();
|
|
}
|
|
} else if (shown) {
|
|
if (which === KEY_ENTER) {
|
|
if (selection) {
|
|
crossvent.fabricate(selection, 'click');
|
|
} else {
|
|
hide();
|
|
}
|
|
stop(e);
|
|
} else if (which === KEY_ESC) {
|
|
hide();
|
|
stop(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
function stop (e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
}
|
|
|
|
function filtering () {
|
|
if (!visible()) {
|
|
return;
|
|
}
|
|
loading(true);
|
|
crossvent.fabricate(attachment, 'horsey-filter');
|
|
var li = ul.firstChild;
|
|
var count = 0;
|
|
while (li) {
|
|
if (count >= limit) {
|
|
crossvent.fabricate(li, 'horsey-hide');
|
|
}
|
|
if (count < limit) {
|
|
crossvent.fabricate(li, 'horsey-filter');
|
|
if (li.className.indexOf('sey-hide') === -1) {
|
|
count++;
|
|
}
|
|
}
|
|
li = li.nextSibling;
|
|
}
|
|
if (!selection) {
|
|
move();
|
|
}
|
|
if (!selection) {
|
|
hide();
|
|
}
|
|
}
|
|
|
|
function deferredFilteringNoEnter (e) {
|
|
var which = e.which || e.keyCode;
|
|
if (which === KEY_ENTER) {
|
|
return;
|
|
}
|
|
deferredFiltering();
|
|
}
|
|
|
|
function deferredShow (e) {
|
|
var which = e.which || e.keyCode;
|
|
if (which === KEY_ENTER) {
|
|
return;
|
|
}
|
|
setTimeout(show, 0);
|
|
}
|
|
|
|
function horseyEventTarget (e) {
|
|
var target = e.target;
|
|
if (target === attachment) {
|
|
return true;
|
|
}
|
|
while (target) {
|
|
if (target === ul || target === attachment) {
|
|
return true;
|
|
}
|
|
target = target.parentNode;
|
|
}
|
|
}
|
|
|
|
function hideOnBlur (e) {
|
|
var which = e.which || e.keyCode;
|
|
if (which === KEY_TAB) {
|
|
hide();
|
|
}
|
|
}
|
|
|
|
function hideOnClick (e) {
|
|
if (horseyEventTarget(e)) {
|
|
return;
|
|
}
|
|
hide();
|
|
}
|
|
|
|
function inputEvents (remove) {
|
|
var op = remove ? 'remove' : 'add';
|
|
if (eye) {
|
|
eye.destroy();
|
|
eye = null;
|
|
}
|
|
if (!remove) {
|
|
eye = bullseye(ul, attachment, { caret: anyInput && attachment.tagName !== 'INPUT' });
|
|
if (!visible()) { eye.sleep(); }
|
|
}
|
|
if (remove || (anyInput && doc.activeElement !== attachment)) {
|
|
crossvent[op](attachment, 'focus', loading);
|
|
} else {
|
|
loading();
|
|
}
|
|
if (anyInput) {
|
|
crossvent[op](attachment, 'keypress', deferredShow);
|
|
crossvent[op](attachment, 'keypress', deferredFiltering);
|
|
crossvent[op](attachment, 'keydown', deferredFilteringNoEnter);
|
|
crossvent[op](attachment, 'paste', deferredFiltering);
|
|
crossvent[op](attachment, 'keydown', keydown);
|
|
if (o.autoHideOnBlur) { crossvent[op](attachment, 'keydown', hideOnBlur); }
|
|
} else {
|
|
crossvent[op](attachment, 'click', toggler);
|
|
crossvent[op](docElement, 'keydown', keydown);
|
|
}
|
|
if (o.autoHideOnClick) { crossvent[op](doc, 'click', hideOnClick); }
|
|
if (form) { crossvent[op](form, 'submit', hide); }
|
|
}
|
|
|
|
function destroy () {
|
|
inputEvents(true);
|
|
if (parent.contains(ul)) { parent.removeChild(ul); }
|
|
cache.splice(cache.indexOf(entry), 1);
|
|
}
|
|
|
|
function defaultSetter (value) {
|
|
if (textInput) {
|
|
el.value = value;
|
|
} else {
|
|
el.innerHTML = value;
|
|
}
|
|
}
|
|
|
|
function defaultRenderer (li, suggestion) {
|
|
li.innerText = li.textContent = getText(suggestion);
|
|
}
|
|
|
|
function defaultFilter (q, suggestion) {
|
|
var text = getText(suggestion) || '';
|
|
var value = getValue(suggestion) || '';
|
|
var needle = q.toLowerCase();
|
|
return fuzzysearch(needle, text.toLowerCase()) || fuzzysearch(needle, value.toLowerCase());
|
|
}
|
|
|
|
function loopbackToAnchor (text, p) {
|
|
var result = '';
|
|
var anchored = false;
|
|
var start = p.start;
|
|
while (anchored === false && start >= 0) {
|
|
result = text.substr(start - 1, p.start - start + 1);
|
|
anchored = ranchorleft.test(result);
|
|
start--;
|
|
}
|
|
return {
|
|
text: anchored ? result : null,
|
|
start: start
|
|
};
|
|
}
|
|
|
|
function filterAnchoredText (q, suggestion) {
|
|
var position = sell(el);
|
|
var input = loopbackToAnchor(q, position).text;
|
|
if (input) {
|
|
return { input: input, suggestion: suggestion };
|
|
}
|
|
}
|
|
|
|
function appendText (value) {
|
|
var current = el.value;
|
|
var position = sell(el);
|
|
var input = loopbackToAnchor(current, position);
|
|
var left = current.substr(0, input.start);
|
|
var right = current.substr(input.start + input.text.length + (position.end - position.start));
|
|
var before = left + value + ' ';
|
|
|
|
el.value = before + right;
|
|
sell(el, { start: before.length, end: before.length });
|
|
}
|
|
|
|
function filterAnchoredHTML () {
|
|
throw new Error('Anchoring in editable elements is disabled by default.');
|
|
}
|
|
|
|
function appendHTML () {
|
|
throw new Error('Anchoring in editable elements is disabled by default.');
|
|
}
|
|
}
|
|
|
|
function isInput (el) { return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA'; }
|
|
|
|
function defaultGetValue (suggestion) {
|
|
return defaultGet('value', suggestion);
|
|
}
|
|
|
|
function defaultGetText (suggestion) {
|
|
return defaultGet('text', suggestion);
|
|
}
|
|
|
|
function defaultGet (type, value) {
|
|
return value && value[type] !== void 0 ? value[type] : value;
|
|
}
|
|
|
|
function tag (type, className) {
|
|
var el = doc.createElement(type);
|
|
el.className = className;
|
|
return el;
|
|
}
|
|
|
|
function defer (fn) { return function () { setTimeout(fn, 0); }; }
|
|
|
|
function isEditable (el) {
|
|
var value = el.getAttribute('contentEditable');
|
|
if (value === 'false') {
|
|
return false;
|
|
}
|
|
if (value === 'true') {
|
|
return true;
|
|
}
|
|
if (el.parentElement) {
|
|
return isEditable(el.parentElement);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
horsey.find = find;
|
|
module.exports = horsey;
|
|
|
|
},{"bullseye":2,"crossvent":14,"fuzzysearch":16,"sell":17}],2:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
var crossvent = require('crossvent');
|
|
var throttle = require('./throttle');
|
|
var tailormade = require('./tailormade');
|
|
|
|
function bullseye (el, target, options) {
|
|
var o = options;
|
|
var domTarget = target && target.tagName;
|
|
|
|
if (!domTarget && arguments.length === 2) {
|
|
o = target;
|
|
}
|
|
if (!domTarget) {
|
|
target = el;
|
|
}
|
|
if (!o) { o = {}; }
|
|
|
|
var destroyed = false;
|
|
var throttledWrite = throttle(write, 30);
|
|
var tailorOptions = { update: o.autoupdateToCaret !== false && update };
|
|
var tailor = o.caret && tailormade(target, tailorOptions);
|
|
|
|
write();
|
|
|
|
if (o.tracking !== false) {
|
|
crossvent.add(window, 'resize', throttledWrite);
|
|
}
|
|
|
|
return {
|
|
read: readNull,
|
|
refresh: write,
|
|
destroy: destroy,
|
|
sleep: sleep
|
|
};
|
|
|
|
function sleep () {
|
|
tailorOptions.sleeping = true;
|
|
}
|
|
|
|
function readNull () { return read(); }
|
|
|
|
function read (readings) {
|
|
var bounds = target.getBoundingClientRect();
|
|
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
|
if (tailor) {
|
|
readings = tailor.read();
|
|
return {
|
|
x: (readings.absolute ? 0 : bounds.left) + readings.x,
|
|
y: (readings.absolute ? 0 : bounds.top) + scrollTop + readings.y + 20
|
|
};
|
|
}
|
|
return {
|
|
x: bounds.left,
|
|
y: bounds.top + scrollTop
|
|
};
|
|
}
|
|
|
|
function update (readings) {
|
|
write(readings);
|
|
}
|
|
|
|
function write (readings) {
|
|
if (destroyed) {
|
|
throw new Error('Bullseye can\'t refresh after being destroyed. Create another instance instead.');
|
|
}
|
|
if (tailor && !readings) {
|
|
tailorOptions.sleeping = false;
|
|
tailor.refresh(); return;
|
|
}
|
|
var p = read(readings);
|
|
if (!tailor && target !== el) {
|
|
p.y += target.offsetHeight;
|
|
}
|
|
el.style.left = p.x + 'px';
|
|
el.style.top = p.y + 'px';
|
|
}
|
|
|
|
function destroy () {
|
|
if (tailor) { tailor.destroy(); }
|
|
crossvent.remove(window, 'resize', throttledWrite);
|
|
destroyed = true;
|
|
}
|
|
}
|
|
|
|
module.exports = bullseye;
|
|
|
|
},{"./tailormade":11,"./throttle":12,"crossvent":14}],3:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var getSelection;
|
|
var doc = global.document;
|
|
var getSelectionRaw = require('./getSelectionRaw');
|
|
var getSelectionNullOp = require('./getSelectionNullOp');
|
|
var getSelectionSynthetic = require('./getSelectionSynthetic');
|
|
var isHost = require('./isHost');
|
|
if (isHost.method(global, 'getSelection')) {
|
|
getSelection = getSelectionRaw;
|
|
} else if (typeof doc.selection === 'object' && doc.selection) {
|
|
getSelection = getSelectionSynthetic;
|
|
} else {
|
|
getSelection = getSelectionNullOp;
|
|
}
|
|
|
|
module.exports = getSelection;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS9ub2RlX21vZHVsZXMvc2VsZWNjaW9uL3NyYy9nZXRTZWxlY3Rpb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG52YXIgZ2V0U2VsZWN0aW9uO1xudmFyIGRvYyA9IGdsb2JhbC5kb2N1bWVudDtcbnZhciBnZXRTZWxlY3Rpb25SYXcgPSByZXF1aXJlKCcuL2dldFNlbGVjdGlvblJhdycpO1xudmFyIGdldFNlbGVjdGlvbk51bGxPcCA9IHJlcXVpcmUoJy4vZ2V0U2VsZWN0aW9uTnVsbE9wJyk7XG52YXIgZ2V0U2VsZWN0aW9uU3ludGhldGljID0gcmVxdWlyZSgnLi9nZXRTZWxlY3Rpb25TeW50aGV0aWMnKTtcbnZhciBpc0hvc3QgPSByZXF1aXJlKCcuL2lzSG9zdCcpO1xuaWYgKGlzSG9zdC5tZXRob2QoZ2xvYmFsLCAnZ2V0U2VsZWN0aW9uJykpIHtcbiAgZ2V0U2VsZWN0aW9uID0gZ2V0U2VsZWN0aW9uUmF3O1xufSBlbHNlIGlmICh0eXBlb2YgZG9jLnNlbGVjdGlvbiA9PT0gJ29iamVjdCcgJiYgZG9jLnNlbGVjdGlvbikge1xuICBnZXRTZWxlY3Rpb24gPSBnZXRTZWxlY3Rpb25TeW50aGV0aWM7XG59IGVsc2Uge1xuICBnZXRTZWxlY3Rpb24gPSBnZXRTZWxlY3Rpb25OdWxsT3A7XG59XG5cbm1vZHVsZS5leHBvcnRzID0gZ2V0U2VsZWN0aW9uO1xuIl19
|
|
},{"./getSelectionNullOp":4,"./getSelectionRaw":5,"./getSelectionSynthetic":6,"./isHost":7}],4:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
function noop () {}
|
|
|
|
function getSelectionNullOp () {
|
|
return {
|
|
removeAllRanges: noop,
|
|
addRange: noop
|
|
};
|
|
}
|
|
|
|
module.exports = getSelectionNullOp;
|
|
|
|
},{}],5:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
function getSelectionRaw () {
|
|
return global.getSelection();
|
|
}
|
|
|
|
module.exports = getSelectionRaw;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS9ub2RlX21vZHVsZXMvc2VsZWNjaW9uL3NyYy9nZXRTZWxlY3Rpb25SYXcuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbIid1c2Ugc3RyaWN0JztcblxuZnVuY3Rpb24gZ2V0U2VsZWN0aW9uUmF3ICgpIHtcbiAgcmV0dXJuIGdsb2JhbC5nZXRTZWxlY3Rpb24oKTtcbn1cblxubW9kdWxlLmV4cG9ydHMgPSBnZXRTZWxlY3Rpb25SYXc7XG4iXX0=
|
|
},{}],6:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var rangeToTextRange = require('./rangeToTextRange');
|
|
var doc = global.document;
|
|
var body = doc.body;
|
|
var GetSelectionProto = GetSelection.prototype;
|
|
|
|
function GetSelection (selection) {
|
|
var self = this;
|
|
var range = selection.createRange();
|
|
|
|
this._selection = selection;
|
|
this._ranges = [];
|
|
|
|
if (selection.type === 'Control') {
|
|
updateControlSelection(self);
|
|
} else if (isTextRange(range)) {
|
|
updateFromTextRange(self, range);
|
|
} else {
|
|
updateEmptySelection(self);
|
|
}
|
|
}
|
|
|
|
GetSelectionProto.removeAllRanges = function () {
|
|
var textRange;
|
|
try {
|
|
this._selection.empty();
|
|
if (this._selection.type !== 'None') {
|
|
textRange = body.createTextRange();
|
|
textRange.select();
|
|
this._selection.empty();
|
|
}
|
|
} catch (e) {
|
|
}
|
|
updateEmptySelection(this);
|
|
};
|
|
|
|
GetSelectionProto.addRange = function (range) {
|
|
if (this._selection.type === 'Control') {
|
|
addRangeToControlSelection(this, range);
|
|
} else {
|
|
rangeToTextRange(range).select();
|
|
this._ranges[0] = range;
|
|
this.rangeCount = 1;
|
|
this.isCollapsed = this._ranges[0].collapsed;
|
|
updateAnchorAndFocusFromRange(this, range, false);
|
|
}
|
|
};
|
|
|
|
GetSelectionProto.setRanges = function (ranges) {
|
|
this.removeAllRanges();
|
|
var rangeCount = ranges.length;
|
|
if (rangeCount > 1) {
|
|
createControlSelection(this, ranges);
|
|
} else if (rangeCount) {
|
|
this.addRange(ranges[0]);
|
|
}
|
|
};
|
|
|
|
GetSelectionProto.getRangeAt = function (index) {
|
|
if (index < 0 || index >= this.rangeCount) {
|
|
throw new Error('getRangeAt(): index out of bounds');
|
|
} else {
|
|
return this._ranges[index].cloneRange();
|
|
}
|
|
};
|
|
|
|
GetSelectionProto.removeRange = function (range) {
|
|
if (this._selection.type !== 'Control') {
|
|
removeRangeManually(this, range);
|
|
return;
|
|
}
|
|
var controlRange = this._selection.createRange();
|
|
var rangeElement = getSingleElementFromRange(range);
|
|
var newControlRange = body.createControlRange();
|
|
var el;
|
|
var removed = false;
|
|
for (var i = 0, len = controlRange.length; i < len; ++i) {
|
|
el = controlRange.item(i);
|
|
if (el !== rangeElement || removed) {
|
|
newControlRange.add(controlRange.item(i));
|
|
} else {
|
|
removed = true;
|
|
}
|
|
}
|
|
newControlRange.select();
|
|
updateControlSelection(this);
|
|
};
|
|
|
|
GetSelectionProto.eachRange = function (fn, returnValue) {
|
|
var i = 0;
|
|
var len = this._ranges.length;
|
|
for (i = 0; i < len; ++i) {
|
|
if (fn(this.getRangeAt(i))) {
|
|
return returnValue;
|
|
}
|
|
}
|
|
};
|
|
|
|
GetSelectionProto.getAllRanges = function () {
|
|
var ranges = [];
|
|
this.eachRange(function (range) {
|
|
ranges.push(range);
|
|
});
|
|
return ranges;
|
|
};
|
|
|
|
GetSelectionProto.setSingleRange = function (range) {
|
|
this.removeAllRanges();
|
|
this.addRange(range);
|
|
};
|
|
|
|
function createControlSelection (sel, ranges) {
|
|
var controlRange = body.createControlRange();
|
|
for (var i = 0, el, len = ranges.length; i < len; ++i) {
|
|
el = getSingleElementFromRange(ranges[i]);
|
|
try {
|
|
controlRange.add(el);
|
|
} catch (e) {
|
|
throw new Error('setRanges(): Element could not be added to control selection');
|
|
}
|
|
}
|
|
controlRange.select();
|
|
updateControlSelection(sel);
|
|
}
|
|
|
|
function removeRangeManually (sel, range) {
|
|
var ranges = sel.getAllRanges();
|
|
sel.removeAllRanges();
|
|
for (var i = 0, len = ranges.length; i < len; ++i) {
|
|
if (!isSameRange(range, ranges[i])) {
|
|
sel.addRange(ranges[i]);
|
|
}
|
|
}
|
|
if (!sel.rangeCount) {
|
|
updateEmptySelection(sel);
|
|
}
|
|
}
|
|
|
|
function updateAnchorAndFocusFromRange (sel, range) {
|
|
var anchorPrefix = 'start';
|
|
var focusPrefix = 'end';
|
|
sel.anchorNode = range[anchorPrefix + 'Container'];
|
|
sel.anchorOffset = range[anchorPrefix + 'Offset'];
|
|
sel.focusNode = range[focusPrefix + 'Container'];
|
|
sel.focusOffset = range[focusPrefix + 'Offset'];
|
|
}
|
|
|
|
function updateEmptySelection (sel) {
|
|
sel.anchorNode = sel.focusNode = null;
|
|
sel.anchorOffset = sel.focusOffset = 0;
|
|
sel.rangeCount = 0;
|
|
sel.isCollapsed = true;
|
|
sel._ranges.length = 0;
|
|
}
|
|
|
|
function rangeContainsSingleElement (rangeNodes) {
|
|
if (!rangeNodes.length || rangeNodes[0].nodeType !== 1) {
|
|
return false;
|
|
}
|
|
for (var i = 1, len = rangeNodes.length; i < len; ++i) {
|
|
if (!isAncestorOf(rangeNodes[0], rangeNodes[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function getSingleElementFromRange (range) {
|
|
var nodes = range.getNodes();
|
|
if (!rangeContainsSingleElement(nodes)) {
|
|
throw new Error('getSingleElementFromRange(): range did not consist of a single element');
|
|
}
|
|
return nodes[0];
|
|
}
|
|
|
|
function isTextRange (range) {
|
|
return range && range.text !== void 0;
|
|
}
|
|
|
|
function updateFromTextRange (sel, range) {
|
|
sel._ranges = [range];
|
|
updateAnchorAndFocusFromRange(sel, range, false);
|
|
sel.rangeCount = 1;
|
|
sel.isCollapsed = range.collapsed;
|
|
}
|
|
|
|
function updateControlSelection (sel) {
|
|
sel._ranges.length = 0;
|
|
if (sel._selection.type === 'None') {
|
|
updateEmptySelection(sel);
|
|
} else {
|
|
var controlRange = sel._selection.createRange();
|
|
if (isTextRange(controlRange)) {
|
|
updateFromTextRange(sel, controlRange);
|
|
} else {
|
|
sel.rangeCount = controlRange.length;
|
|
var range;
|
|
for (var i = 0; i < sel.rangeCount; ++i) {
|
|
range = doc.createRange();
|
|
range.selectNode(controlRange.item(i));
|
|
sel._ranges.push(range);
|
|
}
|
|
sel.isCollapsed = sel.rangeCount === 1 && sel._ranges[0].collapsed;
|
|
updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], false);
|
|
}
|
|
}
|
|
}
|
|
|
|
function addRangeToControlSelection (sel, range) {
|
|
var controlRange = sel._selection.createRange();
|
|
var rangeElement = getSingleElementFromRange(range);
|
|
var newControlRange = body.createControlRange();
|
|
for (var i = 0, len = controlRange.length; i < len; ++i) {
|
|
newControlRange.add(controlRange.item(i));
|
|
}
|
|
try {
|
|
newControlRange.add(rangeElement);
|
|
} catch (e) {
|
|
throw new Error('addRange(): Element could not be added to control selection');
|
|
}
|
|
newControlRange.select();
|
|
updateControlSelection(sel);
|
|
}
|
|
|
|
function isSameRange (left, right) {
|
|
return (
|
|
left.startContainer === right.startContainer &&
|
|
left.startOffset === right.startOffset &&
|
|
left.endContainer === right.endContainer &&
|
|
left.endOffset === right.endOffset
|
|
);
|
|
}
|
|
|
|
function isAncestorOf (ancestor, descendant) {
|
|
var node = descendant;
|
|
while (node.parentNode) {
|
|
if (node.parentNode === ancestor) {
|
|
return true;
|
|
}
|
|
node = node.parentNode;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function getSelection () {
|
|
return new GetSelection(global.document.selection);
|
|
}
|
|
|
|
module.exports = getSelection;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS9ub2RlX21vZHVsZXMvc2VsZWNjaW9uL3NyYy9nZXRTZWxlY3Rpb25TeW50aGV0aWMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO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m9sUmFuZ2Uuc2VsZWN0KCk7XG4gIHVwZGF0ZUNvbnRyb2xTZWxlY3Rpb24oc2VsKTtcbn1cblxuZnVuY3Rpb24gaXNTYW1lUmFuZ2UgKGxlZnQsIHJpZ2h0KSB7XG4gIHJldHVybiAoXG4gICAgbGVmdC5zdGFydENvbnRhaW5lciA9PT0gcmlnaHQuc3RhcnRDb250YWluZXIgJiZcbiAgICBsZWZ0LnN0YXJ0T2Zmc2V0ID09PSByaWdodC5zdGFydE9mZnNldCAmJlxuICAgIGxlZnQuZW5kQ29udGFpbmVyID09PSByaWdodC5lbmRDb250YWluZXIgJiZcbiAgICBsZWZ0LmVuZE9mZnNldCA9PT0gcmlnaHQuZW5kT2Zmc2V0XG4gICk7XG59XG5cbmZ1bmN0aW9uIGlzQW5jZXN0b3JPZiAoYW5jZXN0b3IsIGRlc2NlbmRhbnQpIHtcbiAgdmFyIG5vZGUgPSBkZXNjZW5kYW50O1xuICB3aGlsZSAobm9kZS5wYXJlbnROb2RlKSB7XG4gICAgaWYgKG5vZGUucGFyZW50Tm9kZSA9PT0gYW5jZXN0b3IpIHtcbiAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cbiAgICBub2RlID0gbm9kZS5wYXJlbnROb2RlO1xuICB9XG4gIHJldHVybiBmYWxzZTtcbn1cblxuZnVuY3Rpb24gZ2V0U2VsZWN0aW9uICgpIHtcbiAgcmV0dXJuIG5ldyBHZXRTZWxlY3Rpb24oZ2xvYmFsLmRvY3VtZW50LnNlbGVjdGlvbik7XG59XG5cbm1vZHVsZS5leHBvcnRzID0gZ2V0U2VsZWN0aW9uO1xuIl19
|
|
},{"./rangeToTextRange":8}],7:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
function isHostMethod (host, prop) {
|
|
var type = typeof host[prop];
|
|
return type === 'function' || !!(type === 'object' && host[prop]) || type === 'unknown';
|
|
}
|
|
|
|
function isHostProperty (host, prop) {
|
|
return typeof host[prop] !== 'undefined';
|
|
}
|
|
|
|
function many (fn) {
|
|
return function areHosted (host, props) {
|
|
var i = props.length;
|
|
while (i--) {
|
|
if (!fn(host, props[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
method: isHostMethod,
|
|
methods: many(isHostMethod),
|
|
property: isHostProperty,
|
|
properties: many(isHostProperty)
|
|
};
|
|
|
|
},{}],8:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var doc = global.document;
|
|
var body = doc.body;
|
|
|
|
function rangeToTextRange (p) {
|
|
if (p.collapsed) {
|
|
return createBoundaryTextRange({ node: p.startContainer, offset: p.startOffset }, true);
|
|
}
|
|
var startRange = createBoundaryTextRange({ node: p.startContainer, offset: p.startOffset }, true);
|
|
var endRange = createBoundaryTextRange({ node: p.endContainer, offset: p.endOffset }, false);
|
|
var textRange = body.createTextRange();
|
|
textRange.setEndPoint('StartToStart', startRange);
|
|
textRange.setEndPoint('EndToEnd', endRange);
|
|
return textRange;
|
|
}
|
|
|
|
function isCharacterDataNode (node) {
|
|
var t = node.nodeType;
|
|
return t === 3 || t === 4 || t === 8 ;
|
|
}
|
|
|
|
function createBoundaryTextRange (p, starting) {
|
|
var bound;
|
|
var parent;
|
|
var offset = p.offset;
|
|
var workingNode;
|
|
var childNodes;
|
|
var range = body.createTextRange();
|
|
var data = isCharacterDataNode(p.node);
|
|
|
|
if (data) {
|
|
bound = p.node;
|
|
parent = bound.parentNode;
|
|
} else {
|
|
childNodes = p.node.childNodes;
|
|
bound = offset < childNodes.length ? childNodes[offset] : null;
|
|
parent = p.node;
|
|
}
|
|
|
|
workingNode = doc.createElement('span');
|
|
workingNode.innerHTML = '&#feff;';
|
|
|
|
if (bound) {
|
|
parent.insertBefore(workingNode, bound);
|
|
} else {
|
|
parent.appendChild(workingNode);
|
|
}
|
|
|
|
range.moveToElementText(workingNode);
|
|
range.collapse(!starting);
|
|
parent.removeChild(workingNode);
|
|
|
|
if (data) {
|
|
range[starting ? 'moveStart' : 'moveEnd']('character', offset);
|
|
}
|
|
return range;
|
|
}
|
|
|
|
module.exports = rangeToTextRange;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS9ub2RlX21vZHVsZXMvc2VsZWNjaW9uL3NyYy9yYW5nZVRvVGV4dFJhbmdlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG52YXIgZG9jID0gZ2xvYmFsLmRvY3VtZW50O1xudmFyIGJvZHkgPSBkb2MuYm9keTtcblxuZnVuY3Rpb24gcmFuZ2VUb1RleHRSYW5nZSAocCkge1xuICBpZiAocC5jb2xsYXBzZWQpIHtcbiAgICByZXR1cm4gY3JlYXRlQm91bmRhcnlUZXh0UmFuZ2UoeyBub2RlOi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IGJvdW5kID0gcC5ub2RlO1xuICAgIHBhcmVudCA9IGJvdW5kLnBhcmVudE5vZGU7XG4gIH0gZWxzZSB7XG4gICAgY2hpbGROb2RlcyA9IHAubm9kZS5jaGlsZE5vZGVzO1xuICAgIGJvdW5kID0gb2Zmc2V0IDwgY2hpbGROb2Rlcy5sZW5ndGggPyBjaGlsZE5vZGVzW29mZnNldF0gOiBudWxsO1xuICAgIHBhcmVudCA9IHAubm9kZTtcbiAgfVxuXG4gIHdvcmtpbmdOb2RlID0gZG9jLmNyZWF0ZUVsZW1lbnQoJ3NwYW4nKTtcbiAgd29ya2luZ05vZGUuaW5uZXJIVE1MID0gJyYjZmVmZjsnO1xuXG4gIGlmIChib3VuZCkge1xuICAgIHBhcmVudC5pbnNlcnRCZWZvcmUod29ya2luZ05vZGUsIGJvdW5kKTtcbiAgfSBlbHNlIHtcbiAgICBwYXJlbnQuYXBwZW5kQ2hpbGQod29ya2luZ05vZGUpO1xuICB9XG5cbiAgcmFuZ2UubW92ZVRvRWxlbWVudFRleHQod29ya2luZ05vZGUpO1xuICByYW5nZS5jb2xsYXBzZSghc3RhcnRpbmcpO1xuICBwYXJlbnQucmVtb3ZlQ2hpbGQod29ya2luZ05vZGUpO1xuXG4gIGlmIChkYXRhKSB7XG4gICAgcmFuZ2Vbc3RhcnRpbmcgPyAnbW92ZVN0YXJ0JyA6ICdtb3ZlRW5kJ10oJ2NoYXJhY3RlcicsIG9mZnNldCk7XG4gIH1cbiAgcmV0dXJuIHJhbmdlO1xufVxuXG5tb2R1bGUuZXhwb3J0cyA9IHJhbmdlVG9UZXh0UmFuZ2U7XG4iXX0=
|
|
},{}],9:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
var getSelection = require('./getSelection');
|
|
var setSelection = require('./setSelection');
|
|
|
|
module.exports = {
|
|
get: getSelection,
|
|
set: setSelection
|
|
};
|
|
|
|
},{"./getSelection":3,"./setSelection":10}],10:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var getSelection = require('./getSelection');
|
|
var rangeToTextRange = require('./rangeToTextRange');
|
|
var doc = global.document;
|
|
|
|
function setSelection (p) {
|
|
if (doc.createRange) {
|
|
modernSelection();
|
|
} else {
|
|
oldSelection();
|
|
}
|
|
|
|
function modernSelection () {
|
|
var sel = getSelection();
|
|
var range = doc.createRange();
|
|
if (!p.startContainer) {
|
|
return;
|
|
}
|
|
if (p.endContainer) {
|
|
range.setEnd(p.endContainer, p.endOffset);
|
|
} else {
|
|
range.setEnd(p.startContainer, p.startOffset);
|
|
}
|
|
range.setStart(p.startContainer, p.startOffset);
|
|
sel.removeAllRanges();
|
|
sel.addRange(range);
|
|
}
|
|
|
|
function oldSelection () {
|
|
rangeToTextRange(p).select();
|
|
}
|
|
}
|
|
|
|
module.exports = setSelection;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS9ub2RlX21vZHVsZXMvc2VsZWNjaW9uL3NyYy9zZXRTZWxlY3Rpb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG52YXIgZ2V0U2VsZWN0aW9uID0gcmVxdWlyZSgnLi9nZXRTZWxlY3Rpb24nKTtcbnZhciByYW5nZVRvVGV4dFJhbmdlID0gcmVxdWlyZSgnLi9yYW5nZVRvVGV4dFJhbmdlJyk7XG52YXIgZG9jID0gZ2xvYmFsLmRvY3VtZW50O1xuXG5mdW5jdGlvbiBzZXRTZWxlY3Rpb24gKHApIHtcbiAgaWYgKGRvYy5jcmVhdGVSYW5nZSkge1xuICAgIG1vZGVyblNlbGVjdGlvbigpO1xuICB9IGVsc2Uge1xuICAgIG9sZFNlbGVjdGlvbigpO1xuICB9XG5cbiAgZnVuY3Rpb24gbW9kZXJuU2VsZWN0aW9uICgpIHtcbiAgICB2YXIgc2VsID0gZ2V0U2VsZWN0aW9uKCk7XG4gICAgdmFyIHJhbmdlID0gZG9jLmNyZWF0ZVJhbmdlKCk7XG4gICAgaWYgKCFwLnN0YXJ0Q29udGFpbmVyKSB7XG4gICAgICByZXR1cm47XG4gICAgfVxuICAgIGlmIChwLmVuZENvbnRhaW5lcikge1xuICAgICAgcmFuZ2Uuc2V0RW5kKHAuZW5kQ29udGFpbmVyLCBwLmVuZE9mZnNldCk7XG4gICAgfSBlbHNlIHtcbiAgICAgIHJhbmdlLnNldEVuZChwLnN0YXJ0Q29udGFpbmVyLCBwLnN0YXJ0T2Zmc2V0KTtcbiAgICB9XG4gICAgcmFuZ2Uuc2V0U3RhcnQocC5zdGFydENvbnRhaW5lciwgcC5zdGFydE9mZnNldCk7XG4gICAgc2VsLnJlbW92ZUFsbFJhbmdlcygpO1xuICAgIHNlbC5hZGRSYW5nZShyYW5nZSk7XG4gIH1cblxuICBmdW5jdGlvbiBvbGRTZWxlY3Rpb24gKCkge1xuICAgIHJhbmdlVG9UZXh0UmFuZ2UocCkuc2VsZWN0KCk7XG4gIH1cbn1cblxubW9kdWxlLmV4cG9ydHMgPSBzZXRTZWxlY3Rpb247XG4iXX0=
|
|
},{"./getSelection":3,"./rangeToTextRange":8}],11:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var sell = require('sell');
|
|
var crossvent = require('crossvent');
|
|
var seleccion = require('seleccion');
|
|
var throttle = require('./throttle');
|
|
var getSelection = seleccion.get;
|
|
var props = [
|
|
'direction',
|
|
'boxSizing',
|
|
'width',
|
|
'height',
|
|
'overflowX',
|
|
'overflowY',
|
|
'borderTopWidth',
|
|
'borderRightWidth',
|
|
'borderBottomWidth',
|
|
'borderLeftWidth',
|
|
'paddingTop',
|
|
'paddingRight',
|
|
'paddingBottom',
|
|
'paddingLeft',
|
|
'fontStyle',
|
|
'fontVariant',
|
|
'fontWeight',
|
|
'fontStretch',
|
|
'fontSize',
|
|
'fontSizeAdjust',
|
|
'lineHeight',
|
|
'fontFamily',
|
|
'textAlign',
|
|
'textTransform',
|
|
'textIndent',
|
|
'textDecoration',
|
|
'letterSpacing',
|
|
'wordSpacing'
|
|
];
|
|
var win = global;
|
|
var doc = document;
|
|
var ff = win.mozInnerScreenX !== null && win.mozInnerScreenX !== void 0;
|
|
|
|
function tailormade (el, options) {
|
|
var textInput = el.tagName === 'INPUT' || el.tagName === 'TEXTAREA';
|
|
var throttledRefresh = throttle(refresh, 30);
|
|
var o = options || {};
|
|
|
|
bind();
|
|
|
|
return {
|
|
read: readPosition,
|
|
refresh: throttledRefresh,
|
|
destroy: destroy
|
|
};
|
|
|
|
function noop () {}
|
|
function readPosition () { return (textInput ? coordsText : coordsHTML)(); }
|
|
|
|
function refresh () {
|
|
if (o.sleeping) {
|
|
return;
|
|
}
|
|
return (o.update || noop)(readPosition());
|
|
}
|
|
|
|
function coordsText () {
|
|
var p = sell(el);
|
|
var context = prepare();
|
|
var readings = readTextCoords(context, p.start);
|
|
doc.body.removeChild(context.mirror);
|
|
return readings;
|
|
}
|
|
|
|
function coordsHTML () {
|
|
var sel = getSelection();
|
|
if (sel.rangeCount) {
|
|
var range = sel.getRangeAt(0);
|
|
var needsToWorkAroundNewlineBug = range.startContainer.nodeName === 'P' && range.startOffset === 0;
|
|
if (needsToWorkAroundNewlineBug) {
|
|
return {
|
|
x: range.startContainer.offsetLeft,
|
|
y: range.startContainer.offsetTop,
|
|
absolute: true
|
|
};
|
|
}
|
|
if (range.getClientRects) {
|
|
var rects = range.getClientRects();
|
|
if (rects.length > 0) {
|
|
return {
|
|
x: rects[0].left,
|
|
y: rects[0].top,
|
|
absolute: true
|
|
};
|
|
}
|
|
}
|
|
}
|
|
return { x: 0, y: 0 };
|
|
}
|
|
|
|
function readTextCoords (context, p) {
|
|
var rest = doc.createElement('span');
|
|
var mirror = context.mirror;
|
|
var computed = context.computed;
|
|
|
|
write(mirror, read(el).substring(0, p));
|
|
|
|
if (el.tagName === 'INPUT') {
|
|
mirror.textContent = mirror.textContent.replace(/\s/g, '\u00a0');
|
|
}
|
|
|
|
write(rest, read(el).substring(p) || '.');
|
|
|
|
mirror.appendChild(rest);
|
|
|
|
return {
|
|
x: rest.offsetLeft + parseInt(computed['borderLeftWidth']),
|
|
y: rest.offsetTop + parseInt(computed['borderTopWidth'])
|
|
};
|
|
}
|
|
|
|
function read (el) {
|
|
return textInput ? el.value : el.innerHTML;
|
|
}
|
|
|
|
function prepare () {
|
|
var computed = win.getComputedStyle ? getComputedStyle(el) : el.currentStyle;
|
|
var mirror = doc.createElement('div');
|
|
var style = mirror.style;
|
|
|
|
doc.body.appendChild(mirror);
|
|
|
|
if (el.tagName !== 'INPUT') {
|
|
style.wordWrap = 'break-word';
|
|
}
|
|
style.whiteSpace = 'pre-wrap';
|
|
style.position = 'absolute';
|
|
style.visibility = 'hidden';
|
|
props.forEach(copy);
|
|
|
|
if (ff) {
|
|
style.width = parseInt(computed.width) - 2 + 'px';
|
|
if (el.scrollHeight > parseInt(computed.height)) {
|
|
style.overflowY = 'scroll';
|
|
}
|
|
} else {
|
|
style.overflow = 'hidden';
|
|
}
|
|
return { mirror: mirror, computed: computed };
|
|
|
|
function copy (prop) {
|
|
style[prop] = computed[prop];
|
|
}
|
|
}
|
|
|
|
function write (el, value) {
|
|
if (textInput) {
|
|
el.textContent = value;
|
|
} else {
|
|
el.innerHTML = value;
|
|
}
|
|
}
|
|
|
|
function bind (remove) {
|
|
var op = remove ? 'remove' : 'add';
|
|
crossvent[op](el, 'keydown', throttledRefresh);
|
|
crossvent[op](el, 'keyup', throttledRefresh);
|
|
crossvent[op](el, 'input', throttledRefresh);
|
|
crossvent[op](el, 'paste', throttledRefresh);
|
|
crossvent[op](el, 'change', throttledRefresh);
|
|
}
|
|
|
|
function destroy () {
|
|
bind(true);
|
|
}
|
|
}
|
|
|
|
module.exports = tailormade;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9idWxsc2V5ZS90YWlsb3JtYWRlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUF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b3J0cyA9IHRhaWxvcm1hZGU7XG4iXX0=
|
|
},{"./throttle":12,"crossvent":14,"seleccion":9,"sell":17}],12:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
function throttle (fn, boundary) {
|
|
var last = -Infinity;
|
|
var timer;
|
|
return function bounced () {
|
|
if (timer) {
|
|
return;
|
|
}
|
|
unbound();
|
|
|
|
function unbound () {
|
|
clearTimeout(timer);
|
|
timer = null;
|
|
var next = last + boundary;
|
|
var now = Date.now();
|
|
if (now > next) {
|
|
last = now;
|
|
fn();
|
|
} else {
|
|
timer = setTimeout(unbound, next - now);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
module.exports = throttle;
|
|
|
|
},{}],13:[function(require,module,exports){
|
|
(function (global){
|
|
|
|
var NativeCustomEvent = global.CustomEvent;
|
|
|
|
function useNative () {
|
|
try {
|
|
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } });
|
|
return 'cat' === p.type && 'bar' === p.detail.foo;
|
|
} catch (e) {
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Cross-browser `CustomEvent` constructor.
|
|
*
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
module.exports = useNative() ? NativeCustomEvent :
|
|
|
|
// IE >= 9
|
|
'function' === typeof document.createEvent ? function CustomEvent (type, params) {
|
|
var e = document.createEvent('CustomEvent');
|
|
if (params) {
|
|
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail);
|
|
} else {
|
|
e.initCustomEvent(type, false, false, void 0);
|
|
}
|
|
return e;
|
|
} :
|
|
|
|
// IE <= 8
|
|
function CustomEvent (type, params) {
|
|
var e = document.createEventObject();
|
|
e.type = type;
|
|
if (params) {
|
|
e.bubbles = Boolean(params.bubbles);
|
|
e.cancelable = Boolean(params.cancelable);
|
|
e.detail = params.detail;
|
|
} else {
|
|
e.bubbles = false;
|
|
e.cancelable = false;
|
|
e.detail = void 0;
|
|
}
|
|
return e;
|
|
}
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9jcm9zc3ZlbnQvbm9kZV9tb2R1bGVzL2N1c3RvbS1ldmVudC9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbIlxudmFyIE5hdGl2ZUN1c3RvbUV2ZW50ID0gZ2xvYmFsLkN1c3RvbUV2ZW50O1xuXG5mdW5jdGlvbiB1c2VOYXRpdmUgKCkge1xuICB0cnkge1xuICAgIHZhciBwID0gbmV3IE5hdGl2ZUN1c3RvbUV2ZW50KCdjYXQnLCB7IGRldGFpbDogeyBmb286ICdiYXInIH0gfSk7XG4gICAgcmV0dXJuICAnY2F0JyA9PT0gcC50eXBlICYmICdiYXInID09PSBwLmRldGFpbC5mb287XG4gIH0gY2F0Y2ggKGUpIHtcbiAgfVxuICByZXR1cm4gZmFsc2U7XG59XG5cbi8qKlxuICogQ3Jvc3MtYnJvd3NlciBgQ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cbiAgICBlLmNhbmNlbGFibGUgPSBmYWxzZTtcbiAgICBlLmRldGFpbCA9IHZvaWQgMDtcbiAgfVxuICByZXR1cm4gZTtcbn1cbiJdfQ==
|
|
},{}],14:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var customEvent = require('custom-event');
|
|
var eventmap = require('./eventmap');
|
|
var doc = document;
|
|
var addEvent = addEventEasy;
|
|
var removeEvent = removeEventEasy;
|
|
var hardCache = [];
|
|
|
|
if (!global.addEventListener) {
|
|
addEvent = addEventHard;
|
|
removeEvent = removeEventHard;
|
|
}
|
|
|
|
function addEventEasy (el, type, fn, capturing) {
|
|
return el.addEventListener(type, fn, capturing);
|
|
}
|
|
|
|
function addEventHard (el, type, fn) {
|
|
return el.attachEvent('on' + type, wrap(el, type, fn));
|
|
}
|
|
|
|
function removeEventEasy (el, type, fn, capturing) {
|
|
return el.removeEventListener(type, fn, capturing);
|
|
}
|
|
|
|
function removeEventHard (el, type, fn) {
|
|
return el.detachEvent('on' + type, unwrap(el, type, fn));
|
|
}
|
|
|
|
function fabricateEvent (el, type, model) {
|
|
var e = eventmap.indexOf(type) === -1 ? makeCustomEvent() : makeClassicEvent();
|
|
if (el.dispatchEvent) {
|
|
el.dispatchEvent(e);
|
|
} else {
|
|
el.fireEvent('on' + type, e);
|
|
}
|
|
function makeClassicEvent () {
|
|
var e;
|
|
if (doc.createEvent) {
|
|
e = doc.createEvent('Event');
|
|
e.initEvent(type, true, true);
|
|
} else if (doc.createEventObject) {
|
|
e = doc.createEventObject();
|
|
}
|
|
return e;
|
|
}
|
|
function makeCustomEvent () {
|
|
return new customEvent(type, { detail: model });
|
|
}
|
|
}
|
|
|
|
function wrapperFactory (el, type, fn) {
|
|
return function wrapper (originalEvent) {
|
|
var e = originalEvent || global.event;
|
|
e.target = e.target || e.srcElement;
|
|
e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };
|
|
e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };
|
|
e.which = e.which || e.keyCode;
|
|
fn.call(el, e);
|
|
};
|
|
}
|
|
|
|
function wrap (el, type, fn) {
|
|
var wrapper = unwrap(el, type, fn) || wrapperFactory(el, type, fn);
|
|
hardCache.push({
|
|
wrapper: wrapper,
|
|
element: el,
|
|
type: type,
|
|
fn: fn
|
|
});
|
|
return wrapper;
|
|
}
|
|
|
|
function unwrap (el, type, fn) {
|
|
var i = find(el, type, fn);
|
|
if (i) {
|
|
var wrapper = hardCache[i].wrapper;
|
|
hardCache.splice(i, 1); // free up a tad of memory
|
|
return wrapper;
|
|
}
|
|
}
|
|
|
|
function find (el, type, fn) {
|
|
var i, item;
|
|
for (i = 0; i < hardCache.length; i++) {
|
|
item = hardCache[i];
|
|
if (item.element === el && item.type === type && item.fn === fn) {
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
add: addEvent,
|
|
remove: removeEvent,
|
|
fabricate: fabricateEvent
|
|
};
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9jcm9zc3ZlbnQvc3JjL2Nyb3NzdmVudC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTt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uKTtcbiAgaWYgKGkpIHtcbiAgICB2YXIgd3JhcHBlciA9IGhhcmRDYWNoZVtpXS53cmFwcGVyO1xuICAgIGhhcmRDYWNoZS5zcGxpY2UoaSwgMSk7IC8vIGZyZWUgdXAgYSB0YWQgb2YgbWVtb3J5XG4gICAgcmV0dXJuIHdyYXBwZXI7XG4gIH1cbn1cblxuZnVuY3Rpb24gZmluZCAoZWwsIHR5cGUsIGZuKSB7XG4gIHZhciBpLCBpdGVtO1xuICBmb3IgKGkgPSAwOyBpIDwgaGFyZENhY2hlLmxlbmd0aDsgaSsrKSB7XG4gICAgaXRlbSA9IGhhcmRDYWNoZVtpXTtcbiAgICBpZiAoaXRlbS5lbGVtZW50ID09PSBlbCAmJiBpdGVtLnR5cGUgPT09IHR5cGUgJiYgaXRlbS5mbiA9PT0gZm4pIHtcbiAgICAgIHJldHVybiBpO1xuICAgIH1cbiAgfVxufVxuXG5tb2R1bGUuZXhwb3J0cyA9IHtcbiAgYWRkOiBhZGRFdmVudCxcbiAgcmVtb3ZlOiByZW1vdmVFdmVudCxcbiAgZmFicmljYXRlOiBmYWJyaWNhdGVFdmVudFxufTtcbiJdfQ==
|
|
},{"./eventmap":15,"custom-event":13}],15:[function(require,module,exports){
|
|
(function (global){
|
|
'use strict';
|
|
|
|
var eventmap = [];
|
|
var eventname = '';
|
|
var ron = /^on/;
|
|
|
|
for (eventname in global) {
|
|
if (ron.test(eventname)) {
|
|
eventmap.push(eventname.slice(2));
|
|
}
|
|
}
|
|
|
|
module.exports = eventmap;
|
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9jcm9zc3ZlbnQvc3JjL2V2ZW50bWFwLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6ImdlbmVyYXRlZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIndXNlIHN0cmljdCc7XG5cbnZhciBldmVudG1hcCA9IFtdO1xudmFyIGV2ZW50bmFtZSA9ICcnO1xudmFyIHJvbiA9IC9eb24vO1xuXG5mb3IgKGV2ZW50bmFtZSBpbiBnbG9iYWwpIHtcbiAgaWYgKHJvbi50ZXN0KGV2ZW50bmFtZSkpIHtcbiAgICBldmVudG1hcC5wdXNoKGV2ZW50bmFtZS5zbGljZSgyKSk7XG4gIH1cbn1cblxubW9kdWxlLmV4cG9ydHMgPSBldmVudG1hcDtcbiJdfQ==
|
|
},{}],16:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
function fuzzysearch (needle, haystack) {
|
|
var tlen = haystack.length;
|
|
var qlen = needle.length;
|
|
if (qlen > tlen) {
|
|
return false;
|
|
}
|
|
if (qlen === tlen) {
|
|
return needle === haystack;
|
|
}
|
|
outer: for (var i = 0, j = 0; i < qlen; i++) {
|
|
var nch = needle.charCodeAt(i);
|
|
while (j < tlen) {
|
|
if (haystack.charCodeAt(j++) === nch) {
|
|
continue outer;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
module.exports = fuzzysearch;
|
|
|
|
},{}],17:[function(require,module,exports){
|
|
'use strict';
|
|
|
|
var get = easyGet;
|
|
var set = easySet;
|
|
|
|
if (document.selection && document.selection.createRange) {
|
|
get = hardGet;
|
|
set = hardSet;
|
|
}
|
|
|
|
function easyGet (el) {
|
|
return {
|
|
start: el.selectionStart,
|
|
end: el.selectionEnd
|
|
};
|
|
}
|
|
|
|
function hardGet (el) {
|
|
var active = document.activeElement;
|
|
if (active !== el) {
|
|
el.focus();
|
|
}
|
|
|
|
var range = document.selection.createRange();
|
|
var bookmark = range.getBookmark();
|
|
var original = el.value;
|
|
var marker = getUniqueMarker(original);
|
|
var parent = range.parentElement();
|
|
if (parent === null || !inputs(parent)) {
|
|
return result(0, 0);
|
|
}
|
|
range.text = marker + range.text + marker;
|
|
|
|
var contents = el.value;
|
|
|
|
el.value = original;
|
|
range.moveToBookmark(bookmark);
|
|
range.select();
|
|
|
|
return result(contents.indexOf(marker), contents.lastIndexOf(marker) - marker.length);
|
|
|
|
function result (start, end) {
|
|
if (active !== el) { // don't disrupt pre-existing state
|
|
if (active) {
|
|
active.focus();
|
|
} else {
|
|
el.blur();
|
|
}
|
|
}
|
|
return { start: start, end: end };
|
|
}
|
|
}
|
|
|
|
function getUniqueMarker (contents) {
|
|
var marker;
|
|
do {
|
|
marker = '@@marker.' + Math.random() * new Date();
|
|
} while (contents.indexOf(marker) !== -1);
|
|
return marker;
|
|
}
|
|
|
|
function inputs (el) {
|
|
return ((el.tagName === 'INPUT' && el.type === 'text') || el.tagName === 'TEXTAREA');
|
|
}
|
|
|
|
function easySet (el, p) {
|
|
el.selectionStart = parse(el, p.start);
|
|
el.selectionEnd = parse(el, p.end);
|
|
}
|
|
|
|
function hardSet (el, p) {
|
|
var range = el.createTextRange();
|
|
|
|
if (p.start === 'end' && p.end === 'end') {
|
|
range.collapse(false);
|
|
range.select();
|
|
} else {
|
|
range.collapse(true);
|
|
range.moveEnd('character', parse(el, p.end));
|
|
range.moveStart('character', parse(el, p.start));
|
|
range.select();
|
|
}
|
|
}
|
|
|
|
function parse (el, value) {
|
|
return value === 'end' ? el.value.length : value || 0;
|
|
}
|
|
|
|
function sell (el, p) {
|
|
if (arguments.length === 2) {
|
|
set(el, p);
|
|
}
|
|
return get(el);
|
|
}
|
|
|
|
module.exports = sell;
|
|
|
|
},{}]},{},[1])(1)
|
|
});
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9k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HdoaWNoID0gZS53aGljaCB8fCBlLmtleUNvZGU7XG4gICAgaWYgKHdoaWNoID09PSBLRVlfRE9XTikge1xuICAgICAgaWYgKGFueUlucHV0ICYmIG8uYXV0b1Nob3dPblVwRG93bikge1xuICAgICAgICBzaG93KCk7XG4gICAgICB9XG4gICAgICBpZiAoc2hvd24pIHtcbiAgICAgICAgbW92ZSgpO1xuICAgICAgICBzdG9wKGUpO1xuICAgICAgfVxuICAgIH0gZWxzZSBpZiAod2hpY2ggPT09IEtFWV9VUCkge1xuICAgICAgaWYgKGFueUlucHV0ICYmIG8uYXV0b1Nob3dPblVwRG93bikge1xuICAgICAgICBzaG93KCk7XG4gICAgICB9XG4gICAgICBpZiAoc2hvd24pIHtcbiAgICAgICAgbW92ZSh0cnVlKTtcbiAgICAgICAgc3RvcChlKTtcbiAgICAgIH1cbiAgICB9IGVsc2UgaWYgKHdoaWNoID09PSBLRVlfQkFDS1NQQUNFKSB7XG4gICAgICBpZiAoYW55SW5wdXQgJiYgby5hdXRvU2hvd09uVXBEb3duKSB7XG4gICAgICAgIHNob3coKTtcbiAgICAgIH1cbiAgICB9IGVsc2UgaWYgKHNob3duKSB7XG4gICAgICBpZiAod2hpY2ggPT09IEtFWV9FTlRFUikge1xuICAgICAgICBpZiAoc2VsZWN0aW9uKSB7XG4gICAgICAgICAgY3Jvc3N2ZW50LmZhYnJpY2F0ZShzZWxlY3Rpb24sICdjbGljaycpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGhpZGUoKTtcbiAgICAgICAgfVxuICAgICAgICBzdG9wKGUpO1xuICAgICAgfSBlbHNlIGlmICh3aGljaCA9PT0gS0VZX0VTQykge1xuICAgICAgICBoaWRlKCk7XG4gICAgICAgIHN0b3AoZSk7XG4gICAgICB9XG4gICAgfVxuICB9XG5cbiAgZnVuY3Rpb24gc3RvcCAoZSkge1xuICAgIGUuc3RvcFByb3BhZ2F0aW9uKCk7XG4gICAgZS5wcmV2ZW50RGVmYXVsdCgpO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