SMF 2.1.8 — Nickname to replay mod

Для того, чтобы в simple machines forum версии 2.1.8 реализовать вставку ника в поле быстрого ответа по клику на нем, необходимо добавить в файл Themes/default/Display.template.php перед закрывающей скобкой } функции template_main() следующий код:

if ($context['can_reply'])
	echo '
	<script>
	document.addEventListener("DOMContentLoaded", function() {
		document.querySelectorAll(".poster h4 a").forEach(function(link) {
			if (link.href.indexOf("action=profile") !== -1) {
				link.title = "Вставить ник в ответ";
				link.addEventListener("click", function(e) {
					var qr = document.getElementById("quickreply");
					if (!qr) return;

					e.preventDefault();
					var nick = this.textContent.trim();
					var textToInsert = "[b]" + nick + "[/b], ";
					var inserted = false;

					// 1. Пробуем через стандартный объект SMF
					if (typeof oEditorHandle_quickreply !== "undefined" && oEditorHandle_quickreply.insertText) {
						oEditorHandle_quickreply.insertText(textToInsert);
						inserted = true;
					}

					// 2. Если не сработало, перебираем все SCEditor на странице
					if (!inserted && typeof sceditor !== "undefined") {
						document.querySelectorAll("textarea").forEach(function(ta) {
							var inst = sceditor.instance(ta);
							if (inst && !inserted) {
								inst.focus();
								inst.insert(textToInsert);
								inserted = true;
							}
						});
					}

					// 3. Запасной вариант для обычного текстового поля без WYSIWYG
					if (!inserted) {
						var plainTa = qr.querySelector("textarea[name=\'message\']") || qr.querySelector("textarea");
						if (plainTa) {
							plainTa.focus();
							plainTa.value += textToInsert;
						}
					}

					qr.scrollIntoView({behavior: "smooth"});
				});
			}
		});
	});
	</script>';
Запись опубликована в рубрике IT с метками . Добавьте в закладки постоянную ссылку.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Лимит времени истёк. Пожалуйста, перезагрузите CAPTCHA.