_source.html.erb 1.04 KB
<section id="nuozheng-post">
	<%= f.text_area :detail, id: 'txt-content', 'data-autosave' => 'editor-content', autofocus: nil %>
	<div class="postdetail"></div>
</section>
<script>
	(function() {
		$(function() {
			var $preview, editor, mobileToolbar, toolbar;
			Simditor.locale = 'zh-CN';
			toolbar = ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment'];
			mobileToolbar = ["bold", "underline", "strikethrough", "color", "ul", "ol"];
			if (mobilecheck()) {
				toolbar = mobileToolbar;
			}
			editor = new Simditor({
				textarea: $('#txt-content'),
				placeholder: '这里输入文字...',
				toolbar: toolbar,
				pasteImage: true,
				defaultImage: '/images/logo.png',
				upload: {
					url: '/upload'
				}
			});
			$preview = $('.postdetail');
			if ($preview.length > 0) {
				return editor.on('valuechanged', function(e) {
					return $preview.html(editor.getValue());
				});
			}
		});

	}).call(this);
</script>