• Đăng ký
  • Đăng nhập

Thêm button vào TinyMCE

📅 — 👀 1771 — 👦

Trang này có hữu ích không?

👍 Có (11)        👎 Không (9)


Đây là đoạn code thêm 01 button vào trình soạn thảo TinyMCE, mình lưu trữ tại đây để sau này sử dụng.

<script type="text/javascript">
tinymce.PluginManager.add('example', function(editor, url) {
    // Add a button that opens a window
	editor.addButton('example', {
		text: 'My button',
		icon: false,
		onclick: function() {
			// Open window
			editor.windowManager.open({
				title: 'Example plugin',
				body: [
					{type: 'textbox', name: 'title', label: 'Title'}
				],
				onsubmit: function(e) {
					// Insert content when the window form is submitted
					editor.insertContent('Title: ' + e.data.title);
				}
			});
		}
	});

	// Adds a menu item to the tools menu
	editor.addMenuItem('example', {
		text: 'Example plugin',
		context: 'tools',
		onclick: function() {
			// Open window with a specific url
			editor.windowManager.open({
				title: 'TinyMCE site',
				url: 'http://www.tinymce.com',
				width: 400,
				height: 300,
				buttons: [{
					text: 'Close',
					onclick: 'close'
				}]
			});
		}
	});
});

tinymce.init({
    selector: "textarea",
    plugins: "example",
    toolbar: "example undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>

<form method="post" action="dump.php">
    <textarea name="content"></textarea>
</form>

Trả lời


📁 Tutorial
🔖