cthep-ui-vue3
Version:
Vue 3 试题组件库
82 lines (73 loc) • 3.76 kB
JavaScript
var baseURL = tinymce.baseURL + '/plugins/pinyin/pinyin.html';
tinymce.PluginManager.add('pinyin', function (editor, url) {
// 点击事件
editor.on('dblclick', function () {
var sel = editor.selection.getContent();
var path = /\<img(.*?)src="data:image\/png;base64,[A-Za-z0-9+/=]*"(.*?)data-latex="(.*?)" \/>/g;
var path2 = /data-latex="(.*?)"/g;
if (sel.search(path) == 0) {
sel.replace(path2, function ($0, $1) {
var param = encodeURIComponent($1);
openDialog(param);
return $0;
});
}
});
// 弹出层
var openDialog = function (param) {
let selectText = tinymce.activeEditor.selection.getContent({ format: 'text' })
return editor.windowManager.openUrl({
title: '中文注音',
width: 785,
height: 475,
url: baseURL + "?selectText=" + selectText,
buttons: [
{
type: 'cancel',
text: 'Close',
},
{
type: 'custom',
text: 'Save',
name: 'save',
primary: true,
},
],
initialData: {
myCheckbox: true
},
onAction: function (api, details) {
switch (details.name) {
case 'save':
api.sendMessage('save');
break;
default:
break;
}
}
});
};
editor.ui.registry.addIcon('triangleUp', '<svg t="1691475999624" class="icon" viewBox="0 0 1031 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7393" width="20" height="20"><path d="M786.724571 0H244.589714C109.714286 0 0 108.946286 0 242.870857v538.258286C0 915.053714 109.714286 1024 244.589714 1024h542.134857C921.6 1024 1031.314286 915.053714 1031.314286 781.129143v-538.258286C1031.314286 109.019429 921.6 0 786.724571 0zM958.171429 777.435429c0 95.656229-78.409143 173.421714-174.862629 173.421714H240.6912C144.237714 950.857143 65.828571 873.091657 65.828571 777.435429V239.250286C65.828571 143.601371 144.237714 65.828571 240.6912 65.828571h542.6176C879.762286 65.828571 958.171429 143.594057 958.171429 239.250286v538.185143z" p-id="7394" fill="#2c2c2c"></path><path d="M722.944 184.195657l62.639543 36.183772-41.047772 71.021714H833.828571v72.374857h-72.330971v144.735086H833.828571v72.367543h-72.330971v253.279085h-72.330971V580.878629H577.6384C565.884343 684.434286 521.069714 776.045714 455.753143 841.142857l-56.488229-45.955657c54.966857-52.026514 93.878857-127.4368 105.486629-214.279314h-68.746972v-72.360229l72.330972-0.073143V363.776h-72.330972V291.401143H525.238857l-40.974628-71.029029 62.639542-36.183771 61.878858 107.249371h52.224l61.952-107.249371zM255.195429 573.710629L182.857143 593.108114v-74.898285l72.330971-19.434058V363.776H182.857143V291.401143h72.330971V182.857143h72.330972v108.544h72.330971v72.374857h-72.338286V479.451429l72.338286-19.390172v74.898286l-72.338286 19.390171v189.352229c0 49.956571-40.469943 90.455771-90.404571 90.455771H182.857143v-72.367543h54.250057a18.088229 18.088229 0 0 0 17.788343-14.833371l0.292571-3.254857V573.710629zM689.166629 363.739429H580.681143v144.735085h108.4928V363.739429z" p-id="7395" fill="#2c2c2c"></path></svg>')
// 占位符
editor.ui.registry.addButton('pinyin', {
icon: 'triangleUp',
tooltip: '中文注音',
onAction: function () {
openDialog();
},
});
editor.ui.registry.addMenuItem('pinyin', {
icon: 'triangleUp',
onAction: function () {
openDialog();
},
});
return {
getMetadata: function () {
return {
name: 'pinyin',
url: 'http://hgcserver.gitee.io',
};
},
};
});