Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ Add the formula plugin to your tinyMCE configuration
plugins: "... formula",
```

Add configuration options for the formula plugin. `path` is the only setting and is optional.
Add configuration options for the formula plugin. The setting is optional.

```javascript
formula: {
path: 'path/to/public/plugin/folder'
path: 'path/to/public/plugin/folder',
mlang: 'mml'
},
```

##Configuration

###path (optional if plugin installed inside `tinymce/plugins` folder, required otherwise)

If you have installed the plugin in a different folder than the ```tinymce/plugins``` folder then you need to specify
If you have installed the plugin in a different folder than the ```tinymce/plugins``` folder then you need to specify
the path (public) where the plugin is installed.

###mlang (optional, defaults to 'latex')

If you want to default the editor to MathML instead of latex, define ```mlang: 'mml'``` in the options. The only two supported variables are ```latex``` and ```mml```.

##License

MIT licensed
Expand Down
20 changes: 12 additions & 8 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
(function(tinymce){
tinymce.create('tinymce.plugins.Formula', {
init: function(editor, url) {
var options = editor.getParam('formula') || {};
var path = options.path || url;
var options = editor.getParam('formula') || {},
fOptions = {};
fOptions.path = options.path || url;
fOptions.mlang = options.mlang || 'latex';
editor.addButton('formula', {
image: path + '/img/formula.png',
image: fOptions.path + '/img/formula.png',
tooltip: 'Insert Formula',
onclick: showFormulaDialog.bind(this, editor, path),
onclick: showFormulaDialog.bind(this, editor, fOptions),
onPostRender: function() {
var _this = this; // reference to the button itself
editor.on('NodeChange', function(e) {
Expand All @@ -20,12 +22,13 @@
tinymce.PluginManager.add('formula', tinymce.plugins.Formula);


function showFormulaDialog(editor, url) {
function showFormulaDialog(editor, fOptions) {
var url = fOptions.path;
editor.windowManager.open({
title: "Formula",
width : 900,
height : 610,
html: buildIFrame(editor, url),
html: buildIFrame(editor, fOptions),
buttons: [
{
text: 'Cancel',
Expand Down Expand Up @@ -54,10 +57,11 @@
});
}

function buildIFrame(editor, url){
function buildIFrame(editor, fOptions){
var url = fOptions.path;
var currentNode = editor.selection.getNode();
var lang = editor.getParam('language') || 'en';
var mlangParam = '';
var mlangParam = "&mlang=" + fOptions.mlang;
var equationParam = '';
if (currentNode.nodeName.toLowerCase() == 'img' && currentNode.className.indexOf('fm-editor-equation')>-1) {
if (currentNode.getAttribute('data-mlang')) mlangParam = "&mlang=" + currentNode.getAttribute('data-mlang');
Expand Down
2 changes: 1 addition & 1 deletion plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.