!function(t){t.fn.getCursorPosition=function(){var e,n=this.get(0),o=window.getSelection(),i=-1;if(o.focusNode&&t(o.focusNode).parents(function(t){return t===n}).length)for(e=o.focusNode,i=o.focusOffset;e&&e!==n;)if(e.previousSibling)e=e.previousSibling,i+=e.textContent.length;else if(!(e=e.parentNode))break;return i},t.fn.setCursorPosition=function(e){var n=function(t,e,o){if(o||(o=document.createRange(),o.selectNode(t),o.setStart(t,0)),0===e.count)o.setEnd(t,e.count);else if(t&&e.count>0)if(t.nodeType===Node.TEXT_NODE)t.textContent.length<e.count?e.count-=t.textContent.length:(o.setEnd(t,e.count),e.count=0);else for(var i=0;i<t.childNodes.length&&(o=n(t.childNodes[i],e,o),0!==e.count);i++);return o};if(e>=0){var o=window.getSelection();return range=n(t(this).get(0),{count:e}),!!range&&(range.collapse(!1),o.removeAllRanges(),o.addRange(range),!0)}},t(function(){t(".terminal").each(function(){t(this).html(parse(t(this).text())).attr("autocomplete","off").attr("autocorrect","off").attr("autocapiatlise","off").attr("spellcheck","false").wrap("inline"===t(this).css("display")?'<span class="terminal-wrap"></span>':'<div class="terminal-wrap"></div>')}).on("input",function(){var e,n=parse(t(this).text());n!=t(this).html()&&(e=t(this).getCursorPosition(),t(this).html(n),t(this).setCursorPosition(e),t(this).trigger("update").trigger("change"))}).on("paste",function(t){var e=t.originalEvent.clipboardData.getData("text/plain");t.preventDefault(),document.execCommand("insertHTML",!1,e)}).on("change update",function(){t(this).trigger("input")})})}(jQuery);
|