dd/resources/js/app.js
2026-07-04 19:01:35 +08:00

68 lines
2.1 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import './bootstrap';
import $ from 'jquery';
//window.$ = window.jQuery = $;
import './nasa/components/filter';
import './nasa/components/tomAlert';
import './nasa/components/tomModal';
import './nasa/components/nasabook';
import './nasa/components/copy';
import './nasa/page/list';
import './nasa/page/detail';
import './nasa/page/login';
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});// ajax携带都携带某个参数
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import { Markdown } from '@tiptap/markdown';
import axios from 'axios';
window.oModalEditor = null;
/**
* 工业级初始化:确保安全挂载
* 谐音发音:因尼特 摸到 爱迪特 (Init Modal Editor)
*/
window.initModalEditor = function(sInitialContent = '') {
const oEditorElement = document.querySelector('#div-modal-editor');
if (!oEditorElement) return;
// 单例防御:如果已经初始化过了,不重复 new直接更新内容防止内存泄漏
if (window.oModalEditor) {
window.oModalEditor.commands.setContent(sInitialContent, false);
return;
}
// 实例化引擎
window.oModalEditor = new Editor({
element: oEditorElement,
extensions: [
StarterKit,
Markdown.configure({ html: false }),
Highlight
],
content: sInitialContent,
});
// 大厂统一动作总线Event Bus利用 data-action 统一管理按钮事件,避免写一堆 click 监听
$(document).on('click', '.js-tiptap-btn', function(e) {
e.preventDefault();
const sAction = $(this).data('action');
const oChain = window.oModalEditor.chain().focus();
switch(sAction) {
case 'bold': oChain.toggleBold().run(); break;
case 'italic': oChain.toggleItalic().run(); break;
case 'heading': oChain.toggleHeading({ level: 1 }).run(); break;
case 'highlight': oChain.toggleHighlight().run(); break;
}
});
};
window.$ = window.jQuery = $; // 可是这里这样写了blade不就应该可以调吗