| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- require('./bootstrap');
- require("inline-attachment/src/inline-attachment.js");
- require("inline-attachment/src/codemirror-4.inline-attachment.js");
- window.markdown_editor = function () {
- window.SimpleMDE = require('simplemde');
- // Most options demonstrate the non-default behavior
- var unique_id = $('#slug').val() ? $('#slug').val() : 'markdown';
- var markdown = new SimpleMDE({
- autofocus: true,
- autosave: {
- enabled: true,
- uniqueId: unique_id,
- delay: 1000
- },
- element: document.getElementById("markdown"),
- insertTexts: {
- horizontalRule: ["", "\n\n-----\n\n"],
- image: [""],
- link: ["[", "](https://)"],
- table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
- },
- placeholder: "Type here...",
- spellChecker: false,
- renderingConfig: {
- codeSyntaxHighlighting: true
- },
- showIcons: ["code", "horizontal-rule", "table", "strikethrough", "heading-1", "heading-2", "heading-3"],
- toolbar: [
- {
- name: "bold",
- action: SimpleMDE.toggleBold,
- className: "fa fa-bold",
- title: "Bold"
- },
- {
- name: "bold",
- action: SimpleMDE.toggleItalic,
- className: "fa fa-italic",
- title: "Italic"
- },
- {
- name: "strikethrough",
- action: SimpleMDE.toggleStrikethrough,
- className: "fa fa-strikethrough",
- title: "Strikethrough"
- },
- '|',
- {
- name: "heading",
- action: SimpleMDE.toggleHeadingSmaller,
- className: "fa fa-header",
- title: "Heading"
- },
- {
- name: "heading-1",
- action: SimpleMDE.toggleHeading1,
- className: "fa fa-header fa-header-x fa-header-1",
- title: "H1"
- },
- {
- name: "heading-2",
- action: SimpleMDE.toggleHeading2,
- className: "fa fa-header fa-header-x fa-header-2",
- title: "H2"
- },
- {
- name: "heading-3",
- action: SimpleMDE.toggleHeading1,
- className: "fa fa-header fa-header-x fa-header-3",
- title: "H3"
- },
- '|',
- {
- name: "code",
- action: SimpleMDE.toggleCodeBlock,
- className: "fa fa-code",
- title: "Code"
- },
- {
- name: "quote",
- action: SimpleMDE.toggleBlockquote,
- className: "fa fa-quote-left",
- title: "Quote"
- },
- {
- name: "unordered-list",
- action: SimpleMDE.toggleUnorderedList,
- className: "fa fa-list-ul",
- title: "Generic List"
- },
- {
- name: "ordered-list",
- action: SimpleMDE.toggleOrderedList,
- className: "fa fa-list-ol",
- title: "Numbered List"
- },
- {
- name: "horizontal-rule",
- action: SimpleMDE.drawHorizontalRule,
- className: "fa fa-minus",
- title: "Insert Horizontal Line"
- },
- '|',
- {
- name: "link",
- action: SimpleMDE.drawLink,
- className: "fa fa-link",
- title: "Create Link"
- },
- {
- name: "image",
- action: SimpleMDE.drawImage,
- className: "fa fa-picture-o",
- title: "Insert Image"
- },
- {
- name: "table",
- action: SimpleMDE.drawTable,
- className: "fa fa-table",
- title: "Insert Table"
- },
- '|',
- {
- name: "preview",
- action: SimpleMDE.togglePreview,
- className: "fa fa-eye no-disable",
- title: "Toggle Preview"
- },
- {
- name: "side-by-side",
- action: SimpleMDE.toggleSideBySide,
- className: "fa fa-columns no-disable no-mobile",
- title: "Toggle Side by Side"
- },
- {
- name: "fullscreen",
- action: SimpleMDE.toggleFullScreen,
- className: "fa fa-arrows-alt no-disable no-mobile",
- title: "Toggle Fullscreen"
- },
- {
- name: "guide",
- action: function customFunction(editor) {
- window.open("https://vienblog.com/markdown-yu-fa")
- },
- className: "fa fa-question-circle",
- title: "Help"
- }
- ]
- });
- markdown.codemirror.on("change", function () {
- var html = markdown.value();
- $('input[name="markdown"]').val(html);
- });
- var inlineAttachmentConfig = {
- uploadUrl: '/admin/upload/image/article',
- extraHeaders: {
- 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
- }
- };
- inlineAttachment.editors.codemirror4.attach(markdown.codemirror,
- inlineAttachmentConfig);
- }
|