用户:Sheep-realms/common.js:修订间差异

添加1,132字节 、​ 2020年7月9日 (星期四)
无编辑摘要
无编辑摘要
无编辑摘要
第28行: 第28行:
$('.editButtons').after('<div id="edit-bottom-tools"></div>');
$('.editButtons').after('<div id="edit-bottom-tools"></div>');
$('#edit-bottom-tools').append('<input type="button" value="测试">');
$('#edit-bottom-tools').append('<input type="button" value="测试">');
function codeQueryInsert(code){
    $('textarea #wpTextbox1').insertAtCaret(code);
}
(function ($) {
"use strict";
    $.fn.extend({
        insertAtCaret : function (myValue) {
            var $t = $(this)[0];
            if (document.selection) {
                this.focus();
                var sel = document.selection.createRange();
                sel.text = myValue;
                this.focus();
            } else
                if ($t.selectionStart || $t.selectionStart == '0') {
                    var startPos = $t.selectionStart;
                    var endPos = $t.selectionEnd;
                    var scrollTop = $t.scrollTop;
                    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
                    this.focus();
                    $t.selectionStart = startPos + myValue.length;
                    $t.selectionEnd = startPos + myValue.length;
                    $t.scrollTop = scrollTop;
                } else {
                    this.value += myValue;
                    this.focus();
                }
        }
    });
})(jQuery);