Cập nhật mod Topic prefixes cũ của Việt K. Mod này sẽ tạo ra một danh mục các tiền tố (prefix) cho người dùng lựa chọn khi họ đăng bài viết.
Thay code prefix của ViệtK bằng code này:
- Code:
var prefixes = ["Thông báo", "Tài liệu", "Bàn luận", "Chia sẻ", "Giải trí", "Truyện", "Tin tức", "Video - Clip", "Âm nhạc", "Bầu chọn", "Kiến thức", "Kĩ năng", "Tranh luận"]; //danh sách các prefix
var _pm = false; //true: cho phép dùng prefix khi gửi tin nhắn
/*!
* Topic prefixes - Copyright © 2011 by Viet K - chinhphuc.info
* Fix by Zzbaivong - devs.forumvi.com
*/
$(function() {
var chk = false;
if (_pm) chk = /\privmsg/.test(location.href);
if (/\/post/.test(location.href) || chk) {
var $select = $("<select>", {
id: "prefix",
style: "margin-top: 2px; margin-right:5px; height: 21px",
size: 1,
html: '<option value="">(Chọn tiền tố)</option>'
});
$.each(prefixes, function(i, val) {
$("<option>", {
value: val,
text: val
}).appendTo($select);
});
var $subject = $("input[name='subject']");
$select.insertBefore("input[name='subject']");
$subject.width($subject.width() - $select.width() - 5);
var testPrefix = new RegExp("^\\[(" + prefixes.join("|") + ")\\]");
var title = $subject.val();
if (testPrefix.test(title)) {
var prefix = title.match(/^\[([^\[\]]+)\]\s*(.*)/);
$select.find("option[value='" + prefix[1] + "']").attr("selected", true);
console.log($select.find("option[value='" + prefix[1] + "']"));
$subject.val(prefix[2]);
}
$("input[name='post']").click(function() {
if ($subject.val().trim() !== "" && $select.val() !== "") $subject.val("[" + $select.val() + "] " + $subject.val())
});
}
});
Tags: #mod #javascript #jquery #prefix