| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- tinymce.PluginManager.add('kityformula-editor', function (editor, url) {
- var baseURL = '/tinymce/plugins/kityformula-editor/kityFormula.html'
- editor.on('dblclick', function () {
- var sel = editor.selection.getContent()
- // eslint-disable-next-line no-useless-escape
- var path = /^<img\s+[^>]*src="data:image\/png;base64,[A-Za-z0-9+\/=]*"[^>]*data-latex="([^"]+)"[^>]*>$/
- 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) {
- return editor.windowManager.openUrl({
- title: '插入公式',
- size: 'large',
- width: 785,
- height: 475,
- url: param ? baseURL + '?c=' + param : baseURL,
- buttons: [
- {
- type: 'cancel',
- text: 'Close'
- },
- {
- type: 'custom',
- text: 'Save',
- name: 'save',
- primary: true
- }
- ],
- onAction: function (api, details) {
- switch (details.name) {
- case 'save':
- api.sendMessage('save')
- break
- default:
- break
- }
- }
- })
- }
- editor.ui.registry.addButton('kityformula-editor', {
- text: '公式',
- tooltip: '插入公式',
- onAction: function () {
- openDialog()
- }
- })
- editor.ui.registry.addMenuItem('kityformula-editor', {
- text: '公式',
- onAction: function () {
- openDialog()
- }
- })
- return {
- getMetadata: function () {
- return {
- name: '公式',
- url: ''
- }
- }
- }
- })
|