Jony/assets/lib/extend/extend.min.js

1 line
1.3 KiB
JavaScript
Raw Normal View History

2023-06-30 08:39:08 +00:00
(function(e){e.fn.extend({insertContent:function(t,n){var a=e(this)[0];if(document.selection){this.focus();var s=document.selection.createRange();s.text=t,this.focus(),s.moveStart("character",-i);var c=s.text.length;if(2==arguments.length){var i=a.value.length;s.moveEnd("character",c+n),n<=0?s.moveStart("character",c-2*n-t.length):s.moveStart("character",c-n-t.length),s.select()}}else if(a.selectionStart||"0"==a.selectionStart){var o=a.selectionStart,r=a.selectionEnd,l=a.scrollTop;a.value=a.value.substring(0,o)+t+a.value.substring(r,a.value.length),this.focus(),a.selectionStart=o+t.length,a.selectionEnd=o+t.length,a.scrollTop=l,2==arguments.length&&(a.setSelectionRange(o-n,a.selectionEnd+n),this.focus())}else this.value+=t,this.focus()},selectionRange:function(e,t){var n="",a=this[0];if(void 0===e)n=/input|textarea/i.test(a.tagName)&&/firefox/i.test(navigator.userAgent)?a.value.substring(a.selectionStart,a.selectionEnd):document.selection?document.selection.createRange().text:document.getSelection().toString();else{if(!/input|textarea/.test(a.tagName.toLowerCase()))return!1;if(void 0===t&&(t=e),a.setSelectionRange)a.setSelectionRange(e,t),this.focus();else{var s=a.createTextRange();s.move("character",e),s.moveEnd("character",t-e),s.select()}}return void 0===e?n:this}})})(jQuery);