|
|
Строка 1: |
Строка 1: |
| /* Размещённый здесь код JavaScript будет загружаться только участникам, имеющим статус администраторов (sysops) */ | | /* Размещённый здесь код JavaScript будет загружаться только участникам, имеющим статус администраторов (sysops) */ |
− | jQuery(document).ready(function($) {
| |
− | if(!$("body").hasClass("action-edit"))
| |
− | return;
| |
− |
| |
− | var cursor;
| |
− | window.onload = init_cursor;
| |
− |
| |
− | function init_cursor() {
| |
− | cursor = $("#cursor").get(0);
| |
− | $("#cursor").css("left", "0px");
| |
− | }
| |
− |
| |
− | function nl2br(txt) {
| |
− | return txt.replace(/\n/g, "<br />");
| |
− | }
| |
− |
| |
− | function writeit(from, e) {
| |
− | e = e || window.event;
| |
− | var w = $("#writer").get(0);
| |
− | var tw = from.value;
| |
− | w.innerHTML = nl2br(tw);
| |
− | }
| |
− |
| |
− | function moveIt(count, e) {
| |
− | e = e || window.event;
| |
− | var keycode = e.keyCode || e.which;
| |
− | if (keycode === 37 && parseInt(cursor.style.left) >= (0 - ((count - 1) * 10))) {
| |
− | cursor.style.left = parseInt(cursor.style.left) - 10 + "px";
| |
− | } else if (keycode === 39 && (parseInt(cursor.style.left) + 10) <= 0) {
| |
− | cursor.style.left = parseInt(cursor.style.left) + 10 + "px";
| |
− | }
| |
− |
| |
− | }
| |
− |
| |
− | var terminal = $("<div id='terminal'></div>");
| |
− | var textBox = $("textarea#wpTextbox1");
| |
− | var parent = textBox.parent();
| |
− | parent.append(terminal);
| |
− | textBox.appendTo(terminal);
| |
− | terminal.append('<div id="getter"><span id="writer"></span><b class="cursor" id="cursor">B</b></div>');
| |
− | terminal.on("click", function(e) {
| |
− | $("textarea#wpTextbox1").focus();
| |
− | });
| |
− | textBox.on("keydown", function(e) {
| |
− | var obj = $(this).get(0);
| |
− | writeit(obj, e);
| |
− | moveIt(obj.value.length, e);
| |
− | });
| |
− | textBox.on("keypress keyup", function(e) {
| |
− | var obj = $(this).get(0);
| |
− | writeit(obj, e);
| |
− | });
| |
− |
| |
− | console.log("I'm work!");
| |
− | });
| |